通过ansible一键部署集群ntp时间同步
环境准备
[root@server ~]# cat /etc/redhat-release
CentOS Linux release 7.2. (Core)
[root@server ~]# uname -r
3.10.0-327.el7.x86_64
[root@server ~]# getenforce
Disabled
[root@server ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
[root@server ~]# cat /etc/yum.repos.d/CentOS7-Base-.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - .com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #released updates
[updates]
name=CentOS-$releasever - Updates - .com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - .com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - .com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=
enabled=
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
主机分配
sever 10.0.0.10 主节点
其他节点
client01 10.0.0.11
client02 10.0.0.12
client03 10.0.0.13
client04 10.0.0.14
设置密钥认证
主节点
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys
ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.0.0.10
所有其他节点
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.0.0.10
在主节点
scp ~/.ssh/authorized_keys 10.0.0.11:.ssh/
scp ~/.ssh/authorized_keys 10.0.0.12:.ssh/
scp ~/.ssh/authorized_keys 10.0.0.13:.ssh/
scp ~/.ssh/authorized_keys 10.0.0.14:.ssh/
编写脚本
#!/bin/bash
#安装ansible
yum install ansible –y
echo "10.0.0.10" >>/etc/ansible/hosts
echo "[other]" >>/etc/ansible/hosts
echo -e "10.0.0.11\n10.0.0.12\n10.0.0.13\n10.0.0.14" >>/etc/ansible/hosts
#批量安装ntp服务
ansible all -a "yum install -y ntp"
#批量设置 主机 时区为亚洲上海
ansible all -a "timedatectl set-timezone Asia/Shanghai"
#更改sever端的ntp配置
sed -i 's/# restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap/ restrict 10.0.0.0 mask 255.255.255.0/' /etc/ntp.conf
ansible all -m shell -a "sed -i 's/server 0.centos.pool.ntp.org iburst/#server 0.centos.pool.ntp.org iburst/' /etc/ntp.conf"
ansible all -m shell -a "sed -i 's/server 1.centos.pool.ntp.org iburst/#server 1.centos.pool.ntp.org iburst/' /etc/ntp.conf"
ansible all -m shell -a "sed -i 's/server 2.centos.pool.ntp.org iburst/#server 2.centos.pool.ntp.org iburst/' /etc/ntp.conf"
ansible all -m shell -a "sed -i 's/server 3.centos.pool.ntp.org iburst/#server 3.centos.pool.ntp.org iburst/' /etc/ntp.conf"
echo "server 127.127.1.0" >>/etc/ntp.conf
ansible other[-] -m shell -a "echo 'server 10.0.0.10' >>/etc/ntp.conf"
systemctl enable ntpd; systemctl restart ntpd
ansible other[-] -m shell -a "systemctl stop ntpd"
ansible other[-] -m shell -a "ntpdate 10.0.0.10"
ansible other[-] -m shell -a "systemctl start ntpd;systemctl enable ntpd"
ansible other[-] -m shell -a "timedatectl set-ntp yes"
执行过程
[root@server ~]# bash ntp.sh
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* epel: mirror01.idc.hinet.net
* extras: mirrors..com
* updates: mirrors..com
Package ansible-2.4.2.0-.el7.noarch already installed and latest version
Nothing to do
[WARNING]: Consider using yum module rather than running yum 10.0.0.13 | SUCCESS | rc= >>
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* epel: ftp.cuhk.edu.hk
* extras: mirrors.cn99.com
* updates: mirrors.cn99.com
Package ntp-4.2.6p5-.el7.centos..x86_64 already installed and latest version
Nothing to doRepository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration 10.0.0.12 | SUCCESS | rc= >>
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors..com
* epel: mirrors.ustc.edu.cn
* extras: mirrors..com
* updates: mirrors.aliyun.com
Package ntp-4.2.6p5-.el7.centos..x86_64 already installed and latest version
Nothing to doRepository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration 10.0.0.11 | SUCCESS | rc= >>
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors..com
* epel: ftp.cuhk.edu.hk
* extras: mirrors..com
* updates: mirrors.cn99.com
Package ntp-4.2.6p5-.el7.centos..x86_64 already installed and latest version
Nothing to doRepository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration 10.0.0.14 | SUCCESS | rc= >>
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* epel: mirror01.idc.hinet.net
* extras: mirrors..com
* updates: mirrors..com
Package ntp-4.2.6p5-.el7.centos..x86_64 already installed and latest version
Nothing to doRepository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration 10.0.0.10 | SUCCESS | rc= >>
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* epel: mirror01.idc.hinet.net
* extras: mirrors..com
* updates: mirrors..com
Package ntp-4.2.6p5-.el7.centos..x86_64 already installed and latest version
Nothing to doRepository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration 10.0.0.11 | SUCCESS | rc= >> 10.0.0.14 | SUCCESS | rc= >> 10.0.0.12 | SUCCESS | rc= >> 10.0.0.13 | SUCCESS | rc= >> 10.0.0.10 | SUCCESS | rc= >> [WARNING]: Consider using template or lineinfile module rather than running sed 10.0.0.12 | SUCCESS | rc= >> 10.0.0.13 | SUCCESS | rc= >> 10.0.0.14 | SUCCESS | rc= >> 10.0.0.11 | SUCCESS | rc= >> 10.0.0.10 | SUCCESS | rc= >> [WARNING]: Consider using template or lineinfile module rather than running sed 10.0.0.11 | SUCCESS | rc= >> 10.0.0.14 | SUCCESS | rc= >> 10.0.0.13 | SUCCESS | rc= >> 10.0.0.12 | SUCCESS | rc= >> 10.0.0.10 | SUCCESS | rc= >> [WARNING]: Consider using template or lineinfile module rather than running sed 10.0.0.13 | SUCCESS | rc= >> 10.0.0.12 | SUCCESS | rc= >> 10.0.0.11 | SUCCESS | rc= >> 10.0.0.14 | SUCCESS | rc= >> 10.0.0.10 | SUCCESS | rc= >> [WARNING]: Consider using template or lineinfile module rather than running sed 10.0.0.14 | SUCCESS | rc= >> 10.0.0.12 | SUCCESS | rc= >> 10.0.0.13 | SUCCESS | rc= >> 10.0.0.11 | SUCCESS | rc= >> 10.0.0.10 | SUCCESS | rc= >> [WARNING]: Use [x:y] inclusive subscripts instead of [x-y] which has been removed 10.0.0.11 | SUCCESS | rc= >> 10.0.0.13 | SUCCESS | rc= >> 10.0.0.14 | SUCCESS | rc= >> 10.0.0.12 | SUCCESS | rc= >> [WARNING]: Use [x:y] inclusive subscripts instead of [x-y] which has been removed 10.0.0.13 | SUCCESS | rc= >> 10.0.0.12 | SUCCESS | rc= >> 10.0.0.11 | SUCCESS | rc= >> 10.0.0.14 | SUCCESS | rc= >> [WARNING]: Use [x:y] inclusive subscripts instead of [x-y] which has been removed 10.0.0.13 | SUCCESS | rc= >>
Apr :: ntpdate[]: adjust time server 10.0.0.10 offset 0.007596 sec 10.0.0.12 | SUCCESS | rc= >>
Apr :: ntpdate[]: adjust time server 10.0.0.10 offset 0.017386 sec 10.0.0.14 | SUCCESS | rc= >>
Apr :: ntpdate[]: adjust time server 10.0.0.10 offset 0.013542 sec 10.0.0.11 | SUCCESS | rc= >>
Apr :: ntpdate[]: adjust time server 10.0.0.10 offset 0.012333 sec [WARNING]: Use [x:y] inclusive subscripts instead of [x-y] which has been removed 10.0.0.12 | SUCCESS | rc= >> 10.0.0.13 | SUCCESS | rc= >> 10.0.0.14 | SUCCESS | rc= >> 10.0.0.11 | SUCCESS | rc= >> [WARNING]: Use [x:y] inclusive subscripts instead of [x-y] which has been removed 10.0.0.11 | SUCCESS | rc= >> 10.0.0.13 | SUCCESS | rc= >> 10.0.0.14 | SUCCESS | rc= >> 10.0.0.12 | SUCCESS | rc= >> [root@server ~]# ntpstat
synchronised to local net at stratum
time correct to within ms
polling server every s
[root@server ~]# cat ntp.sh
#!/bin/bash
#安装ansible
yum install ansible –y
echo "10.0.0.10" >>/etc/ansible/hosts
echo "[other]" >>/etc/ansible/hosts
echo -e "10.0.0.11\n10.0.0.12\n10.0.0.13\n10.0.0.14" >>/etc/ansible/hosts
#批量安装ntp服务
ansible all -a "yum install -y ntp"
#批量设置 主机 时区为亚洲上海
ansible all -a "timedatectl set-timezone Asia/Shanghai"
#更改sever端的ntp配置
sed -i 's/# restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap/ restrict 192.168.1.0 mask 255.255.255.0/' /etc/ntp.conf
ansible all -m shell -a "sed -i 's/server 0.centos.pool.ntp.org iburst/#server 0.centos.pool.ntp.org iburst/' /etc/ntp.conf"
ansible all -m shell -a "sed -i 's/server 1.centos.pool.ntp.org iburst/#server 1.centos.pool.ntp.org iburst/' /etc/ntp.conf"
ansible all -m shell -a "sed -i 's/server 2.centos.pool.ntp.org iburst/#server 2.centos.pool.ntp.org iburst/' /etc/ntp.conf"
ansible all -m shell -a "sed -i 's/server 3.centos.pool.ntp.org iburst/#server 3.centos.pool.ntp.org iburst/' /etc/ntp.conf"
echo "server 127.127.1.0" >>/etc/ntp.conf
ansible other[-] -m shell -a "echo 'server 10.0.0.10' >>/etc/ntp.conf"
systemctl enable ntpd; systemctl restart ntpd
ansible other[-] -m shell -a "systemctl stop ntpd"
ansible other[-] -m shell -a "ntpdate 10.0.0.10"
ansible other[-] -m shell -a "systemctl start ntpd;systemctl enable ntpd"
ansible other[-] -m shell -a "timedatectl set-ntp yes"
查看客户端同步情况
随着 reach值不断增加,同步状态由 unsynchronised ----》syncchronised
[root@client01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
10.0.0.10 LOCAL() u 1.081 11.696 0.000
[root@client01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
10.0.0.10 LOCAL() u 0.233 -6.150 17.846
[root@client01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
10.0.0.10 LOCAL() u 0.233 -6.150 17.846
[root@client01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
10.0.0.10 LOCAL() u 0.233 -6.150 17.846
[root@client01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
10.0.0.10 LOCAL() u 0.233 -6.150 17.846
[root@client01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
10.0.0.10 LOCAL() u 0.233 -6.150 17.846
[root@client01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
10.0.0.10 LOCAL() u 0.233 -6.150 17.846
[root@client01 ~]# ntpstat
unsynchronised
time server re-starting
polling server every s
[root@client01 ~]# ntpstat
unsynchronised
time server re-starting
polling server every s
[root@client01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
10.0.0.10 LOCAL() u 0.233 -6.150 17.846
[root@client01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
10.0.0.10 LOCAL() u 0.206 -6.143 12.614
[root@client01 ~]# ntpstat
unsynchronised
time server re-starting
polling server every s
[root@client01 ~]# ntpstat
unsynchronised
time server re-starting
polling server every 8 s
[root@client01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*10.0.0.10 LOCAL(0) 6 u 22 64 37 0.332 -6.075 8.886
[root@client01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*10.0.0.10 LOCAL(0) 6 u 25 64 37 0.332 -6.075 8.886
[root@client01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*10.0.0.10 LOCAL(0) 6 u 26 64 37 0.332 -6.075 8.886
[root@client01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*10.0.0.10 LOCAL(0) 6 u 28 64 37 0.332 -6.075 8.886
[root@client01 ~]# ntpstat
synchronised to NTP server (10.0.0.10) at stratum 7
time correct to within 894 ms
polling server every 64 s
通过ansible一键部署集群ntp时间同步的更多相关文章
- 5分钟实现集群-NTP时间同步
环境:VMware-Workstation-12-Pro,Windows-10,CentOS-7.5,Xshell5 NTP基本介绍 NTP(Network TimeProtocol,网络时间协议), ...
- Kubernetes学习之路(26)之kubeasz+ansible部署集群
目录 1.环境说明 2.准备工作 3.分步骤安装 3.1.创建证书和安装准备 3.2.安装etcd集群 3.3.安装docker 3.4.安装master节点 3.5.安装node节点 3.6.部署集 ...
- [转帖]Ansible管理windows集群
Ansible管理windows集群 http://www.cnblogs.com/Dev0ps/p/10026908.html 写的挺好的 我关注点还是不够好呢 最近公司新项目需要安装400+win ...
- redis在Windows下以后台服务一键搭建集群(多机器)
redis在Windows下以后台服务一键搭建集群(多机器) 一.概述 此教程介绍如何在windows系统中多台机器之间布置redis集群,同时要以后台服务的模式运行.布置以脚本的形式,一键完成.多台 ...
- 从0到1使用Kubernetes系列(三):使用Ansible安装Kubernetes集群
前两期的文章介绍了Kubernetes基本概念和架构,用Kubeadm+Ansible搭建Kubernetes集群所需要的工具及其作用.本篇介绍怎么使用Ansible安装Kubernetes集群. 启 ...
- WebLogic部署集群和代理服务器
应公司要求,最近在学习weblogic集群这块的知识,下面我把我这几天学到的,以及过程中遇到的问题及如何解决的,分享给大家.首先,weblogic是Orcale公司的一款产品,至于其作用,我想就不用我 ...
- shell脚本一键同步集群时间
shell脚本一键同步集群时间 弋嘤捕大 椿澄辄 ψ壤 茇徜燕 ㄢ交涔沔 阚龇棚绍 テ趼蜱棣 灵打了个寒颤也没有去甩脱愣是拖着 喇吉辔 秋北酏崖 琮淄脸酷 茇呶剑 莲夤罱 陕遇骸淫 ...
- ansible一键部署k8s单机环境
一.虚拟机准备 干净的Centsot7.4.4G内存.2个CPU 最小化安装,最好带虚拟化 二.执行初始化脚本 注意:脚本中配置静态网卡根据实际网卡名称配置,我用的是ens33 可以用 sed -i ...
- [转贴]CentOS7.5 Kubernetes V1.13(最新版)二进制部署集群
CentOS7.5 Kubernetes V1.13(最新版)二进制部署集群 http://blog.51cto.com/10880347/2326146 一.概述 kubernetes 1.13 ...
随机推荐
- Django ORM (四) annotate,F,Q 查询
annotate 可以通过计算查询结果中每一个对象所关联的对象集合,从而得出总计值(也可以是平均值或总和),即为查询集的每一项生成聚合. from django.shortcuts import re ...
- Oracle redo与undo 第二弹
首先看一下undo与redo的字面意思: undo:撤销,也就是取消之前的操作. redo:重做,重新执行一遍之前的操作. 什么是REDO REDO记录transaction logs,分为o ...
- (原创)task和function语法的使用讨论(Verilog,CPLD/FPGA)
1. Abstract function和task语句的功能有很多的相似之处,在需要有多个相同的电路生成时,可以考虑使用它们来实现.因为个人使用它们比较少,所以对它们没有进行更深的了解,现在时间比较充 ...
- hive实现根据用户分组,按用户记录求上下两条记录的时间差
在mysql,数据如下:#查询某一用户该日抽奖时间 select draw_time from user_draw_log where user_id = 1 and draw_date='2016- ...
- mybatis是如何防止sql注入?
sql注入发生的时间,sql注入发生的阶段在sql预编译阶段,当编译完成的sql不会产生sql注入 采用jdbc操作数据时候 String sql = "update ft_proposal ...
- NGUI 学习总结
NGUI 学习一段时间了,这里总结一下,用于以后查看. 获取组件 在Awake函数里获取组件,然后就可在Start以及其他函数里使用 lbl = GetComponent<UILabel> ...
- Python-S9——Day100-Web前端框架之Vue
01 课程简介: 02 let和const: 03 箭头函数: 04 对象的单体模式: 05 nodejs介绍和npm操作: 06 webpack.babel介绍和vue的第一个案例: 07 昨日内容 ...
- 我爱学 Python 之文件
读取文件 假设你已经在某个文件夹下创建了 "test.txt" 文件,且里面有一些内容,那你在当前位置输入 Python3,进入到交互模式,然后执行下面的操作: >>& ...
- X-UA-Compatible设置IE浏览器兼容模式
文件兼容性用来告诉IE,让它如何来编译你的网页. 指定 文件兼容性模式 以下是指定为Emulate IE7 mode 兼容性范例. <html> <head> <!-- ...
- CodeForces Round #521 (Div.3) B. Disturbed People
http://codeforces.com/contest/1077/problem/B There is a house with nn flats situated on the main str ...