Elasticsearch是個開源分佈式搜索引擎,提供蒐集、分析、存儲數據三大功能。它的特色有:分佈式,零配置,自動發現,索引自動分片,索引副本機制,restful風格接口,多數據源,自動搜索負載等。java
Logstash 主要是用來日誌的蒐集、分析、過濾日誌的工具,支持大量的數據獲取方式。通常工做方式爲c/s架構,client端安裝在須要收集日誌的主機上,server端負責將收到的各節點日誌進行過濾、修改等操做在一併發往elasticsearch上去。node
Kibana 也是一個開源和免費的工具,Kibana能夠爲 Logstash 和 ElasticSearch 提供的日誌分析友好的 Web 界面,能夠幫助彙總、分析和搜索重要數據日誌。linux
主機名 | IP地址 | 所需軟件 |
---|---|---|
node-1 | 192.168.144.114 | jdk八、elasticsearch2.4.六、logstash2.1.三、kibana-4.3.1-linux-x64.tar.gz |
node-2 | 192.168.144.117 | jdk八、elasticsearch2.4.6 |
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearchgithub
vim elasticsearch.repobootstrap
[elasticsearch-2.x] name=Elasticsearch repository for 2.x packages baseurl=http://packages.elastic.co/elasticsearch/2.x/centos gpgcheck=1 gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch enable=1
yum install elasticsearch -yvim
yum install java -y (1.8版本)centos
java -versionrestful
vim /etc/elasticsearch/elasticsearch.yml網絡
17行 集羣名稱 cluster.name: yun 23行 節點名稱 node.name: linux-node1 33行 工做目錄 path.data: /data/es-data //這兩個目錄建議更改,若採用默認格式,版本更新可能會被默認刪除 path.logs: /var/log/elasticsearch/ //建立這兩個目錄後,注意目錄屬主屬組權限 43行 防止交換swap分區 bootstrap.memory_lock: true 54行 監聽網絡 network.host: 0.0.0.0 58行 端口 http.port: 9200 69行 單播列表自動發現機制 discovery.zen.ping.unicast.hosts: ["127.0.0.1", "192.168.144.117"] //一個本地IP,一個節點2IP
mkdir -p /data/es-data
chown -R elasticsearch:elasticsearch /data/es-data/
systemctl start elasticsearch.service
netstat -ntap | grep 9200
在打開防止交換分區功能後,在es啓動日誌中可觀察到以下信息:
vim /var/log/elasticsearch/abner.log
... [2018-08-19 22:01:12,224][WARN ][bootstrap ] These can be adjusted by modifying /etc/security/limits.conf, for example: # allow user 'elasticsearch' mlockall elasticsearch soft memlock unlimited elasticsearch hard memlock unlimited ...
vim /etc/security/limits.conf
//末尾插入 # allow user 'elasticsearch' mlockall elasticsearch soft memlock unlimited elasticsearch hard memlock unlimited * soft nofile 65535 * hard nofile 65535 //需重啓生效
/usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head
/usr/share/elasticsearch/bin/plugin list
/usr/share/elasticsearch/plugins/head
cat /etc/elasticsearch/elasticsearch.yml | grep -v "^#" | grep -v "^$"
cluster.name: yun //注意:統一羣集下,使用的羣集名稱需相同 node.name: node-2 path.data: /data/es-data path.logs: /var/log/elasticsearch bootstrap.memory_lock: true network.host: 0.0.0.0 http.port: 9200 discovery.zen.ping.unicast.hosts: ["192.168.144.117", "192.168.144.114"]
mkdir -p /data/es-data 建立工做目錄
chown -R elasticsearch:elasticsearch /data/es-data/
systemctl start elasticsearch.service
netstat -ntap | grep 9200
/usr/share/elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf
http://192.168.144.114:9200/_plugin/kopf/#!/cluster
爲了試驗方便起見,本次logstash服務部署在es節點1上。而且將收集到的日誌傳遞給es進行處理。
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
vim /etc/yum.repos.d/logstash.repo
[logstash-2.1] name=Logstash repository for 2.1.x packages baseurl=http://packages.elastic.co/logstash/2.1/centos gpgcheck=1 gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch enable=1
yum install logstash -y
ln -s /opt/logstash/bin/logstash /usr/bin/
vim file.conf
input { file { path => "/var/log/httpd/access_log" type => "accesslog" start_position => "beginning" } file { path => "/var/log/httpd/error_log" type => "errorlog" start_position => "beginning" } } output { if [type] == "accesslog" { elasticsearch { hosts => ["192.168.144.114:9200"] //將日誌收集數據傳遞給es index => "access-%{+YYYY.MM.dd}" } } if [type] == "errorlog" { elasticsearch { hosts => ["192.168.144.114:9200"] index => "error-%{+YYYY.MM.dd}" } } }
wget https://download.elastic.co/kibana/kibana/kibana-4.3.1-linux-x64.tar.gz
tar zxvf kibana-4.3.1-linux-x64.tar.gz -C /opt/
mv kibana-4.3.1-linux-x64/ /usr/local/
mv kibana-4.3.1-linux-x64/ kibana
vim /usr/local/kibana/config/kibana.yml
//2行 server.port: 5601 //5行 server.host: "0.0.0.0" //12行 ES地址 elasticsearch.url: "http://192.168.175.132:9200" //20行 kibana.index: ".kibana"
yum install screen -y
screen 換屏操做
/usr/local/kibana/bin/kibana
ctrl+a+d