#!/bin/bashbash
#By Kaile QQ:10206334ssh
#Blog http://kaile.blog.51cto.comide
RPCSTART=`/etc/init.d/rpcbind star學習
#rsync軟件是否安裝測試
[ $(rpm -qa | grep rsync| wc -l) -eq 1 ] || yum -y install rsyncui
#rsync配置文件blog
[ -f /etc/rsyncd.conf ] || touch /etc/rsyncd.conf 進程
#rsync配置文件內容rpc
echo "#rsyncd.conf start##it
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[backup]
path = /backup
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password" >/etc/rsyncd.conf
#判斷rsync 虛擬用戶是否存在
[ `grep "rsync" /etc/passwd |wc -l` -eq 1 ] || useradd -s /sbin/nologin -M rsync
#判斷共享目錄是否存在
[ -d /backup ] || mkdir -p /backup && chown rsync.rsync /backup
#判斷虛擬認證用戶密碼文件是否存在
[ -f /etc/rsync.password ] || echo "rsync_backup:123456" >/etc/rsync.password && chmod 600 /etc/rsync.password
#啓動rsync 守護進程服務
[ `netstat -lnutp | grep 873 |awk -F "[: ]+" '{print $5}'| sed -n '1p'` -eq 873 ] || rsync --daemon >/dev/null 2>&1
#加入到開機自啓動文件中
[ `ps -ef |grep rsync|grep -v grep | wc -l` -eq 1 ] || rsync --daemon
#rsync服務端配置完畢
[ `rpm -qa | grep sshpass |wc -l` -eq 1 ] || yum -y install sshpass
#rsync服務端進行測試
#此腳本只是模板,提供學習