ELK收集windows服務器日誌筆記

1、軟件版本java

  1.jdk-8u211-linux-x64.rpmnode

  2.elasticsearch-6.8.1.rpmlinux

  3.logstash-6.8.1.rpmnginx

  4.kibana-6.8.1-x86_64.rpmshell

  5.winlogbeat-6.8.4-windows-x86_64   在windows服務器安裝配置數據庫

     說明:elasticsearch作集羣   主機1:192.168.1.102 主機2:192.168.1.104json

     logstash和kibana安裝在主機1上bootstrap

2、安裝軟件vim

  2.1 主機1和主機2:jdk-8u211-linux-x64.rpm和elasticsearch-6.8.1.rpm 並配置elasticsearchwindows

    說明:elasticsearch依賴jdk環境,因此先安裝jdk-8u211-linux-x64.rpm

    yum -y localinstall  jdk-8u211-linux-x64.rpm

            yum -y localinstall  elasticsearch-6.8.1.rpm

        

  建立數據目錄和日誌目錄及權限修改
  [root@linux-elk1 ~]# mkdir -p /elk/{data,logs}
  [root@linux-elk1 ~]# chown elasticsearch.elasticsearch /elk/ -R

  修改內存限制,內存鎖定須要進行配置須要2g以上內存,不然會致使沒法啓動elasticsearch。
  [root@linux-elk1 ~]# vim /usr/lib/systemd/system/elasticsearch.service
  在[Service]下加入下面這行內容
  LimitMEMLOCK=infinity

  [root@linux-elk1 ~]# vim /etc/elasticsearch/jvm.options
  -Xms2g
  -Xmx2g #最小和最大內存限制.

        編輯配置文件:vim /etc/elasticsearch/elasticsearch.yml 

  [root@logsystem src]# grep -v "^#" /etc/elasticsearch/elasticsearch.yml
  cluster.name: my-log
  node.name: node-1
  path.data: /elk/data
  path.logs: /elk/logs
  network.host: 192.168.1.102
  http.port: 9200
  discovery.zen.ping.unicast.hosts: ["192.168.1.102","192.168.1.104"]

  設置開機啓動
  systemctl enable elasticsearch.service

  systemctl daemon-reload
  systemctl start elasticsearch.service

  查看狀態
  systemctl status elasticsearch.service

  正在運行,查看端口
  ss -tnl

  

  查看信息,也是一種檢測。若能出現以下信息,則說明配置正確
  curl http://192.168.1.102:9200

  

  

  集羣有狀態: green ,red , yellow
  綠色表示一切是好的(集羣功能齊全)
  黃色意味着全部數據是可用的,可是一些副本還沒有分配(集羣功能齊全)
  紅色意味着一些數據不可用
  即便一個集羣是紅色的,它仍然是部分功能(即它將繼續搜索請求從服務可用的碎片)可是你可能須要儘快修復它,由於你有缺失的數據。

  Restful API:
  四類API
  1. 檢查集羣,節點,索引等健康與否,以及獲取其相應狀態
  2.管理集羣,節點,索引及元數據
  3.執行CRUD操做
  4.執行高級操做,如paging ,filtering等


  ES訪問接口:9200/tcp

  語法:
  curl -X<VERB> '<PROTOCOL>://host:port/<PATH>?QUERY_STRING/' -d '<BODY>'

  查看elasticsearch相關信息 json格式的
  [root@logsystem ~]# curl http://192.168.1.102:9200/_cluster/health?pretty=true
  {
  "cluster_name" : "elasticsearch",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
  }

  [root@logsystem ~]# curl -X GET http://192.168.1.102:9200/_cat/nodes?v
  ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
  192.168.1.102 7 95 1 0.00 0.01 0.05 mdi * node-1


  [root@logsystem ~]# curl -X GET http://192.168.1.102:9200/_cat/indices?help

  [root@logsystem ~]# curl -X GET 'http://192.168.1.102:9200/_cluster/state/version?pretty'
  {
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "qKuBK9TlQ3G-Rj6IFAXzTQ",
  "version" : 16,
  "state_uuid" : "SzhdF4PvRIGFbwlI_PD_cg"
  }

  2.2主機1: logstash-6.8.1.rpm 並配置

   wget https://artifacts.elastic.co/downloads/logstash/logstash-6.8.1.rpm

   yum -y localinstall  logstash-6.8.1.rpm

  [root@logsystem ~]cd /etc/logstash/conf/

  vim system-log.conf 

  input{

    beats{
    add_field => {"myid"=>"windows_log"}
    port => 5044
  }
    beats {
    add_field => {"myid"=>"nginx_log"}
    port => 5400
    }
  stdin{}
  }

  output{
    if [myid] == "windows_log"{
      elasticsearch{
      hosts=>"192.168.1.102:9200"
      index=>"%{type}-%{+YYYY-MM-dd}"
      }
  }
  if [myid] == "nginx_log"{
      elasticsearch{
      hosts=>"192.168.1.102:9200"
      index=>"nginx_pj_log-%{+YYYY-MM-dd}"
      }
      }
  stdout{ codec=>rubydebug }
  }

  啓動logstash:

    [root@logsystem src]# nohup logstash -f /etc/logstash/conf.d/server_log.conf & 

  測試配置文件是否有語法錯誤:
  [root@logsystem ~]logstash -f /etc/logstash/conf/system-log.conf

  數據類型
  Array: [item1,item2,...]
  Boolean: true,false
  Bytes:
  Codec: 編碼器
  Hash: key=>value
  Number:
  Password:
  Path:文件系統路徑
  String:字符串
  字段引用 []
  條件判斷: == ,!=,<,>, in ,not in ,and,or ....


  經常使用imput Plugin
  imput插件:
  File :從指定的文件中讀取事件流,按行來標記一個事件。
  使用FileWatch(Ruby開發)來監聽文件是否變化; .sincedb保存文件的相關信息數據庫中。

  [root@logsystem logstash]# rpm -ql logstash |grep "patterns" 查找pattern

      elasticsearch服務收到數據驗證:

 

  2.3主機1:安裝配置kibana   

  [root@logsystem src]# wget https://artifacts.elastic.co/downloads/kibana/kibana-6.8.1-x86_64.rpm
  安裝
  [root@logsystem src]# yum localinstall kibana-6.8.1-x86_64.rpm -y 

  配置
  [root@logsystem src]# vim /etc/kibana/kibana.yml
  server.port: 5601 #監聽端口
  server.host: "192.168.1.102" #監聽地址
  elasticsearch.hosts: ["http://192.168.1.102:9200"] #elasticsearch服務器地址
  i18n.locale: "zh-CN" #修改中文

  [root@logsystem src]# systemctl start kibana
  [root@logsystem src]# systemctl enable kibana

    查看服務

 

     訪問:http://192.168.1.102:5601

 

 

 

 

   2.4 收集服務器日誌上安裝winlogbeat-6.8.4-windows-x86_64

  解壓到 C:\Program Files

  從新命名文件夾爲winlogbeat
  用管理員身份打開windows的 powershell
  運行如下命令來安裝服務
  PS C:\Users\Administrator> cd 'C:\Program Files\Winlogbeat'
  PS C:\Program Files\Winlogbeat> .\install-service-winlogbeat.ps1

  不能安裝時,令來關閉一些安全防禦,輸入命令後按Y確認
  PS C:\Program Files\Winlogbeat> set-executionpolicy remotesigned
  PS C:\Program Files\Winlogbeat> set-executionpolicy Bypass

     winlogbeat.yml 配置文件修改:

  winlogbeat.event_logs:
  - name: Application #應用程序事件;
  ignore_older: 8h #忽略8小時後的日誌,初次啓用傳日誌頗有用;
  provider: #過慮源yml列表
  - Application Error
  - Application Hang
  - Windows Error Reporting
  - name: Security #安全日誌
  ignore_older: 8h
  event_id: 4624, 4625, 4700-4800, -4735 #事件ID 匹配中事件ID發送
  - name: System #系統日誌
  ignore_older: 8h

 

  檢查配置語法
.  \winlogbeat.exe test config -c .\winlogbeat.yml -e

  啓動winlogbeat
  C:\Program Files\Winlogbeat> Start-Service winlogbeat

  Windlogbeat基本配置 

  1.配置發送日誌到logstash
  output.logstash:
  # The Logstash hosts
  hosts: ["10.10.10.10:5044"]
  2.配置發送日誌到elasticsearch
  output.elasticsearch:
  hosts: ["10.10.10.10:9200"]
  template.name: "winlogbeat"
  template.path: "winlogbeat.template.json"
  template.overwrite: false

 

坑1:插件存放路徑
報錯:
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: Property [elasticsearch.version] is missing for plugin [head]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-5.2.2.jar:5.2.2]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-5.2.2.jar:5.2.2]
        at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.2.2.jar:5.2.2]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.2.2.jar:5.2.2]
        at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.2.2.jar:5.2.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:89) ~[elasticsearch-5.2.2.jar:5.2.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82) ~[elasticsearch-5.2.2.jar:5.2.2]

緣由:新版本的elasticsearch不容許插件放入/usr/share/elasticsearch/plugins 目錄下。(插件bigdesk,head ...)解決:把插件移到其它目錄便可

相關文章
相關標籤/搜索