elk日誌收集

準備環境
防火牆和selinux: 關閉
主機名     elk-node1   elk-node2
主機名解析
192.168.227.128 elk-node1
192.168.227.129 elk-node2
master-slave模式:
master收集到日誌後,會把一部分數據碎片到slave上(隨機的一部分數據);
同時,master和slave又都會各自做副本,並把副本放到對方機器上,這樣就保證了數據不會丟失。
如果master宕機了,那麼客戶端在日誌採集配置中將elasticsearch主機指向改爲slave,就可以保證ELK日誌的正常採集和web展示。

ELasticsearch安裝
1、下載並安裝GPG Key
[root@elk-node1 ~]# rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
2、準備yum源
[root@elk-node1 ~]# cd /etc/yum.repos.d
[root@elk-node1  yum.repos.d]# vim elasticsearch.repo
[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
enabled=1
3、安裝elasticsearch
[root@elk-node1 ~]# yum -y install elasticsearch
4、安裝java環境
[root@elk-node1 ~]# yum -y install java
[root@elk-node1 ~]# java -version
openjdk version "1.8.0_102"
OpenJDK Runtime Environment (build 1.8.0_102-b14)
OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)

elk-node1配置:
1、修改配置文件
[root@elk-node1 ~]#  mkdir -p /data/es-data
[root@elk-node1 ~]#  vim /etc/elasticsearch/elasticsearch.yml
cluster.name: wingcluster         #組名 (同一個組,組名必須一致(自己定義))
node.name: elk-node1             #節點名稱,建議和主機名一致
path.data:  /data/es-data                            #數據存放位置
path.logs:   /var/log/elasticsearch/  #日誌存放位置
bootstrap.mlockall:  true           #鎖住內存,不被使用到交換分區去
network.host: 0.0.0.0              #網絡設置(0.0.0.0表示監聽所有網卡)
http.port: 9200                       #端口
2、啓動並查看
[root@elk-node1 ~]#  chown elasticsearch.elasticsearch  /data/
[root@elk-node1 ~]#  systemctl  start  elasticsearch
[root@elk-node1 ~]#  systemctl  status elasticsearch
 CGroup: /system.slice/elasticsearch.service
           └─3005 /bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSI...
注意:上面可以看出elasticsearch設置的內存最小256m,最大1g
[root@elk-node1 ~]#  netstat  -antlp  |egrep  “9200|9300”
tcp6       0      0 :::9200                 :::*                    LISTEN      3005/java          
tcp6       0      0 :::9300                 :::*                    LISTEN      3005/java
通過web訪問測試
http://172.16.113.155:9200/

通過命令方式測試
# curl -i -XGET 'http://172.16.113.155:9200/_count?pretty' -d '{"query":{"match_all":{}}}'
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 95
{
"count" : 0,
"_shards" : {
"total" : 0,
"successful" : 0,
"failed" : 0
}
}
elk-node2配置操作同elk-node1(配置文件稍微不同)
[root@elk-node2 ~]#  vim /etc/elasticsearch/elasticsearch.yml
cluster.name: wingcluster       
node.name: elk-node2
path.data: /data/es-data
path.logs: /var/log/elasticsearch/
bootstrap.mlockall: true
network.host: 0.0.0.0 
http.port: 9200       
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: ["172.16.113.155", "172.16.113.156"]

安裝插件
例如安裝head插件
a)插件安裝方法一
[root@elk-node1 ~]#  /usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head
[root@elk-node1 ~]#  chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/plugins
[root@elk-node1 ~]#  systemctl restart elasticsearch
b)插件安裝方法二在/usr/share/elasticsearch/plugins目錄下創建head目錄
下載head插件到/usr/local/src/目錄下(下載地址https://github.com/mobz/elasticsearch-head),將下載的包解壓縮,然後將上面下載的elasticsearch-head-master.zip解壓後的文件都移到/usr/share/elasticsearch/plugins/head下,重啓elasticsearch服務即可!(具體步驟略)
安裝其他插件步驟相同


logstash安裝

主要安裝在客戶機上
elk-node1和elk-node2都安裝,這裏是拿服務器當客戶端用
客戶端安裝logstash,收集到的數據寫入到elasticsearch裏,就可以登陸logstash界面查看到了
1、下載並安裝GPG Key
[root@elk-node1 ~]# rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
2、配置yum源
[root@elk-node1 ~]# cd /etc/yum.repos.d/
[root@elk-node1  yum.repos.d]# vim 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
enabled=1
3、安裝並啓動logstash
[root@elk-node1 ~]#  yum -y install logstash
[root@elk-node1 ~]#  systemctl  restart elasticsearch
測試
1)基本的輸入輸出
[root@elk-node1 ~]# /opt/logstash/bin/logstash -e 'input { stdin{} } output { stdout{} }'
Settings: Default filter workers: 1
Logstash startup completed
hello                                                                                     #輸入這個
2016-11-11T06:41:07.690Z elk-node1 hello                        #輸出這個
wangshibo                                                                            #輸入這個
2016-11-11T06:41:10.608Z elk-node1 wangshibo               #輸出這個

