| |
这里只是实现一个简单的架构形式,关于证书等相关问题,不予处理。

在试验过程中将部署的主机类型分类如下:
1: 主服务器(Master LDAP Server)   192.168.65.66
2: 从服务器(Slave  LDAP Server)   192.168.65.66
3: 客户机  (Client LDAP)          192.168.65.65/66
理解功用就可以了,实际上主机本身可以同时是Master和Client,也可以是Slave和Client。

在下面的实际应用中,分别阐述两种架构
A: LDAP Server --- LDAP Client
B: LDAP Master Server | LDAP Slave Server ---- LDAP Client
实际上A和B的差异并不大,在采用主从结构后,Master和Slave无非就是配置文件及数据库先对考一下,然后主配置文件slapd.conf稍有不同,其次就是在主Server多启动一个用于更新到Slave的守护进程。
  

引用

参考链接:
http://ldots.org/ldap/
http://www.ibm.com/developerworks/cn/linux/l-openldap/index.html#listing19
http://www.ringkee.com/note/opensource/openldap.htm#id2808622
http://blog.chifeng.name/?tag=openldap
http://www.linuxsir.org/bbs/thread307434.html
http://www.cnblogs.com/moonson/archive/2008/11/20/1337775.html
http://hi.baidu.com/%D0%C7203/blog/item/810adf52f19b7a0c0df3e3dd.html
http://www.linuxfly.org/post/104/
http://www.weithenn.idv.tw/cgi-bin/wiki.pl/OpenLDAP-備份_BDB_及匯出_LDIF_檔

相关下载:
1:迁移工具migrationtools(from passwd to ldap)
http://sourceforge.net/projects/freshmeat_migrationtools/
http://www.padl.com/download/MigrationTools.tgz
版本:MigrationTools.tgz
MD5: 3FAF83EB8482E55979BDA47F1D1E6501

2:管理工具phpldapadmin
http://sourceforge.net/projects/phpldapadmin/
版本:phpldapadmin-1.1.0.7.tar.gz  
MD5: A9129F81B347E98C2B31552D1ADC4B51



I: 安装前的介绍和准备

A:所需的软件包(这些软件包包含了既做Server、又做Client所有的软件包,同时也包含需要phpldapadmin所需的软件包)
zypper in  yast2-ldap-server openldap2 openldap2-back-perl php5-ldap nss_ldap openldap2-client yast2-ldap yast2-ldap-client openldap2-back-meta pam_ldap php5 php5-ldap php5-gettext apache2-mod_php5

B:主要进程命令说明
slapd:主 LDAP 服务器
启动脚本:/etc/init.d/ldap   (运行在主从服务器上)
slurpd:负责与复制 LDAP 服务器保持同步的服务器
启动脚本:/etc/init.d/slurpd  (只有采用了主从结构后,仅运行在主服务器上)

ldapadd:打开一个到 LDAP 服务器的连接,绑定、修改或增加条目
ldapsearch:打开一个到 LDAP 服务器的连接,绑定并使用指定的参数进行搜索

slapadd:将以 LDAP 目录交换格式(LDIF)指定的条目添加到 LDAP 数据库中
slapcat:打开 LDAP 数据库,并将对应的条目输出为 LDIF 格式。用于数据库备份。

C:主要配置文件介绍
1:/etc/openldap/slapd.conf
这个openldap的Server端的主配置文件,所有重要的相关设定都在这里面,下面会详细介绍。
2:/etc/openldap/ldap.conf
这个配置文件是用来连接到Server端的配置文件,用来执行ldapsearch、ldapadd等命令(以ldap命令开头的,ldapadd      ldapcompare  ldapdelete   ldapexop     ldapmodify   ldapmodrdn   ldappasswd   ldapsearch   ldapwhoami),在实际应用中,我们将在服务器端用ldapadd命令导入用户的相关信息。怎么理解容易一些呢?容我再想一下。就是用于命令行管理ldap的配置文件。而配置好这个文件,你可以在任意的机器以命令行的方式管理ldap server,只要你有权限。
3:/etc/ldap.conf
这个配置文件用于主机以ldap的方式做用户的登录验证,是客户机上主要的关于ldap的配置文件。
4:/etc/nsswitch.conf
这个是客户机上用来转换主机登录验证转换的开关。可以从本地文件/etc/passwd、shadow、group验证,NIS服务验证,LDAP验证方式。
5:/etc/pam.d/common-account、common-auth、common-password、common-session
这个就是关于ldap验证时需要修改的pam模块,这里需要强调一点。/etc/security/pam_unix2.conf这个配置文件内,直接修改并不等效于,修改这四个模块文件。在实际使用中发现,如果将ldap模块加入在/etc/security/pam_unix2.conf里面,是无法正常使用su命令的,建议直接修改这四个pam模块文件。

