首页 > 代码库 > 一键部署rsync服务

一键部署rsync服务

#!/bin/bash

#By Kaile QQ:10206334

#Blog http://kaile.blog.51cto.com


RPCSTART=`/etc/init.d/rpcbind star

#rsync软件是否安装

[ $(rpm -qa | grep rsync| wc -l) -eq 1 ]  || yum -y install rsync


#rsync配置文件

[ -f /etc/rsyncd.conf  ] || touch /etc/rsyncd.conf 


#rsync配置文件内容

echo "#rsyncd.conf start##

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服务端进行测试


#此脚本只是模板,提供学习

本文出自 “啊凯” 博客,请务必保留此出处http://kaile.blog.51cto.com/12459560/1926401

一键部署rsync服务