close

環境 CentOS 6.7,

LDAP一般可以作為統一認證使用者身分的管理,

對IT人員來說是帳號管理的一大利器,

以下記錄這次安裝的歷程.

 

步驟如下:

安裝套件

如果只想裝server可以不用下openldap-clients指令

sudo yum install -y openldap-devel openldap-servers openldap openldap-clients  

產生管理者密碼

sudo slappasswd

會產生一組SSHA 開頭的字串,複製起來等等設定slapd.conf會用到

複製樣板

sudo cp /usr/share/openldap-servers/slapd.conf.obsolete /etc/openldap/slapd.conf
sudo cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG

編輯ldap設定檔

sudo vi /etc/openldap/slapd.conf

#
# See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
#

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 LDAPv2 client connections.  This is NOT the default.
allow bind_v2

# Do not enable referrals until AFTER you have a working directory
# service AND an understanding of referrals.
#referral       ldap://root.openldap.org

pidfile         /var/run/openldap/slapd.pid
argsfile        /var/run/openldap/slapd.args

loglevel        256
logfile        /var/log/slapd/ldap.log

# Load dynamic backend modules
# - modulepath is architecture dependent value (32/64-bit system)
# - back_sql.la overlay requires openldap-server-sql package
# - dyngroup.la and dynlist.la cannot be used at the same time

# modulepath /usr/lib/openldap
# modulepath /usr/lib64/openldap

# moduleload accesslog.la
# moduleload auditlog.la
# moduleload back_sql.la
# moduleload chain.la
# moduleload collect.la
# moduleload constraint.la
# moduleload dds.la
# moduleload deref.la
# moduleload dyngroup.la
# moduleload dynlist.la
# moduleload memberof.la
# moduleload pbind.la
# moduleload pcache.la
# moduleload ppolicy.la
# moduleload refint.la
# moduleload retcode.la
# moduleload rwm.la
# moduleload seqmod.la
# moduleload smbk5pwd.la
# moduleload sssvlv.la
# moduleload syncprov.la
# moduleload translucent.la
# moduleload unique.la
# moduleload valsort.la

# The next three lines allow use of TLS for encrypting connections using a
# dummy test certificate which you can generate by running
# /usr/libexec/openldap/generate-server-cert.sh. Your client software may balk
# at self-signed certificates, however.
TLSCACertificatePath /etc/openldap/certs
TLSCertificateFile "\"OpenLDAP Server\""
TLSCertificateKeyFile /etc/openldap/certs/password

# Sample security restrictions
#       Require integrity protection (prevent hijacking)
#       Require 112-bit (3DES or better) encryption for updates
#       Require 63-bit encryption for simple bind
# security ssf=1 update_ssf=112 simple_bind=64

# Sample access control policy:
#       Root DSE: allow anyone to read it
#       Subschema (sub)entry DSE: allow anyone to read it
#       Other DSEs:
#               Allow self write access
#               Allow authenticated users read access
#               Allow anonymous users to authenticate
#       Directives needed to implement policy:
# access to dn.base="" by * read
# access to dn.base="cn=Subschema" by * read
# access to *
#       by self write
#       by users read
#       by anonymous auth
#
# if no access controls are present, the default policy
# allows anyone and everyone to read anything but restricts
# updates to rootdn.  (e.g., "access to * by * read")
#
# rootdn can always read and write EVERYTHING!

# enable on-the-fly configuration (cn=config)
database config
access to *
        by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manage
        by * none

# enable server status monitoring (cn=monitor)
database monitor
access to *
        by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read
        by dn.exact="cn=root,dc=ldap,dc=aaron,dc=com,dc=tw" read
        by * none
#增加的部分
access to attrs=userPassword
       by self write
       by anonymous auth
       by dn.base="cn=root,dc=ldap,dc=aaron,dc=com,dc=tw" write
       by * none
#說明部分請看參考的文章

access to *
       by self write
       by users read
       by dn.base="cn=root,dc=ldap,dc=aaron,dc=com,dc=tw" write
       by * none

#######################################################################
# database definitions
#######################################################################

