Linux NTP服务安装配置详解

cbf2f082913d71eb997826cdb1766d3e.png

网络对时服务NTP(全称Network Time Protocol)

NTP主要用来给其他主机提供时间同步服务,在搭建服务器集群的时候,需要保证各个节点的时间是一致的,时间服务器不失为一个好的选择。

准备工作

关闭防火墙、关闭selinux

系统版本:CentOS7.x,

NTP服务器IP:192.168.1.111,客户端IP:192.168.1.179

安装配置NTP服务器端

一、安装ntp

[root@weijishu ~]# yum install ntp -y

二、修改ntp的配置文件

[root@weijishu ~]# cp /etc/ntp.conf{,.bak}
[root@weijishu ~]# vim /etc/ntp.conf
server 127.127.1.0 #以本机作为时间服务器
fudge 127.127.1.0 startnum 10 #设置服务器层级
restrict 127.0.0.1 # 允许本机使用这个时间服务器
restrict 192.168.1.0 netmask 255.255.255.0 #允许允许192.168.1.0/24网段的所有主机使用该时间服务器进行时间同步
driftfile /var/lib/ntp/ #记录当前时间服务器,与上游服务器的时间差的文件
logfile /var/log/ntp/ntp.log #指定日志文件位置,需要手动创建

三、创建日志文件

root@weijishu ~]# mkdir /var/lib/ntp/
[root@weijishu ~]# touch /var/lib/ntp/ntp.log

三、启动服务

[root@weijishu ~]# systemctl start ntpd
[root@weijishu ~]# systemctl enable ntpd

四、查看状态

[root@weijishu ~]# ntp stat
synchronised to local net at stratum 6 time correct to within 11 ms polling server every 64 s
#synchronised:表示时间同步完成(ntp可以正常工作了)
#unsynchronised:表示时间同步尚未完成
# 或者用 ntpq -p查看状态
[root@weijishu ~]# ntpq -p 
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 5 l 13 64 377 0.000 0.000 0.000

afb823c15b9caaaffdd66e9da54811a6.png

安装配置NTP客户端

一、安装

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

二、修改配置文件

[root@weijishu ~]# cp /etc/ntp.conf{,.bak}
[root@weijishu ~]# vim /etc/ntp.conf
server 192.168.1.111 #设置以192.168.1.111做为本机的时间服务器
restrict 127.0.0.1
logfile /var/log/ntp/ntp.log #指定日志文件位置,需要手动创建

三、创建日志文件

[root@weijishu ~]# mkdir /var/log/ntp
[root@weijishu ~]# touch /var/log/ntp/ntp.log

四、先执行一次ntpdate时间同步

[root@weijishu ~]# ntpdate 192.168.1.111

五、启动ntpd

[root@weijishu ~]# systemctl start ntpd

六、检查状态

[root@weijishu ~]# ntpstat
unsynchronised
time server re-starting
polling server every 8 s

或者

[root@weijishu ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
192.168.1.111 LOCAL(0) 6 u 11 64 1 0.502 0.009 0.000

4dd345d9fc30bbf9a388a6d5d6140ac4.gif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值