安装ntpdate时间同步。

yum install ntpdate -y

在crontab -e 中配置自动同步时间:0 * * * * /usr/sbin/ntpdate -u ntp.api.bz

linux系统中CST与EDT时间转换以及系统时间与网络时间同步

为EDT的时间,而有些节点的时间是CST格式的时间。所以为了实现EDT转换成CST时间的命令如下:

mv /etc/localtime /etc/localtime.bak ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

使用上面的两条命令就可以实现从EDT时间变成CST的时间。

将系统时间写入硬件时间

hwclock --systohc

#安装chrony: yum install -y chrony #注释默认ntp服务器 sed -i 's/^server/#&/' /etc/chrony.conf #指定上游公共 ntp 服务器,并允许其他节点同步时间 cat >> /etc/chrony.conf << EOF server 0.asia.pool.ntp.org iburst server 1.asia.pool.ntp.org iburst server 2.asia.pool.ntp.org iburst server 3.asia.pool.ntp.org iburst allow all EOF #重启chronyd服务并设为开机启动: systemctl enable chronyd && systemctl restart chronyd #开启网络时间同步功能 timedatectl set-ntp true

#安装chrony: yum install -y chrony #注释默认服务器 sed -i 's/^server/#&/' /etc/chrony.conf #指定内网 master节点为上游NTP服务器 echo server 192.168.92.56 iburst >> /etc/chrony.conf #重启服务并设为开机启动: systemctl enable chronyd && systemctl restart chronyd

ntp时间同步: yum -y install ntp ntpdate ntpdate 0.asia.pool.ntp.org hwclock --systohc #将系统时间写入硬件时间