ELK是Elasticsearch+Logstash+Kibana的簡稱java
ElasticSearch是一個基於Lucene的分佈式全文搜索引擎,提供 RESTful API進行數據讀寫node
Logstash是一個收集,處理和轉發事件和日誌消息的工具python
總的來講,ElasticSearch負責存儲數據,Logstash負責收集日誌,並將日誌格式化後寫入ElasticSearch,Kibana提供可視化訪問ElasticSearch數據的功能。linux
10.0.0.7 elasticsearch 10.0.0.8 logstash 10.0.0.9 kibana 環境準備: [root@es-node1 ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@logstash ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@kibana ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) #官網下載地址 https://www.elastic.co/downloads
[root@es-node1 ~]# cat /etc/security/limits.conf|tail -5 * soft nofile 65536 * hard nofile 65536 * soft nproc 65536 * hard nproc 65536 [root@es-node1 ~]# cat /etc/security/limits.d/20-nproc.conf|tail -2 * soft nproc 65536 root soft nproc unlimited [root@es-node1 ~]# cat /etc/sysctl.conf |tail -2 vm.max_map_count=655360 fs.file-max=655360 [root@es-node1 ~]# sysctl -p vm.max_map_count = 655360 fs.file-max = 655360
[root@es-node1 ~]# ll total 197448 -rw-r--r-- 1 root root 28017602 Sep 12 23:02 elasticsearch-6.0.0.tar.gz -rw-r--r-- 1 root root 174163338 Sep 12 23:02 jdk-8u151-linux-x64.rpm [root@es-node1 ~]# useradd elasticsearch [root@es-node1 ~]# mv elasticsearch-6.0.0.tar.gz /usr/local/src/ [root@es-node1 ~]# rpm -ivh jdk-8u151-linux-x64.rpm Preparing... ################################# [100%] Updating / installing... 1:jdk1.8-2000:1.8.0_151-fcs ################################# [100%] Unpacking JAR files... tools.jar... plugin.jar... javaws.jar... deploy.jar... rt.jar... jsse.jar... charsets.jar... localedata.jar... [root@es-node1 ~]# cd /usr/local/src/ [root@es-node1 src]# ll total 27364 -rw-r--r-- 1 root root 28017602 Sep 12 23:02 elasticsearch-6.0.0.tar.gz [root@es-node1 src]# tar xf elasticsearch-6.0.0.tar.gz -C ../ [root@es-node1 src]# cd .. [root@es-node1 local]# mv elasticsearch-6.0.0/ elasticsearch [root@es-node1 local]# cd elasticsearch/ [root@es-node1 elasticsearch]# chown -R elasticsearch.elasticsearch . [root@es-node1 elasticsearch]# mkdir -p /data/es/logs /data/es/data [root@es-node1 elasticsearch]# chown -R elasticsearch.elasticsearch /data/es/logs /data/es/data [root@es-node1 elasticsearch]# su - elasticsearch [elasticsearch@es-node1 ~]$ cd /usr/local/elasticsearch/ [elasticsearch@es-node1 elasticsearch]$ cd config/ [elasticsearch@es-node1 config]$ cp elasticsearch.yml{,.bak} [elasticsearch@es-node1 config]$ cat elasticsearch.yml cluster.name: es node.name: es1 path.data: /data/es/data path.logs: /data/es/logs network.host: 10.0.0.7 http.port: 9200 transport.tcp.port: 9300 node.master: true node.data: true discovery.zen.ping.unicast.hosts: ["10.0.0.7:9300"] discovery.zen.minimum_master_nodes: 1 http.cors.enabled: true http.cors.allow-origin: "*" #增長端口 [root@es-node1 ~]# firewall-cmd --add-port=9200/tcp --permanent [root@es-node1 ~]# firewall-cmd --add-port=9300/tcp --permanent #從新加載防火牆規則 [root@es-node1 ~]# firewall-cmd --reload #後臺啓動 [elasticsearch@es-node1 ~]$ /usr/local/elasticsearch/bin/elasticsearch -d [root@es-node1 ~]# curl http://10.0.0.7:9200/_cluster/health #顯示green爲正常
#安裝node步驟略 [elasticsearch@es-node1 ~]$ cd /usr/local/src/ [elasticsearch@es-node1 ~]$ git clone https://github.com/mobz/elasticsearch-head.git [elasticsearch@es-node1 ~]$ cd /usr/local/src/elasticsearch-head/ [elasticsearch@es-node1 ~]$ npm install [elasticsearch@es-node1 ~]$ npm run start &
[root@logstash ~]# ll total 279772 -rw-r--r-- 1 root root 174163338 Sep 13 03:08 jdk-8u151-linux-x64.rpm -rw-r--r-- 1 root root 112316625 Sep 13 03:08 logstash-6.0.0.tar.gz [root@logstash ~]# rpm -ivh jdk-8u151-linux-x64.rpm [root@logstash ~]# tar xf logstash-6.0.0.tar.gz -C /usr/local/ [root@logstash ~]# cd /usr/local/ [root@logstash ~]# mv logstash-6.0.0/ logstash
[root@logstash config]# mkdir -p /data/logstash/{data,logs} [root@logstash config]# cat logstash.yml path.data: /data/logstash/data path.logs: /data/logstash/logs
[root@logstash logstash]# mkdir -p /usr/local/logstash/conf.d [root@logstash logstash]# cd /usr/local/logstash/conf.d [root@logstash logstash]# cat conf.d/system-log.conf input { file { path => "/var/log/messages" type => "systemlog" start_position => "beginning" stat_interval => "3" } file { path => "/var/log/secure" type => "securelog" start_position => "beginning" stat_interval => "3" } } output { if [type] == "systemlog" { elasticsearch { hosts => ["10.0.0.7:9200"] index => "system-log-%{+YYYY.MM.dd}" } } if [type] == "securelog" { elasticsearch { hosts => ["10.0.0.7:9200"] index => "secury-log-%{+YYYY.MM.dd}" } } } #檢查文件ogstash [root@logstash logstash]# ./bin/logstash -f ./conf.d/system-log.conf -t #啓動logstash [root@logstash logstash]# ./bin/logstash -f ./conf.d/system-log.conf
此時elasticsearch的狀態git
[root@kibana src]# ll /usr/local/src/ total 61216 -rw-r--r-- 1 root root 62681537 Sep 11 10:27 kibana-6.0.0-linux-x86_64.tar.gz [root@kibana src]# tar xf kibana-6.0.0-linux-x86_64.tar.gz [root@kibana src]# mv kibana-6.0.0-linux-x86_64 ../kibana #更改配置文件 [root@kibana config]# cat kibana.yml server.port: 5601 server.host: "10.0.0.9" elasticsearch.url: "http://10.0.0.7:9200" #啓動kibana [root@kibana kibana]# ./bin/kibana