ldap本人感覺挺有技術含量的,需要多多聯繫,對了聲明一下本人在uplooking中學習過,所有出現uplooking字眼不要驚訝,知識都是我一點一點總結,寫出來的,沒有做任何抄襲。
ldap 清涼級別訪問協議 用戶集中管理
用戶集中管理的軟件
openldap nis網絡信息服務 他是CS結構 比較麻煩 one dinectory windows的AD
-------------------------------------------------
open l dap 是一個協議 只要程序支持這個協議就都可以用 (裏面的數據支持在AD裏導入)
他的前身是dap 有一個致命的弱點 不支持tcp/ip協議
ldap的優勢
1 他是一個協議
2 可以跨平臺只要支持這個協議
3 只限於讀多 寫少 (讀的比較快)
ldap僅僅限制於身份驗證
ldap的數據存儲結構 是樹形結構根據域名來設計
com
|
uplooking
| |
中國 美國
| |
北京 州
ldp有自己的名詞 比如:
dc----------(地裏位置 域組件)
ou---------- (組織單元比作一個容器可以存放東西) 放的是對象
dn -----------(區別名稱 )
屬性----對象的屬性
所有的屬性 在一塊成爲屬性類
所有的對象 在一塊成爲對象類
屬性類是用來描述 對象類
生活環境中什麼使用要用
1 客戶端要登錄的生活需要服務器驗證 的 有: 網吧,大學的校園網絡
ldap -------- 客戶端
2 三個服務 ftp maill sshd 都需要身份驗證, 可以在公共的一臺服務器上驗證他的三個身份驗證
———— ftp
ldap ———— maill、
———— sshd
--------------------------------------------
配置openldop
[root@xu chroot]# yum install openldap openldap-servers
openldap 協議包
openldap-servers 服務器端
[root@xu chroot]# ls /etc/openldap/ -----------配置文件
cacerts/ ldap.conf slapd.conf
DB_CONFIG.example schema/
ldap.conf -------------如果你作爲客戶端 這是客戶端的配置文件
slapd.conf -------------這個是serVer 端的配置文件
schema/ -------------- 這個文件夾裏都是架構模板文件 他可以幫我們生存對象類和屬性類
裏面有個nis.schema 可以滿足我們的所有需求
vim nis.schema
定義屬性 天書目錄結構 描述信息
49 attributetype ( 1.3.6.1.1.1.1.2 NAME 'gecos'
50 DESC 'The GECOS field; the common name'
51 EQUALITY caseIgnoreIA5Match
52 SUBSTR caseIgnoreIA5SubstringsMatch
53 SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE )
161 objectclass ( 1.3.6.1.1.1.2.0 NAME 'posixAccount'
162 DESC 'Abstraction of an account with POSIX attributes'
163 SUP top AUXILIARY
164 MUST ( cn $ uid $ uidNumber $ gidNumber $ homeDirectory )---------------我用這些屬性來描述 posixAccount' 對象
165 MAY ( userPassword $ loginShell $ gecos $ description ) )
166
[root@www openldap]# cd /etc/openldap/
[root@xu openldap]# vim slapd.conf
5 include /etc/openldap/schema/core.schema ------------定義模板
6 include /etc/openldap/schema/cosine.schema
7 include /etc/openldap/schema/inetorgperson.schema
8 include /etc/openldap/schema/nis.schema
85 database bdb ----波克力 開發的數據庫的意思
86 suffix dc=bj,dc=uplooking,dc=com" ----------------定義 dc區域
87 rootdn(區別名稱) "cn=admin,dc=bj,dc=uplooking,bc=com"
rootpw 123--------------------(設置密碼用倆個tab分割)
dn 就是區別這個的
張三 cn=張三 ou=it dc=bj dc=uplooking
cn=張三 ou=ka dc=bj dc= uplooking
97 directory /var/lib/ldap-------------ldap的數據庫都在這裏
100 index objectClass eq,pres -----------------索引 這些是用來作ldap 優化的
101 index ou,cn,mail,surname,givenname eq,pres,sub
102 index uidNumber,gidNumber,loginShell eq,pres
103 index uid,memberUid eq,pres,sub
104 index nisMapName,nisMapEntry eq,pres,sub
[root@xu openldap]# cp DB_CONFIG.example /var/lib/ldap/DB_CONFIG
[root@xu openldap]# ls /var/lib/ldap/ ------重啓服後會在這裏生成數據庫 必須有DB_CONFIG這個文件
[root@localhost ~]# chown ldap /var/lib/ldap/DB_CONFIG ------必須要該
[root@xu openldap]# service ldap restart 重啓服務
生成數據文件
useradd ldap1 設置密碼
useradd ldap2 設置密碼
useradd ldap3 設置密碼
[root@xu openldap]# grep ldap[1-3] /etc/passwd > /tmp/users.txt --------------提取出用戶和組信息
[root@xu openldap]# grep ldap[1-3] /etc/group > /tmp/groups.txt --------------提取出用戶和組信息
[root@xu migration]# cd /usr/share/openldap/migration/ ------------這裏的的東西可以幫我們聲稱數據庫文件
vim migrate_common.ph
71 $DEFAULT_MAIL_DOMAIN = "bj.uplooking.com"; ------這裏改成和服務器上一樣的
72
73 # Default base
74 $DEFAULT_BASE = "dc=bj,dc=uplooking,dc=com";
75
[root@xu migration]# ./migrate_base.pl > /tmp/uplooling.ldif ----------------- ld i信息 f 格式 聲稱了ou 生成ldap主文件
裏面就是ldap的格式
第一部分是最重要的 定級域
1 dn: dc=bj,dc=uplooking,dc=com
2 dc: bj
3 objectClass: top
4 objectClass: domain
5
36 dn: ou=People,dc=bj,dc=uplooking,dc=com
37 ou: People
38 objectClass: top
39 objectClass: organizationalUnit
40
41 dn: ou=Group,dc=bj,dc=uplooking,dc=com
42 ou: Group
43 objectClass: top
44 objectClass: organizationalUnit
45
有了ou 有對象了 裏面的數值沒有還
用導出的文件生成數據庫數據
[root@xu migration]# ./migrate_passwd.pl /tmp/users.txt > /tmp/users.ldif ------------這裏的所有內容只是一個用戶的信息
[root@xu migration]# ./migrate_group.pl /tmp/groups.txt > /tmp/groups.ldif -----------------------------這裏是組的信息
導入到數據庫去
這的密碼是admin的密碼
ldapadd -x -D "cn=admin,dc=bj,dc=uplooking,dc=com" -w 123 -f /tmp/uplooling.ldif ------導入域進去
ldapadd -x -D "cn=admin,dc=bj,dc=uplooking,dc=com" -w 123 -f /tmp/groups.ldif ----------導入用戶信息
ldapadd -x -D "cn=admin,dc=bj,dc=uplooking,dc=com" -w 123 -f /tmp/users.ldif ---------導入用戶信息
u
信息的文件,注 uplooking.ldif 必須最先導入。
-x 簡單驗證
-D 指定身份
-W 提示輸入口令
ldapsearch -x -w 123 -h 127.0.0.1 -D "cn=admin,dc=bj,dc=uplooking,dc=com" -b "dc=bj,dc=uplooking,dc=com" -----檢查
ssh 192.168.1.113 -X 不加X只能悄命令 加X 可以開啓圖形
客戶端 用 系統-- 管理-- 驗證 用戶信息 設置ldap
[root@xu migration]# system-config-authentication ----配置ldap
登錄 測試 su - test1
------------------------------------------------------------
每次添加 轉換方法
[root@xu openldap]# cd /usr/share/openldap/migration/
用 ldapadd
ldappsearch 太麻煩
用 用戶管理工具
WEB
phpLDAPadmin
LAM
---------------------------
phpLDAPadmin
yum install php-ldap -----------ldap和php連接的包
[root@xu Desktop]# tar -xvf phpldapadmin-1.2.0.4.tgz ----解壓
[root@xu ldap]# mv phpldapadmin-1.2.0.4 /var/www/html/ldap
[root@xu ldap]# service httpd restart`
登錄
firefox http://localhost/ldap
[root@xu ldap]# cd /var/www/html/ldap/config/
[root@xu config]# cp config.php.example config.php ---修改配置文件
---------------------------
apache 和ldap 的結合
[root@xu Desktop]# yum install mod_authz_ldap
[root@xu Desktop]# vim /etc/httpd/conf/httpd.conf
[root@xu Desktop]# ls /etc/httpd/modules/mod_authz_ldap.so 添加了這個模塊
vim /etc/httpd/conf.d/authz_ldap.conf--------------------------配置文件
5
6 LoadModule authz_ldap_module modules/mod_authz_ldap.so
7
8 <IfModule mod_authz_ldap.c>
9 <Directory "/var/www/html/">
10 AuthzLDAPMethod ldap
11 AuthzLDAPServer 192.168.1.113
12 authzldapuserbase ou=people,dc=bj,dc=uplooking,dc=com
13 AuthzLDAPUserKey uid
14 AuthzLDAPUserScope base
15 AuthType basic
16 authname "test"
17 require valid-user
18 </directory>
19
20 # <Location /private>
21 # AuthzLDAPEngine on
service httpd restart 重啓服務