当前位置:文档之家› 生产环境NTP主备服务器配置文档

生产环境NTP主备服务器配置文档

中国银联电子支付研究院
基于云计算的电子支付和电子商务综合服务平台生产环境NTP主备服务器配置文档
第0.02版
中国银联电子支付研究院
二〇一四年十一月二十五日
版本控制信息
文档安全控制信息
目录
版本控制信息 (1)
1概述 (1)
2NTP主服务器配置 (1)
3NTP备服务器配置 (1)
4NTP客户端配置 (2)
5更新基线文档 (4)
1概述
本文档是生产环境NTP主备服务器配置文档。

生产环境NTP主备服务器基本信息如下:
2 NTP主服务器配置
1.备份ntp服务配置文件
A0309005:~ # cp /etc/ntp.conf /etc/ntp.conf_20130805.bak
2.修改ntp服务配置文件
A0309005:~ # cat /etc/ntp.conf
server 144.0.252.7
restrict default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict 145.240.0.0 mask 255.255.0.0 nomodify
restrict 144.240.0.0 mask 255.255.0.0 nomodify
driftfile /var/lib/ntp/drift/ntp.drift
logfile /var/log/ntp
3.重启ntp服务
A0309005:~ # service ntp start
A0309005:~ # chkconfig ntp on
3 NTP备服务器配置
1.备份ntp服务配置文件
A0309006:~ # cp /etc/ntp.conf /etc/ntp.conf_20130805.bak
2.修改ntp服务配置文件
A0309006:~ # cat /etc/ntp.conf
server 144.0.252.7
restrict default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict 145.240.0.0 mask 255.255.0.0 nomodify
restrict 144.240.0.0 mask 255.255.0.0 nomodify
driftfile /var/lib/ntp/drift/ntp.drift
logfile /var/log/ntp
3.重启ntp服务
A0309006:~ # service ntp start
A0309006:~ # chkconfig ntp on
4 NTP客户端配置
4.1 客户端为物理机
1.备份NTP服务配置文件
A0306001:~ # cp /etc/ntp.conf /etc/ntp.conf_20130805.bak
2.修改NTP服务配置文件
A0306001:~ # cat /etc/ntp.conf
driftfile /var/lib/ntp/drift/ntp.drift
logfile /var/log/ntp
server 145.240.4.35
server 145.240.4.36
3.重启ntp服务
A0306001:~ # service ntp start
A0306001:~ # chkconfig ntp on
4.2 客户端为虚拟机
1.备份NTP服务配置文件
node1:~ # cp /etc/ntp.conf /etc/ntp.conf_20130805.bak
2.修改NTP服务配置文件
node1:~ # cat /etc/ntp.conf
driftfile /var/lib/ntp/drift/ntp.drift
logfile /var/log/ntp
server 144.240.4.35
server 144.240.4.36
3.重启ntp服务
node1:~ # service ntp start
node1:~ # chkconfig ntp on
node1:~ # /usr/sbin/sntp -P no -r 144.0.252.7
具体配置如下:
原来的上层服务器及对上层的限制注释掉,然后直接加上这几项
server 210.72.145.44 prefer
server
restrict 210.72.145.44 mask 255.255.255.255 nomodify notrap noquery
restrict mask 255.255.255.255 nomodify notrap noquery
restrict 192.168.1.0 mask 255.255.255.0 nomodify #对内网访问开放,不同网段设置要改一下
6、重启服务:/etc/init.d/ntpd restart
7、加入开机启动:chkconfig ntpd on
8、查看系统日志看有没有报错:tail /var/log/messages
9、查看启动的端口:netstat -tlunp | grep ntp
10、检查与上层服务器是否同步成功(约15分钟后才会和上层连接):
ntpstat 或 ntpq -p
11、先对服务器进行手动较正,要不误差超过1000秒的话服务会自动停掉:
date MMDDHHMMCCYY.SS #设置时间,格式:月月日日时时分分年年.秒秒
/etc/init.d/ntpd stop #要把服务停掉,因为ntp与ntpdate不能同时生效
ntpdate 210.72.145.44
hwclock -w #写入硬件时间,-r是显示硬件时间
/etc/init.d/ntpd restart
vim /etc/crontab
30 7 * * * root (/usr/sbin/ntpdate 210.72.145.44 && /sbin/hwclock -w) &> /dev/null
30 7 * * * root (/usr/sbin/sntp -P no -r 132.129.4.250 && /sbin/hwclock -w) &> /dev/null
30 7 * * * /usr/sbin/sntp -P no -r 132.129.4.250 && /sbin/hwclock -w
# /etc/init.d/crond restart
要点:
Linux 系统本来就有两种时间,一种是 Linux 以 1970/01/01 开始计数的系统时间,一种则是 BIOS 记载的硬件时间;
Linux 可以透过网络校时,最常见的网络校时为使用 NTP 服务器,这个服务启动在 udp port 123;
时区档案主要放置于 /usr/share/zoneinfo/ 目录下,而本地时区则参考/etc/localtime;
NTP 服务器为一种阶层式的服务,所以 NTP 服务器本来就会与上层时间服务器作时间的同步化,因此 nptd 与 ntpdate 两个指令不可同时使用;
NTP 服务器的联机状态可以使用 ntpstat 及 ntpq -p 来查询;
NTP 提供的客户端软件为 ntpdate 这个指令;
在 Linux 下想要手动处理时间时,需以 date 设定时间后,以 hwclock -w 来写入 BIOS 所记录的时间。

NTP 服务器之间的时间误差不可超过 1000 秒,否则 NTP 服务会自动关闭。

5更新基线文档。

相关主题