Yêu cầu:
1. Cài đặt thủ công2. Cài đặt thông qua NTP - Network Time Protocol
Thực hiện:
1. Cài đặt thủ công
- Kiểm tra trước khi cài đặt
[root@CentOS ~]# timedatectl status
Local time: Wed 2020-06-17 08:15:01 IST
Universal time: Wed 2020-06-17 01:15:01 UTC
RTC time: Wed 2020-06-17 01:15:01
Time zone: Asia/Kolkata (IST, +0530)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[root@CentOS ~]#
Noted: Trước khi chỉnh ngày giờ chúng ta nên chỉnh Time zone trước sau đó đến Local time sau
Để biết danh sách các Time zone chúng tôi dùng lệnh timedatectl list-timezones, hoặc chi tiết hơn timedatectl list-timezones | grep Ho_Chi_Minh
[root@CentOS ~]# timedatectl list-timezones | grep Ho_Chi_Minh
Asia/Ho_Chi_Minh
- Cài đặt Time zone là Asia/Ho_Chi_Minh
[root@CentOS ~]# timedatectl set-timezone Asia/Ho_Chi_Minh
[root@CentOS ~]#
- Cài đặt ngày giờ:
[root@CentOS ~]# timedatectl set-time '2020-06-17 09:19:50'
[root@CentOS ~]#
- Kiểm tra sau khi cài đặt
[root@CentOS ~]# timedatectl status
Local time: Sat 2020-06-17 09:21:06 +07
Universal time: Sat 2020-06-17 02:21:06 UTC
RTC time: Sat 2020-06-17 02:21:07
Time zone: Asia/Ho_Chi_Minh (+07, +0700)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[root@CentOS ~]#
2. Cài đặt thông qua NTP - Network Time Protocol
- Kiểm tra trước khi cài đặt
[root@CentOS ~]# timedatectl status
Local time: Wed 2020-06-17 09:48:56 +07
Universal time: Wed 2020-06-17 02:48:56 UTC
RTC time: Wed 2020-06-17 02:48:56
Time zone: Asia/Ho_Chi_Minh (+07, +0700)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[root@CentOS ~]#
- Cài đặt NTP server
[root@CentOS ~]# sudo yum -y install ntp
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 8.3 kB 00:00:00
* base: mirrors.viethosting.com
* centos-sclo-rh: mirrors.viethosting.com
* centos-sclo-sclo: mirrors.viethosting.com
* epel: mirrors.thzhost.com
* extras: mirrors.viethosting.com
* remi-php72: mirrors.thzhost.com
* remi-safe: mirrors.thzhost.com
* updates: mirrors.viethosting.com
base | 3.6 kB 00:00:00
centos-sclo-rh | 3.0 kB 00:00:00
centos-sclo-sclo | 3.0 kB 00:00:00
epel | 5.3 kB 00:00:00
extras | 2.9 kB 00:00:00
remi-php72 | 3.0 kB 00:00:00
remi-safe | 3.0 kB 00:00:00
updates | 2.9 kB 00:00:00
zabbix | 2.9 kB 00:00:00
zabbix-frontend | 2.9 kB 00:00:00
zabbix-non-supported | 951 B 00:00:00
(1/3): updates/7/x86_64/primary_db | 2.1 MB 00:00:00
(2/3): epel/x86_64/updateinfo | 1.0 MB 00:00:01
(3/3): epel/x86_64/primary_db | 6.8 MB 00:00:15
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 0:4.2.6p5-28.el7.centos will be updated
---> Package ntp.x86_64 0:4.2.6p5-29.el7.centos will be an update
--> Processing Dependency: ntpdate = 4.2.6p5-29.el7.centos for package: ntp-4.2.6p5-29.el7.centos.x86_64
--> Running transaction check
---> Package ntpdate.x86_64 0:4.2.6p5-28.el7.centos will be updated
---> Package ntpdate.x86_64 0:4.2.6p5-29.el7.centos will be an update
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================
Updating:
ntp x86_64 4.2.6p5-29.el7.centos base 548 k
Updating for dependencies:
ntpdate x86_64 4.2.6p5-29.el7.centos base 86 k
Transaction Summary
==================================================================================================================================
Upgrade 1 Package (+1 Dependent package)
Total size: 635 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : ntpdate-4.2.6p5-29.el7.centos.x86_64 1/4
Updating : ntp-4.2.6p5-29.el7.centos.x86_64 2/4
Cleanup : ntp-4.2.6p5-28.el7.centos.x86_64 3/4
Cleanup : ntpdate-4.2.6p5-28.el7.centos.x86_64 4/4
Verifying : ntp-4.2.6p5-29.el7.centos.x86_64 1/4
Verifying : ntpdate-4.2.6p5-29.el7.centos.x86_64 2/4
Verifying : ntpdate-4.2.6p5-28.el7.centos.x86_64 3/4
Verifying : ntp-4.2.6p5-28.el7.centos.x86_64 4/4
Updated:
ntp.x86_64 0:4.2.6p5-29.el7.centos
Dependency Updated:
ntpdate.x86_64 0:4.2.6p5-29.el7.centos
Complete!
[root@CentOS ~]#
- Sửa file /etc/ntp.conf với thông tin server NTP cần đồng bộ. Trong lab này chúng tôi chọn server là time.google.com
[root@CentOS ~]# sudo vim /etc/ntp.conf
{...}
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 216.239.35.12
server time.google.com
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
{...}
Noted: Nhấn i để sửa -> nhấn Esc :wq -> Enter để lưu lại thay đổi và thoát khỏi vim. Đảm bảo KHÔNG CÓ dấu thăng "#" phía trước.
- Bật tính năng đồng bộ NTP và khởi động lại service
sudo timedatectl set-ntp yes
sudo systemctl start ntpd.service
- Kiểm tra
[root@CentOS ~]# timedatectl status
Local time: Wed 2020-06-17 11:09:11 +07
Universal time: Wed 2020-06-17 04:09:11 UTC
RTC time: Wed 2020-06-17 04:09:11
Time zone: Asia/Ho_Chi_Minh (+07, +0700)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
[root@CentOS ~]#
Xong!
Add port 123 vào firewall mới chạy đó anh Khanh.
ReplyDeletesudo firewall-cmd --add-port=123/udp --permanent
sudo firewall-cmd --reload