首页 > 其他分享 >[转帖]ldap配置系列三:grafana集成ldap

[转帖]ldap配置系列三:grafana集成ldap

时间:2024-05-09 09:05:34浏览次数:31  
标签:linuxpanda dc grafana 转帖 tech ldap ou

https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_liunx_51_ldap_for_grafana.html

grafana的简介

 grafana是一个类似kibana的东西,是对来自各种数据源的数据进行实时展示的平台,拥有这牛逼的外观。给一个官方的demo体验地址: https://play.grafana.org/d/000000012/grafana-play-home?orgId=1

这里提供一个demo截图。

grafana的安装

grfana安装的官方参考: http://docs.grafana.org/installation/rpm/

复制代码
[root@VM_0_15_centos ~]# sudo yum install https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.1.4-1.x86_64.rpm
[root@VM_0_15_centos ~]# rpm -ql grafana |grep /etc
/etc/grafana
/etc/init.d/grafana-server
/etc/sysconfig/grafana-server

[root@VM_0_15_centos ~]# systemctl start grafana-server
[root@VM_0_15_centos ~]# systemctl status grafana-server

[root@VM_0_15_centos ~]# firewall-cmd --permanent  --add-port=3000/tcp
success
[root@VM_0_15_centos ~]# firewall-cmd --reload 
success

# 添加域名grafana.linuxpanda.tech 
# web访问下grafana.linuxpanda.tech:3000 

复制代码

主界面如下: 

 

默认的用户名和密码都是admin。

ldap用户组和用户创建

如果没有ldap服务,可以参考: https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_liunx_52_ldap.html

这里我们使用 ldapadmin.exe 这个小软件连接到ldap服务, 在group这个ou里面添加一个grafana的ou,然后在grafana这个ou里面添加3个组, 对应管理,编辑和预览。

创建三个用户test01,test02,test03 ,设置密码为oracle, 让其分别属于三个不同的组,方便后续的测试。

ldap配置文件

grafana的ldap配置官方参考: http://docs.grafana.org/installation/ldap/

grafana.ini配置

复制代码
[root@VM_0_15_centos ~]# cd /etc/grafana/
[root@VM_0_15_centos grafana]# ll
total 24
-rw-r----- 1 root grafana 13655 Sep  5 21:39 grafana.ini
-rw-r----- 1 root grafana  3468 Sep  5 21:39 ldap.toml
drwxr-xr-x 4 root grafana  4096 Sep  5 21:39 provisioning
[root@VM_0_15_centos grafana]# cp ldap.toml  ldap.toml.default 
[root@VM_0_15_centos grafana]# cp grafana.ini grafana.ini.default
[root@VM_0_15_centos grafana]# chown grafana.grafana grafana.ini ldap.toml  [root@VM_0_15_centos grafana]# vim grafana.ini # 这个文件修改2项,log的其实没有必要,但是ldap调试比较麻烦,建议先开启debug,等配置好ldap后,在修改回去info级别。 [auth.ldap] enabled = true [log] level = debug
复制代码

配置前需要先做几个查询

查询所有用户

复制代码
[root@VM_0_15_centos ~]# ldapsearch  -LLL -w oracle   -x -H ldap://ldap.linuxpanda.tech -D"cn=admin,dc=linuxpanda,dc=tech" -b "ou=people,dc=linuxpanda,dc=tech" 
dn: ou=people,dc=linuxpanda,dc=tech
objectClass: organizationalUnit
ou: user
ou: people

dn: uid=test01,ou=people,dc=linuxpanda,dc=tech
objectClass: posixAccount
objectClass: top
objectClass: inetOrgPerson
gidNumber: 0
givenName: test01
sn: test01
displayName:: 5rWL6K+VMQ==
uid: test01
homeDirectory: /home/test01
loginShell: /bin/bash
mail: [email protected]
cn:: 5rWL6K+VMQ==
uidNumber: 55545
userPassword:: e1NIQX1ReE5rdGtVUHhIek52Mm9pQmQvYkc2NjNsQkk9

