Centos 7配置时间同步-NTP服务端+客户端crontab定时器定时执行ntpdate同步时间
·
搭建NTP服务一般有两种方式
1.NTP服务端+客户端crontab定时器定时执行ntpdate同步时间
2.NTP服务端+NTP客户端
以下为NTP服务端+客户端crontab定时器定时执行ntpdate同步时间
一.安装NTP
1.1.查看系统是否安装了ntp,一般默认安装ntpdate
rpm -qa | grep ntp
1.2.安装NTP
yum install ntp ntpdate -y
二.配置NTP服务
这里配置一台ntp Server,一台ntp client
2.1配置ntp Server
(1)打开配合文件
vim /etc/ntp.conf
(2)修改ntp Servert同步的时钟地址
首先注释掉原有的server
#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
接下来有两种选择
第一种,读取远端的服务器时钟作为Server的时钟
server 远端IP
第二种,以本机的时钟为标准,不是127.0.0.1,而是127.127.1.0
server 127.127.1.0
(3)开启ntp server
systemctl start ntpd
(4)查看ntp server的状态
systemctl status ntpd
在控制台显示的信息中,会发现使用的UDP进行通信,端口为123
(5)查看是否同步
[root@localhost network-scripts]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
localhost .INIT. 16 l - 64 0 0.000 0.000 0.000
(6)设置开机自启动
systemctl enable ntpd
2.1配置ntp Client
crontab定时器
设置定时任务,定时执行命令:
crontab -e
输入定时命令(例子为每分钟同步一次):
* * * * * /usr/sbin/ntpdate 10.43.182.14 && /sbin/hwclock -w
* * * * * :分 时 日 月 星期
备注:
crontab -l //来查看设置的命令
cat /var/log/cron //查看定时任务执行的命令情况
cat /var/log/syslog //ubuntu可以查看这个文件
更多推荐
所有评论(0)