创建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/目录下
监控包:
提取码:a0cq
创建脚本 vim ts.sh添加以下内容。
#/bin/sh
cd /root/.ssh/ &&
rm -f * &&
/bin/ssh-keygen -t rsa -f /root/.ssh/id_rsa -P "" &>/dev/null
yum install -y sshpass >/dev/null 2>&1
for n in 7 8 31 41 61
do
sshpass -p123456 ssh-copy-id -i ~/.ssh/id_rsa.pub 172.16.1.$n -o StrictHostKeyChecking=no &>/dev/null
if [ $? -eq 0 ]
then
echo "172.16.1.$n Distribute successfully "
else
echo "172.16.1.$n Distribute no successfully "
fi
done &&
scp -P 22 -rp /server/tools/* root@172.16.1.31:/server/tools/ &>/dev/null &&
ssh 172.16.1.41 "cp /etc/rsyncd.conf{,.ori}" &&
ssh 172.16.1.41 "cat >/etc/rsyncd.conf<<EOF
#rsync_config_______________start
#created by oldboy
#site: http://www.oldboyedu.com
uid = rsync
gid = rsync
use chroot = no
fake super = yes
max connections = 200
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
auth users = rsync_backup
secrets file = /etc/rsync.password
[backup]
comment = welcome to oldboyedu backup!
path = /backup/
EOF" &&
ssh 172.16.1.41 "useradd rsync" &&
ssh 172.16.1.41 "mkdir -p /backup" &&
ssh 172.16.1.41 "chown -R rsync.rsync /backup/" &&
ssh 172.16.1.41 "systemctl start rsyncd" &&
ssh 172.16.1.41 "systemctl enable rsyncd &>/dev/null" &&
ssh 172.16.1.41 "echo "rsync_backup:oldboy" > /etc/rsync.password" &&
ssh 172.16.1.41 "mkdir -p /server/tools/"
ssh 172.16.1.41 "chmod 600 /etc/rsync.password" &&
ssh 172.16.1.31 "mkdir -p /data" &&
ssh 172.16.1.31 "echo "oldboy" > /etc/rsync.password" &&
ssh 172.16.1.31 "chmod 600 /etc/rsync.password" &&
ssh 172.16.1.31 "echo ' export RSYNC_PASSWORD=oldboy' >>/etc/bashrc" &&
ssh 172.16.1.31 ". /etc/bashrc" &&
ssh 172.16.1.31 "rsync -az /tmp rsync_backup@172.16.1.41::backup/" &&
echo "推送成功" &&
ssh 172.16.1.31 "tar -xf /server/tools/*.gz -C /server/tools/" >/dev/null 2>&1 &&
ssh 172.16.1.31 "mkdir -p /application/logs/" &&
ssh 172.16.1.31 "touch /application/logs/rsync_fail_log.sh" &&
ssh 172.16.1.31 "/server/tools/application/bin/sersync2 -d -o /server/tools/application/conf/confxml.xml >/dev/null" >/dev/null 2>&1
echo "监控完成"
#---==============
ssh 172.16.1.31 "yum install nfs-utils rpcbind -y >/dev/null 2>&1" &&
ssh 172.16.1.31 "rpm -qa nfs-utils rpcbind >/dev/null 2>&1" &&
ssh 172.16.1.31 "systemctl start nfs" &&
ssh 172.16.1.31 "systemctl enable nfs" &&
ssh 172.16.1.31 "mkdir -p /data/" &&
ssh 172.16.1.31 "echo '/data 172.16.1.0/24(rw,sync)' >/etc/exports" &&
ssh 172.16.1.31 "chown -R nfsnobody.nfsnobody /data" &&
ssh 172.16.1.31 "systemctl reload nfs" &&
echo "nfs 共享文件配置完成" &&
#============
ssh 172.16.1.7 "yum install nfs-utils rpcbind -y >/dev/null 2>&1" &&
ssh 172.16.1.8 "yum install nfs-utils rpcbind -y >/dev/null 2>&1" &&
ssh 172.16.1.7 "mount -t nfs 172.16.1.31:/data /mnt" &&
ssh 172.16.1.7 "chmod +x /etc/rc.local " &&
ssh 172.16.1.7 "echo '/usr/bin/mount -t nfs 172.16.1.31:/data /mnt' >>/etc/rc.local " &&
ssh 172.16.1.8 "mount -t nfs 172.16.1.31:/data /mnt" &&
ssh 172.16.1.8 "chmod +x /etc/rc.local " &&
ssh 172.16.1.8 "echo '/usr/bin/mount -t nfs 172.16.1.31:/data /mnt' >>/etc/rc.local " &&
echo "web 共享完成"