一,chrony服务同步时间
1,实验一:第一台机器从阿里云同步时间 第二台机器从第一台机器同步时间
下载所需要的yum源,并启动服务
yum -y install chrony systemctl enable chronyd systemctl start chronyd
我这里用的是麒麟服务器 V0 SP3自带有所以不用再次下载
[root@server ~]# nkvers ############## Kylin Linux Version ################# Release: Kylin Linux Advanced Server release V10 (Lance) Kernel: 4.19.90-52.31.v2207.ky10.x86_64 Build: Kylin Linux Advanced Server release V10 (SP3) /(Lance)-x86_64-Build23/20230324 #################################################
#查看chrony服务状态
[root@server ~]# systemctl status chronyd ● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2023-12-28 14:52:37 CST; 8min ago Docs: man:chronyd(8) man:chrony.conf(5) Process: 779 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS) Process: 796 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS) Main PID: 784 (chronyd) Tasks: 1 Memory: 948.0K CGroup: /system.slice/chronyd.service └─784 /usr/sbin/chronyd
Chrony的配置文件是/etc/chrony.conf,进入第一台机子的配置文件,根据你具体的所需参数修改如下:
#pool pool.ntp.org iburst #server ntp.ntsc.ac.cn iburst ##指定阿里云的时间服务器为服务器时间,生产环境中建议大家指定多个事件服务器哟,起到对时间服务器备份的效果 server ntp1.aliyun.com iburst #server cn.pool.ntp.org iburst # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # Enable hardware timestamping on all interfaces that support it. #hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. #minsources 2 # Allow NTP client access from local network. #指定允许的客户端网段来当前时间服务器节点同步时间,我们可以使用deny all拒绝所有客户端。 allow 192.0.0.0/8 # Serve time even if not synchronized to a time source. local stratum 10 #当网络时间不可以时使用本地时间
设置开机启动,重启服务
[root@server ~]# systemctl enable chronyd [root@server ~]# systemctl restart chronyd
使用chronyc sources查看时间同步状态
[root@server ~]# chronyc sources 210 Number of sources = 2 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^- 114.118.7.161 1 7 26 148 +2722us[+3262us] +/- 50ms ^* 120.25.115.20 2 7 353 82 +885us[+1472us] +/- 40ms [root@server ~]# chronyc sources 210 Number of sources = 2 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^- 114.118.7.161 1 7 26 154 +2722us[+3262us] +/- 50ms ^* 120.25.115.20 2 7 353 86 +885us[+1472us] +/- 40ms
^*表示chronyd当前同步到的时钟源
2,客户端配置
修改hosts文件做映射
[root@client ~]# tail /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.200.108 server
客户端配置chrony
[root@client ~]# egrep -v "#|^$" /etc/chrony.conf server server iburst #只需要修改此行即可 driftfile /var/lib/chrony/drift makestep 1.0 3 rtcsync logdir /var/log/chrony
重启服务
[root@client ~]# systemctl restart chronyd [root@client ~]# systemctl enable chronyd
标签:同步,chronyd,server,chrony,systemctl,服务器,root From: https://www.cnblogs.com/AchEngsusu/p/17933096.html