D:调试方法及相关目录
主配置文件语法检查
slaptest
手工启动
/usr/lib/openldap/slapd -d 1
查看进程
ps aux | grep slapd
端口状态
netstat -lntp | grep slapd
tail -f /var/log/ldap.log
tail -f /var/log/messages
关于master/slave同步日志
tail -f /var/lib/ldap/replog
进程相关
/var/run/slapd/
数据库位置
/var/lib/ldap/


II: 实现 LDAP Server和 LDAP Client的基本架构
一:LDAP Server端的设定
A:编辑主配置文件/etc/openldap/slapd.conf和/etc/openldap/ldap.conf
include         /etc/openldap/schema/core.schema
include         /etc/openldap/schema/cosine.schema
include         /etc/openldap/schema/inetorgperson.schema
include         /etc/openldap/schema/yast.schema
include         /etc/openldap/schema/nis.schema
pidfile         /var/run/slapd/slapd.pid
argsfile        /var/run/slapd/slapd.args
modulepath      /usr/lib/openldap/modules
access to dn.base=""
        by * read
access to dn.base="cn=Subschema"
        by * read
access to attrs=userPassword,userPKCS12
        by self write
        by * auth
access to attrs=shadowLastChange
        by self write
        by * read
access to *
        by * read
database        bdb
suffix          "dc=kook,dc=com"
checkpoint      1024    5
cachesize       10000
rootdn          "cn=root,dc=kook,dc=com"
rootpw          password
directory       /var/lib/ldap
index   objectClass     eq
loglevel        296
# for master server
#replogfile      /var/lib/ldap/replog
#replica uri=ldap://192.168.65.65:389
#        binddn="cn=root,dc=abc,dc=com"
#        bindmethod=simple credentials=password

# for slave server
#updatedn  "cn=root,dc=kook,dc=com"

修改的地方如下:
注释掉这行shcema,/etc/openldap/schema/rfc2307bis.schema,否则启动报错""Starting ldap-server/etc/openldap/schema/nis.schema: line 53: Duplicate attributeType: "1.3.6.1.1.1.1.2 failed"
添加这个schema
include         /etc/openldap/schema/nis.schema
修改域和密码
suffix          "dc=kook,dc=com"
rootdn          "cn=root,dc=kook,dc=com"
rootpw          {SSHA}ro0Wr/z4ZP9z8fg8r8l8EtYu3i0PzPUI  #使用slappasswd -s password来产生替换
添加记录日志
loglevel 行设置的是日志选项。可以将其设置为这样的级别:调试语句和操作统计信息都会被记录到 /var/log/slapd.log 中。日志级别是累加的:296 = 256 日志连接/操作/结果 + 32 搜索过滤器处理 + 8 连接管理:
loglevel 296
当调试成功后,成功后将日志等级调低。
1      (0x1 trace) trace function calls
2      (0x2 packet) debug packet handling
4      (0x4 args) heavy trace debugging (function args)
8      (0x8 conns) connection management
16     (0x10 BER) print out packets sent and received
32     (0x20 filter) search filter processing
64     (0x40 config) configuration file processing
128    (0x80 ACL) access control list processing
256    (0x100 stats) stats log connections/operations/results
512    (0x200 stats2) stats log entries sent
1024   (0x400 shell) print communication with shell backends
2048   (0x800 parse) entry parsing
4096   (0x1000 cache) caching (unused)
8192   (0x2000 index) data indexing (unused)
16384  (0x4000 sync) LDAPSync replication
32768  (0x8000 none) only messages that get logged whatever log level is set

