LDAP是輕量級目錄訪問協(xié)議,是一種用于訪問和維護分布式目錄服務(wù)信息的標準協(xié)議。而MySQL則是一種開源的關(guān)系型數(shù)據(jù)庫管理系統(tǒng)。本文將介紹如何將LDAP和MySQL進行整合使用。
首先,我們需要在LDAP中配置MySQL相關(guān)信息:
dn: cn=module{0},cn=config objectClass: olcModuleList cn: module{0} olcModulePath: /usr/lib/ldap olcModuleLoad: back_mysql.la dn: olcDatabase={1}mdb,cn=config changetype: modify add: olcDbIndex olcDbIndex: uid eq dn: olcDatabase={1}mdb,cn=config changetype: modify add: olcDbIndex olcDbIndex: mail eq dn: olcDatabase={1}mdb,cn=config changetype: modify add: olcDbIndex olcDbIndex: member eq dn: olcDatabase={1}mdb,cn=config changetype: modify add: olcDbIndex olcDbIndex: sambaSID eq dn: olcDatabase={1}mdb,cn=config changetype: modify add: olcDbIndex olcDbIndex: sambaPrimaryGroupSID eq dn: olcDatabase={1}mdb,cn=config changetype: modify add: olcDbIndex olcDbIndex: sambaGroupType eq dn: olcDatabase={1}mdb,cn=config changetype: modify add: olcSuffix olcSuffix: dc=test,dc=com dn: olcDatabase={1}mdb,cn=config changetype: modify add: olcRootPW olcRootPW: {CLEARTEXT}password dn: olcDatabase={1}mdb,cn=config changetype: modify add: olcRootDN olcRootDN: cn=admin,dc=test,dc=com dn: cn=config changetype: modify replace: olcLogLevel olcLogLevel: stats dn: olcdatabase={1}mdb,cn=config changetype: modify add: olcDbURI olcDbURI: mysql://username:password@localhost/ldap?charset=utf8&tls_cert=/usr/local/ssl/certs/server.crt&tls_key=/usr/local/ssl/private/server.key
然后,我們需要在MySQL中創(chuàng)建相應(yīng)的數(shù)據(jù)庫和表:
CREATE DATABASE ldap; CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `uid` varchar(255) NOT NULL, `cn` varchar(255) NOT NULL, `mail` varchar(255) NOT NULL, `uidNumber` int(11) NOT NULL, `gidNumber` int(11) NOT NULL, `homeDirectory` varchar(255) NOT NULL, `loginShell` varchar(255) NOT NULL, `sambaSID` varchar(255) NOT NULL, `sambaPrimaryGroupSID` varchar(255) NOT NULL, `sambaGroupType` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
最后,在LDAP中添加MySQL中的數(shù)據(jù):
dn: uid=test,ou=People,dc=test,dc=com objectClass: top objectClass: posixAccount objectClass: shadowAccount objectClass: sambaSamAccount uid: test cn: Test User sn: User homeDirectory: /home/test sambaSID: S-1-1-1-1-111-111-111-111 sambaPrimaryGroupSID: S-1-1-1-1-111-111-111-111 sambaGroupType: 2 uidNumber: 1000 gidNumber: 1000 mail: test@test.com userPassword: {SSHA}password
通過以上步驟,我們就可以使用LDAP來管理MySQL中的數(shù)據(jù)了。