centos7.x安装 LDAP
/ /systemctl start slapd
1、防火墙设置
centos7.0+ 默认防火墙为firewalld
#停止firewall
# systemctl stop firewalld.service
#禁止firewall开机启动
# systemctl disable firewalld.service
查看默认防火墙状态:
# firewall-cmd --state
2、修改selinux
# vi /etc/selinux/config
将SELINUX=enforcing改为:SELINUX=disabled
# setenforce 0 或者重启,注意敲黑板重点,之前没有执行该命令然后导致LDAP一直启动不成功,耗费了很长一段时间。
---------------------
yum install -y openldap openldap-clients openldap-servers migrationtools
slappasswd
New password: linux123
Re-enter new password: linux123
{SSHA}r2fcL6Exxgr8oKkaWROUQDCZKqXrH7bE
vi /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}hdb.ldif
修改内容:
olcSuffix: dc=domian,dc=com
olcRootDN: cn=root,dc=domian,dc=com
添加内容:
olcRootPW: {SSHA}r2fcL6Exxgr8oKkaWROUQDCZKqXrH7bE
备注:密码就是{ssha}和后面的那一串,此处使用上面生成的密码替换。
vi /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{1\}monitor.ldif
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=extern
al,cn=auth" read by dn.base="cn=root,dc=domain,dc=com" read by * none
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
chown ldap:ldap -R /var/lib/ldap
chmod 700 -R /var/lib/ldap
slaptest -u
看见:config file testing succeeded #验证成功,否则失败。
[看到checksum那个错误没事]
chown ldap:ldap -R /var/run/openldap
chown -R ldap:ldap /etc/openldap/
systemctl start slapd
systemctl enable slapd
ldapsearch -x -b '' -s base'(objectclass=*)'
# extended LDIF
# LDAPv3
# base <> with scope baseObject
# filter: (objectclass=*)
# requesting: ALL
#
dn:
objectClass: top
objectClass: OpenLDAProotDSE
# search result
search: 2
result: 0 Success
如显示上面信息,表示服务已经启动成功。
---------------------
cd /usr/share/migrationtools/
vim /usr/share/migrationtools/migrate_common.ph
修改
# Default DNS domain
$DEFAULT_MAIL_DOMAIN = "test.com";
# Default base
$DEFAULT_BASE = "dc=test,dc=com";
./migrate_base.pl > /root/base.ldif #生成base.ldif
或者 base.ldif
dn: dc=test,dc=com
dc: test
objectClass: top
objectClass: domain
dn: ou=Hosts,dc=test,dc=com
ou: Hosts
objectClass: top
objectClass: organizationalUnit
dn: ou=People,dc=test,dc=com
ou: People
objectClass: top
objectClass: organizationalUnit
dn: ou=Group,dc=test,dc=com
ou: Group
objectClass: top
objectClass: organizationalUnit
2、导入数据库
ldapadd -x -D "cn=root,dc=test,dc=com" -W -f /root/base.ldif
3、验证
ldapsearch -x -b 'dc=test,dc=com' '(objectClass=*)'