centos时钟同步

#指定时间服务器
timeserver=ntp.sjtu.edu.cn
#设定时区
timedatectl set-timezone Asia/Shanghai
#编辑配置文件,将所有0.centos.pool.ntp.org替换为指定时钟服务器地址
sed -i 's/0.centos.pool.ntp.org/$timeserver/g' /etc/chrony.conf
#重启时钟服务
systemctl restart chronyd

使用ntpd

ntpdate强制更改系统时间,在2012年已经废除;之前ntpdate用于ntpd的初始时间设置,随着ntpd的更新,它不再需要ntpdate

ntpd是一个周期性执行时间同步的工具,要使用ntpd进行时间同步仅需要几步:
配置文件位于:/etc/ntp.conf

ansible all -m shell -a "yum -y install ntp"
ansible all -m shell -a "systemctl enable ntpd"
ansible all -m shell -a "systemctl start ntpd"

#验证同步结果
ntpq -p
#添加防火墙规则,如果检测不成功
firewall-cmd --add-service=ntp --permanent
firewall-cmd --reload


设置服务器时区

 \cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
 hwclock
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值