rsync服务器部署

#!/bin/bash

u="${1:-"rsync"}"
p="${2:-"123.com@"}"
d="${3:-"/backup"}"
check_system() {
    y_cmd=$1
    u_cmd=$2
    # Check if CentOS or Ubuntu
    if [ -f /etc/redhat-release ]; then
        DISTRO="centos"
    elif [ -f /etc/lsb-release ]; then
        DISTRO="ubuntu"
    else
        echo "Unsupported distribution"
        exit 1
    fi

    # Install packages based on distribution
    if [ "$DISTRO" == "centos" ]; then
        # Using yum
        echo "centos "
        /bin/bash -c "$y_cmd"
    elif [ "$DISTRO" == "ubuntu" ]; then
        # Using apt
        echo "ubuntu "

        /bin/bash -c "$u_cmd"
    fi
}
check_system "yum update && yum -y install rsync" "apt-get update && apt-get -y install rsync"

mkdir $d -p
chown -R $u.$u $d
useradd -s /sbin/nologin -M rsync

echo "$u:$p" >/etc/rsync.secrets
cat /etc/rsync.secrets
chmod 600 /etc/rsync.secrets
ls -l /etc/rsync.secrets
cat >/etc/rsyncd.conf <<EOF
uid = $u					     
gid = $u					    
use chroot = yes					
port 873						   
log file = /var/log/rsyncd.log		
pid file = /var/run/rsyncd.pid			
[server]	
read only = no				       
path = $d				
comment = Document Root of www.test.com
dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.z *.mp4 #同步时不再压缩的文件类型
file = /etc/rsync.secrets
EOF
cat >/etc/systemd/system/rsync.service <<EOF
[Unit]
Description=Rsync Daemon

[Service]
ExecStart=/usr/bin/rsync --daemon
Type=forking

[Install]
WantedBy=multi-user.target

EOF
sudo systemctl restart rsync
sudo systemctl enable rsync
sudo systemctl status rsync
netstat -lntup | grep 873
echo "/usr/bin/rsync --daemon" >>/etc/rc.local
tail -1 /etc/rc.local

echo """
推送
echo "$p" >/tmp/rsync.password
chmod 600 /tmp/rsync.password 
echo "hello" >hello
rsync -avz  hello rsync@127.0.0.1::server  --password-file=/tmp/rsync.password 

拉取
rsync -avz rsync@127.0.0.1::server ./ --password-file=/tmp/rsync.password

自定义端口拉取
rsync -avz --port 1873  rsync@127.0.0.1::server ./ --password-file=/tmp/rsync.password


"""
 
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值