您的位置:首页 > 运维架构 > Nginx

Kibana使用Nginx代理验证

2017-12-12 17:59 162 查看

需求实现

在使用ELK进行日志统计的时候,由于Kibana自身并没有身份验证的功能,任何人只要知道链接地址就可以正常登录到Kibana控制界面。由于日常的查询,添加日志和删除日志都是在同一个web 中进行,这样就有极高的安全隐患。任何人都有权限对其进行修改。
为了避免这一问题,可以使用Nginx的验证功能来代理Kibana.

安装配置Kibana

在官方下载对应的RPM包进行安装,链接:https://www.elastic.co/downloads/kibana
这里以kibana-5.6.5-x86_64为例,上传kibana-5.6.5-x86_64.rpm包到主机:

[root@node1 ~]# yum install java-1.8.0-openjdk-devel -y
[root@node1 ~]# yum install kibana-5.6.5-x86_64.rpm  -y

配置Kibana:

[root@node1 ~]# grep "^[a-z]" /etc/kibana/kibana.yml
server.port: 5601
server.host: "192.168.20.60"  # 端口监听地址,此时配置用于测试
elasticsearch.url: "http://192.168.20.61:9200"

启动:

[root@node1 ~]# systemctl start kibana
[root@node1 ~]# netstat -lntp|grep 5601
tcp        0      0 192.168.20.60:5601      0.0.0.0:*               LISTEN      5897/node

使用5601端口访问网页正常,将本地监听IP改为127.0.0.1,只通过本地的nginx访问,禁止外部直接访问Kibana:

[root@node1 ~]# grep "^[a-z]" /etc/kibana/kibana.yml
server.port: 5601
server.host: "127.0.0.1"
elasticsearch.url: "http://192.168.20.61:9200"

重启Kibana,查看本地监听端口:

[root@node1 ~]# systemctl restart kibana
[root@node1 ~]# netstat -lntp|grep 5601
tcp        0      0 127.0.0.1:5601          0.0.0.0:*               LISTEN      6034/node

安装配置Nginx

直接使用yum的方式安装:

[root@node1 ~]# yum install nginx -y

添加配置文件:

[root@node1 ~]# vim /etc/nginx/conf.d/kibana.conf
#添加如下内容

upstream kibana_server {
server  127.0.0.1:5601 weight=1 max_fails=3  fail_timeout=60;
}

server {
listen 80;
server_name 192.168.20.60;
auth_basic "Restricted Access";      # 验证
auth_basic_user_file /etc/nginx/htpasswd.users;             # 验证文件
location / {
proxy_pass http://kibana_server; 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;
}
}

配置验证

创建验证文件授权,需要先安装httpd-tools工具:

[root@node1 ~]# yum install -y  httpd-tools
[root@node1 ~]# htpasswd -bc /etc/nginx/htpasswd.users admin password # 创建验证文件,并添加用户
Adding password for user admin
[root@node1 ~]# cat /etc/nginx/htpasswd.users
admin:$apr1$9AMiN0Ud$Q95cyrPix89nw3h3d4cwo0

如果要添加多个用户密码可以使用如下命令:

[root@node1 ~]# htpasswd -b /etc/nginx/htpasswd.users try trying
Adding password for user try
[root@node1 ~]# cat /etc/nginx/htpasswd.users
admin:$apr1$9AMiN0Ud$Q95cyrPix89nw3h3d4cwo0
try:$apr1$s5QCG32f$9KQFhsiw.PYmmmst.5r/q1

启动nginx:

[root@node1 ~]# nginx -t
[root@node1 ~]# systemctl start nginx
[root@node1 ~]# netstat -lntp|grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      6085/nginx: master

再次使用IP登录时,就需要输入用户名和密码。
可以通过使用
status
查看系统的当前状态:
http://192.168.20.60/status
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Kibana