修改/etc/openldap/ldap.conf,为执行ldapadd命令导入用户和组
BASE dc=kook,dc=com
host 127.0.0.1

B: 日志添加/etc/syslog.conf
echo "local4.* /var/log/ldap.log" >> /etc/syslog.conf
/etc/init.d/syslogd restart

C: 迁移用户、组(使用MigrationTools.tgz,文章上面有下载链接)
1:解压tar zxvf MigrationTools.tgz
2:修改migrate_common.ph
$DEFAULT_BASE = "dc=kook,dc=com";
而下面两个参数,没有跟邮局系统整合,所以不用理它也可以。
$DEFAULT_MAIL_DOMAIN = "kook.com";
$DEFAULT_MAIL_HOST = "mail.kook.com";
3:生成基本域信息
./migrate_base.pl > /tmp/base.ldif
node1:/home/work/MigrationTools-47 # cat /tmp/base.ldif
dn: dc=kook,dc=com
dc: kook
objectClass: top
objectClass: domain

dn: ou=People,dc=kook,dc=com
ou: People
objectClass: top
objectClass: organizationalUnit

dn: ou=Group,dc=kook,dc=com
ou: Group
objectClass: top
objectClass: organizationalUnit
导入基本域细腻系
ldapadd -x -D "cn=root,dc=kook,dc=com" -w password -f /tmp/base.ldif
4:导入用户和组信息
./migrate_passwd.pl /etc/passwd > /tmp/passwd.ldif
./migrate_group.pl /etc/group > /tmp/group.ldif
ldapadd -x -D "cn=root,dc=kook,dc=com" -w password -f /tmp/passwd.ldif
ldapadd -x -D "cn=root,dc=kook,dc=com" -w password -f /tmp/group.ldif

D:安装phpldapadmin
cp config.php.example  config.php
vi /etc/php5/apache2/php.ini
memory_limit = 25M

E:启动服务
/etc/init.d/ldap start
chkconfig ldap on


二:LDAP Client端设定
1:/etc/nsswitch.conf
注释
#passwd: compat
#group:  compat
底部添加
passwd: ldap
shadow: ldap
group:  ldap

2:/etc/ldap.conf
差别如下:
node1:/home/kook # cat /etc/ldap.conf.default
host    127.0.0.1
base    dc=example,dc=com
ldap_version    3
bind_policy     soft
pam_lookup_policy       yes
pam_password    crypt
ssl     start_tls
nss_map_attribute       uniqueMember member


修改这里
host    192.168.65.66
base    dc=kook,dc=com
ssl     no
添加下面
pam_filter      objectclass=posixAccount
nss_base_passwd dc=kook,dc=com
nss_base_shadow dc=kook,dc=com
nss_base_group  dc=kook,dc=com

3:PAM模块修改
修改 /etc/pam.d/common-auth, 最前面加一行
auth    sufficient    pam_ldap.so
修改 /etc/pam.d/common-account, 最前面加一行
account sufficient    pam_ldap.so
修改 /etc/pam.d/common-password, 最前面加一行
password sufficient     pam_ldap.so
修改 /etc/pam.d/common-session或者/etc/pam.d/sshd, 底部加一行
session required        pam_mkhomedir.so skel=/etc/skel/ umask=0022

4:重启服务
/etc/init.d/nscd restart


III 实现 LDAP Master Server、 LDAP Slave Server、LDAP Client的基本架构
一:LDAP Master Server主服务器配置方法
基本方法和上面的Server一直,主要差别如下:
1:配置文件/etc/openldap/slapd.conf,添加如下:
replogfile      /var/lib/ldap/replog
replica uri=ldap://192.168.65.65:389
        binddn="cn=root,dc=kook,dc=com"
        bindmethod=simple credentials=password
#updatedn  "cn=root,dc=kook,dc=com"

2:启动服务
/etc/init.d/ldap start
/etc/init.d/slurpd start
chkconfig ldap on
chkconfig slurpd on

