背景:
在产品开发中可以使用rsync进行大文件的拷贝,断点续传。
host平台 :Ubuntu 16.04
arm平台 : 3531d
arm-gcc :4.9.4
rsync :3.1.3
主机准备:
使用以下的脚本进行编译:
#
# Copyright By Schips, All Rights Reserved
# https://gitee.com/schips/
#
# File Name: make.sh
# Created : Tue 22 Oct 2019 08:57:53 AM CST
#
#
#!/bin/sh
BASE=`pwd`
BUILD_HOST=arm-linux
OUTPUT_PATH=${BASE}/install/
make_dirs() {
cd ${BASE}
mkdir compressed install source -p
sudo ls
}
tget () { #try wget
filename=`basename $1`
echo "Downloading [${filename}]..."
if [ ! -f ${filename} ];then
wget $1
fi
echo "[OK] Downloaded [${filename}] "
}
download_package () {
cd ${BASE}/compressed
#下载包
tget https://rsync.samba.org/ftp/rsync/rsync-3.1.3.tar.gz
}
tar_package () {
cd ${BASE}/compressed
ls * > /tmp/list.txt
for TAR in `cat /tmp/list.txt`
do
tar -xf $TAR -C ../source
done
rm -rf /tmp/list.txt
}
make_rsync () {
cd ${BASE}/source/rsync*
CC=${BUILD_HOST}-gcc ./configure --prefix=${OUTPUT_PATH}/rsync-3.1.3
--disable-ipv6 --disable-debug --mandir="/tmp/"
--host=${BUILD_HOST} && make && make install
}
make_dirs
download_package
tar_package
make_rsync
exit $?
编辑 配置文件
vi /etc/rsyncd.conf
根据自己的需要进行修改
uid = apache
gid = users
port = 873
use chroot = no
#hosts allow = 192.168.9.3
#hosts deny = 192.168.10.0/24
pid file = /usr/local/rsync/rsyncd.pid
lock file = /usr/local/rsync/rsync.lock
#log file = /usr/local/rsync/logs/rsyncd.log
[apache]
comment=all web
path=/
read only=no
secrets file=/usr/local/rsync/etc/rsyncd.passwd
auth users=apache
上文红色的这一行是作为密码规则文件。我们可以指定用户密码,例如:
apache:apachepass
设置rsync启动脚本:
由于 rsync 的启动参数比较多,我们这里用一个脚本来代替它。
vi /usr/bin/rsync.sh
#!/bin/bash
#this script for start|stop rsync daemon service
#date:2019/10/22
status1=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep')
pidfile="/usr/local/rsync/rsyncd.pid"
start_rsync="rsync --daemon --config=/etc/rsyncd.conf"
function rsyncstart() {
if [ "${status1}X" == "X" ];then
rm -f $pidfile
mkdir -p /usr/local/rsync/
${start_rsync}
status2=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep')
if [ "${status2}X" != "X" ];then
echo "rsync service start.......OK"
fi
else
echo "rsync service is running !"
fi
}
function rsyncstop() {
if [ "${status1}X" != "X" ];then
kill -9 $(cat $pidfile)
status2=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep')
if [ "${statusw2}X" == "X" ];then
echo "rsync service stop.......OK"
fi
else
echo "rsync service is not running !"
fi
}
function rsyncstatus() {
if [ "${status1}X" != "X" ];then
echo "rsync service is running !"
else
echo "rsync service is not running !"
fi
}
function rsyncrestart() {
if [ "${status1}X" == "X" ];then
echo "rsync service is not running..."
rsyncstart
else
rsyncstop
for i in 1 2 3 ;
do
sleep 1
echo -n "."
done
rsyncstart
fi
}
case $1 in
"start")
rsyncstart
;;
"stop")
rsyncstop
;;
"status")
rsyncstatus
;;
"restart")
rsyncrestart
;;
*)
echo
echo "Usage: $0 start|stop|restart|status"
echo
esac
设置rsync开机自启动:
注意红色部分的内容是上文的启动脚本所在的位置
#!/bin/bash
rsync=/usr/bin/rsync.sh
function try_start
{
count_num=`ps -ef|grep 'rsync --daemon'|grep -v grep|wc -l`
echo $count_num
rm -f /usr/local/rsync/rsyncd.pid
if [ $count_num -eq 0 ];then
${rsync} start
fi
}
test -x "$sshd" || exit 0
case "$1" in
start)
echo -n "Starting rsync daemon"
try_start
echo "."
;;
stop)
echo -n "Stopping rsync"
${rsync} stop
echo "."
;;
restart)
echo -n "Stopping rsync"
try_stop
echo "."
echo -n "Waiting for rsync to die off"
for i in 1 2 3 ;
do
sleep 1
echo -n "."
done
echo ""
echo -n "Starting rsync daemon"
${rsync} restart
echo "."
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
拷贝对应的文件到指定的位置即可