ansible ad-hoc自动化搭建交作业平台、ansible-plbook自动化搭建交作业平台

ansible自动化搭建交作业平台

#1.安装httpd
ansible web_group -m yum -a 'name=httpd state=present' &&\
#2.创建www用户组
ansible web_group,nfs -m group -a 'name=www gid=666 state=present' &&\
#3.创建www用户
ansible web_group,nfs -m user -a 'name=www uid=666 group=www shell=/sbin/nologin create_home=false' &&\
#4.配置httpd
ansible web_group -m copy -a 'src=/etc/httpd/conf/httpd.conf dest=/etc/httpd/conf/' &&\
#5.解压php安装包到web服务器
ansible web_group -m unarchive -a 'src=/root/php.tar.gz dest=/tmp/' &&\
#6.安装php
ansible web_group -m shell -a 'yum localinstall -y /tmp/*.rpm' &&\
#7.配置php
ansible web_group -m copy -a 'src=/etc/php-fpm.d/www.conf dest=/etc/php-fpm.d/' &&\
ansible web_group -m copy -a 'src=/etc/php.ini dest=/etc/' &&\
#8.启动php
ansible web_group -m systemd -a 'name=php-fpm state=started enabled=yes' &&\
#9.启动httpd
ansible web_group -m systemd -a 'name=httpd state=started enabled=yes' &&\
#10.解压代码
ansible web_group -m unarchive -a 'src=/root/kaoshi.zip dest=/var/www/html/ owner=www group=www' &&\
#11.站点目录授权
ansible web_group -m file -a 'path=/var/www/ state=directory owner=www group=www recurse=yes' &&\
#12.安装NFS
ansible nfs -m yum -a 'name=nfs-utils state=present' &&\
#13.安装rpcbind
ansible web_group,nfs -m yum -a 'name=rpcbind state=present' &&\
#14.配置nfs
ansible nfs -m copy -a 'content="/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)" dest=/etc/exports' &&\
#15.创建挂载目录
ansible nfs -m file -a 'path=/data state=directory owner=www group=www' &&\
#16.启动nfs
ansible nfs -m systemd -a 'name=nfs state=started' &&\
#17.启动rpcbind
ansible nfs -m systemd -a 'name=rpcbind state=started' &&\
#18.创建web端挂载的目录
ansible web_group -m file -a 'path=/var/www/html/upload state=directory owner=www group=www' &&\
#19.挂载
ansible web_group -m mount -a 'src=172.16.1.31:/data path=/var/www/html/upload fstype=nfs opts=defaults state=mounted'

ansible-plbook自动化搭建交作业平台

1.搭建web端并挂载nfs
[root@m01 ~]# cat jiaozuoye.yml 
- hosts: all
  tasks:
    - name: Install group
      group:
        name: www
        gid: 666
        state: present
    - name: Install user
      user:
        name: www
        uid: 666
        group: www
        create_home: false
        shell: /sbin/nologin
        state: present
- hosts: nfs_server
  tasks:
    - name: Install nfs server
      yum:
        name: nfs-utils
        state: present
    - name: Install rpcbind server
      yum:
        name: rpcbind
        state: present
    - name: Config nfs
      copy:
        content: /data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
        dest: /etc/exports
    - name: Mkdir data directory
      file:
        path: /data
        state: directory
        owner: www
        group: www
    - name: Start nfs server
      systemd:
        name: nfs
        state: started
        enabled: yes
    - name: Start rpcbind server
      systemd:
        name: rpcbind
        state: started
        enabled: yes
