openLDAP安装经验分享
????LDAP是一款輕量級目錄訪問協議(Lightweight Directory Access Protocol,簡稱LDAP),屬于開源集中賬號管理架構的實現,且支持眾多系統版本,被廣大互聯網公司所采用。關于openLDAP的更多信息請查看openLDAP官網。
安裝
安裝環境
CentOS 7.5 64bit、 openLDAP 2.4.44
安裝
同步時間、關閉SELINUX、關閉防火墻
ntpdate -u ntp.api.bz sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config setenforce 0 systemctl disable firewalld.service systemctl stop firewalld.service安裝openLDAP
yum install openldap compat-openldap openldap-clients openldap-servers \openldap-servers-sql openldap-devel migrationtools基礎配置
從OpenLDAP2.4.23版本開始所有配置數據都保存在/etc/openldap/slapd.d/中,建議不再使用slapd.conf作為配置文件。
設置管理員密碼
slappasswd -s <your_passwd>提醒:將生成的加密密碼進行復制,后面的配置中會使用。
修改文件olcDatabase={2}hdb.ldif
文件路徑:/etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}hdb.ldif
主要修改以下幾個參數:
數據存儲路徑:olcDbDirectory: /var/lib/ldap
域名:olcSuffix: dc=domain,dc=com
超級賬號:olcRootDN: cn=Manager,dc=domain,dc=com
上一步生成的密碼:olcRootPW: {SSHA}fNJOnWST5pVtJ99hGDVVm11pLqgQxlOa
dc按照自己實際情況填寫!
dn: olcDatabase={2}hdb objectClass: olcDatabaseConfig objectClass: olcHdbConfig olcDatabase: {2}hdb olcDbDirectory: /var/lib/ldap olcSuffix: dc=domain,dc=com olcRootDN: cn=Manager,dc=domain,dc=com olcDbIndex: objectClass eq,pres olcDbIndex: ou,cn,mail,surname,givenname eq,pres,sub structuralObjectClass: olcHdbConfig entryUUID: dd1cf184-f92b-1038-9db2-e1f25a7ff2d3 creatorsName: cn=config createTimestamp: 20190422092215Z entryCSN: 20190422092215.936824Z#000000#000#000000 modifiersName: cn=config modifyTimestamp: 20190422092215Z olcRootPW: {SSHA}fNJOnWST5pVtJ99hGDVVm11pLqgQxlOa修改文件olcDatabase={1}monitor.ldif
文件路徑:/etc/openldap/slapd.d/cn\=config/olcDatabase\=\{1\}monitor.ldif
修改參數olcAccess,注意修改dc為前面自己寫的值。
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=extern al,cn=auth" read by dn.base="cn=Manager,dc=domain,dc=com" read by * none
配置數據庫
/var/lib/ldap是默認路徑,填寫時以自己實際路徑為準。
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG將配置的數據存放路徑權限給ldap
chown -R ldap:ldap /var/lib/ldap/ chmod 700 -R /var/lib/ldap驗證配置
執行命令
slaptest -u最后一行為config file testing successded即可。
啟動slapd并設置為開機自啟
systemctl enable slapd systemctl start slapd查看slapd狀態
systemctl status slapd導入Schema
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/collective.ldif ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/corba.ldif ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/duaconf.ldif ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/dyngroup.ldif ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/java.ldif ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/misc.ldif ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/openldap.ldif ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/pmi.ldif ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/ppolicy.ldif修改文件migrate_common.ph
文件路徑:/usr/share/migrationtools/migrate_common.ph
修改第71、74和90行。
注意填寫自己域名
# Default DNS domain $DEFAULT_MAIL_DOMAIN = "domain.com"; # Default base $DEFAULT_BASE = "dc=domain,dc=com"; $EXTENDED_SCHEMA = 1;生成base.ldif
在目錄/usr/share/migrationtools/下執行命令
./migrate_base.pl > base.ldif添加base.ldif到ldap
在目錄/usr/share/migrationtools/下執行命令
ldapadd -x -D "cn=Manager,dc=domain,dc=com" -W -f ./base.ldif注意填寫自己的dc
這里會要求輸入密碼,輸入的密碼為第一步中的明文密碼。
檢查是否添加成功
必須檢查確認Manager數據添加成功,才能通過phpldapAdmin登錄。
執行命令下面的命令,輸入密碼同樣為明文密碼。
Web管理PhpLdapAdmin
安裝httpd和PhpLdapAdmin
rpm -ivh http://mirrors.ukfast.co.uk/sites/dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm yum install httpd phpldapadmin修改文件phpldapadmin.conf
文件路徑:/etc/httpd/conf.d/phpldapadmin.conf
注意:注釋掉第一個IfModule,否則會禁止訪問。
修改文件config.php
文件路徑:/etc/phpldapadmin/config.php
修改屬性$servers->setValue的uid為dn(文件第397行)
修改文件http.conf
文件路徑:/etc/httpd/conf/httpd.conf
將原來的Directory屬性注釋,修改為如下內容
啟動httpd并設置為開機自啟
systemctl enable httpd systemctl start httpd查看httpd運行狀態
systemctl status httpd訪問phpLDAPadmin
在瀏覽器中輸入http://<IP> /phpldapadmin
輸入賬號填寫cn=Manager,dc=domain,dc=com
自助修改密碼服務
添加repo
在路徑/etc/yum.repos.d下添加文件LTB-Project.repo
文件內容如下
安裝SSP
yum install self-service-password修改文件config.inc.php
文件路徑:/usr/share/self-service-password/conf/
# LDAP $ldap_url = "ldap://<IP>:389"; $ldap_starttls = false; $ldap_binddn = "cn=manager,dc=domain,dc=com"; $ldap_bindpw = "your_passwd"; $ldap_base = "dc=domain,dc=com"; $ldap_login_attribute = "uid"; $ldap_fullname_attribute = "cn"; $ldap_filter = "(&(objectClass=person)($ldap_login_attribute={login}))"; ## Mail # LDAP mail attribute $mail_attribute = "mail"; # Get mail address directly from LDAP (only first mail entry) # and hide mail input field # default = false $mail_address_use_ldap = false; # Who the email should come from $mail_from = "example@example.com"; $mail_from_name = "Self Service Password"; $mail_signature = ""; # Notify users anytime their password is changed $notify_on_change = true; # PHPMailer configuration (see https://github.com/PHPMailer/PHPMailer) $mail_sendmailpath = '/usr/sbin/sendmail'; $mail_protocol = 'smtp'; $mail_smtp_debug = 0; $mail_debug_format = 'html'; $mail_smtp_host = 'smtphm.qiye.163.com'; $mail_smtp_auth = true; $mail_smtp_user = 'example@example.com'; $mail_smtp_pass = 'your_passwd'; $mail_smtp_port = 25; $mail_smtp_timeout = 30; $mail_smtp_keepalive = false; $mail_smtp_secure = 'tls'; $mail_smtp_autotls = true; $mail_contenttype = 'text/plain'; $mail_wordwrap = 0; $mail_charset = 'utf-8'; $mail_priority = 3; $mail_newline = PHP_EOL; $hash = "SSHA"; $keyphrase = "domain"; $who_change_password = "manager";3.修改文件self-service-password.conf
文件路徑:/etc/httpd/conf.d/self-service-password.conf
<VirtualHost *>DocumentRoot /usr/share/self-service-passwordDirectoryIndex index.phpAddDefaultCharset UTF-8Alias /ssp /usr/share/self-service-password <Directory “/usr/share/self-service-password”>AllowOverride NoneRequire all granted </Directory>LogLevel warnErrorLog /var/log/httpd/ssp_error_logCustomLog /var/log/httpd/ssp_access_log combined </VirtualHost>4.登錄SSP
在訪問之前重啟httpd服務
systemctl restart httpd.service在瀏覽器輸入網址http://<IP>/ssp/index.php
日志功能
創建loglevel.ldif
在/etc/openldap下新建文件loglevel.ldif
dn: cn=config changetype: modify replace: olcLogLevel olcLogLevel: stats導入日志文件
ldapmodify -Y EXTERNAL -H ldapi:/// -f /etc/openldap/loglevel.ldif修改rsyslog.conf
文件路徑:/etc/rsyslog.conf
在文件末尾加入以下內容
創建日志文件目錄并授權
mkdir /var/log/slapd chmod 755 /var/log/slapd chown -R ldap:ldap /var/log/slapd/重啟服務
systemctl restart rsyslog.service systemctl restart slapd.serviceFAQ
提示警告信息
Automatically removed objectClass from template Samba: Group Mapping: sambaGroupMapping removed from template as it is not defined in the schema
修改文件/etc/phpldapadmin/config.php第166行
創建通用用戶Generic: User Account時添加email屬性
修改文件posixAccount.xml
文件路徑:/usr/share/phpldapadmin/templates/creation
在文件中添加以下屬性
附錄
| dc | Domain Component | 域名的部分,其格式是將完整的域名分成幾部分,如域名為example.com變成dc=example,dc=com |
| uid | User Id | 用戶ID,唯一值 |
| ou | Organization Unit | 組織單位,類似于Linux文件系統中的子目錄,它是一個容器對象,組織單位可以包含其他各種對象(包括其他組織單元) |
| cn | Common Name | 公共名稱 |
| sn | Surname | 姓 |
| dn | Distinguished Name | 惟一辨別名,類似于Linux文件系統中的絕對路徑,每個對象都有一個惟一的名稱,在一個目錄樹中DN總是惟一的 |
| rdn | Relative dn | 相對辨別名,類似于文件系統中的相對路徑,它是與目錄樹結構無關的部分 |
| c | Country | 國家 |
| o | Organization | 組織名 |
參考文獻
1、爛泥行天下
2、openLDAP初識
總結
以上是生活随笔為你收集整理的openLDAP安装经验分享的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux命令之分屏显示文件内容less
- 下一篇: 志宇-Nginx学习