ELK是三個開源軟件的縮寫,分別表示:Elasticsearch , Logstash, Kibana , 它們都是開源軟件。新增了一個FileBeat,它是一個輕量級的日志收集處理工具(Agent),Filebeat占用資源少,適合於在各個服務器上搜集日志后傳輸給Logstash,官方也推薦此工具。
Elasticsearch是個開源分布式搜索引擎,提供搜集、分析、存儲數據三大功能。它的特點有:分布式,零配置,自動發現,索引自動分片,索引副本機制,restful風格接口,多數據源,自動搜索負載等。
Logstash 主要是用來日志的搜集、分析、過濾日志的工具,支持大量的數據獲取方式。一般工作方式為c/s架構,client端安裝在需要收集日志的主機上,server端負責將收到的各節點日志進行過濾、修改等操作在一並發往elasticsearch上去。
Kibana 也是一個開源和免費的工具,Kibana可以為 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以幫助匯總、分析和搜索重要數據日志。
前提:關閉防火牆和selinux
[root@bogon ~]# systemctl stop firewalld.service
[root@bogon ~]# setenforce 0
[root@bogon ~]#
系統優化:
1 [root@bogon ~]# vim /etc/security/limits.conf 2 [root@bogon ~]# cat /etc/security/limits.conf | grep -v "^#" | grep -v "^$"
3 * soft nproc 65535
4 * soft nofile 65535
5 * hard nproc 65535
6 * hard nofile 65535
7 [root@bogon ~]#
[root@bogon ~]# cat /etc/sysctl.conf | grep -v "^#"
vm.max_map_coun=655360
[root@bogon ~]#
三個組件都安裝到一台服務器上
165:ES+kibana
190:logstash
1,安裝jdk
rpm -ivh jdk-8u131-linux-x64_.rpm
2 配置elasticsearch 的yum源
1 [root@bogon ELK]# vim /etc/yum.repos.d/elasticsearch.repo 2 [root@bogon ELK]# cat /etc/yum.repos.d/elasticsearch.repo 3 [elasticsearch-6.x] 4 name=Elasticsearch repository for 6.x packages 5 baseurl=https://artifacts.elastic.co/packages/6.x/yum
6 gpgcheck=1
7 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
8 enabled=1
9 autorefresh=1
10 type=rpm-md 11 [root@bogon ELK]#
安裝elasticsearch
yum -y install elasticsearch-6.6.2.rpm
配置開機自啟動
systemctl enable elasticsearch.service
開啟服務
systemctl start elasticsearch.service
驗證服務是否啟動
1 [root@bogon ELK]# netstat -lptnu | grep java 2 tcp6 0 0 127.0.0.1:9200 :::* LISTEN 16225/java 3 tcp6 0 0 ::1:9200 :::* LISTEN 16225/java 4 tcp6 0 0 127.0.0.1:9300 :::* LISTEN 16225/java 5 tcp6 0 0 ::1:9300 :::* LISTEN 16225/java 6 [root@bogon ELK]#
監聽端口:
9200作為Http協議,主要用於外部通訊
9300作為Tcp協議,ES集群之間是通過9300進行通訊
修改配置文件:
1 [root@bogon ELK]# vim /etc/elasticsearch/elasticsearch.yml 2 [root@bogon ELK]# cat /etc/elasticsearch/elasticsearch.yml | grep -v '^#'
3 cluster.name: wg007 4 node.name: node-1
5 path.data: /var/lib/elasticsearch 6 path.logs: /var/log/elasticsearch 7 network.host: 192.168.136.190
8 http.port: 9200
9 [root@bogon ELK]#
日志文件路徑:
1 [root@bogon ELK]# cd /var/log/elasticsearch/
2 [root@bogon elasticsearch]# pwd 3 /var/log/elasticsearch 4 [root@bogon elasticsearch]# ll 5 總用量 40
6 -rw-r--r--. 1 elasticsearch elasticsearch 0 5月 12 19:11 elasticsearch_access.log 7 -rw-r--r--. 1 elasticsearch elasticsearch 0 5月 12 19:11 elasticsearch_audit.log 8 -rw-r--r--. 1 elasticsearch elasticsearch 0 5月 12 19:11 elasticsearch_deprecation.log 9 -rw-r--r--. 1 elasticsearch elasticsearch 0 5月 12 19:11 elasticsearch_index_indexing_slowlog.log 10 -rw-r--r--. 1 elasticsearch elasticsearch 0 5月 12 19:11 elasticsearch_index_search_slowlog.log 11 -rw-r--r--. 1 elasticsearch elasticsearch 8297 5月 12 19:12 elasticsearch.log 12 -rw-r--r--. 1 elasticsearch elasticsearch 27115 5月 12 19:14 gc.log.0.current 13 -rw-r--r--. 1 elasticsearch elasticsearch 0 5月 12 19:17 wg007_access.log 14 -rw-r--r--. 1 elasticsearch elasticsearch 0 5月 12 19:17 wg007_audit.log 15 -rw-r--r--. 1 elasticsearch elasticsearch 0 5月 12 19:17 wg007_deprecation.log 16 -rw-r--r--. 1 elasticsearch elasticsearch 0 5月 12 19:17 wg007_index_indexing_slowlog.log 17 -rw-r--r--. 1 elasticsearch elasticsearch 0 5月 12 19:17 wg007_index_search_slowlog.log 18 -rw-r--r--. 1 elasticsearch elasticsearch 5627 5月 12 19:18 wg007.log 19 [root@bogon elasticsearch]#
開啟:
tailf /var/log/elasticsearch/wg007.log
1 [root@bogon ~]# netstat -nlpt | grep java 2 tcp6 0 0 192.168.136.190:9200 :::* LISTEN 66889/java 3 tcp6 0 0 192.168.136.190:9300 :::* LISTEN 66889/java 4 [root@bogon ~]#
3,logstash 安裝
配置logstash yum 源
yum -y install logstash-6.6.0.rpm
配置文件路徑:/etc/logstash/
日志文件路徑:/var/log/logstash/
編寫收集日志的配置文件
1 [root@bogon ELK]# vim /etc/logstash/conf.d/system.conf 2 [root@bogon ELK]# cat /etc/logstash/conf.d/system.conf 3 input { 4 file { 5 path => "/var/log/messages"
6 type => "system-log"
7 start_position => "beginning"
8 } 9 } 10 output { 11 elasticsearch { 12 hosts => "192.168.136.190:9200"
13 index => "system_log-%{+YYYY.MM.dd}"
14 } 15 } 16 [root@bogon ELK]#
將/var/log/messages日志的權限修改
chmod -R 777 /var/log/messages
配置開機自啟動
systemctl enable logstash.service
啟動logstash服務
systemctl start logstash.service
監聽端口:
tailf /var/log/logstash/
[root@bogon ~]# netstat -lptnu|grep java
tcp6 0 0 127.0.0.1:9600 :::* LISTEN 7712/java
[root@bogon ~]#
4,第一台繼續做Kibana
yum -y install kibana-6.6.2-x86_64.rpm
配置kibana
1 [root@bogon ELK]# vim /etc/kibana/kibana.yml 2 [root@bogon ELK]# cat /etc/kibana/kibana.yml |grep -v "^#" |grep -v "^$"
3 server.port: 5601
4 server.host: "192.168.136.190"
5 elasticsearch.hosts: ["http://192.168.136.190:9200"] 6 [root@bogon ELK]#
啟動服務
systemctl start kibana.service
[root@bogon ELK]# netstat -anlpt | grep :5601
tcp 0 0 192.168.136.190:5601 0.0.0.0:* LISTEN 71978/node
[root@bogon ELK]#
5,瀏覽器訪問






