一、此次安装环境及软件版本
CentOS6.4
db-5.1.25.tar.gz
openldap-2.4.36.tgz
二、安装db-5.1.25.tar.gz
tar -zxvf db-5.1.25.tar.gzcd db-5.1.25
cd build_unix
../dist/configure --prefix=/opt/local
make
make install
三、安装openldap-2.4.36.tgz
tar -zxvf openldap-2.4.36.tgz
cd openldap-2.4.36
env CPPFLAGS="-I/opt/local/include" LDFLAGS="-L/opt/local/lib" ./configure --enable-hdb --enable-bdb --enable-overlays=mod --prefix=/opt/local/openldap
提示版本报错:configure: error: Berkeley DB version mismatch
解决方法:
cp /opt/local/include/* /usr/include/
cp /opt/local/lib/* /usr/lib
make
make install
PATH=$PATH:/opt/local/openldap/bin
export PATH
1,修改配置文件
vi /opt/local/openldap/etc/openldap/slapd.conf
include /opt/local/openldap/etc/openldap/schema/core.schema #原本只有这一句,把以下的文件全部加载
include /opt/local/openldap/etc/openldap/schema/corba.schema
include /opt/local/openldap/etc/openldap/schema/cosine.schema
include /opt/local/openldap/etc/openldap/schema/inetorgperson.schema
include /opt/local/openldap/etc/openldap/schema/java.schema
include /opt/local/openldap/etc/openldap/schema/misc.schema
include /opt/local/openldap/etc/openldap/schema/nis.schema
include /opt/local/openldap/etc/openldap/schema/openldap.schema
database bdb
suffix "dc=ldaptest,dc=com"
rootdn "cn=root,dc=ldaptest,dc=com"
# Cleartext passwords, especially for the rootdn, should
# be avoid. See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
rootpw 123456
2,建立basedn.ldif文件
dn: dc=ldaptest,dc=com
dc: ldaptest
objectClass: domain
3,建立userdn.ldif
dn:cn=user1,dc=ldaptest,dc=com
cn: user1
sn: USER1
uid: user1
userPassword: user1
objectClass: inetOrgPerson
注:也可以再建组,objectClass: groupOfUniqueNames
4,启动LDAP服务器
/opt/local/openldap/libexec/slapd
如果启动异常,运行以下命令查看提示
/opt/local/openldap/libexec/slapd -d 256
5,添加记录:
find / -name ldapadd
cp /opt/local/openldap/bin/* /usr/local/bin
ldapadd -D "cn=root,dc=ldaptest,dc=com" -w
123456 -f /basedn.ldif
ldapadd -D "cn=root,dc=ldaptest,dc=com" -w
123456 -f /userdn.ldif
6,确认相关软件已安装
yum install apr apr-util openssl
四、apche配置
1,修改httpd.conf
vi /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /usr/local/www/
ServerName 172.16.146.129
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
include conf/app_auth.conf #添加此句
2,编辑app_auth.conf
vi /etc/httpd/conf/app_auth.conf
<Location />
AuthType basic
AuthName "private area"
AuthBasicProvider ldap
AuthzLDAPAuthoritative off
AuthLDAPURL ldap://localhost:389/dc=ldaptest,dc=com?uid?sub?(objectClass=*)
require ldap-user "user1"
require valid-user
</Location>
3,重启apche
service httpd restart