dn: uid=test02,ou=people,dc=linuxpanda,dc=tech
objectClass: posixAccount
objectClass: top
objectClass: inetOrgPerson
gidNumber: 0
givenName: test02
sn: test02
displayName:: 5rWL6K+VMg==
uid: test02
homeDirectory: /home/test02
loginShell: /bin/bash
mail: [email protected]
cn:: 5rWL6K+VMg==
uidNumber: 50880
userPassword:: e1NIQX1ReE5rdGtVUHhIek52Mm9pQmQvYkc2NjNsQkk9

dn: uid=test03,ou=people,dc=linuxpanda,dc=tech
objectClass: posixAccount
objectClass: top
objectClass: inetOrgPerson
gidNumber: 0
givenName: test03
sn: test03
displayName:: 5rWL6K+VMw==
uid: test03
homeDirectory: /home/test03
loginShell: /bin/bash
mail: [email protected]
cn:: 5rWL6K+VMw==
uidNumber: 46507
userPassword:: e1NIQX1ReE5rdGtVUHhIek52Mm9pQmQvYkc2NjNsQkk9
复制代码

查询特定用户

复制代码
[root@VM_0_15_centos ~]# ldapsearch  -LLL -w oracle   -x -H ldap://ldap.linuxpanda.tech -D"cn=admin,dc=linuxpanda,dc=tech" -b "ou=people,dc=linuxpanda,dc=tech" "(uid=test01)"   
dn: uid=test01,ou=people,dc=linuxpanda,dc=tech
objectClass: posixAccount
objectClass: top
objectClass: inetOrgPerson
gidNumber: 0
givenName: test01
sn: test01
displayName:: 5rWL6K+VMQ==
uid: test01
homeDirectory: /home/test01
loginShell: /bin/bash
mail: [email protected]
cn:: 5rWL6K+VMQ==
uidNumber: 55545
userPassword:: e1NIQX1ReE5rdGtVUHhIek52Mm9pQmQvYkc2NjNsQkk9
复制代码

查询所有组

复制代码
[root@VM_0_15_centos grafana]# ldapsearch  -LLL -w oracle   -x -H ldap://ldap.linuxpanda.tech -D"cn=admin,dc=linuxpanda,dc=tech" -b "ou=grafana,ou=group,dc=linuxpanda,dc=tech"  
dn: ou=grafana,ou=group,dc=linuxpanda,dc=tech
objectClass: top
objectClass: organizationalUnit
ou: grafana

dn: cn=grafana-admins,ou=grafana,ou=group,dc=linuxpanda,dc=tech
objectClass: posixGroup
objectClass: top
cn: grafana-admins
gidNumber: 49004
memberUid: test01

dn: cn=grafana-editors,ou=grafana,ou=group,dc=linuxpanda,dc=tech
objectClass: posixGroup
objectClass: top
gidNumber: 34366
cn: grafana-editors
memberUid: test02

dn: cn=grafana-viewers,ou=grafana,ou=group,dc=linuxpanda,dc=tech
objectClass: posixGroup
objectClass: top
cn: grafana-viewers
gidNumber: 25527
memberUid: test03
复制代码

 查询用户所在的组

复制代码
[root@VM_0_15_centos grafana]# ldapsearch  -LLL -w oracle   -x -H ldap://ldap.linuxpanda.tech -D"cn=admin,dc=linuxpanda,dc=tech" -b "ou=grafana,ou=group,dc=linuxpanda,dc=tech"   "(&(objectClass=posixGroup)(memberUid=test03))"
dn: cn=grafana-viewers,ou=grafana,ou=group,dc=linuxpanda,dc=tech
objectClass: posixGroup
objectClass: top
cn: grafana-viewers
gidNumber: 25527
memberUid: test03
复制代码

修改ldap.toml文件

复制代码
[root@VM_0_15_centos grafana]# vim ldap.toml
[root@VM_0_15_centos grafana]# cat ldap.toml

[[servers]]
host = "ldap.linuxpanda.tech"
port = 389
use_ssl = false
start_tls = false
ssl_skip_verify = false

