Chrony时间服务

1.系统时区配置

1.统一调整时区为亚洲上海, 如不统一则会导致时间同步产生差异

[root@xuliangwei ~]# timedatectl
      Local time: Sun 2018-03-18 08:46:29 CST
  Universal time: Sun 2018-03-18 00:46:29 UTC
        RTC time: Sun 2018-03-18 00:46:29
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

//列出可用时区
[root@xuliangwei ~]# timedatectl list-timezones//必须调整时间为上海
[root@xuliangwei ~]# timedatectl set-timezone Asia/Shanghai//使用网络时间同步(考试必考题)
[root@xuliangwei ~]# timedatectl set-ntp true

2.chrony配置

基础环境准备

[root@ntp-server ~]# systemctl stop  firewalld[root@ntp-server ~]# systemctl disable firewalld[root@ntp-server ~]# setenforce 0[root@ntp-server ~]# getenforce Disabled

1.安装chrony时间同步服务

[root@ntp-server ~]# yum install chrony -y

2.使用chrony服务同步时间

//使用网络时间同步(考试必考题)
[root@ntp-server ~]# timedatectl set-ntp true//配置时间同步服务器
[root@ntp-server ~]# vim /etc/chrony.confserver ntp1.aliyun.com iburst
# Allow NTP client access from local network.
allow 192.168.69.0/24

3.启动chrony服务

[root@ntp-server ~]# systemctl enable chronyd[root@ntp-server ~]# systemctl start chronyd

4.验证服务端是否能同步时间

[root@ntp-server ~]# chronyc sources210 Number of sources = 1MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^~ localhost                     2   6   377    41   -10.8s[ -10.8s] +/-   11ms

3.ntpdate同步

客户端要等几分钟再与新启动的ntp服务器进行时间同步,否则会提示no server suitable for synchronization found错误。

//客户端安装ntpdate命令进行同步(第一种方式)
[root@ntp-client ~]# yum install ntpdate -y[root@ntp-client ~]# ntpdate 192.168.69.11218 Mar 11:01:47 ntpdate[18913]: step time server 192.168.69.112 offset -9.805077 sec//将同步命令写入计划任务。
[root@node1 ~]# crontab -e*/2 * * * * /usr/sbin/ntpdate 172.16.56.11 &>/dev/null

4.chrony同步

客户端安装chrony服务同步内网时间服务器(第二种方式)

//环境准备
[root@ntp-client ~]# systemctl stop firewalld[root@ntp-client ~]# setenforce 0//安装时间同步
[root@ntp-client ~]# yum install chrony -y[root@ntp-client ~]# timedatectl set-ntp true//配置时间同步服务器
[root@ntp-client ~]# vim /etc/chrony.conf#指定内部时间服务器地址server 192.168.69.112 iburst//启动chrony服务
[root@ntp-client ~]# systemctl enable chronyd[root@ntp-client ~]# systemctl start chronyd//客户端同步验证
[root@ntp-client ~]# chronyc sources210 Number of sources = 1MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^? 192.168.69.112                3   6   376   206   -14.1s[ -14.1s] +/-  12.6s


本文 暂无 评论

Top