NỘI DUNG HỌC Phần I: Active Directory and Linux Lab 1: Active directory and Samba Lab 2: Active directory and Bind Lab 3: Openvpn site to site Lab 4: Openvpn client to site Phần II: Web Server Lab 1: Multiple PHP version with Apache on CentOS 8 Lab 2: phpMyAdmin Lab 3: Nginx : Reverse Proxy Phần III: Mail Server Lab 1: Zimbra antivirus antispam Phần IV: High Available Lab 1: MySQL MasterSlave replication Lab 2: MySQL Master Master replication Lab 3: Haproxy – Keepalive Lab 4: High Availability MariaDB Galera Cluster Lab 5: Mysql cluster Phần V: Network monitoring VPS Lab 1: Nagios Monitor Network Services Lab 2: Cacti Monitor Windows Server Cisco Switch Router Lab 3: VPS KVM Phần VI: Storage server Security Lab 1: Gluster Lab 2: Auditd Lab 3: PAM Phần VII: Database Lab 1: Microsoft SQL Server 2019 Lab 2: Oracle database 19c
Trang 1Phần I: Active Directory and Linux
Trang 2ACTIVE DIRECTORY AND SAMBA
DC - DNS File Server - Samba
Máy 2k3:
- Nâng cấp lên domain: nhatnghe1.com
- DNS: dynamic update – secure and nonsecure, trong vùng phân
giải thuận, nghịch, tạo record cho máy samba
- Tạo user: kt1,kt2,kd1,kd2
- Tạo group: g-ketoan(kt1,kt2)
- Tạo group: g-kinhdoanh(kd1,kd2)
Máy samba:
- Đặt tên máy samba.nhatnghe1.com
- Sửa file /etc/hosts (thêm dòng)
B1: Cài đặt Kerberos và samba :
Trang 3- Chỉnh thời gian giữa 2 máy không chênh nhau quá 5 phút
- Chạy lệnh kinit và klist để kiểm tra file /etc/krb5.conf và lấy tickets từ DC
Trang 4Kiểm tra sự chứng thực Kerberos authentication với lệnh smbclient
B3: Soạn file smb.conf
Xóa nội dung cũ, dán nội dung mới như sau :
#vi /etc/samba/smb.conf
[root@samba ~]# kinit administrator@NHATNGHE1.LOCAL
Password for administrator@NHATNGHE1.LOCAL:
[root@samba ~]# klist
Ticket cache: KEYRING:persistent:0:0
Default principal: administrator@NHATNGHE1.LOCAL
Valid starting Expires Service principal
SYSVOL Disk Disk Logon server share Logon server share
OS=[Windows Server 2008 R2 Enterprise 7600] Server=[Windows Server
log file = /var/log/samba/log.%m
max log size = 50
template shell = /bin/bash
Trang 5Tiến hành join domain:
Trên máy 2k8 quan sát thấy đã có máy samba
winbind enum users = Yes
winbind enum groups = Yes
winbind refresh tickets = Yes
idmap config * : range =
idmap config * : backend = tdb
cups options = raw
[root@samba ~]# kinit administrator@NHATNGHE1.LOCAL
Password for administrator@NHATNGHE1.LOCAL:
[root@samba ~]# net ads join -U Administrator
Enter Administrator's password:
Using short domain name NHATNGHE1
Joined 'SAMBA' to dns domain 'nhatnghe1.local'
Trang 6B4 Có thể join domain theo cách sau:
Cấu hình winbind:
Setup, Authentication configuration
Chọn 2 mục
[*] Use Winbind
[*] Use Winbind Authentication
Khai báo các thông tin:
Trang 7Chọn Join domain, chọn Yes
Quan sát:
#vi /etc/pam.d/system-auth
#%PAM-1.0
# This file is auto-generated
# User changes will be destroyed the next time authconfig is run
auth required pam_env.so
auth required pam_faildelay.so delay=2000000
auth sufficient pam_fprintd.so
#vi /etc/nsswitch.conf
33 passwd: files winbind 34
shadow: files winbind 35
group: files winbind
Trang 8auth sufficient pam_unix.so nullok try_first_pass
auth requisite pam_succeed_if.so uid >= 1000 quiet_success
auth sufficient pam_winbind.so use_first_pass
auth required pam_deny.so
account required pam_unix.so broken_shadow
account sufficient pam_localuser.so
account sufficient pam_succeed_if.so uid < 1000 quiet
account [default=bad success=ok user_unknown=ignore] pam_winbind.so
account required pam_permit.so
password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password sufficient pam_unix.so sha512 shadow nullok try_first_pass
use_authtok
password sufficient pam_winbind.so use_authtok
password required pam_deny.so
session optional pam_keyinit.so revoke
session required pam_limits.so
-session optional pam_systemd.so
session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session required pam_unix.so
session optional pam_winbind.so
B5: Soạn mới file smb.conf
Xóa nội dung cũ, tạo nội dung mới như sau :
log file = /var/log/samba/log.%m
max log size = 50
template shell = /bin/bash
winbind enum users = Yes
winbind enum groups = Yes
winbind refresh tickets = Yes
idmap config * : range =
idmap config * : backend = tdb
cups options = raw
#ldap ssl = no
idmap uid = 16777216-33554431
idmap gid = 16777216-33554431
Trang 9Clear the Samba Net cache:
[root@samba ~]# net cache flush
Delete the Winbind caches:
[root@samba ~]# rm -f /var/lib/samba/*.tdb
[root@samba ~]# systemctl restart winbind nmb smb
[root@samba ~]# systemctl enable winbind nmb smb
NHATNGHE1\group policy creator owners
NHATNGHE1\ras and ias servers
NHATNGHE1\allowed rodc password replication group
Trang 10#Thêm dòng sau nếu getent passwd không thấy user
vi /etc/samba/smb.conf
[global]
ldap ssl = no
Clear the Samba Net cache:
[root@samba ~]# net cache flush
Delete the Winbind caches:
[root@samba ~]# rm -f /var/lib/samba/*.tdb
NHATNGHE1\denied rodc password replication group
NHATNGHE1\read-only domain controllers
NHATNGHE1\enterprise read-only domain controllers
NHATNGHE1\group policy creator owners:x:16777233:NHATNGHE1\administrator
NHATNGHE1\ras and ias servers:x:16777234:NHATNGHE1\may1$
Trang 11[root@samba ~]# systemctl enable winbind.service nmb.service smb.service
[root@samba ~]# mkdir -p /home/NHATNGHE1/{kt1,kt2,kd1,kd2}
[root@samba ~]# chmod -R 777 /home/NHATNGHE1
valid users = +NHATNGHE1\g-ketoan
write list = +NHATNGHE1\g-ketoan
[kinhdoanh]
path = /data/kinhdoanh
valid users = +NHATNGHE1\g-kinhdoanh
write list = +NHATNGHE1\g-kinhdoanh
[dungchung]
path = /data/dungchung
valid users = +NHATNGHE1\g-kinhdoanh +NHATNGHE1\g-ketoan
write list = +NHATNGHE1\g-kinhdoanh +NHATNGHE1\g-ketoan
Trang 13ACTIVE DIRECTORY AND BIND
Mục đích
- Tích hợp AD vào DNS của Linux
- Hình ảnh sau là cấu trúc DNS của windows sau khi cài AD, khi sử dụng Linux làm DNS thì tất cả các cấu trúc này phải được thể hiện trên Linux
192.168.1.12 192.168.1.11
Trang 14Chuẩn bị
- Đặt tên 2 máy là: Linux – NS1, windows : DC
- Đặt ip cho 2 máy, chỉ dns về máy linux
Trang 15- Soạn file DomainDNSZones.nhatnghe.db
15M ; retry 1W ; expiry
Trang 16- Soạn file ForestDNSZones.nhatnghe.db
15M ; retry 1W ; expiry 1D ) ; minimum
15M ; retry 1W ; expiry 1D ) ; minimum
Trang 17$TTL 86400
@ IN SOA dns.nhatnghe.com root (
42 ; serial (d adams) 3H ; refresh
15M ; retry 1W ; expiry 1D ) ; minimum
15M ; retry 1W ; expiry 1D ) ; minimum
IN NS dns.nhatnghe.com
$ORIGIN _udp.nhatnghe.com
Trang 18Khởi động dns
#chown -R named /var/named/chroot/
#systemctl stop named
#systemctl disable named
#systemctl start named-chroot
#systemctl enable named-chroot
Kiểm tra:
[root@dns named]# ping dns.nhatnghe.com
PING dns.nhatnghe.com (192.168.1.11) 56(84) bytes of data
64 bytes from dns.nhatnghe.com (192.168.1.11): icmp_seq=1 ttl=64 time=3.92 ms
64 bytes from dns.nhatnghe.com (192.168.1.11): icmp_seq=2 ttl=64 time=0.080 ms
B3: Nâng cấp máy win2k8 lên domain
Start, run, dcpromo, next, next
Chọn Create a new domain in a new
forest
Trang 19Nhập tên domain: nhatnghe.com
Bỏ chọn DNS
Chọn Domain in new forest, next
Trang 20Thông tin kiểm tra DNS trên máy
Linux thành công, next để bắt đầu
Trang 21[root@dns named]# cat _udp.nhatnghe.db
CNAME dns CNAME dns [root@dns named]#
Trang 22[root@dns named]# cat _msdcs.nhatnghe.db
Trang 23OPENVPN
1 client to site: tunnel mode
B1 Cài đặt openvpn từ thư mục openvpn
#yum install openvpn easy-rsa
B2 Configure Public Key Infrastructure Variables
66 export KEY_CITY="Ho chi Minh"
67 export KEY_ORG="Nhat nghe"
68 export KEY_EMAIL="me@myhost.mydomain"
69 export KEY_OU="MyOrganizationalUnit"
[root@samba EasyRSA-2.2.2]# ./pkitool initca
Using CA Common Name: Fort-Funston CA
Generating a 2048 bit RSA private key
-rw-r r 1 root root 1793 Nov 7 09:48 ca.crt
-rw - 1 root root 1704 Nov 7 09:48 ca.key
-rw-r r 1 root root 0 Nov 7 09:47 index.txt
-rw-r r 1 root root 3 Nov 7 09:47 serial
Trang 24B4 Build key server:
./build-key-server server
[root@samba 2.0]# /build-key-server server
Generating a 2048 bit RSA private key
+++
+++
writing new private key to 'server.key'
You are about to be asked to enter information that will be incorporated into your certificate request
What you are about to enter is what is called a Distinguished Name or a DN There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank
Country Name (2 letter code) [VN]:
State or Province Name (full name) [HCM]:
Locality Name (eg, city) [Ho chi Minh]:
Organization Name (eg, company) [Nhat nghe]:
Organizational Unit Name (eg, section) [MyOrganizationalUnit]:
Common Name (eg, your name or your server's hostname) [server]:
Name [EasyRSA]:
Email Address [me@myhost.mydomain]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /usr/share/easy-rsa/2.0/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'VN'
stateOrProvinceName :PRINTABLE:'HCM'
localityName :PRINTABLE:'Ho chi Minh'
organizationName :PRINTABLE:'Nhat nghe'
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
[root@ 2.0]# ll keys/
Trang 25B5 Tạo Certificates cho client
-rw-r r 1 root root 5591 Nov 7 09:49 01.pem
-rw-r r 1 root root 1793 Nov 7 09:48 ca.crt
-rw - 1 root root 1704 Nov 7 09:48 ca.key
-rw-r r 1 root root 146 Nov 7 09:49 index.txt
-rw-r r 1 root root 21 Nov 7 09:49 index.txt.attr
-rw-r r 1 root root 0 Nov 7 09:47 index.txt.old
-rw-r r 1 root root 3 Nov 7 09:49 serial
-rw-r r 1 root root 3 Nov 7 09:47 serial.old
-rw-r r 1 root root 5591 Nov 7 09:49 server.crt
-rw-r r 1 root root 1094 Nov 7 09:49 server.csr
-rw - 1 root root 1704 Nov 7 09:49 server.ke
# ll /etc/openvpn/
total 24
-rw-r r 1 root root 1793 Nov 7 09:54 ca.crt
-rw - 1 root root 1704 Nov 7 09:54 ta.key
-rw-r r 1 root root 424 Nov 7 09:54 dh2048.pem
-rw-r r 1 root root 5591 Nov 7 09:54 server.crt
-rw - 1 root root 1704 Nov 7 09:54 server.key
Trang 26# systemctl -f enable openvpn@server.service
# systemctl restart openvpn@server.service
2 Cấu hình vpn client
(Chu y dong bo gio giua cac may)
Windows 7,10: cài Net farework 4.0: dotNetFx40_Full_x86_x64.exe B1 Cài openvpn GUI
Win 10: openvpn-install-2.4.4-I601.exe
Win xp: openvpn-install-2.3.6-I002-i686.exe
Nhấn Install
Trang 27B2 chép file
client.crt, client.key, và ca.crt, ta.key đến thư mục C:\Program Files\OpenVPN\config
B3 Tạo file C:\Program Files\OpenVPN\config\ client.ovpn
Trang 28Truy cập máy bên trong mạng LAN
Trang 292 openvpn site to site
172.16.0.1 -server1 -192.168.1.11 -192.168.1.12 -server2 - 10.0.0.0/24
Cài openvpn trên 2 server
B1 Cài đặt openvpn từ thư mục openvpn
#yum install openvpn easy-rsa
B2 Configure Public Key Infrastructure Variables
66 export KEY_CITY="Ho chi Minh"
67 export KEY_ORG="Nhat nghe"
Trang 30Thực hiện việc tạo key trên 1 server sau đó chép qua server kia
Đến thư mục sẽ lưu static key
#cd /etc/openvpn/
Taọ file key chứa static key
#openvpn genkey secret key
Chép file key qua server bên kia
route add -net 172.16.0.0 netmask 255.255.255.0 gw 192.168.2.21
netstat -anp | grep :1194
B2 Configure Public Key Infrastructure Variables
[root@samba EasyRSA-2.2.2]# vi vars
Thiết đặt các biến môi trường
Trang 31Common Name (eg, your name or your server's hostname) [Fort-Funston CA]: Enter
Quá trình tạo ra 2 file: ca.crt ca.key
b5: Create Server Certificate
# /build-key-server server1
countryName :PRINTABLE:'VN' stateOrProvinceName :PRINTABLE:'HCM' localityName :PRINTABLE:'HCM' organizationName :PRINTABLE:'NN' organizationalUnitName :PRINTABLE:'MyOrganizationalUnit' commonName :PRINTABLE:'server1'
emailAddress :IA5STRING:'me@myhost.mydomain' Certificate is to be certified until Nov 19 05:21:52 2027 GMT (3650 days) Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries Data Base Updated
b6: Create Client Certificate (server2)
# /build-key server2
countryName :PRINTABLE:'VN' stateOrProvinceName :PRINTABLE:'HCM' localityName :PRINTABLE:'HCM' organizationName :PRINTABLE:'NN' organizationalUnitName :PRINTABLE:'MyOrganizationalUnit' commonName :PRINTABLE:'server2'
emailAddress :IA5STRING:'me@myhost.mydomain' Certificate is to be certified until Nov 19 05:22:44 2027 GMT (3650 days) Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries Data Base Updated
b7: Create Diffie Hellman Keys
Trang 33# systemctl -f enable openvpn@server.service
# systemctl restart openvpn@server.service
B12 Các máy client liên lạc thành công
Trang 34Phần II: Web server
Trang 35B5 Khởi động mysql
# systemctl restart mariadb
B6 Đặt password cho root
# mysqladmin -u root password 123456
B7 Login mysql, tạo csdl
Trang 362 phpMyAdmin
# yum install php-mbstring
# yum install php5-mcrypt
Trang 37Kết quả: file server.key được tạo ra
Remove key trong file server.key
#openssl rsa -in server.key -out server.key
b3: Tạo 1 Certificate Signing Request (CSR) kết hợp với file server.key vừa tạo :
Trang 38B6 Truy cập thử với tên https://www.nhatnghe.com
#yum install epel-release
#yum install nginx
22 access_log /var/log/nginx/access.log main;
36 include /etc/nginx/conf.d/*.conf;
41 server_name 192.168.100.101;
42 root /usr/share/nginx/html;
45 include /etc/nginx/default.d/*.conf;
# systemctl start nginx
# systemctl enable nginx
Truy cập thử
Trang 39B4 Tạo trang web
Tạo trang web
# echo "<h1>Trang web may1</h1>" > /usr/share/nginx/html/index.html
B5 Khởi động nginx và truy cập
5 Nginx, php, Mysql
B1 Cài php, mariadb, mariadb-server, php-mbstring php-pear php-fpm
B2 Cấu hình file www.conf
Trang 40# systemctl restart nginx
Trang 41Phần III: Mail server
Trang 42Cài và cấu hình postfix
- Kiểm tra và cài đặt gói phần mềm postfix
# rpm -ivh /media/Packages/postfix-2.6.6-6.el6_5.x86_64.rpm
- Cấu hình Mail Server - Postfix
Chỉnh sửa các dòng sau trong file cấu hình /etc/postfix/main.cf
- Sửa file cấu hình /etc/postfix/main.cf, chú ý những phần sau:
113 inet_interfaces = all
116 #inet_interfaces = localhost Server sẽ gởi mail ra ngoài bằng domain nào
164 #mydestination = $myhostname, localhost.$mydomain, localhost
165 mydestination = $myhostname, localhost.$mydomain, localhost,
$mydomain
264 mynetworks = 127.0.0.0/8 Lưu trữ mail trong /home/*
419 home_mailbox = Maildir/
- Khởi động dịch vụ
# systemctl restart postfix
# systemctl enable postfix
Cài đặt và cấu hình DOVECOT
- Cài đặt gói dovecot:
# rpm -ivh /media/Packages/dovecot-2.0.9-7.el6_5.1.x86_64.rpm
Hỗ trợ client truy cập mail bằng giao thức pop, imap
- Cài gói dovecot-2.2.10-4.el7_0.1.x86_64.rpm
Trang 43# systemctl start dovecot
# systemctl enable dovecot
- Kiểm tra các cổng
# netstat –nltp
2 Cài đặt và cấu hình Webmail SSL
- Cài package squirrelmail
squirrelmail.noarch 0:1.4.22-16.el7
tmpwatch.x86_64 0:2.11-5.el7
- Cấu hình file /etc/squirrelmail/config.php
Dòng 28 $domain = 'nhatnghe.com';
- Tạo certificate cho web site www.nhatnghe1.com
b1: yum install mod_ssl hoặc cài từ cd
b2: Tạo 1024-bit RSA private key cho Apache server
# cd /etc/pki/tls/certs/
Kết quả: file server.key được tạo ra
[root@node1 certs]# make server.key
Enter pass phrase:
Verifying - Enter pass phrase:
Trang 44Remove key trong file server.key
#openssl rsa -in server.key -out server.key
b3: Tạo 1 Certificate Signing Request (CSR) kết hợp với file server.key vừa tạo :
Kết quả tạo file server.csr được tạo
You are about to be asked to enter information that will be incorporated
into your certificate request
What you are about to enter is what is called a Distinguished Name or a DN
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank
Country Name (2 letter code) [GB]:vn
State or Province Name (full name) [Berkshire]:hcm
Locality Name (eg, city) [Newbury]:hcm
Organization Name (eg, company) [My Company Ltd]:Nhat nghe
Organizational Unit Name (eg, section) []:dao tao
Common Name (eg, your name or your server's hostname)
[]:mail.nhatnghe1.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
Getting Private key
Enter pass phrase for server.key:
[root@node1 certs]# ll
total 1784
-rw-r r 1 root root 786601 Jul 14 2014 ca-bundle.crt
-rw-r r 1 root root 1005005 Jul 14 2014 ca-bundle.trust.crt
-rw - 1 root root 1525 Mar 21 09:35 localhost.crt
-rwxr-xr-x 1 root root 610 Oct 15 18:01 make-dummy-cert
-rw-r r 1 root root 2242 Oct 15 18:01 Makefile
-rwxr-xr-x 1 root root 829 Oct 15 18:01 renew-dummy-cert