内网配置ntp实现时间同步
机器:
1 2 3 4 5 6 7 8 |
10.214.138.132(主) 10.214.138.133 10.214.138.134 10.214.138.135 10.214.138.136 10.214.138.137 10.214.138.138 10.214.138.139 |
1.确认是否存在NTP
每台都需要安装,我这边用SecureCRT通过命令窗口,同时发送控制多个服务器
1 2 3 4 5 |
rpm –qa | grep ntp ---> ntpdate-4.2.6p5-29.el7.centos.x86_64 ntp-4.2.6p5-29.el7.centos.x86_64 |
2.删除已安装ntp
1 2 3 4 5 |
rpm -e --nodeps ntpdate-4.2.6p5-29.el7.centos.x86_64 rpm -e --nodeps ntp-4.2.6p5-29.el7.centos.x86_64 //检查是否还存在 rpm -qa | grep ntp |
ps:如果是内网,则需要准备ntp rpm包--> http://rpm.pbone.net/
我为了麻烦,部署的时候就没有删除原来安装的,所以第三步就剩了,因为还要把rpm传到内网服务器
3.重新安装ntp
因为我是内网实现ntp时间同步,但是内网服务器这边我yum重新安装下载不了rpm,因为需要自己下载上传到服务器.
1 2 3 4 |
yum install ntp 或者 yum -y install ntp |
4.NTP配置
4.1所有服务器配置节点(默认配置可省略)
我这边是使用配置文件默认的内容没做修改,默认代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Permit time synchronization with our time source, but do not # permit the source to query or modify the service on this system. restrict default nomodify notrap nopeer noquery # Permit all access over the loopback interface. This could # be tightened as well, but to do so would effect some of # the administrative functions. restrict 127.0.0.1 restrict ::1 # Hosts on local network are less restricted. #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap |
4.2主服务器(主机)设置
修改/etc/ntp.conf文件
1 2 |
vi /etc/ntp.conf |
在server部分添加一下部分,并注释掉server 0 ~ n,新增内容:
1 2 3 4 5 6 7 8 9 10 11 |
#注释 #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 127.127.1.0 fudge 127.127.1.0 stratum 10 |
4.3从服务器(从机)设置
在server部分添加一下部分,并注释掉server 0 ~ n,新增内容:
1 2 3 4 5 6 7 8 9 |
#注释 #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 10.214.138.132 |
4.4重启ntp服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
systemctl restart ntpd 或者 systemctl start ntpd #查看ntp服务器有无和上层ntp连通 ntpstat #查看ntp服务器与上层ntp的状态 ntpq -p #参数: remote:本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先 refid:参考上一层ntp主机地址 st:stratum阶层 when:多少秒前曾经同步过时间 poll:下次更新在多少秒后 reach:已经向上层ntp服务器要求更新的次数 delay:网络延迟 offset:时间补偿 jitter:系统时间与bios时间差 |