bind_dn = "cn=admin,dc=linuxpanda,dc=tech"
bind_password = 'oracle'

search_filter = "(uid=%s)"

search_base_dns = ["ou=people,dc=linuxpanda,dc=tech"]

group_search_filter = "(&(objectClass=posixGroup)(memberUid=%s))"
group_search_base_dns = ["ou=grafana,ou=group,dc=linuxpanda,dc=tech"]
[servers.attributes]
name = "givenName"
surname = "sn"
username = "uid"
#member_of = "memberOf"
member_of="cn"
email =  "mail"

[[servers.group_mappings]]
group_dn = "grafana-admins"
org_role = "Admin"

[[servers.group_mappings]]
group_dn = "grafana-editors"
org_role = "Editor"

[[servers.group_mappings]]
group_dn = "grafana-viewers"
#group_dn = "*"
org_role = "Viewer"
复制代码

主要配置说明

host:就是指定你的ldap服务器,可以指定多个,需要分隔符。

port:你的ldap服务器的监听的端口。

bind_dn: 你需要特定ou的管理员账号,我这里使用了域管理者。

bind_password: 上面账号的密码。

search_filter:  用户搜索的过滤表达式,配合search_base_dns。

search_base_dns: 用户搜索的范围,这里在people这个ou里面搜索所有的用户,需要配合search_filter来完成用户的过滤。

group_search_filter: 组搜索的过滤表达式,配合group_search_base_dns。

group_search_base_dns: 指定组搜索的范围,我们的grafana这个ou里面设置了3个组。

servers.attributes: 这个主要是用户获取特定提取到的用户条目有特定字段的提取, username从查询的用户信息取特定字段值作为grafana的用户名, 

                              member_of 代表,根据group_search_base_dns和group_search_filter 得到特定的一个组后,取那个字段作为组名字。 这个取到的结果需要和下面的映射保持一致。

                              email代表取特定用户的mail字段作为grafana用户的email信息。

servers_group_mappings: 这个是用于定义ldap用户组和grafana角色组的映射关系的, 上面member_of ,group_search_base_dns和group_search_filter 这三个条件可以获取到ldap的组名,这里要和三个条件获取的一致。

 

一张图说清楚

修改完毕重启服务进行测试。

最终结果图

修改grafana的日志级别为info。

 

 

调试

 判定ldap服务是否可通

[root@VM_0_15_centos grafana]# telnet ldap.linuxpanda.tech 389
Trying 58.87.98.84...
Connected to ldap.linuxpanda.tech.
Escape character is '^]'.

确定开启了ldap配置

检查grafana.ini文件确认有ldap=true启用的,默认去掉注释还是false,注意啦。

关注日志信息

主要的日志有2个,一个是grafana的日志, 一个是ldap的日志。

[root@VM_0_15_centos grafana]# journalctl -f  
Sep 05 22:51:50 VM_0_15_centos grafana-server[12052]: t=2018-09-05T22:51:50+0800 lvl=dbug msg="Ldap User found" logger=ldap info="(*login.LdapUserInfo)(0xc420030fc0)({\n DN: (string) (len=42) \"uid=test01,ou=people,dc=linuxpanda,dc=tech\",\n FirstName: (string) (len=6) \"test01\",\n LastName: (string) (len=6) \"test01\",\n Username: (string) (len=22) \"[email protected]\",\n Email: (string) (len=22) \"[email protected]\",\n MemberOf: ([]string) <nil>\n})\n"
Sep 05 22:51:50 VM_0_15_centos grafana-server[12052]: t=2018-09-05T22:51:50+0800 lvl=dbug msg="Updating last user_seen_at" logger=context userId=2 orgId=1 [email protected] user_id=2
[root@VM_0_15_centos grafana]# tail -f /var/log/slapd/slapd.log 

参考 

grafana官方帮助文档: http://docs.grafana.org/

标签:linuxpanda,dc,grafana,转帖,tech,ldap,ou
From: https://www.cnblogs.com/jinanxiaolaohu/p/15768145.html

