时间同步问题解决
需求:修改ip地址为172.18.2.251的NTP服务器时间与阿里云NTP服务器时间自动同步,并且其它服务器与这台172.18.2.251同步
步骤:1.首先查看一下时区对不对
cat /etc/sysconfig/clock
时区不对的话,需要修改成Zone=’’Asia/Shanghai’’,修改完以后通过查看date -R发现没生效,需要再执行命令sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime更新时区修改的内容。
2.查看NTP服务是否正在运行
service ntpd status
如果发现ntpd服务没有运行,需要service ntpd start
3.设置一下NTP服务开机自启
执行命令chkconfig ntpd on设置开机自启动NTP服务。如果之前设置过,再设置一次没有影响
4. 查看/etc/ntp.conf里面文件是否配置正确
cat /etc/ntp.conf
具体内容如下:
# For more information about this file, see the man pages # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5). driftfile /var/lib/ntp/drift # Permit time synchronization with our time source, but do not # permit the source to query or modify the service on this system. restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery # Permit all access over the loopback interface. This could # be tightened as well, but to do so would effect some of # the administrative functions. restrict 127.0.0.1 restrict -6 ::1 #新增 restrict 172.18.2.0 mask 255.255.255.0 nomodify notrap # Hosts on local network are less restricted. #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #server s1a.time.edu.cn #beijingdaxue #server 2.rhel.pool.ntp.org iburst #server 3.rhel.pool.ntp.org iburst #新增 service ntp1.aliyun.com iburst service ntp2.aliyun.com iburst service ntp3.aliyun.com iburst server 172.18.2.251 iburst fudge 127.0.0.1 stratum 10 restrict ntp1.aliyun.com nomodify notrap noquery restrict ntp2.aliyun.com nomodify notrap noquery restrict ntp3.aliyun.com nomodify notrap noquery #broadcast 192.168.1.255 autokey # broadcast server #broadcastclient # broadcast client #broadcast 224.0.1.1 autokey # multicast server #multicastclient 224.0.1.1 # multicast client #manycastserver 239.255.254.254 # manycast server #manycastclient 239.255.254.254 autokey # manycast client # Enable public key cryptography. #crypto includefile /etc/ntp/crypto/pw # Key file containing the keys and key identifiers used when operating # with symmetric key cryptography. keys /etc/ntp/keys # Specify the key identifiers which are trusted. #trustedkey 4 8 42 # Specify the key identifier to use with the ntpdc utility. #requestkey 8 # Specify the key identifier to use with the ntpq utility. #controlkey 8 # Enable writing of statistics records. #statistics clockstats cryptostats loopstats peerstats server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10
配置完重启一下ntpd服务
service ntpd restart
通过ntpstat查看时间同步状态
出现下面这个说明时间在同步
出现下面这个,说明配置没有成功
5.配置定时任务
crontab -e
*/10 * * * * /usr/sbin/ntpdate -u ntp2.aliyun.com
>/data/qrcode/acquirer/logs/ntp228.log 2>&1
按ESX退出编辑并输入:wq保存
表示每10分钟向阿里云同步一次时间
还需要查看crond定时任务是否已启动
service crond status
后续措辞:
把这个时间同步加入到监控告警中!如果检测到172.18.2.251时间不对,第一时间里面报严重告警!