- hosts: web_group
  tasks:
    - name: Install Httpd Server
      yum:
        name: httpd
        state: present
    - name: Config Httpd Server
      copy:
        src: /etc/httpd/conf/httpd.conf
        dest: /etc/httpd/conf/
    - name: Tar Php
      unarchive:
        src: /root/php.tar.gz
        dest: /tmp
    - name: Install php
      shell: yum localinstall -y /tmp/*.rpm
    - name: Config php-fpm.d
      copy:
        src: /etc/php-fpm.d/www.conf
        dest: /etc/php-fpm.d/
    - name: Config php.ini
      copy:
        src: /etc/php.ini
        dest: /etc/
    - name: Start php server
      systemd:
        name: php-fpm
        state: started
    - name: Start httpd server
      systemd:
        name: httpd
        state: started
    - name: tar kaoshi.zip
      unarchive:
        src: /root/kaoshi.zip
        dest: /var/www/html
        owner: www
        group: www
    - name: Mkdir upload directory
      file:
        path: /var/www/html/
        state: directory
        owner: www
        group: www
        recurse: yes
    - name: Install rpcbind
      yum:
        name: rpcbind
        state: present
    - name: Install nfs
      yum:
        name: nfs-utils
        state: present
    - name: authorized upload
      file:
        path: /var/www/html/upload
        state: directory
        owner: www
        group: www
    - name: Mount web_group directory
      mount:
        src: 172.16.1.31:/data
        path: /var/www/html/upload
        fstype: nfs
        opts: defaults
        state: mounted

2.rsync + sersync 进行实时备份

1)配置rsync主机清单

[root@m01 ~]# cat /etc/ansible/hosts 
[web_group]
web01 ansible_ssh_pass='1'
web02 ansible_ssh_pass='1'


[nfs_server]
nfs ansible_ssh_pass='1'

[rsync_backup]
backup ansible_ssh_pass='1'

[db_server]
db01 ansible_ssh_pass='1'
[www:children]
nfs_server
rsync_backup
web_group

2)配置rsync配置文件

uid = www
gid = www
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
ignore errors
read only = false
list = true
auth users = rsync_backup
secrets file = /etc/rsync.passwd
log file = /var/log/rsyncd.log
#####################################
[web_data]
comment = "该备份文件是web端挂载到nfs服务器的文件"
path = /backup


rsync_server端
[root@m01 lnmp]# cat rsync_server.yml 
- hosts: rsync_backup
  tasks:
   
    - name: Install Rsync Server
      yum:
        name: rsync
        state: present
    - name: Config rsync
      copy:
        src: /etc/rsyncd.conf
        dest: /etc
    - name: Create Password File
      copy:
        content: "rsync_backup:123456"
        dest: /etc/rsync.passwd
        mode: 600
    - name: Create Dir
      file:
        path: /backup
        state: directory
        owner: www
        group: www
    - name: Start Rsync Server
      systemd:
        name: rsyncd
        state: started

rsync_client端
[root@m01 lnmp]# cat rsync_client.yml 
- hosts: nfs_server
  tasks:
    - name: Install Rsync Server
      yum:
        name: rsync
        state: present
    - name: Install Inotify-Tools Server
      yum:
       name: inotify-tools
       state: present
    - name: Install Sersync Server
      unarchive:
        src: /root/sersync2.5.4_64bit_binary_stable_final.tar.gz
        dest: /usr/local
    - name: Rename Sersync Dir
      shell: "mv /usr/local/GNU-Linux-x86 /usr/local/sersync"
    - name: Config Sersync
      copy:
        src: /root/GNU-Linux-x86/confxml.xml
        dest: /usr/local/sersync/
    - name: Chmod Sersync
      copy:
        src: /root/GNU-Linux-x86/sersync2
        dest: /usr/local/sersync/
        mode: 755
    - name: Create Passwd File
      copy:
        content: "123456"
        dest: /etc/rsync.password
        mode: 600 
    - name: Start Sersync Server
      shell: "/usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml"

优化
[root@m01 lnmp]# cat base.yml 
- hosts: all
  tasks:
    - name: Stop Selinux
      selinux:
        state: disabled
    - name: Stop Firewalld Server
      systemd:
        name: firewalld
        state: stopped

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值