Linux系統(tǒng)下安裝配置 OpenLDAP + phpLDAPadmin

實驗環(huán)境:

操作系統(tǒng):Centos 7.4

服務(wù)器ip:192.168.3.41

運行用戶:root

網(wǎng)絡(luò)環(huán)境:Internet

LDAP(輕量級目錄訪問協(xié)議)是一個能實現(xiàn)提供被稱為目錄服務(wù)的信息服務(wù),也是一套用戶認證體系系統(tǒng)章贞;一般在大型企業(yè)祥绞、學(xué)校、政府單位使用的比較多鸭限,LDAP是由4部分組成蜕径,這4部分分別是slapd(獨立LDAP守護進程)、slurpd(獨立的LDAP更新復(fù)制守護進程)败京、LDAP協(xié)議庫兜喻、工具軟件和示例客戶端(phpLDAPadmin),目錄服務(wù)是一種特殊的數(shù)據(jù)庫系統(tǒng)赡麦,用來存儲用戶信息的數(shù)據(jù)庫朴皆,讀寫速度非撑潦叮快,擴展性非常強遂铡,可以實現(xiàn)與地方系統(tǒng)直接對接整合起來統(tǒng)一管理用戶信息肮疗。

LDAP說起來也不簡單,但是ALDP在Linux應(yīng)用范圍是比較廣泛的扒接,如果想要深入的了解LDAP伪货,建議去看下劉遄老師《Linux就該這么學(xué)》這本教程,里面解釋的非常詳細钾怔,也可以在百度輸入此書名去官網(wǎng)看超歌,想要在Linux部署還是推薦這本書去系統(tǒng)的學(xué)習(xí),對初學(xué)者還是很有版本的蒂教,這篇文章搭建ldap+phpldapadmin也是在Linux環(huán)境下運行的巍举,所以還是需要Linux基礎(chǔ)才能看懂下面的配置步驟。

1凝垛、安裝OpenLDAP

[root@centos7 ~]# yum install openldap-servers openldap-clients -y

[root@centos7 ~]# cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG

[root@centos7 ~]# ll /var/lib/ldap/DB_CONFIG

-rw-r--r--. 1 root root 845 Aug? 1 10:04 /var/lib/ldap/DB_CONFIG

[root@centos7 ~]# chown ldap. /var/lib/ldap/DB_CONFIG //授權(quán)配置文件

[root@centos7 ~]# more /etc/passwd|grep ldap

ldap:x:55:55:OpenLDAP server:/var/lib/ldap:/sbin/nologin

[root@centos7 ~]# systemctl start slapd.service //啟動slapd服務(wù)

[root@centos7 ~]# systemctl enable slapd.service //設(shè)置開機自動啟動slapd服務(wù)

2懊悯、設(shè)置OpenLDAP管理員密碼

[root@centos7 ~]# slappasswd

New password:? //password

Re-enter new password:

{SSHA}d5pkA0TU6b+8/kEoMIxJ59QofCLV

為“olcRootPW”指定上面生成的密碼

[root@centos7 ~]# vim chrootpw.ldif

dn: olcDatabase={0}config,cn=config

changetype: modify

add: olcRootPW

olcRootPW: {SSHA}d5pkA0TU6b+8/kEokgQeMIxJ59QofCLV

