1、環境準備linux
echo nameserver 114.114.114.114 > /etc/resolv.conf ##更改DNS
echo 192.168.0.190 hello.com >> /etc/hosts
systemctl disable firewalld.service && systemctl stop firewalld.service #關閉防火牆
sed -i 's//#SELINUX/SELINUX=disable/g' /etc/selinux/config ##永久關閉selinux
setenforce 0
rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
##安裝擴展源
yum -y install openldap-servers openldap-clients ##安裝openldap服務端和客戶端
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
chown ldap:ldap /var/lib/ldap/DB_CONFIG ##受權
systemctl start slapd && systemctl enable slapd ##啓動服務,設置開機啓動數據庫
2、配置管理員密碼
①.slappasswd 或 slappasswd -s 密碼(-s 指定密碼)
輸入完密碼後會生成一串加密字符串
例:{SSHA}5Qiqn6d4U4U9b1G8A7dKmJAkJcUOA4fE #保存,後面會用到
②.vim chrootpw.ldif
# specify the password generated above for "olcRootPW" section
dn: olcDatabase={0}config,cn=config
changetype: modify
add: olcRootPW
olcRootPW: 上面生成的密碼
ldapadd -Y EXTERNAL -H ldapi:/// -f chrootpw.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldifvim
3、在數據庫中設置你的域名
1.生成密碼
slappasswd
2.vi chdomain.ldif
# replace to your own domain name for "dc=***,dc=***" section
# specify the password generated above for "olcRootPW" section
dn: olcDatabase={1}monitor,cn=config
changetype: modify
replace: olcAccess
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth"
read by dn.base="cn=admin,dc=hello,dc=com" read by * noneapi
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=hello,dc=comapp
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=admin,dc=hello,dc=com
dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcRootPW
olcRootPW: 步奏1中生成的密碼dom
dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to attrs=userPassword,shadowLastChange by
dn="cn=admin,dc=hello,dc=com" write by anonymous auth by self write by * none
olcAccess: {1}to dn.base="" by * read
olcAccess: {2}to * by dn="cn=admin,dc=hello,dc=com" write by * read
3、ldapmodify -Y EXTERNAL -H ldapi:/// -f chdomain.ldif
4、vi basedomain.ldif
# replace to your own domain name for "dc=***,dc=***" section
dn: dc=hello,dc=com
objectClass: top
objectClass: dcObject
objectclass: organization
o: qiqiu com
dc: qiqiu
dn: cn=admin,dc=hello,dc=com
objectClass: organizationalRole
cn: admin
description: Directory admin
dn: ou=People,dc=hello,dc=com
objectClass: organizationalUnit
ou: People
dn: ou=Group,dc=hello,dc=com
objectClass: organizationalUnitui
ou: Group
5.ldapadd -x -D cn=admin,dc=hello,dc=com -W -f basedomain.ldif加密