时间服务器
yum install -y ntp ntpdate
修改配置
vim /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
#允许内部服务器同步
restrict 192.168.3.0 mask 255.255.255.0 nomodify notrap
#从服务器上就行时间同步
server 210.72.145.44 perfer # 中国国家受时中心
server 202.112.10.36 # 1.cn.pool.ntp.org
server 59.124.196.83 # 0.asia.pool.ntp.org
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
#允许上层时间服务器主动修改本机时间
restrict 210.72.145.44 nomodify notrap noquery
restrict 202.112.10.36 nomodify notrap noquery
restrict 59.124.196.83 nomodify notrap noquery
# 外部时间服务器不可用时,以本地时间作为时间服务
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
启动ntp服务
service ntpd start
chkconfig ntpd on
查看状态
ntpq -p
将同步好的时间写到CMOS里边
vim /etc/sysconfig/ntpd
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
SYNC_HWCLOCK=yes
客户端
yum install ntp ntpdate
chkconfig ntpd on
vim /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default nomodify
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
#上级时间服务器为
server
#允许上级时间服务器更新时间
restrict nomodify notrap noquery
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
启动服务
service ntpd start
手动同步时间
ntpdate -u
将同步好的时间写到CMOS里边
vim /etc/sysconfig/ntpd
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
SYNC_HWCLOCK=yes
写个计划任务每小时同步一次
crontab -e
20 * * * * /usr/sbin/ntpdate