linux查看用户名chrony,linux服务之NTP及chrony时间同步

一、NTP时间同步

NTP(Network Time Protocol,网络时间协议)是由RFC 1305定义的时间同步协议,用来在分布式时间服务器和客户端之间进行时间同步。NTP基于UDP报文进行传输,使用的UDP端口号为123。

目的:使用NTP的目的是对网络内所有具有时钟的设备进行时钟同步,使网络内所有设备的时钟保持一致,从而使设备能够提供基于统一时间的多种应用。

对于运行NTP的本地系统,既可以接受来自其他时钟源的同步,又可以作为时钟源同步其他的时钟,并且可以和其他设备互相同步。

项目:NTP 时间服务器

centos两台以上

@1 192.168.99.101

@2 192.168.99.102

@1:

yum –y install ntp

同步本机时间:

date

2019年 02月 28日 星期五 11:28:02 CST

date -s 23:41

date

2019年 02月 28日 星期五 23:41:16 CST

ntpdate time.windows.com

28 Feb 11:29:49 ntpdate[9849]: step time server 52.173.193.166 offset -43916.758152 sec

date

2019年 02月 28日 星期五 11:30:30 CST

vim /etc/ntp.conf

restrict 192.168.99.0 mask 255.255.255.0 nomodify notrap #允许访问的网段

server 127.127.1.0 #添加本机作为服务器

fudge 127.127.1.0 stratum 10 #将优先级改为最高

或者

vim /etc/ntp.conf

server 127.127.1.0 #本地时钟地址,以本机作为时间服务器,也可以根据需要选择阿里时间服务器

restrict 127.0.0.1 #允许本机使用时间服务器

restrict 172.20.10.7 mask 255.255.255.240 #允许172.20.10.7使用本机的时间服务器

启动服务

systemctl start ntpd

systemctl enable ntpd

添加防火墙端口

netstat -anp|grep ntp #查询端口

firewall-cmd --add-port=123/udp

firewall-cmd --add-port=123/udp --permanent

查看ntp状态

ntpstat

@2使用ntp同步时间

date -s 00:00

ntpdate 192.168.99.101

在crontab 加入定时任务

crontab -e

0,30 * * * * ntpdate 192.168.99.101

扩展 :

hwclock/clock 显示硬件时钟

hwclock --systohc 系统时钟同步至硬件

hwclock --hctosys 硬件时钟同步至系统

二、chrony时间同步

yum -y install chrony

vim /etc/chrony.conf

###################

allow 192.168.10.0/24

###################

systemctl enable chronyd

systemctl restart chronyd

firewall-cmd --add-port=123/udp

firewall-cmd --add-port=123/udp --permanent

firewall-cmd --add-port=323/udp

firewall-cmd --add-port=323/udp --permanent

yum -y install chrony

echo "server 192.168.10.100 iburst" > /etc/chrony.conf

systemctl enable chronyd

systemctl restart chronyd

chronyc sources

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值