##############################Deploy ntp server ########################
echo "start deploy ntp server" yum install -y ntp if [ ! -f /var/log/ntpd.log ];then
touch /var/log/ntpd.log
fi chown ntp:ntp /var/log/ntpd.log cat $basepath/package/ntp.conf > /etc/ntp.conf systemctl restart ntpd
systemctl enable ntpd ntppid=`ps aux|grep ntp|grep -v "grep"|awk '{print $2}'` if [ "$ntppid" ];then
echo "success ! ntp-server is running now"
fi

通过Ansible playbook 方式安装 ntp

- hosts: 192.168.1.62
remote_user: root
tasks:
- name: Install ntp
yum:
name: ntp
state: present
tags: ntp - name: Configure ntp file
template:
src: ./ntp.conf.j2
dest: /etc/ntp.conf
- name: restart ntp
service: name=ntpd state=restarted - name: Start the ntp service
service:
name: ntpd
state: started
enabled: yes
tags: ntp

  

cat ntp.conf.j2 

driftfile /var/lib/ntp/drift

restrict 127.0.0.1
restrict -6 ::1 server 192.168.1.41 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys

  

执行结果:

ansible-playbook ntp_setup.yml
/usr/lib/python2.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.25.3) or chardet (2.2.1) doesn't match a supported version!
RequestsDependencyWarning) PLAY [192.168.1.62] ******************************************************************************************************************************************* TASK [Gathering Facts] ****************************************************************************************************************************************
ok: [192.168.1.62] TASK [Install ntp] ********************************************************************************************************************************************
ok: [192.168.1.62] TASK [Configure ntp file] *************************************************************************************************************************************
changed: [192.168.1.62] TASK [restart ntp] ********************************************************************************************************************************************
changed: [192.168.1.62] TASK [Start the ntp service] **********************************************************************************************************************************
ok: [192.168.1.62] PLAY RECAP ****************************************************************************************************************************************************
192.168.1.62 : ok=5 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 登录 remote host 查看 ps aux|grep ntp
ntp 27579 0.0 0.0 25720 1920 ? Ss 16:30 0:00 /usr/sbin/ntpd -u ntp:ntp -g
root 27643 0.0 0.0 112708 984 pts/0 S+ 16:30 0:00 grep --color=auto ntp

  

shell脚本安装ntp server 服务的更多相关文章

  1. SVN--下载、安装VisualSVN server 服务端和 TortoiseSVN客户端

    前言: 在http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2407610.html的博客中已经很详细地介绍了SVN的服务器--VisualS ...

  2. shell脚本安装python、pip--这种写法是错误的---每一个命令执行完都要判断是否执行成功,否则无法进行下一步

    shell脚本安装python.pip--不需要选择安装项目--不管用总报错,必须带上判断符号,while没有这种用法,写在这里为了以后少走弯路,所以不要用下面的执行了 首先把pip-.tgz 安装包 ...

  3. Linuxqq shell脚本安装后的卸载

    官方下载和帮助页面: 传送门 linuxqq_2.0.0-b1 的时候,并没有发布 MIPS64 的 DEB 包,只能用 .sh 安装,需要手动删除卸载.愚人节发布的 beta2 新增了 MIPS64 ...

  4. Docker学习3-简单shell脚本安装mysql5.7与docker小技巧

    前言 玩过Windows中的 .bat 的小伙伴是不是觉得很有意思呢,github中一键推送.同步拉取等等操作,哈哈,当然shell脚本也是很类似,可以运行一个脚本就可以自动给我们部署好环境啦!但是这 ...

  5. zabbix通过shell脚本安装异常问题定位

    htxk-106主机信息现象如下: 通过zabbix_get命令 zabbix_get [7189]: Check access restrictions in Zabbix agent config ...

  6. shell脚本--制作自己的服务脚本

    首先注意一下,我用的环境是centos6.5,中间有一些操作和在Ubuntu上有一些地方的操作是不同的, 编写脚本 首先看一个实例:假设有一个test的服务,可以通过命令对test进行启动.关闭或者重 ...

  7. linux可运行的shell脚本与设置开机服务启动(自己总结)

    完整的ln命令参考:http://www.runoob.com/linux/linux-comm-ln.html ln :创建连接文件 - 默认创建的是硬连接,好比复制 ,但是两个文件会同步 命令:l ...

  8. Shell脚本自动重启Java服务

    话不多说直接上代码: cd /home/javaProduct/if [ -d '/home/javaProduct/lib_new/' ]; thenecho 'Has New Lib!'echo ...

  9. shell 脚本安装Tomcat和java

    脚本安装Tomcat和java#!/bin/bash##SCRIPT:install_jdk-8u181-linux-x64_apache-tomcat-8.0.53#AUTHOR:Shinyinfo ...

随机推荐

  1. [luogu_P2045]方格取数加强版

    [luogu_P2045]方格取数加强版 试题描述 给出一个 \(n \times n\) 的矩阵,每一格有一个非负整数 \(A_{i,j},(A_{i,j} \le 1000)\) 现在从 \((1 ...

  2. cf 843 A Sorting by Subsequences [建图]

    题面: 传送门 思路: 这道题乍一看有点难 但是实际上研究一番以后会发现,对于每一个位置只会有一个数要去那里,还有一个数要离开 那么只要把每个数和他将要去的那个位置连起来,构成了一个每个点只有一个入边 ...

  3. redis学习(五)事务

    事务是一个单独的隔离操作:事务中的所有命令都会序列化.按顺序地执行.事务在执行的过程中,不会被其他客户端发送来的命令请求所打断. 1.事务基本命令: multi:标记一个事务块的开始 exec:执行所 ...

  4. jspspy database help

    .

  5. [暑假集训--数论]hdu2136 Largest prime factor

    Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...

  6. 在LINQ TO SQL 中使用MVC3中的DataAnnotations 【MetadataType】

    原文发布时间为:2011-04-07 -- 来源于本人的百度文章 [由搬家工具导入] http://stackoverflow.com/questions/1535662/asp-net-mvc-li ...

  7. ThickBox弹出框的使用方法

    原文发布时间为:2009-08-22 -- 来源于本人的百度文章 [由搬家工具导入] 请访问:http://www.blueidea.com/articleimg/2007/12/5182/tickb ...

  8. 透明层提示框代替windows警告窗口方法!

    原文发布时间为:2009-04-05 -- 来源于本人的百度文章 [由搬家工具导入] 有人会说,怎么网页用JavaScript会有安全提示,而其他网站上面用了JavaScript都没有安全提示,呵呵, ...

  9. pyspider 爬虫教程(一):HTML 和 CSS 选择器

      虽然以前写过 如何抓取WEB页面 和 如何从 WEB 页面中提取信息.但是感觉还是需要一篇 step by step 的教程,不然没有一个总体的认识.不过,没想到这个教程居然会变成一篇译文,在这个 ...

  10. [LeetCode] Search in Rotated Sorted Array II 二分搜索

    Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...