#!/bin/bash
#2019.03.15 wanghaiyang
#yum dajian anzhuang ruanjian
#按道理不能没有网络,没有的话 DHCP脚本
function dhcp(){
yum -y install dhcp &> /dev/null
name="why"
ip1="192.168.200.2"
ip2="192.168.200.100"
ip3="192.168.200.200"
ip4="192.168.200.0"
option domain-name "$name";
option domain-name-servers $ip1; default-lease-time 20000;
max-lease-time 48000;
log-facility local7;
subnet $ip4 netmask 255.255.255.0 {
range $ip2 $ip3;
option routers $ip1;
}
/etc/init.d/dhcp start
chkconfig dhcp --add
}
function benyum(){
umount /dev/sr0 &> /dev/null
[ ! -d /media/cdrom ] && mkdir -p /media/cdrom
mount /dev/sr0 /media/cdrom &> /dev/null
[ $? -ne 0 ] && echo "没插入光盘" && exit 1
[ ! -d /etc/yum.repos.d ] && mkdir -p /etc/yum.repos.d
cd /etc/yum.repos.d
mv -f /etc/yum.repos.d/* /tmp/
cat > /etc/yum.repos.d/yum.repo << KOF
[local]
name=local
baseurl=file:///media/cdrom
gpgcheck=0
enabled=1
KOF
yum -y clean all &> /dev/null
yum makecache &> /dev/null
}
function rsync_dajian(){
#rsync dajian
backup="backup"
mima="/etc/rsync.password"
rsync_backup="rsync_backup"
mimi="123456"
mysql="mysql"
mysql_mima="/etc/rsync_mysql.password"
rsync_mysql="rsync_mysql"
mysql_mimi="123456"
nfs="nfs"
nfs_mima="/etc/rsync_nfs.password"
rsync_nfs="rsync_nfs"
nfs_mimi="123456"
[ -f /var/run/rsyncd.pid ] && rm -rf /var/run/rsyncd.pid
[ -f /var/run/rsyncd.log ] && rm -rf /var/run/rsyncd.log
cat > /etc/rsyncd.conf << ddd
uid = rsync
gid = rsync
use choroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/run/rsyncd.log
[backup]
path = /$backup
ignore errors
read only = false
list = false
hosts allow = 192.168.200.0/24
hosts deny = 0.0.0.0/32
auth users = $rsync_backup
secrets file = $mima
[mysql]
path = /$mysql
ignore errors
read only = false
list = false
hosts allow = 192.168.200.0/24
hosts deny = 0.0.0.0/32
auth users = $rsync_mysql
secrets file = $mysql_mima
[nfs]
path = /$nfs
ignore errors
read only = false
list = false
hosts allow = 192.168.200.0/24
hosts deny = 0.0.0.0/32
auth users = $rsync_nfs
secrets file = $nfs_mima
ddd
iidd="rsync"
id $iidd &> /dev/null
if [ $? -eq 0 ];then
id=`id $iidd |awk -F"[^0-9]+" '{print $2}'`
[ $id -ge 500 ] && userdel -r $iidd &> /dev/null && useradd -M -s /sbin/nologin $iidd
else
useradd -M -s /sbin/nologin $iidd &> /dev/null
fi
#qidong fuwu
pkill -kill rsync
#rm -rf /var/run/rsyncd.pid
rsync --daemon
[ ! -d /$backup ] && mkdir /$backup && chown rsync.rsync /$backup || chown rsync.rsync /$backup &> /dev/null
[ ! -d /$mysql ] && mkdir /$mysql && chown rsync.rsync /$mysql || chown rsync.rsync /$mysql &> /dev/null
[ ! -d /$nfs ] && mkdir /$nfs && chown rsync.rsync /$nfs || chown rsync.rsync /$nfs &> /dev/null
echo "${rsync_backup}:$mimi" > $mima && chmod 600 $mima
echo "${rsync_mysql}:$mysql_mimi" > $mysql_mima && chmod 600 $mysql_mima
echo "${rsync_nfs}:$nfs_mimi" > $nfs_mima && chmod 600 $nfs_mima
sed -i '/rsync --daemon/d' /etc/rc.local
echo "rsync --daemon" >> /etc/rc.local
}
which rsync &> /dev/null && which scp &> /dev/null && which ntpdate &> /dev/null
[ $? -ne 0 ] && yum -y install rsync openssh-clients ntpdate &> /dev/null
[ $? -ne 0 ] && umount /dev/sr0 &> /dev/null && mount /dev/sr0 /media/cdrom &> /dev/null && yum -y install rsync openssh-clients &> /dev/null
[ $? -ne 0 ] && benyum && yum -y install rsync openssh-clients &> /dev/null
ping -c1 aliyun.com &> /dev/null
[ $? -ne 0 ] && echo "没有网" && exit 4 || ntpdate ntp1.aliyun.com &> /dev/null
#rsync搭建
rsync_dajian
rsync 脚本
猜你喜欢
转载自blog.csdn.net/weixin_44439515/article/details/89351379
今日推荐
周排行