[root@centos7 ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f chrootpw.ldif

SASL/EXTERNAL authentication started

SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth

SASL SSF: 0

modifying entry "olcDatabase={0}config,cn=config"

3、導(dǎo)入基本模式

[root@centos7 ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif

SASL/EXTERNAL authentication started

SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth

SASL SSF: 0

adding new entry "cn=cosine,cn=schema,cn=config"

[root@centos7 ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif

SASL/EXTERNAL authentication started

SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth

SASL SSF: 0

adding new entry "cn=nis,cn=schema,cn=config"

[root@centos7 ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif

SASL/EXTERNAL authentication started

SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth

SASL SSF: 0

adding new entry "cn=inetorgperson,cn=schema,cn=config"

4梦皮、在LDAP DB上設(shè)置域名炭分,生成目錄管理器密碼

[root@centos7 ~]# slappasswd

New password:

Re-enter new password:

{SSHA}Oq61fgUFW9+ItZboTaW1+VbLuAYst7zw

注意:下面配置文件這里得注意每一個屬性:?后必須有空格,但是值的后面不能有任何空格

[root@centos7 ~]# vim chdomain.ldif

# replace to your own domain name for "dc=***,dc=***" section

# specify the password generated above for "olcRootPW" section

dn: olcDatabase={1}monitor,cn=config

changetype: modify

replace: olcAccess

olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth"

? read by dn.base="cn=Manager,dc=srv,dc=world" read by * none

dn: olcDatabase={2}hdb,cn=config

changetype: modify

replace: olcSuffix

olcSuffix: dc=srv,dc=world

dn: olcDatabase={2}hdb,cn=config

changetype: modify

replace: olcRootDN

olcRootDN: cn=Manager,dc=srv,dc=world

dn: olcDatabase={2}hdb,cn=config

changetype: modify

add: olcRootPW

olcRootPW: {SSHA}Oq61fgUFW9+ItZboTaW1+VbLuAYst7zw

dn: olcDatabase={2}hdb,cn=config

changetype: modify

add: olcAccess

olcAccess: {0}to attrs=userPassword,shadowLastChange by

? dn="cn=Manager,dc=srv,dc=world" write by anonymous auth by self write by * none

olcAccess: {1}to dn.base="" by * read

olcAccess: {2}to * by dn="cn=Manager,dc=srv,dc=world" write by * read

[root@centos7 ~]# ldapmodify -Y EXTERNAL -H ldapi:/// -f chdomain.ldif

SASL/EXTERNAL authentication started

SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth

SASL SSF: 0

modifying entry "olcDatabase={1}monitor,cn=config"

modifying entry "olcDatabase={2}hdb,cn=config"

modifying entry "olcDatabase={2}hdb,cn=config"

modifying entry "olcDatabase={2}hdb,cn=config"

modifying entry "olcDatabase={2}hdb,cn=config"

[root@centos7 ~]# vim basedomain.ldif

# replace to your own domain name for "dc=***,dc=***" section

dn: dc=srv,dc=world

objectClass: top

objectClass: dcObject

objectclass: organization

o: Server World

dc: Srv

dn: cn=Manager,dc=srv,dc=world

objectClass: organizationalRole

cn: Manager

description: Directory Manager

dn: ou=People,dc=srv,dc=world

objectClass: organizationalUnit

ou: People

dn: ou=Group,dc=srv,dc=world

objectClass: organizationalUnit

ou: Group

[root@centos7 ~]# ldapadd -x -D "cn=Manager,dc=srv,dc=world" -W -f basedomain.ldif

Enter LDAP Password:? ? //輸入上面設(shè)置的目錄管理器密碼 password

adding new entry "dc=srv,dc=world"

adding new entry "cn=Manager,dc=srv,dc=world"

adding new entry "ou=People,dc=srv,dc=world"

adding new entry "ou=Group,dc=srv,dc=world"

[root@centos7 ~]# ldapsearch -x -b "cn=Manager,dc=srv,dc=world"

# extended LDIF

#

# LDAPv3

# base <cn=Manager,dc=srv,dc=world> with scope subtree

# filter: (objectclass=*)

# requesting: ALL

#

# Manager, srv.world

dn: cn=Manager,dc=srv,dc=world

objectClass: organizationalRole

cn: Manager

description: Directory Manager

# search result

search: 2

result: 0 Success

# numResponses: 2

# numEntries: 1

5剑肯、設(shè)置Firewalld捧毛,如果未啟用防火墻關(guān)閉,忽略

[root@centos7 ~]# firewall-cmd --add-service=ldap --permanent

[root@centos7 ~]# firewall-cmd --reload

6让网、安裝并配置Apache

[root@centos7 ~]# yum install httpd-devel.x86_64 httpd.x86_64 -y

[root@centos7 ~]# mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.bak

[root@centos7 ~]# vim /etc/httpd/conf/httpd.conf

# line 86: change to admin's email address

ServerAdmin root@srv.world

# line 95: change to your server's name

ServerName www.srv.world:80

# line 151: change

AllowOverride All

# line 164: add file name that it can access only with directory's name

DirectoryIndex index.html index.cgi index.php

# add follows to the end? //在尾部新增

# server's response header

ServerTokens Prod

# keepalive is ON

KeepAlive On

[root@centos7 ~]# systemctl start httpd.service

[root@centos7 ~]# systemctl enable httpd.service

[root@centos7 ~]# firewall-cmd --add-service=http --permanent //防火墻排除httpd服務(wù)呀忧,如果沒有啟用防火墻,此步驟可以忽略溃睹。

success

[root@centos7 ~]# firewall-cmd --reload //重新加載firewall

success

[root@centos7 ~]# vim /var/www/html/index.html //測試apache服務(wù)

<html>

<body>

<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">

Test Page

</div>

</body>

</html>

測試:http://192.168.3.41/index.html

7而账、安裝PHP

[root@centos7 ~]# yum -y install php php-mbstring php-pear

[root@centos7 ~]# vim /etc/php.ini

#修改時區(qū)? 878行

date.timezone = Asia/Shanghai

[root@centos7 ~]# systemctl restart httpd.service

[root@centos7 ~]# vim /var/www/html/index.php

<html>

<body>

<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">

<?php

? print Date("Y/m/d");

?>

</div>

</body>

</html>

php打印日期

測試:http://192.168.3.41/index.php

可以不安裝phpLDAPadmin工具,直接下載Windows系統(tǒng)下的LdapAdmin應(yīng)用程序

8因篇、安裝phpLDAPadmin

[root@centos7 ~]# yum install phpldapadmin.noarch -y

[root@centos7 ~]# vim /etc/phpldapadmin/config.php

397? $servers->setValue('login','attr','dn');? #取消397行注釋

398 //$servers->setValue('login','attr','uid');? #注釋398

[root@centos7 ~]# vim /etc/httpd/conf.d/phpldapadmin.conf

#

#? Web-based tool for managing LDAP servers

#

Alias /phpldapadmin /usr/share/phpldapadmin/htdocs

Alias /ldapadmin /usr/share/phpldapadmin/htdocs

<Directory /usr/share/phpldapadmin/htdocs>

? <IfModule mod_authz_core.c>

? ? # Apache 2.4

? ? #只允許本地請求訪問

? ? # Require local

? ? #允許所有的請求訪問

? ? ? Require all granted

? ? ? #允許IP段訪問

? ? ? #Require ip 10.0.0.0/24? ? ? ? ?

? </IfModule>

? <IfModule !mod_authz_core.c>

? ? # Apache 2.2

? ? Order Deny,Allow

? ? Deny from all

? ? Allow from 127.0.0.1

? ? Allow from ::1

? </IfModule>

</Directory>

[root@centos7 ~]# systemctl restart httpd.service

[root@centos7 ~]# systemctl status httpd.service

測試:http://192.168.3.41/ldapadmin/

如果是按照上面配置執(zhí)行的操作泞辐,登錄一直提示失敗,需要執(zhí)行

[root@centos7 ~]# setsebool -P httpd_can_connect_ldap on

cn=Manager,dc=srv,dc=world

9竞滓、基本操作和使用

9.1咐吼、添加組

9.2、添加用戶

9.3商佑、phpldapadmin的網(wǎng)站的apache配置文件

# vim /etc/httpd/conf.d/phpldapadmin.conf

#

#? Web-based tool for managing LDAP servers

#

Alias /phpldapadmin /usr/share/phpldapadmin/htdocs

Alias /ldapadmin /usr/share/phpldapadmin/htdocs

#注意:/usr/share/phpldapadmin/htdocs? 是phpldapadmin根目錄

<Directory /usr/share/phpldapadmin/htdocs>

? <IfModule mod_authz_core.c>

? ? # Apache 2.4

? ? #只允許本地請求訪問

? ? # Require local

? ? #允許所有的請求訪問

? ? Require all granted

? ? ? #允許IP段訪問

? ? ? #Require ip 192.168.3.0/24? ? ? ?

? </IfModule>

? <IfModule !mod_authz_core.c>

? ? # Apache 2.2

? ? Order Deny,Allow

? ? Deny from all

? ? Allow from 127.0.0.1

? ? Allow from ::1

? </IfModule>

</Directory>

這里可以直接訪問phpldapadmin后臺锯茄,最好是通過apache做密碼驗證才能登錄,這樣比較安全莉御。

參考文獻:httpd配置認證才能訪問網(wǎng)站(原創(chuàng)實踐操作).note

10撇吞、禁止匿名用戶登錄

# vim /root/ldap_disable_bind_anon.ldif

angetype: modify

add: olcDisallows

olcDisallows: bind_anon

dn: cn=config

changetype: modify

add: olcRequires

olcRequires: authc

dn: olcDatabase={-1}frontend,cn=config

changetype: modify

add: olcRequires

olcRequires: authc

[root@centos7 ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f ldap_disable_bind_anon.ldif

SASL/EXTERNAL authentication started

SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth

SASL SSF: 0

modifying entry "cn=config"

modifying entry "olcDatabase={-1}frontend,cn=config"

[root@centos7 ~]# systemctl restart slapd.service

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末俗冻,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子牍颈,更是在濱河造成了極大的恐慌迄薄,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,496評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件煮岁,死亡現(xiàn)場離奇詭異讥蔽,居然都是意外死亡,警方通過查閱死者的電腦和手機画机,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,407評論 3 392
  • 文/潘曉璐 我一進店門冶伞,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人步氏,你說我怎么就攤上這事响禽。” “怎么了荚醒?”我有些...
    開封第一講書人閱讀 162,632評論 0 353
  • 文/不壞的土叔 我叫張陵芋类,是天一觀的道長。 經(jīng)常有香客問我界阁,道長侯繁,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,180評論 1 292
  • 正文 為了忘掉前任泡躯,我火速辦了婚禮贮竟,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘较剃。我一直安慰自己咕别,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,198評論 6 388
  • 文/花漫 我一把揭開白布重付。 她就那樣靜靜地躺著顷级,像睡著了一般凫乖。 火紅的嫁衣襯著肌膚如雪确垫。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,165評論 1 299
  • 那天帽芽,我揣著相機與錄音删掀,去河邊找鬼。 笑死导街,一個胖子當(dāng)著我的面吹牛披泪,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播搬瑰,決...
    沈念sama閱讀 40,052評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼款票,長吁一口氣:“原來是場噩夢啊……” “哼控硼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起艾少,我...
    開封第一講書人閱讀 38,910評論 0 274
  • 序言:老撾萬榮一對情侶失蹤卡乾,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后缚够,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體幔妨,經(jīng)...
    沈念sama閱讀 45,324評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,542評論 2 332
  • 正文 我和宋清朗相戀三年谍椅,在試婚紗的時候發(fā)現(xiàn)自己被綠了误堡。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,711評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡雏吭,死狀恐怖锁施,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情杖们,我是刑警寧澤沾谜,帶...
    沈念sama閱讀 35,424評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站胀莹,受9級特大地震影響基跑,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜描焰,卻給世界環(huán)境...
    茶點故事閱讀 41,017評論 3 326
  • 文/蒙蒙 一媳否、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧荆秦,春花似錦篱竭、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,668評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至瓤介,卻和暖如春吕喘,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背刑桑。 一陣腳步聲響...
    開封第一講書人閱讀 32,823評論 1 269
  • 我被黑心中介騙來泰國打工氯质, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人祠斧。 一個月前我還...
    沈念sama閱讀 47,722評論 2 368
  • 正文 我出身青樓闻察,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子辕漂,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,611評論 2 353

推薦閱讀更多精彩內(nèi)容