相关文章

  • [转帖]Nginx流量拷贝 - 运维笔记
    https://www.cnblogs.com/kevingrace/p/14001080.html 一、Nginx的ngx_http_mirror_module模块实现流量复制介绍Nginx专门提供了ngx_http_mirror_module模块,用来实现流量拷贝。将生产环境的流量拷贝到预上线环境或测试环境,这样做有很多好处:可以验证功能是否正常,以及服务......
  • [转帖]CPUpower的处理
    用cpupower工具修改,但是在修改过程中会遇到ERROR:[root@wyx~]#cpupowerfrequency-set-f1.6GSettingcpu:0Errorsettingnewvalues.Commonerrors:-Doyouhaveproperadministrationrights?(super-user?)-Isthegovernoryourequestedavailableandmodprobe......
  • [转帖]Release Schedule of Current Database Releases (Doc ID 742060.1)
    https://support.oracle.com/knowledge/Oracle%20Database%20Products/742060_1.html APPLIESTO:OracleDatabase-StandardEdition-Version11.2.0.4andlaterOracleDatabaseCloudService-VersionN/AandlaterGen2ExadataCloudatCustomer-VersionAl......
  • [转帖]【MySQL】字段名与关键字冲突解决办法
    https://www.jianshu.com/p/50e59feb3e83   首先,不推荐使用MySQL的关键词来作为字段名,但是有时候的确没有注意,或者因为之前就这么写了,没办法,那怎么办呢?方法1,改字段名,改了肯定就没问题了。这个就不细说了。方法2,使用引号`来处理。  下面就详细的说明一下怎样使用方法......
  • [转帖]Oracle Exadata 学习笔记之核心特性Part1
    https://www.cnblogs.com/jyzhao/p/12257649.html#2 近年来,国内众多厂商都有一体机的产品,不过更多都是围绕硬件本身的堆砌和优化,那么这些产品和Oracle一体机最大的区别在哪里呢?最近读了李亚的《OracleExadata技术详解》,系统的了解了Exadata的一些核心特性,我个人认为这些特......
  • [转帖]AMD 第四代宵龙价格情况
    OfferingUnmatchedPerformance,LeadershipEnergyEfficiencyandNext-GenerationArchitecture,AMDBrings4thGenAMDEPYC™ProcessorstoTheModernDataCenter —NewAMDEPYC™processorsaretheworld’sfastestandmostenergyefficient,......
  • [转帖]数据库系列之简要对比下GaussDB和OpenGauss数据库
    GaussDB作为一款企业级的数据库产品,和开源数据库OpenGauss之间又是什么样的关系,刚开始接触的时候是一头雾水,因此本文简要对比下二者的区别,以加深了解。1、GaussDB和OpenGauss数据库简要对比GaussDB是华为基于PostgreSQL数据库内核创新研发的企业级分布式关系型数据库,支持......
  • [转帖]Unnecessary GCLocker-initiated young GCs
    https://www.cnblogs.com/zhangshengdong/p/9196128.html DetailsType: BugResolution:FixedPriority: P3FixVersion/s:14AffectsVersion/s:7u60, 8, 8u20, 8u40, 9, 11, 13Component/s:hotspotLabels:8u20-defer-SQE-OK 8u20......
  • [转帖]深入JVM - Code Cache内存池
    https://juejin.cn/post/6985913007142354958 1.本文内容本文简要介绍JVM的CodeCache(本地代码缓存池)。2.CodeCache简要介绍简单来说,JVM会将字节码编译为本地机器码,并使用CodeCache来保存。每一个可执行的本地代码块,称为一个nmethod。nmethod可能对应一个......
  • [转帖]sysbench基准测试
    https://www.cnblogs.com/shixiuxian/p/11229822.html 一、sysbench压力测试工具简介: sysbench是一个开源的、模块化的、跨平台的多线程性能测试工具,可以用来进行CPU、内存、磁盘I/O、线程、数据库的性能测试。目前支持的数据库有MySQL、Oracle和PostgreSQL。以下操作都......