ELK的安裝配置
一、ES簡介
ES是一個基于RESTful web接口并且建構在Apache Lucene之上的開源分布式搜尋引擎。
特點是:高可用,高擴充,是一種NOSQL的資料存儲工具
二、ES安裝前的準備(elk安裝包版本要求一緻)
下載下傳:elasticsearch-6.2.2.tar.gz
elasticsearch-head-master.zip
kibana-6.2.2-linux-x86_64.tar.gz
logstash-6.2.2.tar.gz
node-v8.9.1-linux-x64.tar.gz
三、ELK的安裝
1.把下載下傳好的安裝包,拖拽到/software目錄中
2.輸入:yum install -y unzip 下載下傳解壓縮工具
3.輸入:cd /software 進入安裝包目錄,輸入ll可以檢視目錄中的檔案
4.輸入:tar -zxvf elasticsearch-6.2.2.tar.gz -C /opt
5.輸入:tar -zxvf kibana-6.2.2-linux-x86_64.tar.gz -C/opt
6.輸入:tar -zxvf logstash-6.2.2.tar.gz -C /opt
7.輸入:tar -zxvf node-v8.9.1-linux-x64.tar.gz -C/opt
8.輸入:unzip elasticsearch-head-master.zip
9.輸入 mv elasticsearch-head-master /opt/eshm 把解壓的檔案夾移動并改名
10.輸入:cd /opt
11.輸入:mv kibana-6.2.2-linux-x86_64/ kibana622
12.輸入:mv logstash-6.2.2/ logstash622
13.輸入:mv node-v8.9.1-linux-x64/ node8
四、ES的配置
1.輸入:vi /etc/hostname 修改主機名
2.輸入:vi /etc/hosts 修改主機清單
3.配置es的參數
(1)輸入:vi /opt/es622/config/elasticsearch.yml,按shift+g,快速定位到尾行,按o在下一行插入以下内容:
cluster.name: test --叢集名
node.name: test-master --節點名
node.master: true --是否是主節點
network.host: 192.168.56.110 --本機位址
discovery.zen.ping.unicast.hosts: ["192.168.56.110"] --同上
http.cors.enabled: true
http.cors.allow-origin: "*"
4.配置系統參數
(1)輸入:vi /etc/sysctl.conf 插入内容:vm.max_map_count=655360
注:最好首次也要使用以下指令重新整理 sysctl -w vm.max_map_count=655360
(2)輸入:vi /etc/security/limits.conf(配置完成可能需要重新開機) 插入内容:
* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
5.修改es622目錄的屬組(es不能使用root啟動) chown -R bigdata:bigdata es622
6.輸入:su bigdata 切換到普通使用者
7.在/opt目錄下輸入:./es622/bin/elasticsearch
底部出現 started即是啟動成功
8.在windows界面打開網頁,輸入http://192.168.56.110:9200/,可以正常出頁面,切有節點的資訊,即是啟動成功
五、Head-master及node的配置
1.輸入:vi /etc/profile 按shift+g定位到底部,然後按o在下一行插入以下内容:
export NODE_HOME=/opt/node8
export PATH=$PATH:$NODE_HOME/bin (如之前在java配置過PATH變量則在原先的尾部增加::$NODE_HOME/bin)
2.輸入:source /etc/profile 激活配置檔案,輸入node -v 可以檢視是否配置成功
3.輸入:cd /opt/eshm
4.輸入:npm install -g grunt-cli --等待的時間比較長,要有點耐心
5.輸入:npm install 出錯時需要輸入:
npm install [email protected] --ignore-scripts
6.輸入:vi Gruntfile.js,在以下位置高亮位置增加一行代碼:hostname: ‘*’,
connect: {
server: {
options: {
port: 9100,
hostname: '*',
base: '.',
keepalive: true }
}
7.輸入:vi _site/app.js,找到如下代碼,并進行修改:
this.base_uri =this.config.base_uri ||this.prefs.get("app-base_uri") || "http://localhost:9200";
修改成為:
this.base_uri =this.config.base_uri ||this.prefs.get("app-base_uri") || "http://192.168.56.110:9200";
8.輸入:npm run start 啟動head-master
9.在windows界面,打開網頁,輸入:http://192.168.56.110:9100/
六、使用Head-master對ES進行測試
1.點選索引頁簽,點選建立索引
2.點選總覽頁簽,即可檢視索引的情況
七、kibana安裝,配置和執行個體
1.輸入:cd /opt/kibana622
2.輸入:vi config/kibana.yml 按shift+g跳轉到行末,按o增加以下内容:
server.host: "192.168.56.110"
elasticsearch.url: "http://192.168.56.110:9200"
3.輸入:./bin/kibana 運作kibana
4.在windows界面打開網頁,輸入http://192.168.56.110:5601/
執行個體:
PUT demo --增加
GET demo --查詢
#删除 index
DELETE demo
#送出資料
PUT /demo/user/1
{
"firstName":"luo","lastName":"xin","age":36,"hobby":"I like gongfu","interests":["games"]
}
#查詢資料
GET demo/user/1
GET demo/user/_search
GET demo/user/1?_source=age,lastName,hobby
#删除指定資料
DELETE /demo/user/A_KKx3ABEZ3jJD3MqVuu
#修改
POST /demo/user/1/_update{ "doc":{ "age":30 } }
POST /demo/user/
{ "firstName":"wang","lastName":"feng","age":51,"hobby":"I like changge","interests":["toutiao"] }
GET /_mget
GET /demo/user/_mget
GET /demo/user/_mget{ "ids":[1,"BPKUx3ABEZ3jJD3MSlvF"] }
POST _analyze{
"analyzer": "standard",
"text": ["我是回家"]
}
POST _analyze{
"analyzer": "whitespace",
"text": ["我 要 回家"]
}
POST demo2/books/_bulk
{"index":{"_id":1}}{"title":"JAVA","price":35}
{"index":{"_id":2}}{"title":"HTML","price":45}
{"index":{"_id":3}}{"title":"MYSQL","price":55}
GET demo2/books/_mget
POST demo2/books/_bulk
{"delete":{"_index":"demo2","_type":"books","_id":3}}
{"update":{"_index":"demo2","_type":"books","_id":2}}
{"doc":{"price":59}}
DELETE demo2/books/3
GET demo2/books/_search?q=title:JAVA
GET demo2/books/_search?q=title:JAVA&q=price:35
八、logstash執行個體
1.輸入:cd /opt/logstash622 進入logstash的安裝目錄
2.輸入:./bin/logstash -e ‘input { stdin{} } output { stdout{} }’ 來測試logstash是否正常工作
3.輸入:./bin/logstash -e ‘input { stdin{} } output { stdout{ codec => json } }’
把控制台輸入的資料轉換成json格式的資料,也可以替換成rubydebug類型的
4../bin/logstash -e ‘input { stdin{} } output { stdout{ codec => json } elasticsearch { hosts => [“192.168.56.110:9200”] } }’
把控制台輸入的資料轉換成rubydebug類型的資料,同時上傳到es伺服器,
可以在對應192.168.56.110:9100的頁面進行檢視
5.使用logstash讀取檔案
./bin/logstash -f demo.conf
demo.conf 的内容代碼如下:
input{
file{
path => "/opt/logstash622/test/demo.txt"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter{
ruby{
code => "event.timestamp.time.localtime"
}
}
output{
stdout{
codec => rubydebug
}
elasticsearch{
hosts => ["192.168.56.110:9200"]
}
}