dn: olcDatabase=monitor,cn=config objectClass: olcDatabaseConfig olcDatabase: monitor olcAccess: to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,c n=auth" read by dn.base="cn=Manager,dc=abc,dc=com" read by * none
设置一个密码
[root@server home]# slappasswd New password: Re-enter new password: {SSHA}6ZV4bJxlj6a0CPsqAwaXdS+AjPmSZ9Do
[root@server /]# cat /home/slapd.ldif # # See slapd-config(5) for details on configuration options. # This file should NOT be world readable. #
dn: cn=config objectClass: olcGlobal cn: config olcArgsFile: /var/run/openldap/slapd.args olcPidFile: /var/run/openldap/slapd.pid # # TLS settings # olcTLSCACertificatePath: /etc/openldap/certs olcTLSCertificateFile: "OpenLDAP Server" olcTLSCertificateKeyFile: /etc/openldap/certs/password # # Do not enable referrals until AFTER you have a working directory # service AND an understanding of referrals. # #olcReferral: ldap://root.openldap.org # # Sample security restrictions # Require integrity protection (prevent hijacking) # Require 112-bit (3DES or better) encryption for updates # Require 64-bit encryption for simple bind # #olcSecurity: ssf=1 update_ssf=112 simple_bind=64
# # Load dynamic backend modules: # - modulepath is architecture dependent value (32/64-bit system) # - back_sql.la backend requires openldap-servers-sql package # - dyngroup.la and dynlist.la cannot be used at the same time #
dn: olcDatabase=frontend,cn=config objectClass: olcDatabaseConfig objectClass: olcFrontendConfig olcDatabase: frontend # # Sample global access control policy: # Root DSE: allow anyone to read it # Subschema (sub)entry DSE: allow anyone to read it # Other DSEs: # Allow self write access # Allow authenticated users read access # Allow anonymous users to authenticate # #olcAccess: to dn.base="" by * read #olcAccess: to dn.base="cn=Subschema" by * read #olcAccess: to * # by self write # by users read # by anonymous auth # # if no access controls are present, the default policy # allows anyone and everyone to read anything but restricts # updates to rootdn. (e.g., "access to * by * read") # # rootdn can always read and write EVERYTHING! #
# # Configuration database #
dn: olcDatabase=config,cn=config objectClass: olcDatabaseConfig olcDatabase: config olcAccess: to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,c n=auth" manage by * none
# # Server status monitoring #
dn: olcDatabase=monitor,cn=config objectClass: olcDatabaseConfig olcDatabase: monitor olcAccess: to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,c n=auth" read by dn.base="cn=Manager,dc=abc,dc=com" read by * none
[root@server home]# slapadd -F /etc/openldap/slapd.d/ -n 0 -l /home/slapd.ldif 591fd54d str2entry: entry -1 has no dn slapadd: could not parse entry (line=724) _################### 99.70% eta none elapsed none spd 3.3 M/s Closing DB...
[root@server slapd.d]# chown -Rv ldap.ldap /etc/openldap/slapd.d/ changed ownership of ‘/etc/openldap/slapd.d/cn=config.ldif’ from root:root to ldap:ldap changed ownership of ‘/etc/openldap/slapd.d/cn=config/cn=schema.ldif’ from root:root to ldap:ldap changed ownership of ‘/etc/openldap/slapd.d/cn=config/cn=schema/cn={0}core.ldif’ from root:root to ldap:ldap changed ownership of ‘/etc/openldap/slapd.d/cn=config/cn=schema/cn={1}collective.ldif’ from root:root to ldap:ldap changed ownership of ‘/etc/openldap/slapd.d/cn=config/cn=schema’ from root:root to ldap:ldap changed ownership of ‘/etc/openldap/slapd.d/cn=config’ from root:root to ldap:ldap ownership of ‘/etc/openldap/slapd.d/’ retained as ldap:ldap
确认下所有者和所属组
[root@server slapd.d]# ll total 4 drwxr-x--- 3 ldap ldap 45 May 20 13:34 cn=config -rw------- 1 ldap ldap 589 May 20 13:34 cn=config.ldif
创建数据库配置文件
[root@server slapd.d]# cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG [root@server slapd.d]# chown -Rv ldap.ldap /var/lib/ldap/DB_CONFIG changed ownership of ‘/var/lib/ldap/DB_CONFIG’ from root:root to ldap:ldap
[root@client home]# ls [root@client home]# [root@client home]# cd ldapuser [root@client ldapuser]# ls lduser1 lduser2 lduser3 lduser4 lduser5 lduser6 [root@client ldapuser]#
这样当你每次切换目录都会自动挂载
[root@client home]# su - lduser1 Last login: Sat May 2023:12:22 EDT 2017 on pts/0 [lduser1@client ~]$ [lduser1@client ~]$ [lduser1@client ~]$ ls [lduser1@client ~]$ cd /home/ [lduser1@client home]$ ls ldapuser [lduser1@client home]$ cd ldapuser/ [lduser1@client ldapuser]$ ls lduser1 lduser2 lduser3 lduser4 lduser5 lduser6 [lduser1@client ldapuser]$
故障处理
发现无法切换到服务器的用户,查看日志
[root@client ~]# tail -n 20 -f /var/log/messages May 2022:39:36 client nslcd[2266]: [4a3fe6] <group/member="gdm"> no available LDAP serverfound: Serveris unavailable: Transport endpoint isnot connected May 2022:39:36 client nslcd[2266]: [4ef005] <group/member="gdm"> no available LDAP serverfound: Serveris unavailable: Transport endpoint isnot connected May 2022:39:36 client nslcd[2266]: [4ef005] <group/member="gdm"> no available LDAP serverfound: Serveris unavailable: Transport endpoint isnot connected May 2022:40:02 client systemd: Started Session2ofuser root. May 2022:40:02 client systemd: Starting Session2ofuser root. May 2022:40:02 client nslcd[2266]: [f9c13c] <group/member="gdm"> failed to bind to LDAP server ldap://abc.com: Can't contact LDAP server: Transport endpoint is not connected May 20 22:40:02 client nslcd[2266]: [f9c13c] <group/member="gdm"> no available LDAP server found: Can't contact LDAP server: Transport endpoint isnot connected May 2022:40:02 client nslcd[2266]: [f9c13c] <group/member="gdm"> no available LDAP serverfound: Serveris unavailable: Transport endpoint isnot connected May 2022:40:02 client nslcd[2266]: [9bb77c] <group/member="root"> no available LDAP serverfound: Serveris unavailable May 2022:40:02 client nslcd[2266]: [9bb77c] <group/member="root"> no available LDAP serverfound: Serveris unavailable May 2022:40:02 client nslcd[2266]: [5ac794] <group/member="gdm"> no available LDAP serverfound: Serveris unavailable May 2022:40:02 client nslcd[2266]: [5ac794] <group/member="gdm"> no available LDAP serverfound: Serveris unavailable
发现客户端 Telnet 服务22端口是可以的,但是389端口不行
[root@client ~]# telnet 172.10.100.129 22 Trying 172.10.100.129... Connected to172.10.100.129. Escape character is'^]'. SSH-2.0-OpenSSH_6.6.1 ^C Connection closed by foreign host. [root@client ~]# [root@client ~]# telnet 172.10.100.129 389 Trying 172.10.100.129... telnet: connect to address 172.10.100.129: No route to host