centos ntp日志_centos下部署NTP时间服务器同步环境记录

1)服务端部署

安装所需软件包

[root@test ~]# yum -y install ntp ntpdate

服务端自己先手工同步一次时间。

[root@test ~]# ntpdate ntp.sjtu.edu.cn

21 Jun 16:48:54 ntpdate[10781]: the NTP socket is in use, exiting

或者使用阿里云的时间服务器进行在线同步

[root@test ~]# ntpdate ntp2.aliyun.com

[root@test ~]# ntpdate ntp1.aliyun.com

编辑NTP主配置文件,添加NTP服务器(对于大陆地区的服务器)并同步BIOS时间。

对于位于中国大陆地区IDC机房的服务器,由于CentOS/RHEL默认的ntp服务器无法访问,因此要设置中国大陆地区自己的ntp服务器;

对于位于中国大陆地区以外的IDC机房的服务器,可以使用CentOS/RHEL默认的ntp服务器(但一定要检查确保可以访问);

修改如下:

[root@test ~]# cp /etc/ntp.conf /etc/ntp.conf.bak

[root@test ~]# vim /etc/ntp.conf

restrict default nomodify notrap noquery

restrict 127.0.0.1

restrict 192.168.0.0 mask 255.255.0.0 nomodify #只允许192.168.0.0网段的客户机进行时间同步。如果允许任何IP的客户机都可以进行时间同步,就修改为"restrict default nomodify"

server ntp1.aliyun.com

server ntp2.aliyun.com

server time1.aliyun.com

server time2.aliyun.com

server time-a.nist.gov

server time-b.nist.gov

server 127.127.1.0 # local clock

fudge 127.127.1.0 stratum 10

driftfile /var/lib/ntp/drift

broadcastdelay 0.008

keys /etc/ntp/keys

[root@test ~]# service ntpd start

Starting ntpd: [ OK ]

[root@test ~]# netstat -tulnp | grep ntp

udp 0 0 182.48.115.233:123 0.0.0.0:* 10023/ntpd

udp 0 0 127.0.0.1:123 0.0.0.0:* 10023/ntpd

udp 0 0 0.0.0.0:123 0.0.0.0:* 10023/ntpd

udp 0 0 fe80::5054:ff:feab:db19:123 :::* 10023/ntpd

udp 0 0 ::1:123 :::* 10023/ntpd

udp 0 0 :::123 :::* 10023/ntpd

设置开机自启动

[root@test ~]# /sbin/chkconfig --level=2345 ntpd on

查看现有连接客户端

[root@test ~]# watch ntpq -p

服务端可以设置定期在线同步一次时间

[root@test ~]# crontab -l

#服务器时间同步

0 * * * * /usr/sbin/ntpdate ntp1.aliyun.com; /sbin/hwclock -w

2)客户端配置 (记住要关闭客户端机器的ntpd服务, 否则使用nepdate的时候, 会报错"ntpdate[14431]: the NTP socket is in use, exiting"; 或者开启ntpd服务前提下, 使用ntpdate -u ip就不会有那个报错了)

命令行手动执行一次验证是否可用:

[root@test2 ~]# ntpdate 182.148.15.33 #182.148.15.33是上面ntp服务器的ip地址

21 Jun 16:45:35 ntpdate[2323]: adjust time server 182.148.15.33 offset 0.319548 sec

配置自动同步

[root@test2 ~]# crontab -l

#服务器时间同步

*/5 * * * * /usr/sbin/ntpdate 182.148.15.33; /sbin/hwclock -w

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值