[root@elk-node1 yum.repos.d]# /opt/logstash/bin/logstash -e 'input { stdin{} } output { stdout{} }'
Settings: Default filter workers: 2
Logstash startup completed
wing
2018-07-09T07:13:50.851Z elk-node1 wing
你的標準輸入是什麼,就打印它到標準輸出
2018-07-09T07:14:16.819Z elk-node1 你的標準輸入是什麼,就打印它到標準輸出


kibana安裝

kibana安裝配置
1)、kibana的安裝:
1)kibana的安裝:
[root@elk-node1 ~]# cd /usr/local/src
[root@elk-node1 src]# wget https://download.elastic.co/kibana/kibana/kibana-4.3.1-linux-x64.tar.gz
[root@elk-node1 src]# tar zxf kibana-4.3.1-linux-x64.tar.gz
[root@elk-node1 src]# mv kibana-4.3.1-linux-x64 /usr/local/
[root@elk-node1 src]# ln -s /usr/local/kibana-4.3.1-linux-x64/ /usr/local/kibana
2)修改配置文件:
[root@elk-node1 config]# pwd
/usr/local/kibana/config
[root@elk-node1 config]# cp kibana.yml kibana.yml.bak
[root@elk-node1 config]# vim kibana.yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: "http://192.168.1.160:9200"
kibana.index: ".kibana"
因爲它一直運行在前臺,所以我們要麼選擇重開一個窗口,要麼選擇使用screen
安裝並使用screen
[root@elk-node1 ~]# yum -y install screen
[root@elk-node1 ~]# screen                          #這樣就另開啓了一個終端窗口
[root@elk-node1 ~]# /usr/local/kibana/bin/kibana
  log   [18:23:19.867] [info][status][plugin:kibana] Status changed from uninitialized to green - Ready
   log   [18:23:19.911] [info][status][plugin:elasticsearch] Status  changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [18:23:19.941] [info][status][plugin:kbn_vislib_vis_types] Status changed from uninitialized to green - Ready
  log   [18:23:19.953] [info][status][plugin:markdown_vis] Status changed from uninitialized to green - Ready
  log   [18:23:19.963] [info][status][plugin:metric_vis] Status changed from uninitialized to green - Ready
  log   [18:23:19.995] [info][status][plugin:spyModes] Status changed from uninitialized to green - Ready
  log   [18:23:20.004] [info][status][plugin:statusPage] Status changed from uninitialized to green - Ready
  log   [18:23:20.010] [info][status][plugin:table_vis] Status changed from uninitialized to green - Ready

然後按ctrl+a+d組合鍵,暫時斷開screen會話
這樣在上面另啓的screen屏裏啓動的kibana服務就一直運行在前臺了....
[root@elk-node1 ~]# screen -ls
There is a screen on:
        15041.pts-0.elk-node1   (Detached)
1 Socket in /var/run/screen/S-root.


注:screen重新連接會話
    下例顯示當前有兩個處於detached狀態的screen會話,你可以使用screen -r <screen_pid>重新連接上:
    [root@tivf18 root]# screen –ls
    There are screens on:
            8736.pts-1.tivf18       (Detached)
            8462.pts-0.tivf18       (Detached)
    2 Sockets in /root/.screen.
    
    [root@tivf18 root]# screen -r 8736
3)、訪問kibana測試    http://192.168.227.128:5601
  
   




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章