当前位置: 首页 > news >正文

ansible一键部署脚本

一键部署rsync服务

[root@m01 conf]# cat /server/scripts/rsync.yaml 
# command playbook
- hosts: 172.16.1.41
  tasks:
     - name: setup01:install rsync
       yum: 
        name: rsync 
        state: installed
    - name: setup02:edit rsync conf file
        copy: 
          src: /etc/ansible/conf/rsyncd.conf 
          dest: /etc/
    - name: setup03:create rsync user
        user: 
          name: rsync 
          state: present 
          create_home: no 
          shell: /sbin/nologin
    - name: setup04:create auth file
        copy: 
          src: /etc/ansible/conf/rsync.password 
          dest: /etc/ 
          mode: 600
    - name: setup05:create backup dir
        file: 
          dest: /backup 
          state: directory 
          owner: rsync 
          group: rsync
    - name: setup06:boot rsync server
        shell: rsync --daemon creates=/var/run/rsyncd.pid
 - hosts: 172.16.1.31
    tasks:
      - name: setup01:create auth file
        copy: 
          src: /etc/ansible/conf/rsync_client.password 
          dest: /etc/rsync.password 
          mode: 600

ansible一键部署脚本(NFS)

[root@m01 scripts]# cat nfs.yaml 
# command playbook
#部署服务器
- hosts: nfs
  tasks:
    - name: setup01:install rpcbind server
      yum: 
        name: nfs-utils 
        state: installed
    - name: setup02:install rpcbind server
      yum: 
        name: rpcbind 
        state: installed
    - name: setup03:edit conf
      copy: 
        src: /etc/ansible/conf/nfs_conf/exports 
        dest: /etc/
    - name: setup04:create backup directory
      file: 
        dest: /data 
        state: directory 
        owner: nfsnobody 
        group: nfsnobody
    - name: setup05:boot rpc server
      shell: /etc/init.d/rpcbind start
    - name: setup06:boot nfs server
      shell: /etc/init.d/nfs start
#部署客户端
- hosts: web
  tasks:
    - name: setup01:install nfs rpc
      yum: 
        name: nfs-utils 
        state: installed
    - name: setup02:install rpcbind server
      yum: 
        name: rpcbind 
        state: installed
    - name: setup03:mount 
      mount:
        name: /mnt 
        src: 172.16.1.31:/data 
        fstype: nfs 
        state: mounted

一键部署inotify服务(在已有rsync服务的前提下)

#inotify.yaml文件
[root@m01 scripts]# cat inotify.yaml 
# command playbook

- hosts: nfs
  tasks:
   - name: setup01:install inotify-tools
     yum:
       name: inotify-tools
       state: installed
   - name: setup02:inotify建立rsync服务的连接
     shell: /bin/sh /server/scripts/inotify.sh &
# inotify脚本
[root@m01 scripts]# cat inotify.sh 
#!/bin/bash
inotifywait -mrq --format "%w%f" -e create,delete,moved_to,close_write /data |\
while read line
do
rsync -az --delete /data/ rsync@172.16.1.41::backup --password-file=/etc/rsync.password
done
[root@m01 scripts]# 

一键部署sersync服务(在已有rsync服务前提下)

[root@m01 sersync_conf]# cat /server/scripts/sersync.yaml 
# command playbook

- hosts: nfs
  tasks:
   - name: setup01 dir tools
     file:
       dest: /tools
       state: directory
   - name: setup02:unzip sersync-master
     unarchive: 
       src: /tools/sersync-master.zip
       dest: /tools/
       copy: yes
   - name: setup03:tar sersync
     unarchive: 
       src: /tools/sersync-master/sersync2.5.4_64bit_binary_stable_final.tar.gz  
       dest: /tools/
       copy: no 
   - name: setup04:mv GNU-Linux-x86 to nfs
     shell: mv /tools/GNU-Linux-x86 /usr/local/sersync
   - name: setup05:edit conf
     copy:
       src: /etc/ansible/conf/sersync_conf/confxml.xml
       dest: /usr/local/sersync/
   - name: setup06:boot sersync
     shell: /usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml

一键部署Nginx服务

[root@m01 scripts]# cat nginx.yaml 
# command playbook

