elasticsearch負責存儲數據,充當搜索引擎
logstash包括index和agent,前者負責收集數據,後者負責過濾數據
kibana提供友好的web界面
其中,elasticsearch與logstash是java編寫,需要部署jdk1.8.0
kibana用node.js框架
服務器之間的時間需要實時且同步
防火牆和selinux保持關閉
環境
192.168.2.112 jdk/elasticsearch/kibana CentOS release 6.5
192.168.2.118 jdk/logstash CentOS release 6.3 (Final)
elasticsearch部署
elasticsearch的主要配置參數
cluster.name: chuck-cluster 判別節點是否是統一集羣
node.name: linux-node1 節點的hostname
path.data: /data/es-data 數據存放路徑
path.logs: /var/log/elasticsearch/ 日誌路徑
bootstrap.mlockall: true 鎖住內存,使內存不會在swap中使用
network.host: 0.0.0.0 允許訪問ES的ip
http.port: 9200 端口
安裝步驟
mkdir elktest;cd elktest
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.3.0.tar.gz
tar -zxvf elasticsearch-5.3.0.tar.gz
mv elasticsearch-5.3.0 /usr/local/elasticsearch/
- ES參數配置
cd /usr/local/elasticsearch/config
1)在elasticsearch.yml裏,在Network下面配置監聽地址和端口
network.host: 0.0.0.0
http.port: 9200
2)由於centos6不支持seccomp,需要在Memory下面添加(注意順序)
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
3)在後面的head插件安裝後需要配置跨域操作
http.cors.enabled: true
http.cors.allow-origin: "*"
4)若內存不夠大,可以把默認分配jvm的空間設置成1G
在/usr/local/elasticsearch/config/jvm.options裏修改
-Xms1g
-Xmx1g
- 內核參數配置
1)有時候在啓動es的時候會提示elasticsearch process is too low, increase to at least [65536]
在/etc/security/limits.conf添加
* soft nofile 65536
* hard nofile 65536
2)若提示max number of threads [1024] for user [hadoop] is too low, increase to at least [2048]
在/etc/security/limits.d/90-nproc.conf把1024改成2048
* soft nproc 1024
3)若提示max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
在/etc/sysctl.conf文件尾部添加
vm.max_map_count=655360
4)最後執行
sysctl -p
5)由於ES5.3不能用root啓動,需要建立子賬號來啓動ES
useradd elk
chown -R elk:elk /usr/local/elasticsearch
su - elk
/usr/local/elasticsearch/bin/elasticsearch -d
ps -ef| grep elasticsearch
netstat -tunlp | grep -E "9200|9300"
如下圖所示:
啓動ES後
[root@log-nginx logs]# curl 192.168.2.112:9200
{
"name" : "Li5G4mg",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "w3Iu6U4kQWqc6Sdtoq88pQ",
"version" : {
"number" : "5.3.0",
"build_hash" : "3adb13b",
"build_date" : "2017-03-23T03:31:50.652Z",
"build_snapshot" : false,
"lucene_version" : "6.4.1"
},
"tagline" : "You Know, for Search"
}
- ES插件head安裝
yum -y install nodejs npm
yum install -y git
cd /usr/local/elasticsearch/
git clone https://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install 如果網速不好,用下面一行的命令
#npm install -g cnpm --registry=https://registry.npm.taobao.org
1)head修改監聽地址,在Gruntfile.js下添加hostname: ‘*’,
connect: {
server: {
options: {
hostname: '*',
port: 9100,
base: '.',
keepalive: true
}
}
}
2)設置head連接ES的ip地址,在_site/app.js下
this.prefs.get("app-base_uri") || "http://192.168.2.112:9200";
3)啓動head服務
cd /usr/local/elasticsearch/elasticsearch-head/
nohup ./node_modules/grunt/bin/grunt server &>/dev/null &
如下圖所示:
logstash部署
wget https://artifacts.elastic.co/do4wnloads/logstash/logstash-5.3.0.tar.gz
tar -zxvf logstash-5.3.0.tar.gz
mv logstash-5.3.0 /usr/local/logstash
cd /usr/local/logstash
mkdir etc; cd etc
1)建立文件logstash.conf並添加下面內容
input {
stdin { }
}
output {
stdout {
codec => rubydebug {}
}
elasticsearch {
hosts => "192.168.2.112" }
}
2)啓動logstash
/usr/local/logstash/bin/logstash -f logstash.conf
# nohup /usr/local/logstash/bin/logstash -f logstash.conf &>/dev/null & 後臺啓動
3)此時開啓了ES後,再執行logstash啓動命令,則如下圖所示:
4)然後繼續在界面輸入內容,則會把數據發送給ES:
在網頁上可以看到:
上圖中外圍帶綠色框的爲主分片,不帶框的爲副本分片,另外圖右上角顯示黃色背景,是因爲沒有設置副本
kibana部署
wget https://artifacts.elastic.co/downloads/kibana/kibana-5.3.0-linux-x86_64.tar.gz
tar -zxvf kibana-5.3.0-linux-x86_64.tar.gz
mv kibana-5.3.0-linux-x86_64 /usr/local/kibana/
1)kibana參數配置
進入cd /usr/local/kibana/config/kibana.yml裏設置
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: "http://192.168.2.112:9200" 設置與ES的連接
2)啓動kibana
nohup /usr/local/kibana/bin/kibana &>/dev/null &
在web界面,需要配置至少一個索引模式,用於確認ES index,實現搜索和分析功能
Index contains time-based events 索引基於時間的事件
Logstash-* 定義動態的索引名字,用符號*作爲通配符
@timestamp
按照上圖配置點擊create按鈕後,進入discover頁面,默認搜索時間是最近15分鐘,可以點擊右上角的時間修改
當有數據的時候,如下圖所示:
至此ELK環境部署完成。