Write the code. Change the World.
一个企业经常会碰上部署多台机器的问题,但是账号管理就成了问题,怎么在N台机器上统一部署账号管理,完成账号统一认证和管理是让我们后续非常方便的地方。
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
//安装三大应用,服务端,客户端,导出导入工具yum install -y openldap-servers openldap-clients migrationtools//配置文件cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIGchown ldap. /var/lib/ldap/DB_CONFIG//启动服务systemctl start slapdsystemctl enable slapd//生成root密码╭─root@ykdev ~╰─# slappasswdNew password:Re-enter new password:{SSHA}/UFZ8EehpMMtKiiAy+vxdxH6fObhaF3l//修改rootdn密码cat chrootpw.ldifdn: olcDatabase={0}config,cn=configchangetype: modifyadd: olcRootPWolcRootPW: {SSHA}/UFZ8EehpMMtKiiAy+vxdxH6fObhaF3lldapadd -Y EXTERNAL -H ldapi:/// -f chrootpw.ldif//导出基础的Schema,这些 Schema 文件位于 /etc/openldap/schema/ 目录中,定义了我们以后创建的条目可以使用哪些属性[root@localhost ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif SASL/EXTERNAL authentication startedSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=authSASL SSF: 0adding new entry "cn=cosine,cn=schema,cn=config"[root@localhost ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif SASL/EXTERNAL authentication startedSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=authSASL SSF: 0adding new entry "cn=nis,cn=schema,cn=config"[root@localhost ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif SASL/EXTERNAL authentication startedSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=authSASL SSF: 0adding new entry "cn=inetorgperson,cn=schema,cn=config"//配置 LDAP 的顶级域[root@proxy ldap]# cat chdomain.ldifdn: 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=Manager,dc=my-domain,dc=com" read by * nonedn: olcDatabase={2}hdb,cn=configchangetype: modifyreplace: olcSuffixolcSuffix: dc=my-domain,dc=comdn: olcDatabase={2}hdb,cn=configchangetype: modifyreplace: olcRootDNolcRootDN: cn=Manager,dc=my-domain,dc=comdn: olcDatabase={2}hdb,cn=configchangetype: modifyreplace: olcRootPWolcRootPW: {SSHA}/UFZ8EehpMMtKiiAy+vxdxH6fObhaF3ldn: olcDatabase={2}hdb,cn=configchangetype: modifyadd: olcAccessolcAccess: {0}to attrs=userPassword,shadowLastChange by dn="cn=Manager,dc=my-domain,dc=com" write by anonymous auth by self write by * noneolcAccess: {1}to dn.base="" by * readolcAccess: {2}to * by dn="cn=Manager,dc=my-domain,dc=com" write by * read[root@localhost ~]# ldapmodify -Y EXTERNAL -H ldapi:/// -f chdomain.ldif //导入基础组信息什么的[root@proxy ldap]# cat base.ldifdn: dc=my-domain,dc=comdc: my-domainobjectClass: topobjectClass: domaindn: ou=People,dc=my-domain,dc=comou: PeopleobjectClass: topobjectClass: organizationalUnitdn: ou=Group,dc=my-domain,dc=comou: GroupobjectClass: topobjectClass: organizationalUnitldapadd -x -D "cn=Manager,dc=my-domain,dc=com" -W -f base.ldif//导入用户信息//修改域名基础信息vi /usr/share/migrationtools/migrate_common.ph$DEFAULT_BASE = "dc=my-domain,dc=com";[root@proxy ldap]# /usr/share/migrationtools/migrate_passwd.pl /etc/passwd passwd.ldif[root@proxy ldap]# /usr/share/migrationtools/migrate_group.pl /etc/group group.ldif[root@proxy ldap]# ldapadd -x -D cn=Manager,dc=my-domain,dc=com -W -f passwd.ldif[root@proxy ldap]# ldapadd -x -D cn=Manager,dc=my-domain,dc=com -W -f group.ldif//查看所有记录[root@proxy ldap]# ldapsearch -x -b "dc=my-domain,dc=com" -H ldap://192.168.1.1
至此全部搭建完毕
Seraching...