安装NTP服务端
设计思想,局域网内多数服务器没开通外网权限,需要搭建最基本的yum源和时间同步服务器,因为内网系统之间有定时任务,服务器集群,oracle集群等都依赖时间同步,服务器之间存在时差就会有问题。因此需要搭建时间同步服务器 搭建非常简单,主要是找到同步的源,设置策略
yum install ntp ntpdate -y
查看NTP服务器状态 systemctl status ntpd systemctl start ntpd
vim /etc/ntp.conf
################################################### driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery
restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap #允许更新的IP地址段 restrict 127.0.0.1 restrict -6 ::1
server 120.25.108.11 prefer #优先同步地址 server 158.69.48.97
server ntp1.aliyun.com server time1.aliyun.com
restrict 120.25.108.11 nomodify notrap noquery restrict 158.69.48.97 nomodify notrap noquery restrict time1.aliyun.com nomodify notrap noquery restrict ntp1.aliyun.com nomodify notrap noquery server 127.127.1.0 #local clock fudge 127.127.1.0 stratum 10 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitor #############################################################
客户端设置同步(默认客户端安装ntpdate) ntpdate -u 120.25.108.11(NTP服务器地址)
查看同步状态 ntpq -p
设置同步 vim /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root
For details see man 4 crontabs
Example of job definition:
.---------------- minute (0 - 59)
| .------------- hour (0 - 23)
| | .---------- day of month (1 - 31)
| | | .------- month (1 - 12) OR jan,feb,mar,apr ...
| | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
| | | | |
* * * * * user-name command to be executed
*/2 * * * * root /usr/bin/timedatectl set-timezone Asia/Shanghai */5 * * * * root /usr/sbin/ntpdate -u 120.25.108.11