此处就不介绍了 网上类似的文章很多
1.系统环境
server端 ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) ~]# uname -r 3.10.0-327.el7.x86_64 ~]# systemctl disable firewalld.service ~]# systemctl stop firewalld.service ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config ~]# getenforce Disabled [root@node01 .ssh]# hostname -I 192.168.56.68 172.16.1.68 client端 ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) ~]# uname -r 3.10.0-327.el7.x86_64 ~]# systemctl disable firewalld.service ~]# systemctl stop firewalld.service ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config ~]# getenforce Disabled ##IP地址 192.168.56.5 192.168.56.6 192.168.56.7 192.168.56.8
2.安装Chrony服务
2.1使用ansible进行批量安装
1.安装ansible wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum install -y ansible [root@node01 ~]# cat >>/etc/ansible/hosts<<EOF [client] 192.168.56.5 192.168.56.6 192.168.56.7 192.168.56.8 EOF for ip in {5..8};do sshpass -p123456 ssh-copy-id -i /root/.ssh/id_dsa.pub -o StrictHostKeyChecking=no "root@192.168.56.$ip";done 2.批量安装Chrony服务 [root@node01 ~]# yum install chrony -y ##服务端安装 [root@node01 ~]# ansible client -m shell -a "yum install -y chrony" [root@node01 ~]# ansible client -m shell -a "rpm -qa chrony" 192.168.56.5 | SUCCESS | rc=0 >> chrony-3.2-2.el7.x86_64 192.168.56.6 | SUCCESS | rc=0 >> chrony-3.2-2.el7.x86_64 192.168.56.7 | SUCCESS | rc=0 >> chrony-3.2-2.el7.x86_64 192.168.56.8 | SUCCESS | rc=0 >> chrony-3.2-2.el7.x86_64 3.启动Chrony服务 [root@node01 ~]# systemctl start chronyd.service ##服务端启动 ##client端启动 [root@node01 ~]# ansible client -m service -a "name=chronyd state=started enabled=yes"
2.2编辑配置文件
[root@node01 ~]# egrep -v "#|^$" /etc/chrony.conf server ntp1.aliyun.com server time1.aliyun.com driftfile /var/lib/chrony/drift makestep 1.0 3 rtcsync allow 192.168.56.0/24 local stratum 10 logdir /var/log/chrony client端的/etc/chrony.conf文件与server端内容一样其 修改的地方为: server 192.168.56.68 iburst
2.3查看时间是否同步
[root@node01 ~]# ansible client -m shell -a "date +%F" 192.168.56.7 | SUCCESS | rc=0 >> 2018-05-29 192.168.56.5 | SUCCESS | rc=0 >> 2018-05-29 192.168.56.8 | SUCCESS | rc=0 >> 2018-05-29 192.168.56.6 | SUCCESS | rc=0 >> 2018-05-29
3.Centos7也可以使用ntpdate工具同步时间
~]# yum install -y ntpdate ~]# ntpdate 192.168.56.68
如无特殊说明,文章均为本站原创,转载请注明出处
- 转载请注明来源:Centos7时间服务之Chrony搭建
- 本文永久链接地址:https://www.xionghaier.cn/archives/325.html