作者:star
QQ:653945222
操作環(huán)境:centos 6.7
| 服務(wù)器IP | 角色 | 說(shuō)明 |
|---|---|---|
| 192.168.6.61 | NTPD服務(wù)器 | 作為內(nèi)外網(wǎng)絡(luò)的NTPD服務(wù) |
| 192.168.6.62 | NTPD客戶端 | 內(nèi)網(wǎng)設(shè)備與192.168.6.61時(shí)間同步 |
| 192.168.6.63 | NTPD客戶端 | 內(nèi)網(wǎng)設(shè)備與192.168.6.61時(shí)間同步 |
| 192.168.6.64 | NTPD客戶端 | 內(nèi)網(wǎng)設(shè)備與192.168.6.61時(shí)間同步 |
| 192.168.6.65 | NTPD客戶端 | 內(nèi)網(wǎng)設(shè)備與192.168.6.61時(shí)間同步 |
1.安裝ntp時(shí)間服務(wù)器(所有機(jī)器)
1.1 yum安裝方式:#yum install -y ntp
1.2 tar包安裝方式:
- 下載tar包:http://www.ntp.org/downloads.html
- 安裝
tar -zxvf ntp-4.2.8p8.tar.gz
cd ntp-4.2.8p8
./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks
make && make install
rpm -q ntp #查看是否安裝成功
2.設(shè)置ntp服務(wù)為開(kāi)機(jī)自啟動(dòng)(所有機(jī)器)
chkconfig ntpd on
[root@mini1 ~]# chkconfig --list ntpd
ntpd 0:關(guān)閉 1:關(guān)閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關(guān)閉
3.設(shè)置NTP Server
vi /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
#允許192.168.6網(wǎng)段機(jī)器同步時(shí)間
restrict 192.168.6.0 mask 255.255.255.0 nomodify notrap
#遠(yuǎn)程時(shí)間服務(wù)器的地址
server 210.72.145.44 perfer #中國(guó)國(guó)家授時(shí)中心
server 1.cn.pool.ntp.ofg
#允許上層服務(wù)器主動(dòng)修改本機(jī)時(shí)間
restrict 210.72.145.44 nomodify notrap noquery
restrict 1.cn.pool.ntp.ofg nomodify notrap noquery
#外部時(shí)間服務(wù)器不可用時(shí),以本地時(shí)間作為時(shí)間服務(wù)
server 127.127.1.0
fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
4.設(shè)置NTP client
vi /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict 127.0.0.配置只有192.168.6這個(gè)網(wǎng)段的可以從本NTP 服務(wù)器同步時(shí)間
server 192.168.6.61
restrict 210.72.145.44 nomodify notrap noquery
restrict 1.cn.pool.ntp.ofg nomodify notrap noquery
#允許上層時(shí)間服務(wù)器主動(dòng)修改本機(jī)時(shí)間
#遠(yuǎn)程時(shí)間服務(wù)器的地址
includefile210.72.145.44 perfer #中國(guó)國(guó)家授時(shí)中心
includefile1.cn.pool.ntp.ofg
keys /etc/ntp/keys
5.重啟ntpd服務(wù)(所有機(jī)器)
service ntpd restart
6.查看NTP服務(wù)
ntpq -p #NTP Server
remote refid st t when poll reach delay offset jitter
==============================================================================
210.72.145.44 .INIT. 16 - - 256 0 0.000 0.000 0.000
*LOCAL(0) .LOCL. 10 l - 64 377 0.000 0.000 0.000
ntpq -p #NTP Client
remote refid st t when poll reach delay offset jitter
==============================================================================
*mini1 LOCAL(0) 11 u 60 64 7 0.334 -0.487 0.034
查看時(shí)間同步狀態(tài),一般需要5-10分鐘后才能成功連接和同步。所以,服務(wù)器啟動(dòng)后需要稍等下。
ntpstat
剛啟動(dòng)時(shí)時(shí):unsynchronised
啟動(dòng)并連接同步后:
synchronised to NTP server (192.168.6.61) at stratum 12
time correct to within 263 ms
polling server every 64 s
image