LDAP [Phần 1] - Hướng Dẫn Cài đặt LDAP Trên CentOS 7
Có thể bạn quan tâm

LDAP viết tắt của Lightweight Directory Access Protocol là một giao thức dạng client-server được phát triển trên chuẩn X500 có chức năng phục vụ cho việc truy cập dịch vụ thư mục. LDAP có thể được sử dụng để lưu trữ bất kỳ loại thông tin nào và thường được sử dụng như một thành phần của hệ thống xác thực tập chung.
Mục lục
- Cấu hình đề nghị
- Cài đặt LDAP trên CentOS 7
- Cài đặt PHP Ldap Admin để quản lý tài khoản LDAP trên giao diện
1. Cấu hình đề nghị
Để cài đặt thành công LDAP, cấu hình đề nghị tối thiểu như sau:
- Hệ điều hành: CentOS 7
- RAM: 1GB
- CPU: 1 Core
- DISK: 15GB
2. Cài đặt LDAP trên CentOS 7
Cấu hình hostname
hostnamectl set-hostname "LDAP" exec bashTắt firewalld
systemctl stop firewalld systemctl disable firewalldTắt Selinux
sudo setenforce 0 sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux sed -i 's/SELINUX=permissive/SELINUX=disabled/g' /etc/sysconfig/selinux sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config sed -i 's/SELINUX=permissive/SELINUX=disabled/g' /etc/selinux/configCài đặt epel-release và cập nhật các gói phần mềm
yum install epel-release -y yum update -yKhởi động lại máy để lấy lại cấu hình mới nhất :
init 6Cài đặt OpenLDAP
yum -y install openldap-servers openldap-clientsSao chép file cấu hình và phân quyền
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG chown ldap. /var/lib/ldap/DB_CONFIGKhởi động slapd
systemctl start slapd systemctl enable slapdThiết lập LDAP admin password, tạo mật khẩu
[root@ldap ~]# slappasswd New password: Re-enter new password: {SSHA}xxxxxxxxxxxxxxxxxxxxxLDAPPASS1Thêm mới file chroot.ldif
cat > chrootpw.ldif << EOF # Chỉ định mật khẩu được tạo ở trên cho phần "olcRootPW" dn: olcDatabase={0}config,cn=config changetype: modify add: olcRootPW olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxLDAPPASS1 EOFChạy lệnh sau để update thông tin từ file chroot.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f chrootpw.ldifKết quả

Import các schemas:
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldifKết quả

Thiết lập Manager Password, tạo mật khẩu :
# Tạo mật khẩu cho người quản lý [root@ldap ~]# slappasswd New password: Re-enter new password: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxxLDAPPASS2Thêm mới file chdomain.ldif:
cat > chdomain.ldif << EOF # Thay thế domain của bạn và các section dc=**,dc=** # Chỉ định mật khẩu vừa được tạo ở trên vào phần "olcRootPW" dn: olcDatabase={1}monitor,cn=config changetype: modify replace: olcAccess olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read by dn.base="cn=Manager,dc=cloud365,dc=local" read by * none dn: olcDatabase={2}hdb,cn=config changetype: modify replace: olcSuffix olcSuffix: dc=cloud365,dc=local dn: olcDatabase={2}hdb,cn=config changetype: modify replace: olcRootDN olcRootDN: cn=Manager,dc=cloud365,dc=local dn: olcDatabase={2}hdb,cn=config changetype: modify add: olcRootPW olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxxLDAPPASS2 dn: olcDatabase={2}hdb,cn=config changetype: modify add: olcAccess olcAccess: {0}to attrs=userPassword,shadowLastChange by dn="cn=Manager,dc=cloud365,dc=local" write by anonymous auth by self write by * none olcAccess: {1}to dn.base="" by * read olcAccess: {2}to * by dn="cn=Manager,dc=cloud365,dc=local" write by * read EOFChạy lệnh sau để update thông tin:
ldapmodify -Y EXTERNAL -H ldapi:/// -f chdomain.ldifKết quả

