當服務器多了,時間准確與否,一致與否是個大問題。雖然這個問題總是被忽略,但是統一一致的時間是很有必要的。下面說一下在局域網內配置Linux時間服務器的方法。
NtpServer篇:
#1.安裝ntp
yum -y install ntp
#2.修改配置文件
vi /etc/ntp.conf
#更改配置文件如下:
#上級同步服務器:北京大學同步地址
server s2m.time.edu.cn
#上級服務器不通時使用本地服務
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
#記錄上次的NTP server與上層NTP server聯接所花費的時間
driftfile /var/lib/ntp/drift
#允許訪問時間服務器的IP地址
restrict 127.0.0.1
restrict -6 ::1
restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap #允許任何主機跟進行時間同步
#設置日志路徑
startsdir /var/log/ntp/
#設置ntp日志文件
logfile /var/log/ntp/ntp.log
#3.手動同步
ntpdate s2m.time.edu.cn
#4.啟動服務
service ntpd start
開機啟動:
chkconfig ntpd on
Ntp客戶端
#1.安裝ntp
yum -y install ntp
#2.修改配置文件
注釋默認配置,添加剛剛創建的ntpserver
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 192.168.2.151
至此,ntp服務器配置介紹完畢。
附:修改服務器本地時區
rm -rf localtime
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
