Centos6配置ldapphp
設備基本信息:html
1、系統基本信息java
cat /etc/redhat-release linux
CentOS release 6.6 (Final)web
uname -a數據庫
Linux master 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linuxapache
2、軟件版本基本信息,軟件都是yum安裝的vim
1、基礎配置windows
1、關閉防火牆bash
iptables -F
/etc/init.d/iptables save
/etc/init.d/iptables stop
chkconfig --del iptables
2、關閉selinux
sed -i 's/SELINUX=enabled/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
查看selinux
getenforce
三、配置域名解析hosts
echo "192.168.18.184 hxy.com" >> /etc/hosts
4、安裝ldap
yum -y install openldap openldap-servers openldap-clients openldap-devel compat-openldap -y
5、查看安裝完成後的結果:
[root@bogon ~]# tail -1 /etc/passwd
ldap:x:55:55:OpenLDAP server:/var/lib/ldap:/sbin/nologin
6、還能夠經過rpm -qa|grep openldap看到安裝了5個軟件包
rpm -qa|grep openlda
openldap-servers-2.4.40-16.el6.x86_64
openldap-2.4.40-16.el6.x86_64
openldap-clients-2.4.40-16.el6.x86_64
compat-openldap-2.3.43-2.el6.x86_64
openldap-devel-2.4.40-16.el6.x86_64
7、複製配置文件
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
cp /usr/share/openldap-servers/slapd.conf.obsolete /etc/openldap/slapd.conf
8、生成密碼:(密碼你本身設定hxy123)這條命令是將輸出結果輸入到slapd.conf文件尾部
注:-s後面接的是你的密碼
slappasswd -s hxy123|sed -e "s#{SSHA}#rootpw\t{SSHA}#g">>/etc/openldap/slapd.conf
tail -1 /etc/openldap/slapd.conf
rootpw {SSHA}8oL44HqnBOxEZyKGJr1Som2WV7apHHG0
9、查看slapd.conf配置文件:
grep -Ev "^$|^#" /etc/openldap/slapd.conf > /etc/openldap/slapd.conf_bak
\cp /etc/openldap/slapd.conf_bak /etc/openldap/slapd.conf
cat /etc/openldap/slapd.conf
include /etc/openldap/schema/corba.schema
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/duaconf.schema
include /etc/openldap/schema/dyngroup.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/java.schema
include /etc/openldap/schema/misc.schema
include /etc/openldap/schema/nis.schema
include /etc/openldap/schema/openldap.schema
include /etc/openldap/schema/ppolicy.schema
include /etc/openldap/schema/collective.schema
allow bind_v2
pidfile /var/run/openldap/slapd.pid
argsfile /var/run/openldap/slapd.args
TLSCACertificatePath /etc/openldap/certs
TLSCertificateFile "\"OpenLDAP Server\""
TLSCertificateKeyFile /etc/openldap/certs/password
database config
access to *
by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manage
by * none
database monitor
access to *
by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read
by dn.exact="cn=Manager,dc=my-domain,dc=com" read
by * none
database bdb
suffix "dc=my-domain,dc=com"
checkpoint 1024 15
rootdn "cn=Manager,dc=my-domain,dc=com"
directory /var/lib/ldap
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,sub
rootpw {SSHA}8oL44HqnBOxEZyKGJr1Som2WV7apHHG0
10、修改配置文件
sed -i 's@cn=Manager,dc=my-domain,dc=com@cn=Forand,dc=hxy,dc=com@g' /etc/openldap/slapd.conf
sed -i 's@dc=my-domain,dc=com@dc=hxy,dc=com@' /etc/openldap/slapd.conf
echo -e 'loglevel 296\ncachesize 1000'>>/etc/openldap/slapd.conf
vim /etc/openldap/slapd.conf
by dn.exact="cn=Forand,dc=hxy,dc=com" read
suffix "dc=hxy,dc=com"
rootdn "cn=Forand,dc=hxy,dc=com"
rootpw {SSHA}8oL44HqnBOxEZyKGJr1Som2WV7apHHG0
loglevel 296
cachesize 1000
這是和源文件不一樣的幾個地方
11、修改完成後測試一下配置文件是否有問題
slaptest -f /etc/openldap/slapd.conf
我這裏報錯了!:
[root@hxy openldap]# slaptest -f /etc/openldap/slapd.conf -v
5b0d6f3d bdb_db_open: DB_CONFIG for suffix "dc=hxy,dc=com" has changed.
5b0d6f3d Performing database recovery to activate new settings.
5b0d6f3d bdb_db_open: database "dc=hxy,dc=com": recovery skipped in read-only mode. Run manual recovery if errors are encountered.
5b0d6f3d bdb_db_open: database "dc=hxy,dc=com": db_open(/var/lib/ldap/id2entry.bdb) failed: No such file or directory (2).
5b0d6f3d backend_startup_one (type=bdb, suffix="dc=hxy,dc=com"): bi_db_open failed! (2)
slap_startup failed (test would succeed using the -u switch)
在網上查了一下,
db_open(/var/lib/ldap/id2entry.bdb) failed: No such file or directory (2)
backend_startup_one (type=bdb, suffix="dc=hxy,dc=com"): bi_db_open failed! (2)
(這個文件須要登slapd啓動時,纔會生成 因此如今沒有 不用管)
這裏報錯是由於在第三步後沒有從新生成配置文件,啓動slapd。而是直接修改配置文件去了
12、能夠試下這樣啓動
slaptest -f /etc/openldap/slapd.conf -u
config file testing succeeded
測試配置文件沒問題
1三、啓動服務
(1)問題1:
這裏又報錯,這是由於沒有給/var/lib/ldap受權,受權後chown -R ldap.ldap /var/lib/ldap/,再重啓slapd,/etc/init.d/slapd restart,能夠看到成功的
chown -R ldap.ldap /var/lib/ldap/
/etc/init.d/slapd restart
Stopping slapd: [FAILED]
Starting slapd: [ OK ]
(2)問題2:若是出現:
報錯緣由爲權限問題,解決方法爲
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
/etc/init.d/slapd restart
14、把ldap的日誌加入系統日誌記錄
cp /etc/rsyslog.conf /etc/rsyslog.conf.bak.$(date +%F%T)
echo '#record ldap.log by hxy 2018-07-08' >> /etc/rsyslog.conf
echo 'local4.* /var/log/ldap.log'>> /etc/rsyslog.conf
tail -1 /etc/rsyslog.conf
#local4.* /var/log/ldap.log
service rsyslog restart
15、從新生成配置文件的配置信息:
rm -rf /etc/openldap/slapd.d/*
從新生成:
slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d/
config file testing succeeded
查看是否生成的是本身修改的配置文件信息:
cat /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif
他這裏會輸出一推信息,咱們只關心咱們的信息是否存在就好了:
cat /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif|egrep "olcSuffix|olcRootDN"
olcSuffix: dc=hxy,dc=com
olcRootDN: cn=Forand,dc=hxy,dc=com
這樣就OK了
受權, 重啓:
chown -R ldap.ldap /etc/openldap/slapd.d/
/etc/init.d/slapd restart
16、配置ldap數據庫權限
ll /var/lib/ldap/DB_CONFIG
chown ldap.ldap /var/lib/ldap/DB_CONFIG
chmod 700 /var/lib/ldap/
ls -l /var/lib/ldap/
1七、驗證是否成功:
slaptest -u
config file testing succeeded
18、建立一個帳號,用於導入ldap數據庫(密碼123456)
useradd testuser
passwd testuser
useradd ldapuser
passwd ldapuser
19、至此,這些用戶僅僅是系統上存在的用戶(存儲在/etc/passwd和/etc/shadow上),並無在LDAP數據庫裏,因此要把這些用戶導入到LDAP裏面去。但LDAP只能識別特定格式的文件 即後綴爲ldif的文件(也是文本文件),因此不能直接使用/etc/passwd和/etc/shadow。 須要migrationtools這個工具把這兩個文件轉變成LDAP能識別的文件。
20、安裝配置migrationtools
yum install migrationtools -y
21、進入migrationtool配置目錄
cd /usr/share/migrationtools/
23、首先編輯
sed -i 's/padl/hxy/g' migrate_common.ph
vim migrate_common.ph
改成
# Default DNS domain
$DEFAULT_MAIL_DOMAIN = "hxy.com";
# Default base
$DEFAULT_BASE = "dc=hxy,dc=com";
24、建立LDIF文件
拷貝密碼和組的文件到tmp下面而後留下你須要的用戶和組,否則整個用系統的文件有不少很雜,
cp /etc/passwd /tmp/
cp /etc/group /tmp/
cat /tmp/passwd
testuser:x:501:501::/home/testuser:/bin/bash
ldapuser:x:502:502::/home/ldapuser:/bin/bash
cat /tmp/group
testuser:x:501:
ldapuser:x:502:
25、下面利用pl腳本將/etc/passwd 和/etc/shadow生成LDAP能讀懂的文件格式,保存在/tmp/下
cd /usr/share/migrationtools/
./migrate_base.pl > /tmp/base.ldif
./migrate_passwd.pl /tmp/passwd > /tmp/passwd.ldif
./migrate_group.pl /tmp/group > /tmp/group.ldif
26、下面就要把這三個文件導入到LDAP,這樣LDAP的數據庫裏就有了咱們想要的用戶
ldapadd -x -D "cn=Forand,dc=hxy,dc=com" -W -f /tmp/base.ldif
ldapadd -x -D "cn=Forand,dc=hxy,dc=com" -W -f /tmp/passwd.ldif
ldapadd -x -D "cn=Forand,dc=hxy,dc=com" -W -f /tmp/group.ldif
過程若無報錯,則LDAP服務端配置完畢
這過程當中會讓你輸密碼,密碼就是你上面配置的密碼
注:若是遇到以下錯誤:
解決辦法是:
rm -rf /etc/openldap/slapd.d/*
chown -R ldap.ldap /etc/openldap
slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d
config file testing succeeded
2七、測試查找內容
ldapsearch -LLL -W -x -H ldap://hxy.com -D "cn=Forand,dc=hxy,dc=com" -b "dc=hxy,dc=com" "(uid=*)"
若是找不到就重啓下ldap就行
到這裏ldap的基本配置算是完成了
咱們還能夠下載個web管理界面來更號的管理ldap
2八、爲ldap master配置web管理接口
①、安裝lamp環境
yum install -y httpd php php-ldap php-gd
②、安裝ldap-account-manager管理軟件
https://www.ldap-account-manager.org/lamcms/releases?page=3
將ldap-account-manager-3.7.tar.gz安裝包上傳到/var/www/html目錄
cd /var/www/html/
tar zxf ldap-account-manager-3.7.tar.gz
mv ldap-account-manager-3.7 ldap
cd ldap/config
cp config.cfg_sample config.cfg
cp lam.conf_sample lam.conf
sed -i 's#cn=Manager#cn=Forand#g' lam.conf
sed -i 's#dc=my-domain#dc=hxy#g' lam.conf
chown -R apache.apache /var/www/html/ldap
③頁面登陸一下
http://192.168.18.184/ldap/templates/login.php
密碼就是上面你配置的ldap的密碼
選擇中文登陸
④
點擊創建
⑤查看你導入進來的用戶
⑥新建新的用戶
點擊新用戶
1)、編輯我的信息
2)、編輯unix信息
3)、再設置密碼(123456),點擊肯定,而後點擊保存
4)、再在用戶裏面查看一下
2九、檢查新建的ldap用戶是否可以查詢到
ldapsearch -LLL -W -x -H ldap://hxy.com -D "cn=Forand,dc=hxy,dc=com" -b "dc=hxy,dc=com" "(uid=test1)"
能查詢到OK ldap配置完成
到此ldap配置完成
2、配置svn
1、安裝svn
yum install -y subversion
2、新建svn目錄
mkdir -p /root/svn/svnserver
4、啓動svn
svnserve -d -r /root/svn/svnserver/
備註:若是要更改端口啓動的時候接上「--listen-port」新端口。
5、建立版本庫
svnadmin create /root/svn/svnserver/patch
6、修改svnserve.conf配置文件,在[general]下方加入這四行
> /root/svn/svnserver/patch/conf/svnserve.conf
cat >> /root/svn/svnserver/patch/conf/svnserve.conf<<EOF
[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
realm = patch
[sasl]
use-sasl = true
EOF
vim /root/svn/svnserver/patch/conf/svnserve.conf
[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
realm = patch
[sasl]
use-sasl = true
備註:realm 這行也能夠不加。
7、建立svn用戶和權限分配
在 /root/svn/svnserver/patch/conf目錄下,有兩個文件是配置用戶帳號密碼和用戶權限的。
passwd 此文件配置用戶帳號和密碼
vim /root/svn/svnserver/patch/conf/passwd
[users]
svnTest= 123456
test = 123456
authz 此文件配置用戶權限
vim /root/svn/svnserver/patch/conf/authz
[aliases]
[groups]
ldap_user = test1
admin = test
user = test,svnTest
[patch:/]
@admin = rw
@user = rw
@ldap_user = rw
備註:authz這個文件詳細控制權限
9、在linux上檢查命令是
svn checkout svn://192.168.18.184:3690/patch
輸入完成後這個就是svn了
或者是在windows上面下個客戶端作實驗都行
3、SVN配置完成後配置saslauthd的認證方式
1、saslauthd
cat >> /etc/saslauthd.conf <<EOF
ldap_servers: ldap://hxy.com/
ldap_bind_dn: cn=Forand,dc=hxy,dc=com
ldap_bind_pw: hxy123
ldap_search_base: ou=People,dc=hxy,dc=com
ldap_filter: uid=%U
ldap_password_attr: userPassword
EOF
vim /etc/saslauthd.conf
ldap_servers: ldap://hxy.com/ #你的ldap地址
ldap_bind_dn: cn=Forand,dc=hxy,dc=com
ldap_bind_pw: hxy123 #你ldap的密碼
ldap_search_base: ou=People,dc=hxy,dc=com
ldap_filter: uid=%U
ldap_password_attr: userPassword
2、修改saslauthd認證方式爲ldap認證
sed -i 's/MECH=pam/MECH=ldap/' /etc/sysconfig/saslauthd
vim /etc/sysconfig/saslauthd
MECH=pam
改成
MECH=ldap
3、修改svn使用saslauthd認證
echo -e 'pwcheck_method: saslauthd\nmech_list: PLAIN LOGIN' >>/etc/sasl2/svn.conf
vim /etc/sasl2/svn.conf
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
4、而後重啓saslauthd服務
/etc/init.d/saslauthd restart
5、而後試着驗證一下ldap用戶用
testsaslauthd -utest1 -p123456
這樣就沒問題了
六、在svn的server的配置文件上把saslauth的認證開啓
7、取消這個的註釋
vim /root/svn/svnserver/patch/conf/svnserve.conf
use-sasl = true
或者能夠直接用sed
sed -i 's/# use-sasl = true/use-sasl = true/' /root/svn/svnserver/patch/conf/svnserve.conf
八、重啓svn服務
pkill svn
svnserve -d -r /root/svn/svnserver/
九、而後用ldap帳戶提交svn
svn checkout svn://192.168.18.184/patch /tmp --username=test1 --password=123456
這樣就沒問題了
到此ldap+svn試驗完成
本文參考:
https://www.cnblogs.com/dadong616/p/5092655.html
https://blog.csdn.net/reblue520/article/details/51804162