ldap連接mysql (openldap-2.4.40 rpm + 操作系統CentOS 6.5標準版)
1. 將附件解壓到服務器/usr/local/ldap目錄下
2. 進入/usr/local/ldap/libdbi目錄,安裝libdbi依賴庫,如果存在老版本,請rpm -e卸載或rpm -Uvh升級老版本
rpm -ivh libdbi-0.8.3-4.el6.x86_64.rpm
rpm -ivh libdbi-devel-0.8.3-4.el6.x86_64.rpm
rpm -ivh libdbi-drivers-0.8.3-5.1.el6.x86_64.rpm
rpm -ivh libdbi-dbd-mysql-0.8.3-5.1.el6.x86_64.rpm
3. 進入/usr/local/ldap/cyrus目錄,安裝cyrus依賴庫,如果存在老版本,請rpm -e卸載或rpm -Uvh升級老版本
rpm -ivh cyrus-sasl-lib-2.1.23-15.el6_6.2.x86_64.rpm
rpm -ivh cyrus-sasl-2.1.23-15.el6_6.2.x86_64.rpm
rpm -ivh cyrus-sasl-plain-2.1.23-15.el6_6.2.x86_64.rpm
rpm -ivh cyrus-sasl-devel-2.1.23-15.el6_6.2.x86_64.rpm
4. 進入/usr/local/ldap/unixODBC目錄,安裝unixODBC和依賴庫libtool-ltdl
rpm -ivh libtool-ltdl-2.2.6-15.5.el6.x86_64.rpm
rpm -ivh unixODBC-2.2.14-14.el6.x86_64.rpm
rpm -ivh unixODBC-devel-2.2.14-14.el6.x86_64.rpm
5. 進入/usr/local/ldap/mysql,安裝mysql,如果存在老版本,請rpm -e卸載或rpm -Uvh升級老版本
rpm -ivh mysql-libs-5.1.73-8.el6_8.x86_64.rpm
rpm -ivh perl-DBD-MySQL-4.013-3.el6.x86_64.rpm
rpm -ivh mysql-5.1.73-8.el6_8.x86_64.rpm
rpm -ivh mysql-server-5.1.73-8.el6_8.x86_64.rpm
rpm -ivh mysql-connector-odbc-5.1.5r1144-7.el6.x86_64.rpm
6. 操作mysql,準備數據
1. 啟動mysql
service mysql start
2. 設置mysql密碼
mysql_secure_installation
3. 登錄mysql
mysql -uroot -p密碼
4. 創建用戶,創建數據庫ldap,賦權
CREATE USER [email protected] IDENTIFIED BY ‘123456‘;
CREATE DATABASE IF NOT EXISTS ldap;
GRANT ALL PRIVILEGES ON ldap.* TO [email protected] identified by ‘123456‘;
GRANT ALL PRIVILEGES ON ldap.* TO [email protected] identified by ‘123456‘;
GRANT ALL PRIVILEGES ON *.* TO [email protected]%‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;
FLUSH PRIVILEGES;
5. 導入表和測試數據
source /usr/local/ldap/ldap.sql
6. 導入庫
cd /usr/share/doc/openldap-servers-sql-2.4.40/rdbms_depend/mysql
mysql -ulinying -p123456 ldap< backsql_create.sql
mysql -ulinying -p123456 ldap< testdb_create.sql
mysql -ulinying -p123456 ldap< testdb_data.sql
mysql -ulinying -p123456 ldap< testdb_metadata.sql
7. 配置/etc/odbc.ini和/etc/odbcinst.ini文件
odbc.ini
odbcinst.ini(沒有修改,默認配置)
8. 測試連接:isql -v ldap
9. 進入/usr/local/ldap/openldap,安裝openldap,如果存在openldap老版本先卸載
rpm -ivh openldap-2.4.40-16.el6.x86_64.rpm
rpm -ivh pam_ldap-185-11.el6.x86_64.rpm
rpm -ivh openldap-devel-2.4.40-16.el6.x86_64.rpm
rpm -ivh openldap-servers-2.4.40-16.el6.x86_64.rpm
rpm -ivh openldap-servers-sql-2.4.40-16.el6.x86_64.rpm
rpm -ivh openldap-clients-2.4.40-16.el6.x86_64.rpm
10.配置openldap
1. 設置openldap密碼
slappasswd
{SSHA}rJ3sVQ8nJ3Mp5an0UeSm2sTb4XWE3r6J
2.將配置模版拷貝到執行目錄
cp /usr/share/openldap-servers/slapd.conf.obsolete /etc/openldap/slapd.conf
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
3.配置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
# 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
modulepath /usr/lib64/openldap
moduleload back_sql
# 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=Directory Manager,o=h3gat" write
by * none
#######################################################################
# database definitions
#######################################################################
database sql
suffix "o=h3gat"
rootdn "cn=Directory Manager,o=h3gat"
rootpw {SSHA}rJ3sVQ8nJ3Mp5an0UeSm2sTb4XWE3r6J
dbname ldap
dbuser linying
dbpasswd 123456
subtree_cond "ldap_entries.dn LIKE CONCAT(‘%‘,?)"
insentry_stmt "INSERT INTO ldap_entries(dn, oc_map_id, parent, keyval) VALUES(?, ?, ?, ?)"
has_ldapinfo_dn_ru no
# 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
# [email protected]
4. 刪除默認配置文件,賦權,重新生成新配置文件
rm -rf /etc/openldap/slapd.d/*
chown -R ldap:ldap /var/lib/ldap/
chown -R ldap:ldap /etc/openldap/
slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d/
5. 賦權,啟動openldap
chown -R ldap.ldap /etc/openldap/slapd.d/*
service slapd start
6. 停止openldap,查看mysql連接
service slapd stop
slapd -d 1
註:安裝中請註意版本,盡量與我版本一致,rpm包在文件欄中。
ldap連接mysql (openldap-2.4.40 rpm + 操作系統CentOS 6.5標準版)