|
| 1 | +# LDAP 安装和配置 |
| 2 | + |
| 3 | + |
| 4 | +## LDAP 基本概念 |
| 5 | + |
| 6 | +- <https://segmentfault.com/a/1190000002607140> |
| 7 | +- <http://www.itdadao.com/articles/c15a1348510p0.html> |
| 8 | +- <http://blog.csdn.net/reblue520/article/details/51804162> |
| 9 | + |
| 10 | +## LDAP 服务器端安装 |
| 11 | + |
| 12 | +- 环境:CentOS 7.3 x64(为了方便,已经禁用了防火墙) |
| 13 | +- 常见服务端: |
| 14 | + - [OpenLDAP](http://www.openldap.org/) |
| 15 | +- 这里选择:OpenLDAP,安装(最新的是 2.4.40):`yum install -y openldap openldap-clients openldap-servers migrationtools` |
| 16 | +- 配置: |
| 17 | + - `cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG` |
| 18 | + - `chown ldap. /var/lib/ldap/DB_CONFIG` |
| 19 | +- 启动: |
| 20 | + - `systemctl start slapd` |
| 21 | + - `systemctl enable slapd` |
| 22 | +- 查看占用端口(默认用的是 389):`netstat -tlnp | grep slapd` |
| 23 | + |
| 24 | +### 设置OpenLDAP管理员密码 |
| 25 | + |
| 26 | +- 输入命令:`slappasswd`,重复输入两次明文密码后(我是:123456),我得到一个加密后密码(后面会用到):`{SSHA}YK8qBtlmEpjUiVEPyfmNNDALjBaUTasc` |
| 27 | +- 新建临时配置目录: |
| 28 | + - `mkdir /root/my_ldif ; cd /root/my_ldif` |
| 29 | + - `vim chrootpw.ldif`,添加如下内容: |
| 30 | + |
| 31 | +``` ini |
| 32 | +dn: olcDatabase={0}config,cn=config |
| 33 | +changetype: modify |
| 34 | +add: olcRootPW |
| 35 | +olcRootPW: {SSHA}YK8qBtlmEpjUiVEPyfmNNDALjBaUTasc |
| 36 | +``` |
| 37 | + |
| 38 | +- 添加刚刚写的配置(过程比较慢):`ldapadd -Y EXTERNAL -H ldapi:/// -f chrootpw.ldif ` |
| 39 | +- 导入默认的基础配置(过程比较慢):`for i in /etc/openldap/schema/*.ldif; do ldapadd -Y EXTERNAL -H ldapi:/// -f $i; done` |
| 40 | + |
| 41 | +### 修改默认的domain |
| 42 | + |
| 43 | +- 输入命令:`slappasswd`,重复输入两次明文密码后(我是:111111),我得到一个加密后密码(后面会用到):`{SSHA}rNLkIMYKvYhbBjxLzSbjVsJnZSkrfC3w` |
| 44 | +- `cd /root/my_ldif ; vim chdomain.ldif`,添加如下内容(cn,dc,dc,olcRootPW 几个值需要你自己改): |
| 45 | + |
| 46 | +``` ini |
| 47 | +dn: olcDatabase={1}monitor,cn=config |
| 48 | +changetype: modify |
| 49 | +replace: olcAccess |
| 50 | +olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" |
| 51 | + read by dn.base="cn=gitnavi,dc=youmeek,dc=com" read by * none |
| 52 | + |
| 53 | +dn: olcDatabase={2}hdb,cn=config |
| 54 | +changetype: modify |
| 55 | +replace: olcSuffix |
| 56 | +olcSuffix: dc=youmeek,dc=com |
| 57 | + |
| 58 | +dn: olcDatabase={2}hdb,cn=config |
| 59 | +changetype: modify |
| 60 | +replace: olcRootDN |
| 61 | +olcRootDN: cn=gitnavi,dc=youmeek,dc=com |
| 62 | + |
| 63 | +dn: olcDatabase={2}hdb,cn=config |
| 64 | +changetype: modify |
| 65 | +add: olcRootPW |
| 66 | +olcRootPW: {SSHA}rNLkIMYKvYhbBjxLzSbjVsJnZSkrfC3w |
| 67 | + |
| 68 | +dn: olcDatabase={2}hdb,cn=config |
| 69 | +changetype: modify |
| 70 | +add: olcAccess |
| 71 | +olcAccess: {0}to attrs=userPassword,shadowLastChange by |
| 72 | + dn="cn=gitnavi,dc=youmeek,dc=com" write by anonymous auth by self write by * none |
| 73 | +olcAccess: {1}to dn.base="" by * read |
| 74 | +olcAccess: {2}to * by dn="cn=gitnavi,dc=youmeek,dc=com" write by * read |
| 75 | +``` |
| 76 | + |
| 77 | +- 添加配置:`ldapadd -Y EXTERNAL -H ldapi:/// -f chdomain.ldif` |
| 78 | + |
| 79 | +### 添加一个基本的目录 |
| 80 | + |
| 81 | +- `cd /root/my_ldif ; vim basedomain.ldif`,添加如下内容(cn,dc,dc 几个值需要你自己改): |
| 82 | + |
| 83 | +``` ini |
| 84 | +dn: dc=youmeek,dc=com |
| 85 | +objectClass: top |
| 86 | +objectClass: dcObject |
| 87 | +objectclass: organization |
| 88 | +o: youmeek dot Com |
| 89 | +dc: youmeek |
| 90 | + |
| 91 | +dn: cn=gitnavi,dc=youmeek,dc=com |
| 92 | +objectClass: organizationalRole |
| 93 | +cn: gitnavi |
| 94 | +description: Directory Manager |
| 95 | + |
| 96 | +dn: ou=People,dc=youmeek,dc=com |
| 97 | +objectClass: organizationalUnit |
| 98 | +ou: People |
| 99 | + |
| 100 | +dn: ou=Group,dc=youmeek,dc=com |
| 101 | +objectClass: organizationalUnit |
| 102 | +ou: Group |
| 103 | +``` |
| 104 | + |
| 105 | +- 添加配置:`ldapadd -x -D cn=gitnavi,dc=youmeek,dc=com -W -f basedomain.ldif`,会提示让你输入配置 domain 的密码,我是:111111 |
| 106 | +- `简单的配置到此就好了` |
| 107 | + |
| 108 | +### 测试连接 |
| 109 | + |
| 110 | +- 重启下服务:`systemctl restart slapd` |
| 111 | +- 本机测试,输入命令:`ldapsearch -LLL -W -x -D "cn=gitnavi,dc=youmeek,dc=com" -H ldap://localhost -b "dc=youmeek,dc=com"`,输入 domain 密码,可以查询到相应信息 |
| 112 | +- 局域网客户端连接测试,下载 Ldap Admin(下载地址看文章下面),具体连接信息看下图: |
| 113 | +-  |
| 114 | + |
| 115 | + |
| 116 | +## LDAP 客户端 |
| 117 | + |
| 118 | +- 常见客户端: |
| 119 | + - [LdapAdmin](http://www.ldapadmin.org/download/ldapadmin.html) |
| 120 | + - [LdapBrowser](http://www.ldapbrowser.com/) |
| 121 | + - [phpLDAPadmin](http://phpldapadmin.sourceforge.net/wiki/index.php/Main_Page) |
| 122 | + - [Softerra LDAP Administrator](http://softerra-ldap-administrator.software.informer.com/3.5/) |
| 123 | + |
| 124 | +## 资料 |
| 125 | + |
| 126 | +- <https://superlc320.gitbooks.io/samba-ldap-centos7/ldap_+_centos_7.html> |
| 127 | +- <http://yhz61010.iteye.com/blog/2352672> |
| 128 | +- <https://kyligence.gitbooks.io/kap-manual/zh-cn/security/ldap.cn.html> |
| 129 | +- <http://gaowenlong.blog.51cto.com/451336/1887408> |
0 commit comments