创建m01、backup、nfs、web01、web02
m01(172.16.1.61)、backup(172.16.1.41)、nfs(172.16.1.31)、web01(172.16.1.7)、web02(172.16.1.8)
下载监控包上传到m01上的/server/tools/目录下
提取码:a0cq1、[root@m01 /server/scripts]# vim back.sh 。
vim /server/scripts/back.sh
yum install -y rsync >/dev/null 2>&1 &&\ cp /etc/rsyncd.conf{,.ori} &&\ cat >/etc/rsyncd.conf</dev/null &&\ echo rsync_backup:oldboy > /etc/rsync.password &&\ mkdir -p /server/tools/ chmod 600 /etc/rsync.password echo "=====ok====="
2、[root@m01 /server/scripts]# 。
vim /server/scripts/nfs.sh
#!/bin/bash mkdir -p /data &&\ echo oldboy > /etc/rsync.password &&\ chmod 600 /etc/rsync.password &&\ echo ' export RSYNC_PASSWORD=oldboy' >>/etc/bashrc &&\ . /etc/bashrc &&\ rsync -az /tmp rsync_backup@172.16.1.41::backup/ &&\ echo 推送成功 &&\ tar -xf /server/tools/*.gz -C /server/tools/ >/dev/null 2>&1 &&\ mkdir -p /application/logs/ &&\ touch /application/logs/rsync_fail_log.sh &&\ /server/tools/application/bin/sersync2 -d -o /server/tools/application/conf/confxml.xml >/dev/null 2>&1 yum install nfs-utils rpcbind -y >/dev/null 2>&1 &&\ rpm -qa nfs-utils rpcbind >/dev/null 2>&1 &&\ systemctl start nfs &&\ systemctl enable nfs &&\ mkdir -p /data/ &&\ echo '/data 172.16.1.0/24(rw,sync)' >/etc/exports echo "======ok======"
3、[root@m01 /server/scripts]# vim。
vim /server/scripts/web.sh
#!/bin/bash yum install nfs-utils rpcbind -y >/dev/null 2>&1 &&\ mount -t nfs 172.16.1.31:/data /mnt &&\ chmod +x /etc/rc.local &&\ echo '/usr/bin/mount -t nfs 172.16.1.31:/data /mnt' >>/etc/rc.local &&\ echo "=========ok============="
4、[root@m01 /server/scripts]# vim。
vim /server/scripts/web.sh
#!/bin/bash yum install nfs-utils rpcbind -y >/dev/null 2>&1 &&\ mount -t nfs 172.16.1.31:/data /mnt &&\ chmod +x /etc/rc.local &&\ echo '/usr/bin/mount -t nfs 172.16.1.31:/data /mnt' >>/etc/rc.local &&\ echo "=========ok============="
4、将02.sh脚本放在m01(172.16.1.61)的/server/scripts/目录下。
vim /server/scripts/02.sh
#!/bin/bash scp -P 22 -rp /server/tools/* root@172.16.1.31:/server/tools/ &>/dev/null &&\ cp /etc/ansible/hosts{,.ori} &&\ cat >/etc/ansible/hosts</dev/null 2>&1 &&\ ansible oldboy1 -m command -a "sh /server/scripts/back.sh" ansible oldboy2 -m copy -a "src=/server/scripts/nfs.sh dest=/server/scripts/" >/dev/null 2>&1 &&\ ansible oldboy2 -m command -a "sh /server/scripts/nfs.sh" ansible oldboy3 -m copy -a "src=/server/scripts/web.sh dest=/server/scripts/" >/dev/null 2>&1 &&\ ansible oldboy3 -m command -a "sh /server/scripts/web.sh"