配置ntp时间同步

1、安装ntp服务

[root@zabbix-server gitlab_backup]# yum install ntp -y 

2、检查是否安装

[root@zabbix-server gitlab_backup]# rpm -qa ntp
ntp-4.2.6p5-25.el7.centos.2.x86_64

3、过滤配置文件

[root@zabbix-server etc]# egrep -v '#|^$' /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1 
restrict ::1
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
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor

4、备份配置文件

[root@zabbix-server gitlab_backup]# cp /etc/ntp.conf /etc/ntp.conf.bak

5、修改配置文件

[root@zabbix-server etc]# cat /etc/ntp.conf

driftfile /var/lib/ntp/drift
restrict default nomodify
restrict 127.0.0.1
restrict -6 ::1
server ntp1.aliyun.com
#server time.nist.gov
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

6、重启服务

[root@zabbix-server etc]# systemctl restart ntpd

7、开机自启动

[root@zabbix-server etc]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

8、查看服务状态

[root@zabbix-server etc]# systemctl status ntpd
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: active (running) since 三 2017-07-12 11:41:08 CST; 9s ago
Process: 30441 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 30442 (ntpd)
CGroup: /system.slice/ntpd.service
└─30442 /usr/sbin/ntpd -u ntp:ntp -g

9、检查是否启动

[root@zabbix-server etc]# ps -ef|grep ntpd
ntp 30442 1 0 11:41 ? 00:00:00 /usr/sbin/ntpd -u ntp:ntp -g
root 30473 21910 0 11:41 pts/0 00:00:00 grep --color=auto ntpd

10、查看ntp状态

[root@zabbix-server etc]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
time5.aliyun.co 10.137.38.86 2 u 7 64 1 44.439 11.857 0.000 

11、配置定时任务,每5分钟同步一次时间

[root@zabbix-server etc]# crontab -e

#times sync by lee at 2017-06-28
*/5 * * * * /usr/sbin/ntpdate 10.0.100.208 >/dev/null 2>&1

12、查看时间

[root@zabbix-server etc]# date
2017年 07月 12日 星期三 12:01:35 CST

 

posted @ 2017-07-12 12:03  努力哥  阅读(1019)  评论(0)    收藏  举报