- hosts: web
  tasks:
   - name: setup01:install pcre-devel
     yum:
      name: pcre-devel
      state: installed
   - name: setup02:install openssl-devel
     yum: 
       name: openssl-devel
       state: installed
   - name: setup03:create www user
     user:
       name: www
       state: present
       create_home: no
       shell: /sbin/nologin
   - name: setup04:create dir
     file:
       dest: /server/tools
       state: directory
   - name: setup05:wget nginx
     get_url: 
       url: http://nginx.org/download/nginx-1.15.8.tar.gz
       dest: /server/tools
   - name: setup06:tar nginx
     unarchive:
       src: /server/tools/nginx-1.15.8.tar.gz
       dest: /server/tools
       copy: no
   - name: setup06:install nginx
     shell: cd /server/tools/nginx-1.15.8;./configure --prefix=/application/nginx-15.
8 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module   - name: setup07:make
     shell: cd /server/tools/nginx-1.15.8;make && make install
   - name: setup08:ln nginx
     file:
      src: /application/nginx-15.8 
      dest: /application/nginx
      state: link
   - name: setup09:boot nginx
     shell: /application/nginx/sbin/nginx

转载于:https://www.cnblogs.com/yjiu1990/p/10508645.html

相关文章:

  • Android后台任务(HandlerThread、AsyncTask、IntentService)
  • 为什么开发人员必须要了解数据库锁?
  • 前嗅ForeSpider脚本教程:基本语句
  • Redis保证事务一致性,以及常用的数据结构
  • LNMP基础知识及简单搭建(用于个人学习与回顾)
  • Gnu/Linux 链接XServer方法
  • vue中添加favicon.ico
  • 面试篇三
  • SAP开源Java SCA工具,提供静态代码安全性测试功能
  • 最快1天搭建短视频APP!阿里云短视频解决方案上线
  • CSS3 属性
  • 《重新定义团队》读书笔记及阅读感想2600字
  • Kubernetes — 作业副本与水平扩展
  • BootStack 权限管理平台体验环境正式上线了
  • Windows Server 2016 检查更新时,错误代码8024401C 的解决方案
  • .pyc 想到的一些问题
  • 《网管员必读——网络组建》(第2版)电子课件下载
  • 【刷算法】求1+2+3+...+n
  • CoolViewPager:即刻刷新,自定义边缘效果颜色,双向自动循环,内置垂直切换效果,想要的都在这里...
  • create-react-app做的留言板
  • gulp 教程
  • iOS 系统授权开发
  • JavaScript HTML DOM
  • SQL 难点解决:记录的引用
  • Synchronized 关键字使用、底层原理、JDK1.6 之后的底层优化以及 和ReenTrantLock 的对比...
  • WebSocket使用
  • 基于游标的分页接口实现
  • 警报:线上事故之CountDownLatch的威力
  • 蓝海存储开关机注意事项总结
  • 爬虫模拟登陆 SegmentFault
  • 新版博客前端前瞻
  • # 数论-逆元
  • (27)4.8 习题课
  • (Redis使用系列) Springboot 实现Redis 同数据源动态切换db 八
  • (差分)胡桃爱原石
  • (第一天)包装对象、作用域、创建对象
  • (附源码)springboot社区居家养老互助服务管理平台 毕业设计 062027
  • (附源码)计算机毕业设计大学生兼职系统
  • (四)Controller接口控制器详解(三)
  • (转)ObjectiveC 深浅拷贝学习
  • .net 发送邮件
  • .NET面试题(二)
  • .NET设计模式(7):创建型模式专题总结(Creational Pattern)
  • @property括号内属性讲解
  • [ CTF ] WriteUp- 2022年第三届“网鼎杯”网络安全大赛(朱雀组)
  • [ vulhub漏洞复现篇 ] JBOSS AS 4.x以下反序列化远程代码执行漏洞CVE-2017-7504
  • [ vulhub漏洞复现篇 ] JBOSS AS 5.x/6.x反序列化远程代码执行漏洞CVE-2017-12149
  • [<事务专题>]
  • [22]. 括号生成
  • [2544]最短路 (两种算法)(HDU)
  • [Android]Tool-Systrace
  • [BT]BUUCTF刷题第8天(3.26)
  • [BZOJ5125]小Q的书架(决策单调性+分治DP+树状数组)
  • [C puzzle book] types
  • [C#][DevPress]事件委托的使用