1. 程式人生 > >ELK安裝使用

ELK安裝使用

6.42版本為例

一、安裝elasticsearch

1、下載https://www.elastic.co/downloads/past-releases/elasticsearch-6-4-2

2、修改配置檔案,結尾新增兩個配置

cd elasticsearch-6.4.2/config
vi elasticsearch.yml

server.host: 本機ip
http.cors.enabled: true
http.cors.allow-origin: "*"

3、啟動(不能用root使用者,必須新建立一個使用者並授權)

nohup ./bin/elasticsearch &

4、安裝ik(非必須)

1、安裝:
  ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.2/elasticsearch-analysis-ik-6.4.2.zip
2、啟動
  curl -H "Content-Type: application/json" -XPOST http://localhost:9200/_index/_doc/_mapping -d' { "properties": { "content": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word" } } }'

二、安裝kibana

1、下載https://www.elastic.co/downloads/past-releases/kibana-6-4-2

2、修改配置檔案

cd kibana-6.4.2-linux-x86_64/config
vi kibana.yml
server.host: 本機ip

3、kibana沒有許可權管理功能,可藉助nginx驗證許可權(非必須)

建立密碼檔案

yum install -y httpd
htpasswd -c /usr/local/nginx/db/passwd.db user

先安裝httpd, user是使用者名稱,接著輸入兩次一樣的密碼。然後配置到nginx中

server {
  listen       80;
  server_name localhost;
  location / {
     auth_basic "secret";
     auth_basic_user_file /usr/local/nginx/db/passwd.db;
     proxy_pass http://localhost:5601;
     proxy_set_header Host $host:5601;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header Via "nginx";
  }
}

auth_basic_user_file路徑是上面建立的密碼檔案

4、啟動

nohup ./bin/kibana &

三、安裝logstash

1、下載https://www.elastic.co/downloads/past-releases/logstash-6-4-2

2、建立配置檔案

cd logstash-6.4.2
mkdir conf_logs
cd conf_logs
vi test.conf
input {
     file {
        type => "log"
        path => "/Users/chenfenli/Log/haozhun/hz-model/*.log"
        start_position => "beginning"
    }
}
output {
  stdout {
   codec => rubydebug { }
  }
  elasticsearch {
    hosts => "localhost"
    index => "hz-log-%{+YYYY.MM.dd}"
  }
}

3、啟動

nohup ./bin/logstash -f conf_logs/test.conf &