Thiết lập hệ thống mạng Ubuntu quản lý tập trung với LDAP
1. Giới thiệu 3. Cấu hình hệ thống Các bước thực hiện lần lượt như sau: Cài đặt và cấu hình DNS server với phần mềm BIND 1. Cài đặt Ubuntu server, phiên bản 7.10 2. Cấu hình DNS server Hiệu chỉnh file /etc/resolv.conf để liệt kê danh sách các DNS server trong mạng của mình: Cài đặt và cấu hình LDAP server với phần mềm OpenLDAP 1. Cài đặt OpenLDAP Các bước thực hiện như sau: 2. Cấu hình LDAP server Thực hiện các bước như sau để bổ sung entry vào LDAP server: Nếu các thao tác bổ sung entry vào LDAP server được thực hiện một cách chính xác, tiện ích ldapsearch sẽ hiển thị thông tin về các entry này tương tự như nội dung đã tạo trong file /etc/init.ldif. Với các bước cấu hình như trên, chúng ta đã hoàn thành thao tác cài đặt và cấu hình LDAP server trên máy tính ubuntu-server. Tiếp theo, chúng ta tiến hành các thao tác cài đặt và cấu hình các hệ thống máy trạm Ubuntu. Các bước thực hiện như sau: root@ubuntu-desktop01:~# apt-get install libnss-ldap Khi cài đặt thư viện này, chúng ta cần cung cấp các thông số: Chú ý: một hộp thoại xuất hiện, thông báo rằng hệ thống không thể quản lý file nsswitch.conf một cách tự động. Chúng ta nhấn nút OK và sẽ thay đổi cấu hình của file này ở phần sau. 2. Cấu hình LDAP client Hiệu chỉnh các file này theo các bước như sau: Chú ý: nếu không thực hiện bước này sau khi đã tạo tài khoản trên LDAP, chúng ta sẽ gặp thông báo lỗi trong quá trình đăng nhập vào máy trạm Ubuntu. 3. Tạo tài khoản đăng nhập với phpLDAPadmin Nhấn vào nút Login ở panel bên trái, nhập thông tin tài khoản root: Nhấn nút Authenticate để đăng nhập. Nếu đăng nhập vào LDAP server thành công, hệ thống sẽ thông báo: Tạo tài khoản trên phpLDAPadmin: Nhấn nút Add để hoàn thành thao tác tạo và hiệu chỉnh tài khoản. Đến bước này, chúng ta nhấn nút Logout và bắt đầu kiểm tra khả năng hoạt động của hệ thống LDAP trên Ubuntu. Hệ thống sẽ thông báo: “Creating directory ‘/home/users/ktm/tthai’”, chúng ta nhấn nút OK để hoàn thành thao tác đăng nhập. Kết luận Mở file /etc/group, bổ sung user01 vào dòng admin… 2. Sử dụng đĩa USB trên Ubuntu server 3. Xem lỗi đăng nhập trên máy trạm Ubuntu
Trong tương lai không xa, phần mềm mã nguồn mở và miễn phí rất có thể sẽ trở thành một lựa chọn tất yếu đối với các tổ chức/doanh nghiệp. Với ưu điểm mã nguồn mở, dễ dàng mở rộng, hoạt động ổn định… lĩnh vực ứng dụng này đang ngày càng chứng tỏ tính khả dụng và hiệu quả của nó.
Hầu hết các tổ chức/doanh nghiệp đều cần đến một hệ thống mạng nội bộ để hỗ trợ xử lý công việc thường ngày, điều hành hoạt động, phối hợp làm việc…
Bài viết sẽ hướng dẫn các bước xây dựng hệ thống mạng Ubuntu quản lý tập trung với LDAP, một giải pháp hoàn toàn có thể thay thế hệ thống mạng Microsoft Windows với Active Directory.
2. Yêu cầu hệ thống
Chúng ta sử dụng 03 máy tính với thông tin như sau:
3.1. Cấu hình ubuntu-server
Trên máy ubuntu-server, chúng ta thực hiện:
ubuntu-desktop01.bits.com.vn 192.168.10.12
ubuntu-desktop02.bits.com.vn 192.168.10.14
Account 01 - tthai:********
Account 02 - ctbach:********
Trong quá trình cài đặt, thiết lập các thông số sau:
Phần mềm dùng để xây dựng DNS server trên Ubuntu là BIND (Berkeley Internet Name Domain). Chúng ta sẽ thao tác trên các file của BIND để cấu hình DNS server. Các bước thực hiện như sau:
tthai@ubuntu-server:~$ sudo -i
[sudo] password for tthai:
root@ubuntu-server:~#
root@ubuntu-server:~# mkdir /backup
root@ubuntu-server:~# cp -R /etc/bind /backup
Hiệu chỉnh file cấu hình chính của BIND - /etc/bind/named.conf - bằng cách bổ sung các dòng sau vào cuối file:
root@ubuntu-server:~# vim /etc/bind/named.conf
...
// The zone definition
zone “bits.com.vn” {
type master;
file “/etc/bind/zones/bits.com.vn.db”;
};
// The zone definition for reverse DNS
zone “10.168.192.in-addr.arpa” {
type master;
file “/etc/bind/zones/rev.10.168.192.in-addr.arpa”;
};
Hiệu chỉnh file /etc/bind/named.conf.options để chuyển (forward) những yêu cầu mà DNS server này không phân giải được:
root@ubuntu-server:~# vim /etc/bind/named.conf.options
options {
...
forwarders {
10.238.200.1;
10.238.200.8;
10.238.200.12;
};
};
Tạo các file zone:
root@ubuntu-server:~# mkdir /etc/bind/zones
root@ubuntu-server:~# vim /etc/bind/zones/bits.com.vn.db
$TTL 604800
@ IN SOA ubuntu-server.bits.com.vn. admin.bits.com.vn. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800) ; Negative Cache TTL
;
; Replace the following line as necessary:
; ns1 = DNS server name
; mail = Mail server name
; bits.com.vn. IN MX 10 mail.bits.com.vn.
@ IN NS ubuntu-server.bits.com.vn.
@ IN A 192.168.10.2
ubuntu-server.bits.com.vn. IN A 192.168.10.2
root@ubuntu-server:~# vim /etc/bind/zones/rev.10.168.192.in-addr.arpa
; The number before IN PTR ubuntu-server.bits.com.vn is
; the machine address of the DNS server. In this case, it’s
; 2, as my IP address is 192.168.10.2.
$TTL 604800
@ IN SOA ubuntu-server.bits.com.vn. admin.bits.com.vn. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800) ; Negative Cache TTL
;
@ IN NS ubuntu-server.bits.com.vn.
2 IN PTR ubuntu-server.bits.com.vn.
root@ubuntu-server:~# vim /etc/resolv.conf
search bits.com.vn
nameserver 192.168.10.2
root@ubuntu-server:~# /etc/init.d/bind9 restart
root@ubuntu-server:~# dig bits.com.vn
Bên cạnh đó, chúng ta cũng cần sử dụng tiện ích ping để kiểm tra:
root@ubuntu-server:~# ping bits.com.vn
root@ubuntu-server:~# ping ubuntu-server
root@ubuntu-server:~# ping ubuntu-server.bits.com.vn
Phần mềm dùng để xây dựng LDAP server trên Ubuntu là OpenLDAP. Chúng ta sẽ cài đặt các phần mềm và tiện ích cần thiết để thiết lập LDAP server, bao gồm:
tthai@ubuntu-server:~$ sudo -i
[sudo] password for tthai:
root@ubuntu-server:~#
root@ubuntu-server:~# aptitude update
root@ubuntu-server:~# apt-get install slapd
root@ubuntu-server:~# apt-get install ldap-utils
root@ubuntu-server:~# apt-get install db4.2-util
Lưu ý: khi cài đặt các gói slapd, ldap-utils, db4.2-util, hệ thống cần sử dụng đĩa CD chứa Ubuntu server 7.10.
Chúng ta sẽ thao tác trên các file của OpenLDAP để cấu hình LDAP server. Các bước thực hiện như sau:
root@ubuntu-server:~# cp -R /etc/ldap /backup
root@ubuntu-server:~# slappasswd >> /etc/ldap/slapd.conf
New password:
Re-enter new password:
Hiệu chỉnh file /etc/ldap/slapd.conf (file cấu hình chính của OpenLDAP) như sau:
root@ubuntu-server:~# vim /etc/ldap/slapd.conf
suffix “dc=bits,dc=com,dc=vn”
rootdn “cn=admin,dc=bits,dc=com,dc=vn”
# password này do tiện ích ldappasswd tạo ra.
rootpw {SSHA}AwiGYep3HmBbL5rQka4Bchd4g8ofhnXC
directory “/var/lib/ldap”
# Set change password permission
access to attrs=userPassword,shadowLastChange
by dn=“cn=admin,dc=bits,dc=com,dc=vn” write
by anonymous auth
by self write
by * none
# Ensure read access to the base for things like
# supportedSASLMechanisms.
access to dn.base=“” by * read
# The admin dn has full write access, everyone else can
# read everything.
access to *
by dn=“cn=admin,dc=bits,dc=com,dc=vn” write
by * read
Lưu ý: giữ lại những thiết lập mặc định của file /etc/ldap/slapd.conf không được đề cập ở trên.
root@ubuntu-server:~# /etc/init.d/slapd start
Starting OpenLDAP: slapd
Đến bước này, LDAP server đã sẵn sàng. Để bắt đầu đưa server này vào hoạt động, chúng ta cần bổ sung các entry (thực thể - user, group, ou…) khởi tạo trên server.
LDAP server có thể bổ sung các entry bằng câu lệnh hoặc từ các file có định dạng ldif (ldap directory interchange format). Dưới đây, chúng ta tạo ra file init.ldif và lưu vào thư mục /etc/ldap.
root@ubuntu-server:~# vim /etc/ldap/init.ldif
dn: dc=bits,dc=com,dc=vn
objectClass: dcObject
objectClass: organizationalUnit
dc: bits
ou: bits.com.vn
dn: cn=admin,dc=bits,dc=com,dc=vn
objectClass: simpleSecurityObject
objectClass: organizationalRole
cn: admin
description: LDAP administrator
userPassword: {SSHA}AwiGYep3HmBbL5rQka4Bchd4g8ofhnXC
dn: ou=users,dc=bits,dc=com,dc=vn
objectClass: organizationalUnit
ou: users
dn: ou=groups,dc=bits,dc=com,dc=vn
objectClass: organizationalUnit
ou: groups
dn: cn=ktm,ou=groups,dc=bits,dc=com,dc=vn
objectClass: posixGroup
cn: ktm
gidNumber: 5000
Lưu ý: UID/GID trong bài viết này được thiết lập theo qui định sau:
Dừng dịch vụ LDAP:
root@ubuntu-server:~# /etc/init.d/slapd stop
Xóa nội dung đã tự động tạo ra trong khi cài đặt OpenLDAP:
root@ubuntu-server:~# rm -rf /var/lib/ldap/*
Bổ sung entry mới:
root@ubuntu-server:~# slapadd -l init.ldif
Hiệu chỉnh quyền trên cơ sở dữ liệu:
root@ubuntu-server:~# chown -R openldap:openldap /var/lib/ldap
Khởi chạy dịch vụ LDAP:
root@ubuntu-server:~# /etc/init.d/slapd start
Chúng ta có thể kiểm tra các entry vừa mới bổ sung vào bằng cách sử dụng tiện ích ldapsearch:
root@ubuntu-server:~# ldapsearch –xLLL –b “dc=bits,dc=com,dc=vn”
Trong đó:
3.2. Cấu hình ubuntu-desktop01
Để máy trạm đăng nhập với tài khoản được tạo ra trên LDAP server, chúng ta cần thực hiện các bước cấu hình trên các file PAM (Pluggable Authentication Modules) và NSSWITCH (Name Service Switch) trong Ubuntu. Các bước thực hiện như sau:
1. Cài đặt LDAP client
Các phần mềm và tiện ích cần phải cài đặt trên máy trạm Ubuntu là:
ctbach@ubuntu-desktop01:~$ sudo -i
[sudo] password for ctbach:
root@ubuntu-desktop01:~#
root@ubuntu-desktop01:~# aptitude update
root@ubuntu-desktop01:~# apt-get install libpam-ldap
Khi cài đặt thư viện này, chúng ta cần cung cấp các thông số:
root@ubuntu-desktop01:~# apt-get install nss-updatedb
Chúng ta sẽ thao tác trên các file của PAM và NSSWITCH để cấu hình LDAP client. Các bước thực hiện như sau:
root@ubuntu-desktop01:~# mkdir /backup
root@ubuntu-desktop01:~# cp /etc/nsswitch.conf /backup
root@ubuntu-desktop01:~# cp -R /etc/pam /backup
Hiệu chỉnh file /etc/nsswitch.conf (file cấu hình chính của NSSWITCH). File này xác định các name service mà hệ thống sử dụng để truy vấn thông tin (search for information). File này cũng chỉ ra thứ thự của các name service để hệ thống ưu tiên tìm kiếm theo một thứ tự đã được lập ra.
root@ubuntu-desktop01:~# vim /etc/nsswitch.conf
passwd: files ldap
group: files ldap
Kiểm tra cấu hình vừa thiết lập bằng cách thực hiện 02 lệnh:
root@ubuntu-desktop01:~# getent passwd
root@ubuntu-desktop01:~# getent group
02 lệnh trên sẽ liệt kê mật khẩu và các nhóm trên Ubuntu desktop và trên LDAP server.
Có 04 file cấu hình của PAM liên quan đến LDAP:
account sufficient pam_ldap.so
account required pam_unix.so
auth sufficient pam_ldap.so
auth required pam_unix.so nullok_secure use_first_pass
password sufficient pam_ldap.so
password required pam_unix.so nullok obscure min=4 max=8 md5
session required pam_unix.so
session required pam_mkhomedir.so skel=/etc/skel/
session optional pam_ldap.so
session optional pam_foreground.so
root@ubuntu-desktop01:~# mkdir /home/users
root@ubuntu-desktop01:~# mkdir /home/users/ktm
Để đơn giản trong việc quản lý OpenLDAP server, chúng ta sử dụng phpLDAPadmin. Đây là ứng dụng web được sử dụng để thao tác với OpenLDAP server.
Các bước sau đây sẽ giúp chúng ta cài đặt và sử dụng phpLDAPadmin trên máy trạm Ubuntu để quản lý LDAP server.
Cài đặt phpLDAPadmin với lệnh:
root@ubuntu-desktop01:~# apt-get install phpldapadmin
Cấu hình phpLDAPadmin:
root@ubuntu-desktop01:~# cp -R /usr/share/phpldapadmin /var/www/myphpldapadmin
root@ubuntu-desktop01:~# cp /etc/phpldapadmin/config.php /etc/phpldapadmin/first.config.php
root@ubuntu-desktop01:~# rm /var/www/myphpldapadmin/config/config.php
root@ubuntu-desktop01:~# ln –s /etc/phpldapadmin/first.config.php /var/www/myphpldapadmin/config/config.php
root@ubuntu-desktop01:~# chmod +r /etc/phpldapadmin/first.config.php
Truy cập phpLDAPadmin:
3.3. Cấu hình ubuntu-desktop02
Thực hiện các bước tương tự như với máy tính ubuntu-desktop01.
4. Kiểm tra hệ thống
Để kiểm tra hệ thống sau khi hoàn thành các bước cấu hình, từ máy trạm ubuntu, chúng ta đăng nhập bằng tài khoản được tạo ra trên LDAP server. Trong trường hợp của mình, trên máy ubuntu-desktop01, sau khi hệ thống khởi động, chúng ta nhập:
Sử dụng LDAP để xây dựng mạng nội bộ theo mô hình client/server, với các máy tính Ubuntu là một giải pháp quản lý tập trung hiệu quả và tiết kiệm chi phí. Với các bước cài đặt đơn giản, cấu hình dễ dàng, việc thiết kế hệ thống mạng nội bộ với LDAP và Ubuntu là hoàn toàn khả thi.
Phụ lục 1 – Một số thao tác hữu ích khi cấu hình LDAP trên Ubuntu
1. Cấu hình máy tính Ubuntu để cho phép account trên LDAP server có thể chuyển sang (sudo) account quản trị hệ thống root
Để cho phép account tthai trên LDAP server có thể chuyển sang account root, trên máy trạm Ubuntu, chúng ta thực hiện như sau:
# gedit /etc/group
Tìm đến dòng admin:x:117:ctbach,administrator
Bổ sung user01 vào cuối dòng. Sau khi bổ sung, chúng ta nhận được kết quả tương tự như sau:
admin:x:117:ctbach,administrator,tthai
Tiếp đến, cần cập nhật password LDAP server để hệ thống Ubuntu có thể hiểu được password này:
root@ubuntu-server:~# passwd tthai
Enter login (LDAP) password: ******
New password: ******
Re-enter new password: ******
Để sử dụng được các đĩa USB trên Ubuntu server (giao diện dòng lệnh), chúng ta phải thực hiện thao tác mount đĩa USB vào Ubuntu server.
root@ubuntu-server:~# mkdir /usb-disk
root@ubuntu-server:~# mount -t vfat /dev/sdb1 /usb-disk
root@ubuntu-server:~# mkdir /usbmp3-disk
root@ubuntu-server:~# mount -t vfat /dev/sdb /usbmp3-disk
root@ubuntu-server:~# umount /usb-disk
root@ubuntu-server:~# umount /usbmp3-disk
Để xem được các lỗi đăng nhập trên máy trạm Ubuntu nhằm giúp chúng ta xác định nguyên nhân phát sinh lỗi trong quá trình Ubuntu đăng nhập qua LDAP, chúng ta mở file /var/log/auth.log
Tài liệu tham khảo
1. OpenLDAP Server
https://help.ubuntu.com/community/OpenLDAPServer
2. LDAP Client Authentication
https://help.ubuntu.com/community/LDAPClientAuthentication
3. OpenLDAP Client Configuration Guide
http://ubuntuforums.org/showthread.php?t=597056
4. Ubuntu User Document (good)
https://help.ubuntu.com/community/UserDocumentation
5. DNS Server Setup Using Bind in Ubuntu
http://www.ubuntugeek.com/dns-server-setup-using-bind-in-ubuntu.html
6. BIND9 Administrator Reference Manual
http://www.isc.org/index.pl?/sw/bind/index.php
7. Installing phpLDAPadmin
https://help.ubuntu.com/community/InstallingphpLDAPadmin
8. An Introduction to LDAP
http://www.ldapman.org/articles/intro_to_ldap.html
9. Introduction to LDAP (good)
http://quark.humbug.org.uau/publications/ldap/ldap_tut.html
10. LDAP mini HOWTO (good)
http://www.grennan.com/ldap_HOWTO.html
11. OpenLDAP 2.2 Administrator’s Guide
http://www.bind9.net/manual/openldap/2.2/index.html
12. OpenLDAP Everywhere
http://www.linuxjournal.com/article/6266
13. LDAP Attributes
http://www.computerperformance.co.uk/Logon/LDAP_attributes_active_directory.htm
14. Berkeley v4.2 Database Utility
http://packages.ubuntu.com/feisty/utils/db4.2.-util
15. Berkeley Database
http://packages.ubuntu.com/edgy/doc/db3-doc
16. Berkeley Database
http://directory.fsf.org/project/BerkeleyDB/
17. Performing Backup and Recovery with Berkeley DB
http://packages.ubuntu.com/edgy/doc/db3-doc
18. Chapter 19. I/O Redirection (Advanced Bash – Scripting Guide)
http://tldp.org/LDP/abs/html/io-redirection.html
19. /etc/nsswitch.conf -- Name Service Switch File
http://www.softpanorama.org/Solaris/Reference/etc/nsswitch.shtml
Posted
0 comments:
Post a Comment