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 【中止開機自啓動】