ntpdate cn.ntp.org.cn
其中 time.nist.gov 是一个时间服务器.vim
rm -rf /etc/localtime ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
设置定时任务:
00 0 1 root rdate -s time.nist.govcentos
问题1:[root@BBB ~]# /usr/sbin/ntpdate time.nist.gov
18 Dec 22:36:19 ntpdate[2797]: no server suitable for synchronization found
解决:打开防火墙把123端口给开放
添加服务器
vi /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 123 -j ACCEPT
保存退出重启防火墙便可socket
/etc/init.d/iptables restart
解决后的状况tcp
[root@moban Asia]# /usr/sbin/ntpdate time.nist.gov 3 Mar 22:02:40 ntpdate[2174]: adjust time server 132.163.4.103 offset 0.070296 sec
选择局域网中的一台机器做为ntp服务器,在这台机器上须要安装并启动ntpd
其余机器上要关闭ntpd,安装ntpdate
CentOS6.3上这两个软件都是自带的,只需根据须要打开或者关闭。
注意其余机器的ntpd必须关闭:ide
service ntpd stop
修改ntp服务器上的/etc/ntp.conf,加上如下的配置:ui
server 127.127.1.0 fudge 127.127.1.0 stratum 10
后面哪一个数字在0-15之间均可以,这样就将这台机器的本地时间做为ntp服务提供给客户端rest
重启ntpd:code
service ntpd restart
等五六分钟,让ntpd完成自身的时间同步,这期间能够用:server
watch ntpq -p
查看状态,第6列达到17时就能够了。等待的时间是第5列poll的秒数乘
以5。
配置开机自启动
chkconfig ntpd on
查看服务启动状况
chkconfig --list |grep ntpd
而后其余的机器上执行:
ntpdate xxxx
xxxx是ntp服务器的ip地址或者主机名
定时任务配置: crontab -e
/10 * /usr/sbin/ntpdate 192.168.199.110
问题1.ntpdate同步服务器时间时报:ntpdate[xxx]: the NTP socket is in use, exiting
缘由:启动ntpd服务后就不能够用netpdata 同步时间了
解决:关闭ntpd服务
service ntpd stop
chkconfig ntpd off
查看ntpd 状态
#/etc/init.d/ntpd status ntpd is stopped
修改ntp的配置文件
#vim /etc/ntp.conf server 2.centos.pool.ntp.org iburst server 10.200.63.134【指定内网时间同步ip】
启动ntpd 服务
#/etc/init.d/ntpd start Starting ntpd: [ OK ]
设置开机自启动
#chkconfig --list|grep ntpd ntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off #chkconfig ntpd on #chkconfig --list|grep ntpd ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
查看是否连通指定ip
#ntpq -p
sentos 7 后 ntpd 服务启动方法
systemctl status ntpd 【查看服务状态】 systemctl start ntpd 【开启服务】 systemctl enable ntpd 【 设置开机自启动】 systemctl disable ntpd 【中止开机自启动】