在RedHat AS4安装Openldap server
作者:管怀剑(james_guan)
更新时间:2006/07/19
RedHat AS4中已经有了openldap的rpm包了,所以我们不必重新用tar包安装。
使用的测试机器
ldapserver.gg.com 172.16.242.55
ldapclient.gg.com 172.16.242.54
step1 :安装相关软件
需要用到的软件包:
openssl-0.9.7a-43.1
pam-0.77-65.1
nss_ldap-226-1
openldap-servers-2.2.13-2
openldap-2.2.13-2
openldap-devel-2.2.13-2
step2 :创建ldap server
创建ldap server主要是配置/etc/openldap/slapd.conf等。
[root@ldapserver ldap]# cat /etc/hosts|grep server
172.16.242.55 ldapserver.gg.com
[root@ldapserver ldap]# cat /etc/ldap.conf |grep -v ^#|grep -v ^$
host ldapserver.gg.com
base dc=gg,dc=com
pam_password md5
[root@ldapserver ldap]# cat /etc/openldap/ldap.conf |grep -v ^#|grep -v ^$
HOST ldapserver.gg.com
BASE dc=gg,dc=com
[root@ldapserver ldap]# cat /etc/openldap/slapd.conf
#
# See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
#
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/nis.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
pidfile /var/run/slapd.pid
argsfile /var/run/slapd.args
# Load dynamic backend modules:
# modulepath /usr/sbin/openldap
# moduleload back_bdb.la
# moduleload back_ldap.la
# moduleload back_ldbm.la
# moduleload back_passwd.la
# moduleload back_shell.la
# The next three lines allow use of TLS for encrypting connections using a
# dummy test certificate which you can generate by changing to
# /usr/share/ssl/certs, running "make slapd.pem", and fixing permissions on
# slapd.pem so that the ldap user or group can read it. Your client software
# may balk at self-signed certificates, however.
# TLSCACertificateFile /usr/share/ssl/certs/ca-bundle.crt
# TLSCertificateFile /usr/share/ssl/certs/slapd.pem
# TLSCertificateKeyFile /usr/share/ssl/certs/slapd.pem
#TLSCipherSuite HIGH:MEDIUM:+TLSv1:+SSLv2:+SSLv3
#TLSCACertificateFile /etc/openldap/cacert.pem
#TLSCertificateFile /etc/openldap/slapd-cert-ldap1.pem
#TLSCertificateKeyFile /etc/openldap/slapd-key-ldap1.pem
# 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
#
access to attrs=userPassword
by self write
by * auth
access to *
by self write
by * read
# 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!
#######################################################################
# ldbm and/or bdb database definitions
#######################################################################
#database bdb
database ldbm
suffix "dc=gg,dc=com"
rootdn "cn=Manager,dc=gg,dc=com"
# Cleartext passwords, especially for the rootdn, should
# be avoided. See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
rootpw cecret
# rootpw {crypt}ijFYNcSNctBYg
# 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
#
配置好后就可以启动ldap service,
service ldap start
下面向ldap 服务器中添加记录
首先添加root
[root@ldapserver ~]# cat gg.ldif
dn: dc=gg,dc=com
dc: gg
objectClass: dcObject
objectClass: organization
o: gg.com
ldapadd -c -x -D "cn=Manager,dc=gg,dc=com" -w cecret -f gg.ldif
下面添加OU
[root@ldapserver ~]# cat gg.com.ldif
dn: cn=Manager,dc=gg,dc=com
objectclass: organizationalRole
cn: Manager
dn: ou=People,dc=gg,dc=com
objectclass: organizationalUnit
ou: People
dn: ou=group,dc=gg,dc=com
objectclass: organizationalUnit
ou: group
ldapadd -c -x -D "cn=Manager,dc=gg,dc=com" -w cecret -f gg.com.ldif
下面添加user
[root@ldapserver ~]# cat user.ldif
dn: uid=jamesg,ou=People,dc=gg,dc=com
uid: jamesg
cn: James Guan
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 504
gidNumber: 504
homeDirectory: /home/jamesg
gecos: James Guan
shadowLastChange: 12204
ldapadd -c -x -D "cn=Manager,dc=gg,dc=com" -w cecret -f user.ldif
来看看结果
[root@ldapserver ~]# ldapsearch -x -LLL
dn: dc=gg,dc=com
dc: gg
objectClass: dcObject
objectClass: organization
o: gg.com
dn: cn=Manager,dc=gg,dc=com
objectClass: organizationalRole
cn: Manager
dn: ou=People,dc=gg,dc=com
objectClass: organizationalUnit
ou: People
dn: ou=group,dc=gg,dc=com
objectClass: organizationalUnit
ou: group
dn: uid=jamesg,ou=People,dc=gg,dc=com
uid: jamesg
cn: James Guan
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 504
gidNumber: 504
homeDirectory: /home/jamesg
gecos: James Guan
shadowLastChange: 12204
step3:配置ldap client
-bash-3.00$ cat /etc/ldap.conf |grep -Ev "^$|^#"
host ldapserver.gg.com
base dc=gg,dc=com
pam_password md5
-bash-3.00$ cat /etc/openldap/ldap.conf |grep -Ev "^$|^#"
BASE dc=gg,dc=com
HOST ldapserver.gg.com
-bash-3.00$ cat /etc/hosts|grep ldap
172.16.242.55 ldapserver.gg.com ldapserver
-bash-3.00$ cat /etc/nsswitch.conf
#
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned
# up nothing. Note that if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the
# next entry.
#
# Legal entries are:
#
# nisplus or nis+ Use NIS+ (NIS version 3)
# nis or yp Use NIS (NIS version 2), also called YP
# dns Use DNS (Domain Name Service)
# files Use the local files
# db Use the local database (.db) files
# compat Use NIS on compat mode
# hesiod Use Hesiod for user lookups
# [NOTFOUND=return] Stop searching if not found so far
#
# To use db, put the "db" in front of "files" for entries you want to be
# looked up first in the databases
#
# Example:
#passwd: db files nisplus nis
#shadow: db files nisplus nis
#group: db files nisplus nis
passwd: files ldap
shadow: files ldap
group: files ldap
#hosts: db files nisplus nis dns
hosts: files dns
# Example - obey only what nisplus tells us...
#services: nisplus [NOTFOUND=return] files
#networks: nisplus [NOTFOUND=return] files
#protocols: nisplus [NOTFOUND=return] files
#rpc: nisplus [NOTFOUND=return] files
#ethers: nisplus [NOTFOUND=return] files
#netmasks: nisplus [NOTFOUND=return] files
bootparams: nisplus [NOTFOUND=return] files
ethers: files
netmasks: files
networks: files
protocols: files ldap
rpc: files
services: files ldap
netgroup: files ldap
publickey: nisplus
automount: files ldap
aliases: files nisplus
测试看看是否可以连到ldapserver
-bash-3.00$ ldapsearch -x -LLL
dn: dc=gg,dc=com
dc: gg
objectClass: dcObject
objectClass: organization
o: gg.com
dn: cn=Manager,dc=gg,dc=com
objectClass: organizationalRole
cn: Manager
dn: ou=People,dc=gg,dc=com
objectClass: organizationalUnit
ou: People
dn: ou=group,dc=gg,dc=com
objectClass: organizationalUnit
ou: group
dn: uid=jamesg,ou=People,dc=gg,dc=com
uid: jamesg
cn: James Guan
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 504
gidNumber: 504
homeDirectory: /home/jamesg
gecos: James Guan
shadowLastChange: 12204
下面登录看看
[root@xiaodongq ~]# su - jamesg
su: warning: cannot change directory to /home/jamesg: No such file or directory
-bash-3.00$ id
uid=504(jamesg) gid=504(jamesg) groups=504(jamesg)
恭喜你,简单的ldap 架设成功。