table of Contents
1. Deployment planning
Ensure that 4 machines are in the same LAN
192.168.44.10 main server
192.168.44.11
192.168.44.12
192.168.44.13
2. Install ntp service
4 machines must be executed
yum -y install ntp
3. Configure the main server
Only configure 192.168.44.10
vi /etc/ntp.conf
# 注释掉server0~n
# 添加如下
server 127.127.1.0
Fudge 127.127.1.0 stratum 10
4. Start the ntpd service
Only need to start the ntpd service of the main server, other servers do not need to operate
systemctl start ntpd && systemctl enable ntpd
5. Time synchronization
Write the time synchronization command /usr/sbin/ntpdate 192.168.44.10 into the scheduled task, synchronize it every 15 minutes, and write the synchronization result into the result.txt file to save, and restart the crond service to take effect.
# 在除主服务器外的三台执行
mkdir /usr/local/sh && cd /usr/local/sh && touch result.txt
/usr/sbin/ntpdate 192.168.44.10
crontab -e
*/15 * * * * /usr/sbin/ntpdate 192.168.44.10 >> /usr/local/sh/result.txt 2>&1
systemctl restart crond
One of the effects is as follows:
Since the test is a virtual machine, the error between the time and the main server is millimeter-0.003014 sec
[root@minio2 ~]# /usr/sbin/ntpdate 192.168.44.10
14 Jan 01:18:03 ntpdate[16798]: adjust time server 192.168.44.10 offset -0.003014 sec
[root@minio2 ~]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
[root@minio2 ~]# systemctl restart crond
6. Matters needing attention
This method of configuring the ntp time server is the simplest, and there are other better solutions, which can be used in business scenarios where the time accuracy is not very high, otherwise use it with caution.
The main disadvantages are: 1. The main service does not synchronize the time server. If the main service time is inaccurate, the time of the entire time server will be inaccurate.
2. What we synchronize is the system time. If the hardware time is inconsistent with the system time, errors will occur in some cases.