Centos7 安裝配置OpenLdap服務及OpenLdap管理工具php
咱們上一篇文章中介紹了,Centos7+Open***使用Windows AD(LDAP)驗證登陸的配置介紹。說到LDAP服務,咱們知道不止windows有,linux下也有,好比openldap,sambaLDAP服務,具體就很少介紹了,咱們今天主要介紹一下Centos7 安裝配置OpenLdap及Ldap管理工具等操做,爲後面的Centos7+Open***+openldap驗證登陸作好基礎。html
咱們首先配置一個指定源,咱們源地址指向了阿里雲的倉庫源linux
cd /etc/yum.repos.d vim epel.repo [epel] name=aliyun epel baseurl=http://mirrors.aliyun.com/epel/7Server/x86_64/ gpgcheck=0
咱們開始安裝openldap服務及客戶端,migrationtools等服務web
migrationtools 實現OpenLDAP 用戶及用戶組的添加,migrationtools 開源工具經過查找/etc/passwd、/etc/shadow、/etc/groups 生成LDIF 文件,並經過ldapadd 命令更新數據庫數據,完成用戶添加數據庫
yum install -y openldap-servers openldap-clients migrationtools
咱們首先要設置openldap的管理員密碼:vim
咱們須要注意的是:必定要記住及拷貝出執行的後的加密的密碼信息。windows
slappasswd new password: 123456 re-enter new password:123456 {SSHA}pGybT1cAqDtSA910VC/E7v1CJgd6dnl6
cd /etc/openldap/slapd.d/cn\=config/
vi olcDatabase\=\{2\}hdb.ldif 增長一行 olcRootPW: {SSHA}pGybT1cAqDtSA910VC/E7v1CJgd6dnl6 修改域信息 olcSuffix: dc=ixmsoft,dc=com olcRootDN: cn=Manager,dc=ixmsoft,dc=com
vi olcDatabase\=\{1\}monitor.ldif 修改域信息
slaptest –u
啓動服務bash
systemctl start slapd systemctl enable slapd
接下來咱們須要建立openldap的數據庫文件app
vim /root/base.ldif dn: dc=ixmsoft,dc=com objectClass: top objectClass: dcObject objectclass: organization o: ixmsoft com dc: ixmsoft dn: cn=Manager,dc=ixmsoft,dc=com objectClass: organizationalRole cn: Manager description: Directory Manager dn: ou=People,dc=ixmsoft,dc=com objectClass: organizationalUnit ou: People dn: ou=Group,dc=ixmsoft,dc=com objectClass: organizationalUnit ou: Group
cat /root/base.ldif
Creating users and groups useradd ldapuser01 useradd ldapuser02
passwd ldapuser01 passwd ldapuser02 或者 echo "redhat" | passwd --stdin ldapuser01
分配全部用戶和組的信息到指定的文件中ide
[root@bogon ~]# grep ":10[0-9][0-9]" /etc/passwd > /root/passwd [root@bogon ~]# grep ":10[0-9][0-9]" /etc/group > /root/group
ls /root
cd /usr/share/migrationtools vim migrate_common.ph $DEFAULT_MAIL_DOMAIN = "ixmsoft.com"; $DEFAULT_BASE = "dc=ixmsoft,dc=com"; $EXTENDED_SCHEMA = 1;
保存退出:
如今咱們須要將導出的用戶文件到LDIF文件中
Now Convert the Individual Users file to LDAP Data Interchange Format (LDIF)
./migrate_passwd.pl /root/password
./migrate_group.pl /root/groups /root/groups.ldif
導入用戶到LDAP數據庫
ldapadd -x -W -D "cn=Manager,dc=ixmsoft,dc=com" -f /root/base.ldif
ldapadd -x -W -D "cn=Manager,dc=ixmsoft,dc=com" -f /root/users.ldif
ldapadd -x -W -D "cn=Manager,dc=ixmsoft,dc=com" -f /root/groups.ldif
ldapsearch -x cn=ldapuser01 -b dc=ixmsoft,dc=com
ldapsearch -x -b 'dc=ixmsoft,dc=com' '(objectclass=*)'
Allow firewall ports firewall-cmd --permanent --add-service=ldap firewall-cmd --permanent --add-service=ldaps firewall-cmd --reload Install NFS util packages yum -y install rpcbind nfs-utils
systemctl enable nfs-server.servic systemctl start nfs-server.service systemctl start rpcbind systemctl enable rpcbind
configure NFS export vi /etc/exports /home *(rw,sync)
systemctl restart nfs-server
Enable NFS and it’s supported Firewall ports firewall-cmd --permanent --add-service=nfs firewall-cmd --permanent --add-service=rpc-bind firewall-cmd --permanent --add-service=mountd firewall-cmd --reload showmount -e localhost
systemctl restart slapd.service systemctl status slapd.service
接下來咱們就是測試了,咱們準備安裝PHPLdapadmin管理工具進行操做
使用該工具能夠建立用戶及組織,可是使用PHPLdapadmin的前提須要安裝httpd,php
因此咱們先安裝httpd
首先安裝yum install -y httpd
vim /etc/httpd/conf/httpd.conf
firewall-cmd --add-service=http --permanent firewall-cmd --reload 添加默認頁面 vim /var/www/html/index.html
systemctl start httpd systemctl enable httpd
Configure httpd to use PHP scripts Install PHP. yum -y install php php-mbstring php-pear
vim +878 /etc/php.ini # line 878: uncomment and add your timezone date.timezone = "Asia/Shanghai"
systemctl restart httpd
Create a PHP test page and access to it from client PC with web browser. It's OK if following page is shown.
vim /var/www/html/index.php <html> <body> <div style=" 100%; font-size: 40px; font-weight: bold; text-align: center;"> <?php print Date("Y/m/d"); ?> </div> </body> </html>
保存退出後,咱們重啓httpd服務
systemctl restart httpd
而後訪問默認的index.php頁面
yum --enablerepo=epel -y install phpldapadmin
vim /etc/phpldapadmin/config.php # line 397: uncomment, line 398: comment out $servers->setValue('login','attr','dn'); // $servers->setValue('login','attr','uid');
vim /etc/httpd/conf.d/phpldapadmin.conf Alias /phpldapadmin /usr/share/phpldapadmin/htdocs Alias /ldapadmin /usr/share/phpldapadmin/htdocs <Directory /usr/share/phpldapadmin/htdocs> <IfModule mod_authz_core.c> # Apache 2.4 # line 12: add access permission Require local Require 192.168.2.0/24 ---- 容許192.168.2.0網段能夠訪問
systemctl restart httpd
而後咱們訪問: 192.168.5.20/ldapadmin/
單擊登陸,而後經過cn的方式進行登陸
接下來咱們新建一個用戶
選擇默認模板
選擇路勁及建立的用戶類型
填寫用戶已信息
咱們使用命令來查看剛纔新建的用戶
咱們經過命令搜索一下
ldapsearch -x -W -D "cn=manager,dc=ixmsoft,dc=com" -b "ou=people,dc=ixmsoft,dc=com" -h 192.168.5.20