ELFK日誌平臺入門3---Kibana搭建

ELFK日誌平臺入門1---架構設計

ELFK日誌平臺入門2---Elasticseach集羣搭建   

ELFK日誌平臺入門3---Kibana搭建

ELFK日誌平臺入門4---Kafka集羣搭建

ELFK日誌平臺入門5---Logstash+Filebeat集羣搭建

這個章節我們介紹下Kibana搭建。

 1、Kibana部署

  • 解壓Kibana安裝包:
# tar zxf kibana-6.2.4-linux-x86_64.tar.gz && mv kibana-6.2.4-linux-x86_64 /usr/local/kibana
  •  修改配置:
# vim /usr/local/kibana/config/kibana.yml

server.port: 5601               #監聽端口
server.host: "0.0.0.0"              #監聽IP
elasticsearch.hosts: ["http://192.168.0.0:9200","http://192.168.0.1:9200","http://192.168.0.2:9200"]                #集羣es地址
logging.dest: /usr/local/kibana/logs/kibana.log                 #日誌路徑
kibana.index: ".kibana"                 #默認索引

# mkdir /usr/local/kibana/logs && touch /usr/local/kibana/logs/kibana.log
  • 啓動kibana:
# /usr/local/kibana/bin/kibana &
  • 配置成kibana服務:
# vim /etc/default/kibana

user="elk"
group="elk"
chroot="/"
chdir="/"
nice=""


# If this is set to 1, then when `stop` is called, if the process has
# not exited within a reasonable time, SIGKILL will be sent next.
# The default behavior is to simply log a message "program stop failed; still running"
KILL_ON_STOP_TIMEOUT=0

       新增服務文件:

# vim /etc/systemd/system/kibana.service

# vim /etc/sysconfig/elasticsearch
 
################################
# Elasticsearch
################################
 
# Elasticsearch home directory
#ES_HOME=/usr/share/elasticsearch
ES_HOME=/usr/local/elasticsearch
 
# Elasticsearch Java path
#JAVA_HOME=
JAVA_HOME=/usr/local/jdk
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib
 
# Elasticsearch configuration directory
#ES_PATH_CONF=/etc/elasticsearch
ES_PATH_CONF=/usr/local/elasticsearch/config
 
# Elasticsearch PID directory
#PID_DIR=/var/run/elasticsearch
PID_DIR=/usr/local/elasticsearch/run
 
# Additional Java OPTS
#ES_JAVA_OPTS=
 
# Configure restart on package upgrade (true, every other setting will lead to not restarting)
#RESTART_ON_UPGRADE=true
 
################################
# Elasticsearch service
################################
 
# SysV init.d
#
# The number of seconds to wait before checking if Elasticsearch started successfully as a daemon process
ES_STARTUP_SLEEP_TIME=5
 
################################
# System properties
################################
 
# Specifies the maximum file descriptor number that can be opened by this process
# When using Systemd, this setting is ignored and the LimitNOFILE defined in
# /usr/lib/systemd/system/elasticsearch.service takes precedence
#MAX_OPEN_FILES=65535
 
# The maximum number of bytes of memory that may be locked into RAM
# Set to "unlimited" if you use the 'bootstrap.memory_lock: true' option
# in elasticsearch.yml.
# When using systemd, LimitMEMLOCK must be set in a unit file such as
# /etc/systemd/system/elasticsearch.service.d/override.conf.
#MAX_LOCKED_MEMORY=unlimited
 
# Maximum number of VMA (Virtual Memory Areas) a process can own
# When using Systemd, this setting is ignored and the 'vm.max_map_count'
# property is set at boot time in /usr/lib/sysctl.d/elasticsearch.conf
#MAX_MAP_COUNT=262144

       管理服務:

# chown -R elk:elk /usr/local/kibana

# systemctl daemon-reload

# systemctl enable kibana

# systemctl start kibana                #先kill之前的kibana進程
  •  瀏覽器訪問(Kibana默認端口5601)

 2、Kibana開啓密碼登錄

   因爲Kibana部署好後,不需要賬號密碼可以直接登錄訪問界面,這樣對於生產環境而言,安全性較差,那如何提供設置Kibana賬號密碼登錄呢?這裏提供一種方案:

   nginx提供ngx_http_auth_basic_module模塊,實現代理之後權限控制。那下面看下如何配置(默認已安裝好nginx,這裏不做介紹):

  • 創建用戶名密碼文件:
# htpasswd -b -c /usr/local/nginx/conf/passwd.db user 123456
  • nginx增加auth_basic和auth_basic_user_file兩項配置: 
# vi nginx.conf

server {
        listen       5601;
        server_name  127.0.0.1;

        location / {
            auth_basic "secret";
            auth_basic_user_file /usr/local/nginx/db/passwd.db;
            proxy_pass  http://*.*.*.*:5601;                           #kibana訪問地址
            proxy_set_header Host $host:5601;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Via "nginx";
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         }

    }
  • 重新加載nginx配置:
# ./nginx -s reload
  • 瀏覽器訪問 :

至此,Kibana已部署完成,如果需要集羣,可以自己在nginx配置。

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