ntp服务器修改,ntp服务器搭建与修改时区
NTP是最長用的也是最基本的服務了,很多加密應用都依賴此服務,比如:open***、puppet、saltstack等都需要首先同步好時間,所以把搭建NTPserver總結下,方便以后自己查詢。
首先下載ntp server源碼包:ntp-4.2.6p5.tar,如附件。
解壓,進入ntp-4.2.6p5目錄開始安裝,命令如下:
./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks
make && make install
安裝完成后直接配置/etc/ntp.conf? 是ntp這個包提供的配置文件,配置如下:
driftfile /var/lib/ntp/drift
#restrict default kod nomodify notrap nopeer noquery
restrict 58.55.127.0 mask 255.255.255.0 nomodify
restrict 221.235.188.0 mask 255.255.255.0 nomodify
restrict default nomodify notrap noquery
restrict -6 default kod nomodify notrap nopeer noquery
# Permit all access over the loopback interface.? This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1
server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org
修改配置文件:
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.pool.ntp.org
#server 0.centos.pool.ntp.org
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org
配置完成后開啟ntp服務:
[root@box logs]# /etc/init.d/ntpd restart
Shutting down ntpd:??????????????????????????????????????? [FAILED]
Starting ntpd:???????????????????????????????????????????? [? OK? ]
查看服務是否正常運行:
root@box logs]# netstat -lntup |grep ntp
udp??????? 0????? 0 192.168.2.137:123? ?????????0.0.0.0:*?????????????????????????????? 14010/ntpd
udp??????? 0????? 0 58.55.127.137:123?????????? 0.0.0.0:*?????????????????????????????? 14010/ntpd
udp??????? 0????? 0 127.0.0.1:123?????????????? 0.0.0.0:*??????????????????? ???????????14010/ntpd
udp??????? 0????? 0 0.0.0.0:123???????????????? 0.0.0.0:*?????????????????????????????? 14010/ntpd
udp??????? 0????? 0 fe80::2a0:d1ff:feea:bd15:123 :::*??????????????????????????????????? 14010/ntpd
udp? ??????0????? 0 fe80::2a0:d1ff:feea:bd14:123 :::*??????????????????????????????????? 14010/ntpd
udp??????? 0????? 0 ::1:123???????????????????? :::*??????????????????????????????????? 14010/ntpd
udp??????? 0????? 0 :::123????????????????????? :::*??????????????????????????????????? 14010/ntpd
查看NTP狀態是否同步上層NTP服務器成功:
[root@box logs]# ntpstat
synchronised to NTP server (83.137.98.96) at stratum 3
time correct to within 499 ms
polling server every 64 s
看到synchronised to NTP server,說明已經同步成功了,
查看NTP Server時間是否正確:
[root@box logs]# date
Thu Sep? 5 11:03:33 CST 2013
如果顯示如下:
[root@box logs]# ntpstat
unsynchronised
polling server every 16 s
說明未同步成功,請檢查配置是否修改正確。
還可以用這個命令查看;
[root@box logs]# ntpq -p
remote?????????? refid????? st t when poll reach?? delay?? offset? jitter
==============================================================================
spacys.de?????? 130.133.1.10???? 2 u?? 35?? 64??? 3? 346.738?? -7.946?? 0.536
blueshift.trevo 209.51.161.238?? 2 u?? 56?? 64??? 1? 252.679??? 0.387?? 0.000
jaded.fsck.ca?? 132.163.4.103??? 2 u?? 45?? 64??? 1? 286.477? -37.529?? 0.000
每項含義可以參照:
PS:
每次重啟NTP?服務器之后大約要3-5 分鐘客戶端才能與server 建立正常的通訊
切記每次修改了配置文件后都需要重新啟動服務來使配置生效。
命令行修改時區三步:
[root@localhost ~]# vi /etc/sysconfig/clock
ZONE="Asia/Shanghai"
[root@localhost ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp: overwrite `/etc/localtime'? y
[root@localhost ~]# date
Thu Sep? 5 19:33:12 CST 2013
最后crontab中添加:
*/5 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1
Ntpdate –u +ip? 同步時間。
總結
以上是生活随笔為你收集整理的ntp服务器修改,ntp服务器搭建与修改时区的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2021年钟霖高考成绩查询,2021年高
- 下一篇: 51单片机知识点汇总