###############################################################################
# Name : Mahavairocana
# Author : Mahavairocana
# QQ : 10353512
# WeChat : shenlan-qianlan
# Blog : http://www.cnblogs.com/Mahavairocana/
# Description : You are welcome to reprint, or hyperlinks to indicate the
# source of the article, as well as author information. ###############################################################################node
第一步 下載安裝數據庫
[root@s ~]# yum install openldap-servers openldap-clients openldap openldap-develbash
第二步 配置LDAP服務器
1. 拷貝配置文件到相應的目錄 [root@s ~]# cp /usr/share/openldap-servers/slapd.conf.obsolete /etc/openldap/slapd.conf [root@s ~]# cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG 2. 設置密碼 [root@s ~]# slappasswd New password: Re-enter new password: {SSHA}lSYJYCeKzk+EebNtqyqHGdc16sTrlAng 3. 修改配置文件 [root@s ~]# vi /etc/openldap/slapd.conf database bdb suffix "dc=google,dc=cn" checkpoint 1024 15 rootdn "cn=Manager,dc=google,dc=cn" rootpw {SSHA}lSYJYCeKzk+EebNtqyqHGdc16sTrlAng #這裏就是上面生成的 4. 創建 root-unit.ldif來定義整個樹狀結構(注意: 每一個冒號後都要多一個空格) [root@s ~]# mkdir -p /etc/openldap/data [root@s ~]# vi /etc/openldap/data/root-unit.ldif #root node dn: dc=google,dc=cn dc: google objectClass: dcObject objectClass: organizationalUnit ou: google cn #login top dn: ou=login,dc=google,dc=cn ou: login objectClass: organizationalUnit 5. 剛 root-unit.ldif 加入到LDAP的數據庫 [root@s ~]# mv /etc/openldap/slapd.d /etc/openldap/slapd.d.bak [root@s ~]# mkdir /etc/openldap/slapd.d [root@s ~]# slapadd -v -l /etc/openldap/data/root-unit.ldif The first database does not allow slapadd; using the first available one (2) bdb_db_open: DB_CONFIG for suffix "dc=google,dc=cn" has changed. Performing database recovery to activate new settings. added: "dc=google,dc=cn" (00000001) added: "ou=login,dc=google,dc=cn" (00000002) _#################### 100.00% eta none elapsed none fast! Closing DB... ---------------------------------------若是出現問題----------------------------------------- bdb_db_open: database "dc=google,dc=cn": database already in use. backend_startup_one (type=bdb, suffix="dc=google,dc=cn"): bi_db_open failed! (-1) slap_startup failed 就說明,程序已經被你啓動,先關閉 service slapd stop -------------------------------------------------------------------------------------------- 6. 將LDAP新的數據庫產生到 slapd.d 目錄 [root@s ~]# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d config file testing succeeded 讓目錄有執行權限 [root@s ~]# chown -R ldap:ldap /var/lib/ldap [root@s ~]# chown -R ldap:ldap /etc/openldap/slapd.d ----------------------------若是你要修改 slapd.conf 內容,執行以下-------------------------- # rm -rf /etc/openldap/slapd.d/* # slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d # chown -R ldap:ldap /etc/openldap/slapd.d # service slapd restart -------------------------------------------------------------------------------------------- 7. 啓動 ldap server 並開機啓動 [root@s ~]# service slapd start 正在啓動 slapd: [肯定] [root@s ~]# chkconfig --level 345 slapd on 8. 確認樹狀結構是否完成 [root@s ~]# ldapsearch -x -b "dc=google,dc=cn" # extended LDIF # # LDAPv3 # base dc=google,dc=cn with scope subtree # filter: (objectclass=*) # requesting: ALL # # google.cn dn: dc=google,dc=cn dc: google objectClass: dcObject objectClass: organizationalUnit ou: google cn # login, google.cn dn: ou=login,dc=google,dc=cn ou: login objectClass: organizationalUnit # search result search: 2 result: 0 Success # numResponses: 3 # numEntries: 2 9. 建立用戶 [root@s ~]# vi /etc/openldap/data/users.ldif dn: uid=test,dc=google,dc=cn uid: test cn: test objectClass: account objectClass: posixAccount objectClass: top objectClass: shadowAccount userPassword: {SSHA}lSYJYCeKzk+EebNtqyqHGdc16sTrlAng shadowLastChange: 14335 shadowMax: 99999 shadowWarning: 7 loginShell: /bin/bash uidNumber: 10000 gidNumber: 10000 homeDirectory: /home/test gecos: test [root@s ~]# ldapadd -a -x -D 'cn=Manager,dc=google,dc=cn' -W -f /etc/openldap/data/users.ldif Enter LDAP Password: adding new entry "uid=test,dc=google,dc=cn" 10. 重啓下 ldap 服務器 [root@s ~]# service slapd restart 第三步 客戶端使用SSH登陸 1. 先安裝 ldap [root@c2 ~]# yum install fprintd-pam openldap-clients nss_ldap nss-pam-ldapd 2. 先登陸到客戶端 [root@c2 ~]# authconfig-tui 選擇「Use LDAP」和「Use LDAP Authentication」,其它默認,下一步 (建議:這裏最好所有刪除,從新輸入,否則老多字母什麼的,有錯能夠看 /var/logs/messages ) Server: ldap://192.168.100.254 #這裏就是你LDAP服務器的IP Base DN: dc=google,dc=cn #這裏填服務器同樣的,而後完成 3. 用命令查看是否鏈接成功 [root@c2 ~]# id test #這個賬號 test 是在 ldap 中的,上面配置了,在客戶端能夠看到成功了 uid=10000(zaici) gid=10000 groups=10000 而後你能夠 ssh 登陸了