2011年10月7日 星期五

CentOS 5.6 LDAP Server + Samba Server

續上篇的安裝方式後。

接下來我們要開始應用LDAP Server。

因為公司環境的關係,讓我們只好拿很多台PC來架設Samba Server。

為了解決每台Server帳號同步的問題,所以我決定使用LDAP。
(雖然帳號同步也可以不靠LDAP就能決解,但我還是比較喜歡玩新東西)

首先我們依上續「CentOS 5.6 Install LDAP + phpldapadmin」安裝完後。

接下來我們可以使用phpldapadmin創使用者,或可以匯入本機使用者群組。

轉換使用者群組

1.先對LDAP Server建立People與Group
#cat << EOT | ldapadd -x -D "cn=admin,dc=ecc,dc=stu" -W
>dn:People,dc=ecc,dc=stu
>ou:People
>objectClass:organizationalUnit
>EOT


#cat << EOT | ldapadd -x -D "cn=admin,dc=ecc,dc=stu" -W
>dn:Group,dc=ecc,dc=stu
>ou:Group
>objectClass:organizationalUnit
>EOT



2.建立完該有的東西後,接下來下載MigrationTools套件來轉換帳號
#tar  -zxvf MigrationTools.tgz 
#mv MigrationTools-47 /usr/src/MigrationTool



3.轉換前置作業,更改 site-specific defaul
#vi /usr/src/MigrationTools/migrate_common.ph 
$DEFAULT_MAIL_DOMAIN="ecc.stu";                                   
$DEFAULT_BASE="dc=ecc,dc=stu";


4.開始轉換所有本機帳號、群組,格式為ldif
帳號轉換
#cd /usr/src/MigrationTools
#./migrate_passwd.pl /etc/passwd local.passwd.ldif

群組轉換
#./migrate_group.pl /etc/group local.group.ldif

開始匯入
#slapadd -v -l local.passwd.ldif

#slapadd -v -l local.group.ldif

5.將LDAP資料庫設定擁有者與群組給 ldap
#chown ldap:ldap /var/lib/ldap/*

6.啟動LDAP
#service ldap start

##可以測試一下剛剛所匯入的資料##
#ldapsearch -x -b "dc=ecc,dc=stu"
大致上都會成功

7.更改/etc下的ldap.conf
#vim /etc/ldap.conf
host 127.0.0.1
base dc=ecc,dc=stu
url ldap://127.0.0.1
bind_policy soft


##設定到這裡,LDAP大致上已經完成了,接下來我們準備安裝Samba Server##


安裝Samba Server整合LDAP Server

1.Install Samba Server
#yum -y install samba samba-client

2.安裝authconfig-tui (主要是設定LDAP Client)
#yum -y install authconfig

3.執行authconfig
#authconfig-tui
選擇緩衝區資訊、使用LDAP、使用MD5密碼、使用Shadow密碼、使用LDAP認證
按下一步
設定伺服器:ldap://(LDAP IP)/
基底 DN:dc=ecc,dc=stu

4.修改smb.conf
#vim /etc/samba/smb.conf
workgroup = WORKGROUP
server string = Samba Server Version %    v
netbios name = LB215-Drives
encrypt passwords = yes
unix charset = utf8
display charset = utf8
dos charset = cp950
.
.
.
log file = /var/log/samba/log.%m
max log size = 50
.
.
.
security = user
passdb backend = ldapsam:ldap://192.168.20.44/
ldap suffix = "ou=People,dc=ecc,dc=stu"
ldap admin dn = "cn=admin,dc=ecc,dc=stu"
ldap group suffix = "ou=Group,dc=ecc,dc=stu"
ldap user suffix = "ou=People,dc=ecc,dc=stu"
ldap delete dn = no
ldap ssl = no
.
.
.
local master = no
os level = 33
.
.
.
load printers = no
cups options = raw
.
.
.
map to guest = Bad User
.
.
.
[Drives]
comment = Drives
path = /home/samba/Drives
read only = yes
write list = @samba
create mask = 0774
directory mask = 0775

5.複製samba.schema到LDAP Server
#scp user@Samba.Server.IP:/usr/share/doc/samba-3.5.4/LDAP/samba.schema /etcopenldap/schema/


6.修改slapd.conf
#註解下列幾行                                                       
#index objectClass     eq,pres                         
#index ou,cn,mail,surname,givenname eq,pres,sub                        
#index uidNumber,gidNumber,loginShell eq,pres                          
#index uid,memberUid    eq,pres,sub                       
#index nisMapName,nisMapEntry  eq,pres,su

#新增下列幾行                                                       
index  cn,sn,uid,displayName   pres,sub,eq
index  uidNumber,gidNumber   eq
index  sambaSID     eq
index  sambaPrimaryGroupSID   eq
index  sambaDomainName   eq
index  objectClass     pres,eq
index  default      sub

#新增下列幾行
access to attrs=userPassword,shadowLastChange
        by dn="cn=admin,dc=eecc,dc=stu" write
        by anonymous auth
        by self write
        by * none
access to *
        by dn="cn=admin,dc=eecc,dc=stu" write
        by * read

#儲存後離開
#重新啟動LDAP Server

7.將LDAP Server管理者帳號的密碼存入 /etc/samba/secrets.tdb
#smbpasswd -w



大致上只要上面的步驟就可以成功將Samba+LDAP安裝完成
如果沒有成功,不是你漏掉了,不然就是我漏掉了。


備註:
在安裝的過程中所遇上的一些問題記錄在此

1.遇上無法在/home目錄裡分享的資料夾
將目錄設定為777

如果出現tree connect failed: NT_STATUS_BAD_NETWORK_NAME
#setsebool -P samba_enable_home_dirs=1

那如果又出現一樣的訊息tree connect failed: NT_STATUS_BAD_NETWORK_NAME
#chcon -R -t samba_share_t /free (/free為分享的資料夾)



2.當使用者登不進samba所分享的資料裡時,可能原因如下
i.使用者帳號未新增到LDAP Server裡或未設定samba密碼
如果已新增到LDAP Server執行
#smbpasswd -a uid (uid為存在LDAP的帳號)




參考資料: