[Advanced Operation and Maintenance Knowledge] One-click deployment of time synchronization server

This article will introduce to you how to turn the current server into a time synchronization server, which can synchronize other server times with this server time. I integrated the operation method into the script to implement one-click deployment of the time synchronization server.

Time server deployment

[root@Ansible ~]# cat /bash/ntpdate_server.sh 
#!/bin/bash

# 安装 NTP 服务
yum -y install ntp

# 配置ntp.conf文件
cat << EOF >> /etc/ntp.conf
server 127.127.1.0
fudge 127.127.1.0 stratum 8

restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
EOF

# 启动ntp服务并设置开机自启动
systemctl start ntpd.service
systemctl enable ntpd.service

# 开放udp 123端口
firewall-cmd --add-port=123/udp --permanent
firewall-cmd --reload

echo "已将10.0.0.61配置为NTP时间服务器!"
[root@Ansible ~]# sh /bash/ntpdate_server.sh
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                            | 3.6 kB     00:00     
epel                            | 4.7 kB     00:00     
extras                          | 2.9 kB     00:00     
updates                         | 2.9 kB     00:00     
(1/2): epel/x86_64/updateinfo     | 1.0 MB   00:05     
(2/2): epel/x86_64/primary_db     | 7.0 MB   00:21     
Package ntp-4.2.6p5-29.el7.centos.2.x86_64 already installed and latest version
Nothing to do
FirewallD is not running
FirewallD is not running
已将10.0.0.61配置为NTP时间服务器!

Client testing 

[root@LB00 ~]# date -s 20080808
Fri Aug  8 00:00:00 CST 2008
[root@LB00 ~]# date
Fri Aug  8 00:00:02 CST 2008
[root@LB00 ~]# ntpdate 10.0.0.61
13 May 16:43:45 ntpdate[5658]: step time server 10.0.0.61 offset 465836637.498873 sec

For successful proofreading, the idea is to install the NTP service, configure the NTP file, enable the NTP service, and open the NTP port.

The server modifies the time and the client synchronizes again.

[root@Ansible ~]# date -s 20080808
Fri Aug  8 00:00:00 CST 2008
[root@Ansible ~]# systemctl restart ntpd

[root@LB00 ~]# ntpdate 10.0.0.61
 8 Aug 00:02:10 ntpdate[5665]: step time server 10.0.0.61 offset -465842879.257505 sec

There is also no problem, but the server needs to restart the service and re-read the configuration file, which means reading the current time of the server.


My name is Koten. I have 10 years of operation and maintenance experience. I continue to share operation and maintenance tips. Thank you for reading and paying attention!

 

Guess you like

Origin blog.csdn.net/qq_37510195/article/details/130657769
Recommended