ramlife

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

同步

使用 rsync 来进行同步,linux 系统中 rsync 速度快于 rclone。 rclone 只是多提供了云服务商。

服务端安装 rsync

sudo yum install -y rsync

服务端配置

vim /etc/rsyncd.conf

# global config
port=9999
uid = xyz
gid = xyz
use chroot = no
max connections = 200
timeout = 300
motd file = /var/rsyncd/rsync.motd
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# module
[hugo]
path = /home/ptz/www/public/
ignore errors
read only = false
write only = false
list = false
auth users = rsync_backup
secrets file = /etc/rsyncd.passwd

配置虚拟用户只用于传输验证

echo "rsync_backup:123456" >> /etc/rsyncd.passwd
chmod 600 /etc/rsyncd.passwd 

启动

systemctl start rsyncd
systemctl list-unit-files |grep rsync

如果发现服务没有启动,那么

systemctl enable rsyncd.service
systemctl enable rsyncd.socket
systemctl restart rsyncd.service
systemctl restart rsyncd.socket

systemctl list-unit-files |grep rsync
systemctl |grep rsync
sudo netstat -tulpn | grep rsync

端口相关

关闭端口先测试一下列表,是否可用,记得把配置中的 list 改为 true,然后关闭用户验证,才能有列表。

systemctl stop firewalld
firewall-cmd --list-all
sudo firewall-cmd --zone=public --add-port=9264/tcp --permanent
firewall-cmd --reload
systemctl restart firewalld.service

下面两种写法都可以,并且也可以用域名。

rsync --list-only rsync://xxx.xxx.xxx.xxx:9999/hugo/
rsync --list-only --port 9999 xxx.xxx.xxx.xxx::hugo/

测试用户验证

rsync --list-only rsync://rsync_backup@xxx.xxx.xxx.xxx:9999/hugo/ --password-file=/home/xxx/rsync_passwd

如果类似上面的这个命令可以打印列表,说明用户验证是正常的。

同步

rsync -avzP /home/xxx/hugo/quickstart/public/ rsync://xxx@xxx.xxx.xxx.xxx:9999/hugo/ --password-file=/home/xxx/rsync_passwd

错误1

客户端进行推送的时候,提示这个错误:

rsync: failed to connect to ramlife.me (104.234.11.235): Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(128) [sender=3.1.3]

这个就是网络问题了,你懂的。

错误2

客户端进行推送的时候,提示这个错误:

rsync: did not see server greeting
rsync error: error starting client-server protocol (code 5) at main.c(1682) [sender=3.1.3]

在服务器端,使用 sudo netstat -tulpn | grep rsync 来检查对应的端口 rsyncd 是否在监听。 结果发现没有在监听,那么直接重启即可。 systemctl restart rsyncd

参考:

第2章 rsync(一):基本命令和用法
https://www.cnblogs.com/f-ck-need-u/p/7220009.html

hugo博客部署到腾讯云轻量级服务器
https://www.sulvblog.cn/posts/blog/hugo_deploy/

posted on 2023-01-18 18:12  ramlife  阅读(64)  评论(0编辑  收藏  举报