乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      ELK部署詳解

       笑觀云卷云舒 2018-04-24

      前言:

      最近部署了ELK,遇到了不少的坑,而網絡上又較少有比較完整且詳細的文檔,
      因此將自己部署的過程記錄總結下,開始使用的服務器配置如下:
      主機:2 (elk1,elk2)
      系統:CentOS7
      配置:416G內存
      網絡:內網互通
      ELK版本:elasticsearch-2.4.1 kibana-4.6.1
              logstash-2.4.0 logstash-forwarder-0.4.0
              redis-3.0.7
      
      

      ELK簡單介紹

      ELK是三個不同工具的簡稱,組合使用可以完成各種日志分析,下面簡單介紹下三個工具的作用

      Elasticsearch:是一個基于Apache Lucene(TM)的開源搜索引擎,簡單點說就是用于建立索引并存儲日志的工具,可參考(http://es./)

      Logstash:是一個應用程序,它可以對日志的傳輸、過濾、管理和搜索提供支持。我們一般用它來統一對應用程序日志進行收集管理,提供Web接口用于查詢和統計

      Kibana:用于更友好的展示分析日志的web平臺,簡單點說就是有圖有真相,可以在上面生成各種各樣的圖表更直觀的顯示日志分析的成果

      圖片描述

      總結:將三個工具組合起來使用我們就可以收集日志分析并展示分析結果

      部署安裝

      簡要:
      安裝過程我基本上參考了:https://www./...來做,
      不過遺憾的是,這里只告訴最最基本的安裝方式,如果日志量較大又怎么辦,遇到問題又怎么查看,資料相對較少,這里我根據自己的安裝來詳細闡明步驟

      注意:
      1.本文下載的官網RPM包安裝(比較方便),可自行選擇
      2.這里是單臺服務器安裝elk,集群安裝一樣,修改配置文件即可

      一、去下載最新的穩(wěn)定版,因為功能最多最全,這里貼出官網

      https://www./downloads

      二、Elasticsearch安裝

      1 由于安裝ELK需要jdk,因此沒有jdk的可以先安裝1.8版本以上

      $cd ~
      $wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u65-b17/jdk-8u65-linux-x64.rpm"
      $sudo yum localinstall jdk-8u65-linux-x64.rpm
      $rm ~/jdk-8u65-linux-x64.rpm
      

      2 下載并安裝Elasticsearch

      $rpm -ivh elasticsearch-2.4.1.rpm
      

      3 編輯配置文件,主要修改以下幾項

      $vim /etc/elasticsearch/elasticsearch.yml
      
      path.data: /data/elasticsearch     #日志存儲目錄
      path.logs: /data/elasticsearch/log #elasticsearch啟動日志路徑
      network.host: elk1        #這里是主機IP,我寫了hosts
      node.name: "node-2"       #節(jié)點名字,不同節(jié)點名字要改為不一樣
      http.port: 9200           #api接口url
      node.master: true         #主節(jié)點
      node.data: true           #是否存儲數據
          
      #手動發(fā)現節(jié)點,我這里有兩個節(jié)點加入到elk集群
      discovery.zen.ping.unicast.hosts: [elk1, elk2]
       

      4 創(chuàng)建配置文件夾后啟動

       $mkdir -pv /data/elasticsearch/log
       $systemctl start elasticsearch

      檢查:/data/elasticsearch/elasticsearch/nodes/0/indices目錄是否正確創(chuàng)建

      三、Kibana安裝

      1 下載并安裝Kibana

      $rpm -ivh kibana-4.6.1-x86_64.rpm

      2 編輯配置文件,主要修改如下

      vim /opt/kibana/config/kibana.yml
      
      server.port: 5601
      #server.host: "localhost"
      server.host: "0.0.0.0"
      elasticsearch.url: "http://elk1:9200"

      3 啟動并檢查是否安裝成功

      $systemctl start kibana
      $netstat -ntlp|grep 5601 #檢查5601是否監(jiān)聽
      tcp        0      0 0.0.0.0:5601            0.0.0.0:*               LISTEN      8354/node
      

      四、安裝redis

      1 此處我選擇安裝redis-cli 3.0.7,可以去官網下載編譯安裝(https:///)

      2 啟動

      $redis-server /etc/redis_6379.conf &

      注:redis安裝此處就不多贅述,需要指出的是由于redis是單進程,在ELK中一般用作隊列,對I/O讀寫消耗較高,因此我起多個進程(將在后面優(yōu)化詳細提到),將不同的日志分發(fā)到不同的redis,更多redis安裝請自行百度

      五、生成SSL證書用于Logstash免密傳輸日志

      1 編輯配置文件/etc/pki/tls/openssl.cnf

      $vim /etc/pki/tls/openssl.cnf
      
      # 這里的IP信息填寫logstash的IP,最好內網傳輸
      subjectAltName = IP: 10.26.215.110
      

      2 生成證書

      $cd /etc/pki/tls
      $sudo openssl req -config /etc/pki/tls/openssl.cnf -x509 -days 3650 -batch -nodes -newkey rsa:2048 -keyout private/logstash-forwarder.key -out certs/logstash-forwarder.crt
      

      六、Logstash安裝

      1 下載并安裝Logstash

      $rpm -ivh logstash-2.4.0.noarch.rpm
      

      2 接收日志并放入redis的配置文件
      elasticsearch output參數參考:
      http://www./guide/e...
      elasticsearch input參數參考:
      https://www./guide/...
      elasticsearch filter參考
      https://www./guide/...

      注意:Logstash沒有默認的配置文件,需要手動編輯,此處我給出我使用的兩個實例

      vim /etc/logstash/conf.d/redis-input.conf
      
      input {
        lumberjack {
          port => 5043
          type => "logs"
          ssl_certificate => "/etc/pki/tls/certs/logstash-forwarder.crt"
          ssl_key => "/etc/pki/tls/private/logstash-forwarder.key"
        }
      }
      filter{
      #這里可以不做任何操作,用于過濾日志分割字段
      }
      
      output {
          ####將接收的日志放入redis消息隊列####
          redis {
              host => "127.0.0.1"
              port => 6379
              data_type => "list"
              key => "logstash:redis"
          }
      }

      3 讀取redis消息隊列日志,調用elasticsearch接口建立索引

      vim /etc/logstash/conf2.d/redis-output.conf
      
      input {
          # 讀取redis
          redis {
              data_type => "list"
              key => "logstash:redis"
              host => "10.24.245.21"  #redis-server
              port => 6379
              #threads => 5
          }
      output {
          elasticsearch {
              # 這里填寫elasticsearch的http端口
              hosts => ["meizu-elk:9200"]  
              
              # 建立的索引名,這里我以type加時間來建不同索引        
              index => "%{type}-%{+YYYY.MM.dd}"
              document_type => "%{type}"
              
              # 線程數,對redis隊列消費能力有顯著影響
              # 建議自己測試不同值觀察
              workers => 100
              
              template_overwrite => true
              #codec => "json"
          }
          
          #如果你要將logstash讀取redis并建立索引的
          # 過程顯示或者調試,可以打開stdout
          #stdout { codec => rubydebug }
      }
      

      4 啟動Logstash

      自己編寫了下啟動腳本,用于適應我自己需求

      #!/bin/bash
      # chkconfig: - 07 02
      # description: logstash start|stop|restart|reload|check
      # author=WZJ
      # date=2016-11-7
      # 用于管理進程啟動關閉查看,此處比較特殊,因為logstash是日志的中間件,負責日志的輸入輸出
      # 而瓶頸在于建立索引,因此,在建立索引的時候多幾個進程去讀取redis,然后連接elasticsearch
      
      function conf()
      {
          # 啟動腳本名字
          script_name="logstash"
          # 啟動程序文件
          start_command=/opt/logstash/bin/logstash
          # 啟動配置文件
          conf_file=/etc/logstash/conf.d/redis-input.conf
          # 啟動建立索引進程的配置
          output_conf=/etc/logstash/conf2.d/redis-output.conf
          # Log文件
          log_path=/var/log/logstash_output.log
      
          # input-redis log
          log_input_path=/var/log/logstash_input.log
          
          # 建立索引的work進程數量
          works=4
      }
      
      
      function getPid()
      {
          i_pid=$(ps -ef | grep "${conf_file}"|grep -v "grep"|awk '{print $2}')
          o_pid=$(ps -ef | grep "${output_conf}"|grep -v "grep"|awk '{print $2}')
      }
      
      function _start(){
          getPid
          [ -n "$i_pid" ] && { echo "[start] ${start_command} -f ${conf_file} is already unning,exit";exit; }
          ${start_command} -f ${conf_file} >> ${log_input_path} 2>&1 & 
          [ $? != 0 ] && { echo "[start] Running ${start_command} -f ${conf_file} Error";exit; }
          echo "[startBase] Config file:${start_command} ${conf_file}"
      
          [ -n "$o_pid" ] && { echo "[start] ${start_command} -f ${output_conf} is already unning,exit";exit; }
          for i in $(seq ${works});do
              ${start_command} -f ${output_conf} >> ${log_path} 2>&1 &
          done
          [ $? != 0 ] && { echo "[start] Running ${start_command} -f ${output_conf} Error";exit; }
          echo "[startToElastic] Config file:${start_command} ${output_conf}"
      }
      
      function _stop(){
          getPid
          for i in ${i_pid[@]}
          do
              kill -9 $i || echo "[stop] Stop php-fpm Error"
              sleep 1 && echo "[stop] ${start_command} pid:$i stoped"
          done
      
          for i in ${o_pid[@]}
          do
              kill -9 $i || echo "[stop] Stop php-fpm Error"
              sleep 1 && echo "[stop] ${start_command} pid:$i stoped"
          done
          sleep 1
      }
      
      function _check(){
          getPid
          if [ ! -n "$i_pid" ];then
              echo "[check] ${start_command} -f ${conf_file} is already stoped"
          else
              for i in ${i_pid[@]}
              do
                  echo "[check] ${start_command} -f ${conf_file} is running,pid is $i"
              done
          fi
      
          if [ ! -n "$o_pid" ];then
              echo "[check] ${start_command} -f ${output_conf} is already stoped"
          else
              for i in ${o_pid[@]}
              do
                  echo "[check] ${start_command} -f ${output_conf} is running,pid is $i"
              done
          fi
      }
      
      function manager()
      {
          case "$1" in
          start)
              _start
              _check
              ;;
          stop)
              _stop
              _check
              ;;
          check)
              _check
              ;;
          restart)
              _check
              _stop
              _start
              _check
              ;;
          *)
              printf "Arguments are error!You only set: start|check|stop|restart"
              ;;
          esac
      }
      
      conf
      if [ "$#" -ne "1" ];then
          echo ""
          echo "Scripts need parameters,parameters=1"
          echo "For example:"
          echo "/etc/init.d/${script_name} startAll|startBase|startToElastic|stop|check|restart" 
          echo "start | 啟動需要啟動的進程"
          echo ""
          exit 1
      fi
      
      ctrl=$1 && manager ${ctrl}
      

      啟動logstash

      $systemctl start logstash
      

      七、安裝logstash客戶端logstash-forwarder發(fā)送日志

      1 在需要收集的服務器上面安裝客戶端,收集日志后通過TCP協議傳輸過去

      這里我隨便選擇一臺服務器,例如web1
      $rpm -ivh logstash-forwarder-0.4.0-1.x86_64.rpm
      

      2 修改默認配置文件

      vim /etc/logstash-forwarder.conf
      
      #找到"network",在此作用域中修改
      "servers": [ "10.26.215.116:5043" ],
      "ssl ca": "/etc/pki/tls/certs/logstash-forwarder.crt",
      "timeout": 15
      
      #找到"files"在此作用域中修改
      "files": [
          {
            "paths": [ "/var/log/message.log"],
            "fields": { "type": "logstash" }
          },
          {
            "paths": [ "/data/log/nginx/access.log"],
            "fields": { "type": "web1_nginx" } 
          }
      ]

      3 將elk1服務器的/etc/pki/tls/certs/logstash-forwarder.crt復制到web1

      4 啟動logstash-forwarder

      $/etc/init.d/logstash-forwarder start
      

      八、安裝并配置nginx用于http訪問

      1 nginx安裝

      $sudo yum -y install epel-release
      $sudo yum -y install nginx httpd-tools
      

      2 設置用于http訪問的權限

      #創(chuàng)建kibanaadmin用戶,這里會讓你輸入密碼,比如輸入123
      $sudo htpasswd -c /etc/nginx/htpasswd.users kibanaadmin
      

      3 nginx配置

      $vim /etc/nginx/nginx.conf

      include /etc/nginx/conf.d/*.conf;

      $vim /etc/nginx/conf.d/kibana.conf

      server {
          listen 80;
      
          server_name ;
      
          auth_basic "Restricted Access";
          auth_basic_user_file /etc/nginx/htpasswd.users;
      
          location / {
              proxy_pass http://localhost:5601;
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection 'upgrade';
              proxy_set_header Host $host;
              proxy_cache_bypass $http_upgrade;        
          }
      }

      啟動nginx

      $sudo systemctl start nginx
      $sudo systemctl enable nginx
      

      校驗各服務是否正常

      我們安裝好了elk服務,但是如何知道是否安裝正確,如何知道數據是否進行了正確傳輸流向呢
      下面就說下幾個檢查點

      一、logstash檢查

      1 查看logstash-forwarder是否發(fā)送日志給logstash服務

      [root@test]# tail -f /var/log/logstash-forwarder/logstash-forwarder.err 
      2016/12/01 21:22:00.856750 Registrar: processing 116 events
      2016/12/01 21:22:05.877525 Registrar: processing 100 events
      # 看到這種就表示連接成功并發(fā)送給服務端

      2 檢查logstash服務端日志是否異常

      查看input收集日志情況

      $tail -f /var/log/logstash_input.log
      {:timestamp=>"2016-12-01T15:54:55.113000+0800", :message=>"Pipeline main started"}
      
      #此處是寫入到redis的日志文件,更詳細的我們可以登錄redis更直觀查看是否有數據
      $redis-cli -h IP -p 6379
      10.24.245.1:6379> LLEN "logstash:redis"
      (integer) 10
      10.24.245.1:6379> LRANGE "logstash:redis" 1 10  #查看具體內容

      查看output連接elasticsearch建立索引情況

      $tail -f /var/log/logstash_output.log
      {:timestamp=>"2016-12-01T15:54:55.113000+0800", :message=>"Pipeline main started"}
      {:timestamp=>"2016-12-01T15:54:57.095000+0800", :message=>"Pipeline main started"}
      
      此處的日志很少,因為我們關閉了處理的詳細日志,我們可以通過兩種方式來查看詳細內容
      (1)修改配置文件
      vim /etc/logstash/conf2.d/redis-output-bbs.conf
      
      # 這行打開,這樣就能在日志里面查看更詳細的信息
      stdout { codec => rubydebug }  
      
      (2)手動啟動進程,并調試打印在屏幕
      /opt/logstash/bin/logstash -f /etc/logstash/conf2.d/redis-output-bbs.conf -vv
      

      二、查看elasticsearch是否建立索引

      1 查看日志

      tail -f /data/elasticsearch/log/elasticsearch.log
      

      2 進入elasticsearch數據索引目錄,查看是否有索引被創(chuàng)建

      $ll -h /data/elasticsearch/elasticsearch/nodes/0/indices/
      

      三、檢查kibana

      1 可以在命令行直接啟動,查看是否有報錯信息

      $/opt/kibana/bin/kibana

      2 http訪問kibana,http://

      綁定hosts
      Your_ip  example.com

      圖片描述

      圖片描述

      相關優(yōu)化

      這里提到優(yōu)化主要還是針對單臺服務器性能不能滿足業(yè)務需求和盡可能的將服務器處理日志的能力發(fā)揮到最大,如日志量比較大時

      由于elk本來就是分布式集群日志分析系統,因此可以將各個功能獨立出來,單獨服務器運行,避免相互影響

      1 關于redis
      筆者實驗中,先后將各個功能獨立出來,其中redis對性能的相互影響最大,因為redis用作消息隊列,又是單進程,因此對既讀又寫時候有瓶頸,且在日志量處理不過來的時候,會堆積到redis里面,所以跟elk放到一起容易導致oom和內存爭搶,最要命的是經常導致I/O等待
      最后的解決方式:(1)將redis單獨運行在一臺服務器(2)業(yè)務隔離,不同業(yè)務日志放入不同的redis實例,多實例多通道充分利用服務器性能

      2 關于logstash
      logstash在讀取收集并寫入redis方面貌似并沒有太大壓力,筆者開啟了一個socket用于接收日志,測試中并發(fā)寫入redis很快,1W條/s的日志量應該都沒有問題,就算日志量比較大,可以開多個socket分開傳輸

      3 關于elasticsearch
      elk一般用于大量日志分析,因此就不得不做集群,而日志的索引建立查詢等操作最終都要回到elasticsearch這里,這會導致它壓力非常大,集群可以擁有更好的處理能力,elasticsearch集群非常簡單,只需要簡單的配置即可

      在主節(jié)點設置

      $vim /etc/elasticsearch/elasticsearch.yml
      
      node.name: node-1
      node.master: true
      node.data: true
      
      #手動發(fā)現節(jié)點,可以填寫多個節(jié)點
      discovery.zen.ping.unicast.hosts: [elk1, elk2] 
      

      在從節(jié)點配置

      $vim /etc/elasticsearch/elasticsearch.yml
      
      node.name: node-1
      node.master: false
      node.data: true
      

      參考:

      http://www./articl... elasticsearch配置
      https://www./guide/... logstash官方文檔
      https://www./guide/... elasticsearch官方文檔

        本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯系方式、誘導購買等信息,謹防詐騙。如發(fā)現有害或侵權內容,請點擊一鍵舉報。
        轉藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多