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

kibana安全——设置访问账号密码

2018-12-24 14:47 1326 查看

前言

kibana默认没有访问的权限控制,如果需要设置访问的账号密码,可以使用nginx配置代理来发布kibana。
本次实验基于《海量日志下的日志架构优化:filebeat+logstash+kafka+ELK》,kibana是部署在test102服务器上,因此在test102服务器上安装一个nginx来发布kibana,并设置用户名密码验证。

实验演示

1、在test102上安装nginx

创建安装nginx的yum文件:

[root@test102 ~]# cat /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
[root@test102 ~]#

安装nginx:

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

2、修改nginx配置,使用nginx发布kibana

修改配置文件/etc/nginx/conf.d/default.conf
将/etc/nginx/conf.d/default.conf原有的

location / {
root   /usr/share/nginx/html;
index  index.html index.htm;
}

改成:

location / {
proxy_pass http://10.0.0.102:5601$request_uri;
}

然后启动nginx,访问http://10.0.0.102 就是kibana的界面了(用nginx发布,就不需要带5601端口访问了):

3、修改nginx配置,增加登录验证

修改配置文件/etc/nginx/conf.d/default.conf,增加两行登录验证配置:

location / {
proxy_pass http://10.0.0.102:5601$request_uri;

#加上下面两行内容:
auth_basic "登陆验证";
auth_basic_user_file /etc/nginx/htpasswd;   #/etc/nginx/htpasswd是密码文件,路径自定义
}

然后使用htpasswd命令生成密码文件:

[root@test102 conf.d]# htpasswd -cm /etc/nginx/htpasswd crystal     #/etc/nginx/htpasswd就是配置文件里面配置的密码文件,crystal就是用户名
New password:     #输入密码
Re-type new password:     #再次输入密码,回车
Adding password for user crystal

生成后,查看密码文件/etc/nginx/htpasswd,已经OK:

[root@test102 conf.d]# cat /etc/nginx/htpasswd
crystal:$apr1$Xxm/x/fn$PVzP6RL2aQr1H89gf9wK.1
[root@test102 conf.d]#

重启nginx,再访问http://10.0.0.102 ,就提示输入用户名和密码登录了;

输入刚刚设置的用户名crystal和密码crystal,登录OK:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息