NTP SER
ntp server 安装
安装
sudo apt-get install ntp
启动服务
sudo systemctl start ntp.service
查看服务状态
sudo systemctl status ntp.service
停止服务
sudo systemctl stop ntp.service
时间同步命令
sudo ntpdate ip_addr
为了防止出现一些问题,还要编辑/etc/ntp.conf,加入:
server 127.127.1.0
fudge 127.127.1.0 stratum 8
主要是解决同步时出现 no server suitable for synchronization found错误。
安装ntpd后,在本机运行ntpdate出错,如下:
ntpdate[19979]: the NTP socket is in use, exiting
在执行命令,添加-u选项即可,比如:
ntpdate -u 202.120.2.101
ntpdate -u 133.100.11.8
主节点配置文件ntp_master.conf
driftfile /var/lib/ntp/drift
statsdir /var/log/ntpstats/
#下面默认是拒绝所有来源的任何访问
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
#开放本机的任何访问
restrict 127.0.0.1
restrict ::1
#允许上层时间服务器主动修改本机时间(当前节点)
restrict 192.168.81.131 nomodify notrap noquery
# 允许内网其他机器同步时间(允许网段主机进行时间同步)
restrict 192.168.81.255 mask 255.255.255.0 nomodify notrap
#外部时间服务器不可用时,以本地时间作为时间服务
server 127.127.1.0
fudge 127.127.1.0 stratum 10
二、客户端配置
1.安装ntpdate
sudo apt-get install ntpdate
2.手动校时
sudo ntpdate 192.168.81.131
3.编辑crontab
sudo vim /etc/crontab
追加一行,保存。
*/1 * * * * root sudo ntpdate 192.168.81.131 //使用root用户一分钟自动对时一次