database        bdb
suffix          "dc=ldap,dc=aaron,dc=com,dc=tw"
checkpoint      1024 15
rootdn          "cn=root,dc=ldap,dc=aaron,dc=com,dc=tw"
# Cleartext passwords, especially for the rootdn, should
# be avoided.  See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
# rootpw                secret
# rootpw                {crypt}ijFYNcSNctBYg
rootpw          {SSHA}BYQXJRzOu7ZUfAlaS8QtfNnnDdkVhAf5  #前面產生的管理者密碼

# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory       /var/lib/ldap

# Indices to maintain for this database
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

# Replicas of this database
#replogfile /var/lib/ldap/openldap-master-replog
#replica host=ldap-1.example.com:389 starttls=critical
#     bindmethod=sasl saslmech=GSSAPI
#     authcId=host/ldap-master.example.com@EXAMPLE.COM
 

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

修改rsyslog,增加LDAP的記錄

sudo vi /etc/rsyslog.conf

local4.*                     /var/log/slapd/ldap.log  #隨便找個位置把這行加進去

sudo /etc/init.d/rsyslog restart

建立LDAP根路徑檔

mkdir /etc/openldap/arch

cd /etc/openldap/arch

vi arch.ldif

# Aaron LDAP Root DN
dn: dc=ldap,dc=aaron,dc=com,dc=tw
objectClass: dcObject
objectClass: organization
dc: ldap
o: Aaron-LDAP

# Magager ldap.aaron.com.tw Root DN
dn: cn=root,dc=ldap,dc=aaron,dc=com,dc=tw
objectClass: organizationalRole
cn: root

dn: ou=staff,dc=ldap,dc=aaron,dc=com,dc=tw
ou: staff
objectClass: organizationalUnit
description: staff

 

刪除就資料前要先停用服務

sudo service slapd stop

sudo rm -rf /etc/openldap/slapd.d/* 

sudo slapadd -v -l /etc/openldap/arch/arch.ldif

以下是加入顯示的訊息

56b6149d The first database does not allow slapadd; using the first available one (2)
added: "dc=ldap,dc=aaron,dc=com,dc=tw" (00000001)
added: "cn=root,dc=ldap,dc=aaron,dc=com,dc=tw" (00000002)
added: "ou=staff,dc=ldap,dc=aaron,dc=com,dc=tw" (00000003)
_#################### 100.00% eta   none elapsed            none fast!
Closing DB...

 

sudo slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d

config file testing succeeded
 

sudo chown -R ldap:ldap /etc/openldap/slapd.d

啟動服務

sudo service slapd restart 

sudo chkconfig slapd on

 

測試

sudo ldapsearch -x -b "dc=ldap,dc=aaron,dc=com,dc=tw"

# extended LDIF
#
# LDAPv3
# base <dc=ldap,dc=aaron,dc=com,dc=tw> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# ldap.aaron.com.tw
dn: dc=ldap,dc=aaron,dc=com,dc=tw
objectClass: dcObject
objectClass: organization
dc: ldap
o: Aaron-LDAP

# root, ldap.aaron.com.tw
dn: cn=root,dc=ldap,dc=aaron,dc=com,dc=tw
objectClass: organizationalRole
cn: root

# staff, ldap.aaron.com.tw
dn: ou=staff,dc=ldap,dc=aaron,dc=com,dc=tw
ou: staff
objectClass: organizationalUnit
description: staff

# search result
search: 2
result: 0 Success

# numResponses: 4
# numEntries: 3

 

參考

http://blog.xuite.net/tolarku/blog/161523701-LDAP+%E5%AE%89%E8%A3%9D%E4%BB%8B%E7%B4%B9+-+CentOS+6.4+-+openldap

http://yu-li-liang.blogspot.tw/2014/04/linux-centos-ldap-server-24.html

http://ha.shsps.kh.edu.tw/web/centos/ldap.html

使用Webmin管理OpenLDAP,參考

http://books.bod.idv.tw/2011/10/ubuntuwebminopenldap.html

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 abcg5 的頭像
    abcg5

    Aaron Yang

    abcg5 發表在 痞客邦 留言(0) 人氣()