Keycloak
- 先用docker容器部署一个Keycloak服务,可以参考以下网址:
https://hub.docker.com/r/jboss/keycloak
我简单搭一个马上可以用的服务,不考虑volume
docker run -d -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin jboss/keycloak
-
配置
2.1 新建Realm
2.2 新建Client
2.3 配置Client
2.3 拿secret
Client中点击Credentials把Secret拿出来,之后配置Grafana会用到。
2.4 新建用户
在Credentials中给用户设置密码,取消Temporary
Grafana
使用docker命令如下,因为之前有部署过,所以有挂载
sudo docker run \
-d \
--network host \
--name=grafana \
--restart=always \
-e "GF_SERVER_ROOT_URL=http://192.168.1.137:3000" -e "GF_SECURITY_ADMIN_PASSWORD=felix" \
-v grafana-storage:/var/lib/grafana \
-v /opt/monitor/grafana/plugins:/var/lib/grafana/plugins \
-v /opt/monitor/grafana/grafana.db:/var/lib/grafana/grafana.db \
-v /opt/monitor/grafana/logs:/var/log/grafana \
-v /opt/monitor/grafana/config/grafana.ini:/etc/grafana/grafana.ini \
grafana/grafana
修改配置文件如下
#################################### Generic OAuth ##########################
[auth.generic_oauth]
enabled = true
name = Signgle-Sign-On
allow_sign_up = true
client_id = grafana
client_secret = e7afec8e-1ba8-4730-811b-5af0b5e7a7f1
scopes = openid email name
auth_url = http://192.168.1.137:8081/auth/realms/Signgle-Sign-On/protocol/openid-connect/auth
token_url = http://192.168.1.137:8081/auth/realms/Signgle-Sign-On/protocol/openid-connect/token
;api_url =
;team_ids =
;allowed_organizations =
;tls_skip_verify_insecure = false
;tls_client_cert =
;tls_client_key =
;tls_client_ca =
; Set to true to enable sending client_id and client_secret via POST body instead of Basic authentication HTTP header
; This might be required if the OAuth provider is not RFC6749 compliant, only supporting credentials passed via POST payload
;send_client_credentials_via_post = false
重启容器,登录界面如下:
点击下边Sign in with Signgle-Sign-On,进入KeyCloak的验证
用我们刚刚在KeyCloak新建好的用户登录
这样就完成了Grafana和KeyCloak的集成,用户只需要在KeyCloak新建就可以了,不过目前测试下来发现,从Grafana退出登录,或者从KeyCloak踢掉session,都不影响另外一面。
想写一些东西分享,欢迎转载,请注明出处。
简书-板凳儿儿
https://www.jianshu.com/p/a538af117112