1)先安裝ntp服務:
# yum -y install ntp
(2)配置時間源
# vi /etc/ntp.confserver pool.ntp.org
供參考的其他時間服務器
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
(3)配置是否爲其他計算機提供時間服務
# vi /etc/ntp.conf
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
(4)配置開機自動運行時間同步服務
# chkconfig ntpd on
(5)啓動或停止時間同步服務
# service ntpd start# service ntpd stop# service ntpd restart
(6)驗證NTP服務是否已經運行
# pgrep ntpd
(7)初始同步
# ntpdate -u time.lib.tsinghua.edu.cn
(8)確認同步成功
# ntpq -p
(9)同時建議修改一下 /etc/sysconfig/ntpd 文件,是服務器BIOS時間一併更新
# vi /etc/sysconfig/ntpd
SYNC_HWCLOCK=yes
#service ntpd restart
把SYNC_HWCLOCK改成 yes 之後, 主機 BIOS 的時間也會跟着一起改變。
當然,如果要提供時間服務,還相應的開放udp 123端口。
(10) 調整服務器時區設置(以東八區-北京時間爲例)
#cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#reboot #重啓服務器