85.1 演示环境介绍
- CentOS版本为:6.5
- OpenLDAP版本为:2.4.40
85.2 操作演示
- OpenLDAP服务信息
- IP地址
- 186.31.7.186
- 186.31.9.33
- HOSTNAME
- ip-186-31-7-186.fayson.com
- cdh04.fayson.com
- IP地址
- 将186.31.7.186做为OpenLDAP的主节点,186.31.9.33做为OpenLDAP的备节点
- 均已安装OpenLDAP
1、添加测试用户及用户组
- 添加一个测试用户faysontest2,将faysontest2用户添加到faysontest2和faysontest3组中
- 编辑user_faysontest2.ldif文件:
- 用户的ldif文件中包含了用户默认的用户组faysontest2,在文件中使用gidNumber来添加依赖
- 编辑user_faysontest2.ldif文件:
[root@ip-186-31-7-186 openldap-ldif]# vim user_faysontest2.ldif
dn: uid=faysontest2,ou=People,dc=fayson,dc=com
uid: faysontest2
cn: faysontest2
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: {SSHA}KYgsfyI/uny0dKPNeMRNG54BdwV6KlWA
shadowLastChange: 17493
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 999
gidNumber: 999
homeDirectory: /home/faysontest2
- 编辑group_faysontest2.ldif文件:
- 在组的ldif文件中,faysontest3组条目下增加了memberUid: faysontest2来添加组和用户的依赖关系
[root@ip-186-31-7-186 openldap-ldif]# vim group_faysontest2.ldif
dn: cn=faysontest2,ou=Group,dc=fayson,dc=com
objectClass: posixGroup
objectClass: top
cn: faysontest2
userPassword: {SSHA}KYgsfyI/uny0dKPNeMRNG54BdwV6KlWA
gidNumber: 999
dn: cn=faysontest3,ou=Group,dc=fayson,dc=com
objectClass: posixGroup
objectClass: top
cn: faysontest3
userPassword: {SSHA}KYgsfyI/uny0dKPNeMRNG54BdwV6KlWA
gidNumber: 997
memberUid: faysontest2
- 将用户和用户组导入OpenLDAP
ldapadd -D "cn=Manager,dc=fayson,dc=com" -W -x -f group_faysontest2.ldif
ldapadd -D "cn=Manager,dc=fayson,dc=com" -W -x -f user_faysontest2.ldif
- 查看用户faysontest2的用户组
- 这里可以看到faysontest2用户包含了两个组faysontest2和faysontest3
[root@ip-186-31-7-186 openldap-ldif]# id faysontest2
uid=999(faysontest2) gid=998(Faysontest2) groups=998(faysontest2),997(faysontest3)
[root@ip-186-31-7-186 openldap-ldif]#
2、将用户添加到已有的组
- 查看faysontest现有的用户组
[root@ip-186-31-7-186 openldap-ldif]# id faysontest
uid=510(faysontest) gid=510(faysontest) groups=510(faysontest)
[root@ip-186-31-7-186 openldap-ldif]#
- 编辑update_group_faysontest3.ldif文件:
[root@ip-186-31-7-186 openldap-ldif]# vim update_group_faysontest3.ldif
dn: cn=faysontest3,ou=Group,dc=fayson,dc=com
changetype: modify
add: memberUid
memberUid: faysontest
memberUid: faysontest2
- 使用如下命令导入修改的ldif文件
ldapmodify -x -D "cn=Manager,dc=fayson,dc=com" -W -f update_group_faysontest3.ldif
- 查看faysontest用户是否在faysontest3组中
[root@ip-186-31-7-186 openldap-ldif]# id faysontest
uid=510(faysontest) gid=510(faysontest) groups=510(faysontest),997(faysontest3)
[root@ip-186-31-7-186 openldap-ldif]#
总结
- 如果需要用户拥有多个组,只需要在需要加入组的条目下增加一条记录memberUid: faysontest2,faysontest2即为你用户的uid
- 一个组条目下支持多个memberUid属性
大数据视频推荐:
CSDN
大数据语音推荐:
企业级大数据技术应用
大数据机器学习案例之推荐系统
自然语言处理
大数据基础
人工智能:深度学习入门到精通