二:LDAP Slave Server的配置方法
1: 从主服务器上拷贝如下文件
A:把主服务器上/etc/ldap/slapd.conf文件拷贝到从服务器的同目录中,覆盖原文件。
B:把主服务器上/var/lib/ldap目录下的所有数据库文件全部拷贝到从服务器的同目录中,覆盖原文件。
C:把主服务器上的/etc/ldap/schema目录下的所有schema文件拷贝到从服务器的同目录中,覆盖原有文件

2:基本配置/etc/openldap/slapd.conf,添加如下:
#replogfile      /var/lib/ldap/replog
#replica uri=ldap://192.168.65.65:389
#        binddn="cn=root,dc=kook,dc=com"
#        bindmethod=simple credentials=password
updatedn  "cn=root,dc=kook,dc=com"

3: 启动服务
/etc/init.d/ldap start
chkconfig ldap on

三:LDAP Client的配置方法
修改/etc/ldap.conf文件,仅修改以下部分
host 192.168.65.66 192.168.65.65
其它都是一致的。

重启服务:/etc/init.d/nscd restart



IV:LDAP数据库的备份与恢复

一:通过ldap命令备份和恢复
适用条件:在Server、Client均可以备份,建议多点编写脚本定期备份。可以在线备份。
1:备份
ldapsearch -x -D "cn=root,dc=kook,dc=com" -w password > backup.ldif
2:恢复
A:清空库
ldapdelete -x -D "cn=root,dc=kook,dc=com" -w password -r "dc=kook,dc=com"
B:导入库
ldapadd -x -D "cn=root,dc=kook,dc=com" -w password -f backup.ldif

二:备份/usr/lib/openldap/*数据库文件
适用条件:仅在Server端备份,这个没有什么好说的。需要停库备份。复制文件即可。

三:通过slapcat/slapadd备份和恢复
适用条件:在Server端备份,这个与ldapsearch备份有什么差别呢?简单看好像,有数据创建时间戳都会保留。在研究一下吧。


2009年11月10日补充:

1:关于VSFTP的整合支持,本地用户的验证支持:
vi /etc/pam.d/vsftpd
#%PAM-1.0

# Uncomment this to achieve what used to be ftpd -A.
# auth       required     pam_listfile.so item=user sense=allow file=/etc/ftpchroot onerr=fail

auth     sufficient     pam_ldap.so
account  sufficient     pam_ldap.so
password sufficient     pam_ldap.so


auth     required       pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed
# Uncomment the following line for anonymous ftp.
#auth    sufficient     pam_ftp.so
auth     required       pam_unix2.so
auth     required       pam_shells.so
account  required       pam_unix2.so
password required       pam_unix2.so
session  required       pam_unix2.so

这里写的不严谨,如果考虑ftpusers这些的话,需要调整一下。现在这里相当于下面的都没有用了。

2:关于限制本地用户的su的调整,只允许wheel组用户su到root
参考:http://www.redhat.com/archives/pam-list/2001-April/msg00055.html
需要修改/etc/nsswitch
passwd: files ldap
shadow: files ldap
group:  files ldap
修改/etc/pam.d/su,插入到pam_rootok.so行下面
#%PAM-1.0
auth     sufficient     pam_rootok.so
auth     required       pam_wheel.so use_uid  # 不加 use_uid,经测试也可以。
auth     include        common-auth
account  include        common-account
password include        common-password
session  include        common-session
session  optional       pam_xauth.so
同时修改两边的/etc/group
添加用户到wheel组里面,即可了。
wheel:x:10:kook,test,foo,bar


20091202补充:
关于用户安全
参考链接:http://www.zytrax.com/books/ldap/ch6/ppolicy.html(Chapter 6 OpenLDAP password policy overlay)
关于命令使用
http://blog.csdn.net/zouahaijun/archive/2009/08/31/4503330.aspx


本文链接:http://www.52zhe.cn/read.php/236.htm
本文作者:kook(若就博客内所涉及的技术问题交流,请用下面的MSN或Gmail联系我)
联系方式:(MSN:kook#live.com) (Google talk:kookliu)
没有版权:GNU,转载时请注明“转载人”欠本人一顿饭,来日见面之时兑现!谢谢合作!
by kook | 分类: SuSE | 评论(0) | 引用(0) | 阅读(320)
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]