标签:fresh 监控目录 play exp tip content com http folder
外网IP | 内网IP | 主机名 |
---|---|---|
10.0.0.5 | 172.16.1.5 | lb01 (负载均衡) |
10.0.0.6 | 172.16.1.6 | lb02 |
10.0.0.7 | 172.16.1.7 | web01(服务器) |
10.0.0.8 | 172.16.1.8 | web02 |
10.0.0.9 | 172.16.1.9 | web03 |
10.0.0.31 | 172.16.1.31 | nfs (共享存储) |
10.0.0.41 | 172.16.1.41 | backup |
10.0.0.51 | 172.16.1.51 | db01 (数据库) |
10.0.0.52 | 172.16.1.52 | db02 |
10.0.0.53 | 172.16.1.53 | db03(代理机) |
10.0.0.54 | 172.16.1.54 | db04(代理机) |
10.0.0.61 | 172.16.1.61 | m01 (跳板机) |
10.0.0.71 | 172.16.1.71 | zabbix |
1.安装ansible
2.优化ansible
3.推送公钥
4.开启防火墙
5.开启80 443 873 nfs等端口和服务白名单
6.关闭selinux
7.创建同一的用户
1.安装sersync
2.拷贝sersync配置文件
3.配置rsync密码文件
4.启动sersync
1.创建密钥对
[root@m01 ~]# ssh-keygen
2.推送公钥
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.5
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.6
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.7
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.8
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.9
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.31
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.41
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.51
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.52
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.53
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.54
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.61
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.71
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.81
1.下载
[root@m01 ~]# yum install -y ansible
2.优化
[root@m01 ~]# vim /etc/ansible/ansible.cfg #改为
host_key_checking = False
[root@m01 ~]# vim /root/ansible/hosts
#[]标签名任意,但是最好不要用特殊符号(- | &)和大写字母,中文(不能是nginx)
#端口是22的时候可以省略
[web_group]
172.16.1.7 ansible_ssh_port=22 asible_ssh_user=root ansible_ssh_pass=‘1‘
172.16.1.8 ansible_ssh_port=22 asible_ssh_user=root ansible_ssh_pass=‘1‘
172.16.1.9 ansible_ssh_port=22 asible_ssh_user=root ansible_ssh_pass=‘1‘
[db_group]
172.16.1.51 ansible_ssh_port=22 asible_ssh_user=root ansible_ssh_pass=‘1‘
172.16.1.52 ansible_ssh_port=22 asible_ssh_user=root ansible_ssh_pass=‘1‘
172.16.1.53 ansible_ssh_port=22 asible_ssh_user=root ansible_ssh_pass=‘1‘
172.16.1.54 ansible_ssh_port=22 asible_ssh_user=root ansible_ssh_pass=‘1‘
[nfs_group]
172.16.1.31 ansible_ssh_port=22 asible_ssh_user=root ansible_ssh_pass=‘1‘
[redis_group]
172.16.1.81 ansible_ssh_port=22 asible_ssh_user=root ansible_ssh_pass=‘1‘
[lb_group]
172.16.1.5 ansible_ssh_port=22 asible_ssh_user=root ansible_ssh_pass=‘1‘
172.16.1.6 ansible_ssh_port=22 asible_ssh_user=root ansible_ssh_pass=‘1‘
[backup_group]
172.16.1.41 ansible_ssh_port=22 asible_ssh_user=root ansible_ssh_pass=‘1‘
[zabbix_group]
172.16.1.71 ansible_ssh_port=22 asible_ssh_user=root ansible_ssh_pass=‘1‘
[m01_group]
172.16.1.61 ansible_ssh_port=22 asible_ssh_user=root ansible_ssh_pass=‘1‘
[mtj_group]
172.16.1.202 ansible_ssh_port=22 asible_ssh_user=root ansible_ssh_pass=‘1‘
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="false"/>
<fileSystem xfs="false"/>
<filter start="false">
<exclude expression="(.*)\.svn"></exclude>
<exclude expression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
<exclude expression="^static/*"></exclude>
</filter>
<inotify>
<!-- inotify监控的事件,true为监控,false为不监控 -->
<delete start="true"/>
<createFolder start="true"/>
<createFile start="true"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="true"/>
<modify start="true"/>
</inotify>
<sersync>
<!-- 监控的目录和rsync服务器的IP地址,rsync的模块名称 -->
<localpath watch="{{ watch_dir }}">
<remote ip="{{ sersync_push }}" name="{{ user_dir_mk }}"/>
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<!--rsync推送的选项-->
<commonParams params="-az"/>
<!--是否开启认证,认证模块的用户名,用于认证的本地密码配置文件-->
<auth start="true" users="{{ user_dir_mk }}" passwordfile="/etc/rsync.passwd"/>
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
<crontab start="false" schedule="600"><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.php"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>
<plugin start="false" name="command"/>
</sersync>
<plugin name="command">
<param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix-->
<filter start="false">
<include expression="(.*)\.php"/>
<include expression="(.*)\.sh"/>
</filter>
</plugin>
<plugin name="socket">
<localpath watch="/opt/tongbu">
<deshost ip="192.168.138.20" port="8009"/>
</localpath>
</plugin>
<plugin name="refreshCDN">
<localpath watch="/data0/htdocs/cms.xoyo.com/site/">
<cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
<sendurl base="http://pic.xoyo.com/cms"/>
<regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
</localpath>
</plugin>
</head>
1.安装sersync
[root@m01 sersync]# vim tasks/install.yml
- name: check nfs-utils inotify-tools
shell: "rpm -q nfs-utils && rpm -q inotify-tools"
ignore_errors: yes
register: check_nfs_inotify
- name: install nfs inotify
yum:
name: "{{ item }}"
state: present
when: check_nfs_inotify.rc != 0
loop:
- "nfs-utils"
- "inotify-tools"
- name: get sersync packages
get_url:
url: "http://test.driverzeng.com/other/sersync2.5.4_64bit_binary_stable_final.tar.gz"
dest: "/tmp"
- name: jieya sersync packages
unarchive:
src: "/tmp/sersync2.5.4_64bit_binary_stable_final.tar.gz"
dest: /usr/local
copy: no
2.创建监控目录
[root@m01 sersync]# vim tasks/dir.yml
- name: create watch_data
file:
path: /{{ watch_data }}
state: directory
recurse: yes
3.创建密码文件
[root@m01 sersync]# vim tasks/pass.yml
- name: backup server pass
copy:
content: "{{ rsync_pass }}"
dest: /etc/rsync.passwd
owner: root
group: root
mode: 0600
4.拷贝配置文件
[root@m01 sersync]# vim tasks/config.yml
- name: copy sersync.conf
template:
src: sersync.j2
dest: /usr/local/GNU-Linux-x86/confxml.xml
backup: yes
5.启动
[root@m01 sersync]# vim tasks/start.yml
- name: start sersync
shell: /usr/local/GNU-Linux-x86/sersync2 -rdo /usr/local/GNU-Linux-x86/confxml.xml
6.include
[root@m01 sersync]# vim tasks/main.yml
- include: install.yml
- include: dir.yml
- include: config.yml
- include: pass.yml
- include: start.yml
[root@m01 roles]# vim site.yml
- hosts: all
roles:
#- { role: base }
#- { role: rsync_client,when: ansible_fqdn is match ‘web*‘ }
#- { role: rsync_client,when: ansible_fqdn is match ‘nfs*‘ }
#- { role: rsync_server,when: ansible_fqdn is match ‘backup*‘ }
#- { role: nfs_server,when: ansible_fqdn is match ‘nfs*‘ }
#- { role: nfs_client,when: ansible_fqdn is match ‘web*‘ }
#- { role: mount_server,when: ansible_fqdn is match ‘nfs*‘ }
#- { role: mount_client,when: ansible_fqdn is match ‘web*‘ }
- { role: sersync,when: ansible_fqdn is match ‘nfs*‘ }
[root@m01 roles]# ansible-playbook site.yml
标签:fresh 监控目录 play exp tip content com http folder
原文地址:https://www.cnblogs.com/syy1757528181/p/13166158.html