centos配置安裝LDAP基礎知識

來源:互聯網
上載者:User

LDAP 伺服端基本說明 389--Centos5

OPENLDAP 相關程式

slapd:openLDAP 的 daemon

slurpd:多個 LDAP 伺服器進行?寫時所用的程式

相關檔案及目錄

/etc/openldap:openldap 的主要目錄

/etc/openldap/slapd.conf:伺服器設定檔

/etc/openldap/cacerts:為一目錄,存放憑證相關資料

/etc/openldap/DB_CONFIG.example:資料庫設定檔範例

/etc/openldap/schema:為一目錄,存放綱要資料,支援哪種資料類型

/var/lib/ldap:資料庫的存放路徑

/etc/openldap/ldap.conf:使用者端設定檔

 

LDAP目錄結構組成

•DN(Distinguished Name):識別名稱,一條記錄的位置

•RDN(Relative Distinguished Name):相對識別名稱,(指的就是cn及cn的值 ex.cn=weithenn,獨一無二的屬性)

•CN(Common Name) /uid:顯示名稱,一條記錄的名字/ID

•OU(Organizational Unit):組織,一條記錄所屬組織

•DC(Domain Componet):網域元件,一條記錄所屬地區

包含 cn 的 dn 記錄:dn:cn=username,ou=group,dc=kh,dc=edu,dc=tw
 
LDAP伺服器設定

1.安裝 openldap-servers

yum -y install openldap openldap-devel openldap-servers


2.建立 LDAP 密碼

slappasswd
New password:
Re-enter new password:
{SSHA}dKmbTeq19LgSL9tLKEiv7nyrkCJhaa83


設定密碼
slappasswd -h {MD5}

3.設定slap.conf以下三個部份

vi /etc/openldap/slap.conf

先將預設的設定值加上#,把以下的規格全部放進來比較方便。
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/nis.schema
include /etc/openldap/schema/redhat/autofs.schema
include /etc/openldap/schema/misc.schema
include /etc/openldap/schema/openldap.schema
include /etc/openldap/schema/phpgwaccount.schema
include /etc/openldap/schema/phpgwcontact.schema
include /etc/openldap/schema/samba.schema
.
.
database ldbm
.
suffix          "dc=server,dc=kh,dc=edu,dc=tw"
rootdn          "cn=Manager,dc=domain,dc=kh,dc=edu, dc=tw"一般 cn 值是 Manager
rootpw        {SSHA}dKmbTeq19LgSL9tLKEiv7nyrkCJhaa83 可為明碼或加密碼

4.透過檔案傳輸(FTP)的方式,將原有的schema格式放到/etc/openldap/schema/

 

5.若要匯入原有的domain.ldif 檔案,記得檢查是否關掉ldap,並且清空原先資料庫檔案

service slapd stop

