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/* [email protected]:/opt/ &>/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 [email protected]::backup/" &&\
echo "推送成功" &&\
ssh 172.16.1.31 "tar -xf /opt/application.tar.gz -C /opt/" >/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 "/opt/application/bin/sersync2 -d -o /opt/application/conf/confxml.xml" >/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.7 "yum install nfs-utils rpcbind -y >/dev/null 2>&1" &&\
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 共享完成"
fuck! want to forget you
猜你喜欢
转载自www.cnblogs.com/jiangyatao/p/10760349.html
今日推荐
周排行