一、环境准备
echo nameserver 114.114.114.114 > /etc/resolv.conf ##更改DNSecho 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 ##永久关闭selinuxsetenforce 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 ##启动服务,设置开机启动
二、配置管理员密码
①.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.ldif 返回值如下图
三、在数据库中设置你的域名
1.生成密码
slappasswd
2.vi chdomain.ldif
# replace to your own domain name for "dc=***,dc=***" section# specify the password generated above for "olcRootPW" sectiondn: olcDatabase={1}monitor,cn=configchangetype: modifyreplace: olcAccessolcAccess: {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 * nonedn: olcDatabase={2}hdb,cn=configchangetype: modifyreplace: olcSuffixolcSuffix: dc=hello,dc=comdn: olcDatabase={2}hdb,cn=configchangetype: modifyreplace: olcRootDNolcRootDN: cn=admin,dc=hello,dc=comdn: olcDatabase={2}hdb,cn=configchangetype: modifyadd: olcRootPWolcRootPW: 步奏1中生成的密码dn: olcDatabase={2}hdb,cn=configchangetype: modifyadd: olcAccessolcAccess: {0}to attrs=userPassword,shadowLastChange by dn="cn=admin,dc=hello,dc=com" write by anonymous auth by self write by * noneolcAccess: {1}to dn.base="" by * readolcAccess: {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=***" sectiondn: dc=hello,dc=comobjectClass: topobjectClass: dcObjectobjectclass: organizationo: qiqiu comdc: qiqiudn: cn=admin,dc=hello,dc=comobjectClass: organizationalRolecn: admindescription: Directory admindn: ou=People,dc=hello,dc=comobjectClass: organizationalUnitou: Peopledn: ou=Group,dc=hello,dc=comobjectClass: organizationalUnitou: Group
5.ldapadd -x -D cn=admin,dc=hello,dc=com -W -f basedomain.ldif