Thêm file basedomain.ldif:
cat > basedomain.ldif << EOF # Thay thế domain của bạn và các section dc=**,dc=** dn: dc=cloud365,dc=local objectClass: top objectClass: dcObject objectclass: organization o: Cloud365 Local dc: Cloud365 dn: cn=Manager,dc=cloud365,dc=local objectClass: organizationalRole cn: Manager description: Directory Manager dn: ou=People,dc=cloud365,dc=local objectClass: organizationalUnit ou: People dn: ou=Group,dc=cloud365,dc=local objectClass: organizationalUnit ou: Group EOFCập nhật thông tin của basedomain
ldapadd -x -D cn=Manager,dc=cloud365,dc=local -W -f basedomain.ldif Enter LDAP Password: # password của managerKết quả

Sau khi thực hiện xong các bước chúng ta sử dụng lệnh sau để kiểm tra các entry:
slapcatKết quả

Để thêm mới một entry chúng ta cần tạo ra file ldif và update thông tin các file ldif đó và dùng slapcat để kiểm tra.
Ví dụ về thêm một entry user :
cat > adduser_1.ldif << EOF dn: cn=adduser_1,ou=People,dc=cloud365,dc=local objectClass: person objectClass: inetOrgPerson userPassword:: V2VsY29tZTEyMw== sn: user cn: adduser_1 EOFUpdate file adduser_1.ldif để thông tin user được thêm vào cây LDAP :
ldapadd -x -D cn=Manager,dc=cloud365,dc=local -W -f adduser_1.ldif3. Cài đặt PHP LDAP Admin để quản trị LDAP trên giao diện
Cài đặt httpd
yum -y install httpdMở file /etc/httpd/conf/httpd.conf và sửa đổi các thông tin sau :
# Tại dòng 151 sửa như sau : AllowOverride All # Tại dòng 164, sửa thông tin như sau: DirectoryIndex index.html index.cgi index.php # Thêm vào cuối file những cấu hình sau: ServerTokens Prod KeepAlive OnKhởi động lại httpd
systemctl restart httpd systemctl enable httpdCài đặt PHP
yum -y install php php-mbstring php-pearMở file /etc/php.ini:
# Tại dòng 878 sửa lại timezone: date.timezone = "Asia/Ho_Chi_Minh"Cài đặt phpLdapadmin
yum --enablerepo=epel -y install phpldapadminMở file /etc/phpldapadmin/config.php và sửa các thông tin như sau :
# Tại dòng 398: $servers->setValue('login','attr','dn'); // $servers->setValue('login','attr','uid');Mở file /etc/httpd/conf.d/phpldapadmin.conf và thêm thông tin sau
# Tại dòng 11 sửa lại như Require all grantedKhởi động lại httpd
systemctl restart httpdTruy cập vào trang quản trị theo đường dẫn “http://IP_Server/phpldapadmin/”
Kết quả

Tiến hành đăng nhập như sau

Nếu đúng thông tin đăng nhập sẽ chuyển đến màn quản trị LDAP

Cảm ơn bạn đã theo dõi bài viết. Ở những bài viết sau tôi sẽ chia sẻ cách tích hợp LDAP làm hệ thống xác thực tập chung cho một số hệ thống khác.
Chúc các bạn thành công !!!
Từ khóa » Cài đặt Ldap Trên Linux
-
Cài đặt Và Cấu Hình Open LDAP Trong Linux - Đại Học Không Giấy
-
LDAP [Part 2] - Cài đặt OpenLDAP Trên CentOS 7 - Blog - Cloud365
-
Cách Cài đặt LDAP Server Trên Ubuntu - Viblo
-
Cài đặt OpenLDAP Và PhpLDAPadmin Trên Ubuntu 20.04 - TEL4VN
-
Cài Đặt Và Cấu Hình LDAP Server Trên CentOS 7 | An Ninh Mạng
-
Cách Cài đặt Và Cấu Hình OpenLDAP Và PhpLDAPadmin Trên ...
-
Cách Cài đặt Và Cấu Hình OpenLDAP Trên CentOS / RHEL Linux
-
Thiết Lập Hệ Thống Mạng Ubuntu Quản Lý Tập Trung Với LDAP
-
Dịch Vụ LDAP Trên Linux
-
Cài đặt Và Cấu Hình LDAP Server | CentOS7 - YouTube
-
Cài đặt OpenLDAP Trên CentOS - Passion
-
9.2. OpenLDAP - Red Hat Enterprise Linux
-
Cách định Cấu Hình Ứng Dụng Khách LDAP Trên CentOS / RHEL 6 ...
-
Dịch Vụ Thư Mục Với OpenLDAP [7 Và Cuối Cùng?]: Trình Quản Lý Tài ...