rm -rf /var/lib/ldap/*

6.準備好後,匯入之前的備份資料檔案

slapadd -l 來源

slapadd -l /etc/openldap/domain.ldif

.匯入後,記得修改資料庫目錄許可權

chown -R ldap:ldap /var/lib/ldap/*

啟動 LDAP 服務

service slapd start

用原domain.ldif內的使用者登入測試看看吧!
 
備份LDAP伺服器檔案

1.可用於定期備份的執行檔內

vi /root/back.sh

slapcat -b "dc=server,dc=kh,dc=edu,dc=tw" -l 存放位置

slapcat -b "dc=server,dc=kh,dc=edu,dc=tw" -l /tmp/domain.ldif 範例

存檔後,可立即執行

chmod 755 back.sh

./back.sh

2.或直接執行

slapcat -b "dc=server,dc=kh,dc=edu,dc=tw" -l /tmp/domain.ldif

 
 
LDAP 使用者端設定(Centos 6.2)
本檔案參考Server World - ネットワ?クサ?バ?構築

•http://www.server-world.info/
•http://www.server-world.info/en/note?os=CentOS_6&p=ldap&f=2
1.安裝相關套件

yum -y install openldap openldap-clients nss-pam-ldapd

2.設定 LDAP 服務

setup

 

 

伺服器:ldap://IP 或 ldap://主機名稱

ldap://ldap.do.kh.edu.tw

基底DN:dc=do,dc=kh,dc=edu,dc=tw

 

另外一法:可用修改設定檔

vi /etc/openldap/ldap.conf

URI ldap://ldap.do.kh.edu.tw
BASE dc=do,dc=kh,dc=edu,dc=tw
 

接下來,編輯以下四個檔案。

vi /etc/openldap/ldap.conf

# add at the last line
# LDAP server's URI
URI ldap://ldap.do.kh.edu.tw/

# specify Suffix
BASE dc=do,dc=kh,dc=edu,dc=tw
TLS_CACERTDIR /etc/openldap/cacerts 

 vi /etc/nslcd.conf

# line 131: specify URI, Suffix
uri ldap://163.32.X.X/
base dc=kh,dc=edu,dc=tw
ssl no
tls_cacertdir /etc/openldap/cacerts

 vi /etc/pam_ldap.conf

# line 17: make it comment
# host 127.0.0.1

# line 20: specify Suffix
base dc=do,dc=kh,dc=edu,dc=tw

# add at the last line
uri ldap://ldap.do.kh.edu.tw/
ssl no
tls_cacertdir /etc/openldap/cacerts
pam_password md5

 vi /etc/pam.d/system-auth(自行找到以下四列,再去修改)

auth        sufficient    pam_ldap.so use_first_pass
account     [default=bad success=ok user_unknown=ignore] pam_ldap.so
password   sufficient    pam_ldap.so use_authtok
session     optional      pam_ldap.so
# add if you need ( create home directory automatically if it's none )
session     optional      pam_mkhomedir.so skel=/etc/skel umask=077

 vi /etc/nsswitch.conf

passwd: files ldap # line 33: add
shadow: files ldap # add
group: files ldap # add
netgroup: ldap # line 57: change
automount: files ldap # line 61: change

vi /etc/sysconfig/authconfig

USELDAP= yes # line 18: change

設定開機啟用

chkconfig nslcd on
shutdown -r now

3.使用者端無法立即重新啟動,必須重新開機。

4.重新開機後,在Client端本機,用其他帳號登入測試看看!會出現沒有家目錄,是正常的,除非有安裝nfs,或自動建立原生目錄。

 
 
LDAP 使用者端,啟用SSHD + VSFTPD
之前已經完成LDAP Client端的設定與啟用。

接下來,我們再來將  VSFTPD 及 SSHD 也啟用服務吧!

VSFTPD(啟用FTP功能,好用!)

cp /etc/pam.d/vsftpd  /etc/pam.d/vsftpd.bk

vi /etc/pam.d/vsftpd

auth       include      system-auth
account    required     pam_nologin.so
account    include      system-auth
password   include      system-auth
session    optional     pam_keyinit.so force revoke
session    include      system-auth
session    required     pam_loginuid.so

SSHD(其實,這個功能可以不用啟用,沒事開給使用者,沒什麽作用...)

cp /etc/pam.d/sshd /etc/pam.d/sshd.bk

vi  /etc/pam.d/sshd

auth       include      system-auth
account    required     pam_nologin.so
account    include      system-auth
password   include      system-auth
session    optional     pam_keyinit.so force revoke
session    include      system-auth
session    required     pam_loginuid.so

 
LDAP 使用者端,結合openwebmail
設定整合之前,先確認perl-Authen-PAM有無安裝

yum -y install perl-Authen-PAM
 

1.修改openwebmail的設定檔,使用pam認證

vi /var/www/cgi-bin/openwebmail/etc/openwebmail.conf

auth_module auth_unix.pl 修改為 auth_module auth_pam.pl

另外再新增一行,這樣讓使用者登入時可以自動建立相關的目錄與檔案
create_syshomedir yes

2.在auth_pam.pl內參數,將login修改為 openwebmail
vi /var/www/cgi-bin/openwebmail/auth/auth_pam.pl

my $servicename = $conf{'servicename'} || "openwebmail";

3.??auth_pam.conf到主要位置

cp /var/www/cgi-bin/openwebmail/etc/defaults/auth_pam.conf /var/www/cgi-bin/openwebmail/etc/auth_pam.conf

4.修改auth_pam.conf內參數,servicename為openwebmail

vi /var/www/cgi-bin/openwebmail/etc/auth_pam.conf

servicename             openwebmail
passwdfile_plaintext    /etc/passwd
check_nologin           no
check_shell             no
check_cobaltuser        no

4.在/etc/pam.d/內新增openwebmail

vi /etc/pam.d/openwebmail

auth include system-auth
account include system-auth
password include system-auth
session include system-auth

5.(可以不用修改,測試用)修改auth_ldap.conf

vi /var/www/cgi-bin/openwebmail/etc/defaults/auth_ldap.conf

ldaphost 192.168.0.1 # LDAP SERVER IP
ou user # LDAP ORGANIZATIONAL UNIT
cn Manager # LDAP USER
dc1 domain
dc2 kh
dc3 edu
dc4 tw
password secret

另外,不要亂改,因為系統啟動時尚未啟用ldap服務,所以先做原先的認證即可。我修改順序後,導致開機異常。

vi /etc/nsswitch.conf

passwd:     files ldap shadow:     files ldap group:      files ldap 

5.重新啟動openwebmail

/var/www/cgi-bin/openwebmail/openwebmail-tool.pl --init


 
 
openwebmail與LDAP問題:無法更改密碼
問題描述
全部正常後,發現無法在openwebmail內修改個人檔案,出現訊息change password error auth_pam.pl, ret -4, pam_authtok() err 6, Permission denied 。

 

在ldap伺服器中加入以下許可權參數

vi /etc/openldap/slapd.conf

#使用者密碼只能由自己變更, 對於?棵?褂謎咧幌抻糜諉藶胙櫓? 其餘禁止取用

access to attrs=userPassword

by self write

by users read

by anonymous auth

#以上沒有規範到的部份, 都授予讀取許可權

access to * by * read
 
次要LDAP
Step1.停止 「主要LDAP」

service slapd stop

Step2.修改 「主要LDAP」 slapd.conf 內容

vi /etc/openldap/slapd.conf

replogfile /var/lib/ldap/slapd.replog //指定 slurpd 更新檔路徑
replica host=server.kh.edu.tw:389 // Slaver LDAP 主機
suffix="dc=server,dc=kh,dc=edu,dc=tw" //更新的 DN
binddn="uid=admin2,cn=Manager,dc=shsps,dc=kh,dc=edu,dc=tw" // Slaver LDAP RootDN
bindmethod=simple //認證方式
credentials=123456 //Manager2的密碼(注意須為明碼)
tls=yes //開啟 TLS 支援

Step3. 將 「主要LDAP」 BDB Copy To Slaver LDAP

方法一:直接??

在?? Master LDAP BDB 之前記得執行 db_checkpoint 已確保所有資料已寫入 BDB 資料庫中,本次我的實作為直接把 BDB 資料庫??到 Slaver LDAP 的 BDB 資料庫路徑。

先確保資料寫入資料庫中
db_checkpoint-4.3 -1 -h /var/db/openldap-data/
scp /var/lib/ldap/* root@wwww.shsps.kh.edu.tw:/var/lib/ldap/

方法二:按照步驟來

匯出「主要LDAP」資料庫資料

slapcat -b "dc=server,dc=kh,dc=edu,dc=tw" -l /tmp/contents.ldif

??資料到「次要LDAP」

scp /tmp/contents.ldif root@server.kh.edu.tw:/tmp/contents.ldif

匯入資料到「次要LDAP」

slapadd -l /tmp/contents.ldif

修該資料庫擁有者

chown ldap.ldap /var/lib/ldap/*.*

Step4. 修改 Slaver LDAP slapd.conf 內容

vi /etc/openldap/slapd.conf

rootdn "uid=donlboy,cn=Manager,dc=domain,dc=kh,dc=edu,dc=tw" //Slaver LDAP RootDN
rootpw {MD5}FkyWuaT5c+FdMK43DGG6GA== //( MD5加密)
updatedn "uid=admin2,cn=Manager,dc=domain,dc=kh,dc=edu,dc=tw" //Master LDAP slurpd ??
updateref ldap:// www.111cn.net //更新要求送給 Master LDAP

Step5. 先啟動 Slaver LDAP slapd daemon

service slapd start

Step6.後啟動 Master LDAP slapd daemon

service slapd start

測實驗證是否成功

ldapsearch -x -b "cn=Manager,dc=domain,dc=kh,dc=edu,dc=tw" uid=*

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.