部署完ELK後,可以直接在瀏覽器進入kibana頁面進行訪問,而這樣對一些重要數據來說是不安全的,可以利用密碼驗證來設置權限訪問。
環境
192.168.2.112 kibana
192.168.2.119 nginx
在kibana所在的服務器上安裝nginx服務,利用nginx的轉發指令實現。
安裝好nginx後,進入nginx配置頁面,修改如下:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#添加upstream模塊
upstream kibana_web {
server 192.168.2.112:5601 weight=1 max_fails=2 fail_timeout=30s;
}
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
proxy_set_header Host $host;
proxy_pass http://kibana_web;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
開啓nginx服務,在瀏覽器輸入ip192.168.2.119後如下圖所示
添加權限認證
在nginx.conf下的location /模塊下添加
auth_basic "The Kibana Monitor Center";
auth_basic_user_file /usr/local/nginx/html/.htpasswd;
通過加密工具htpasswd生成賬號和密碼
[root@leeclient html]# htpasswd -c /usr/local/nginx/html/.htpasswd admin
New password:
Re-type new password:
Adding password for user admin
重啓nginx,瀏覽器輸入ip後顯示如下圖
輸入賬號密碼後就可以進入kibana頁面