LeLe < tonnyom@hotmail.com >
版权声明:可以任意转载,转载时请务必以文字形式标明文章原始出处和作者信息及本声明.
Server IP:172.18.5.251 Hostname: freebsd-1
Client IP:172.18.5.247 Hostname: freebsd-2
apache_1.3.29
rsync-2.5.7
一,Rsync Server
Step 1: 安装
freebsd-1#cd /usr/ports/net/rsyncfreebsd-1#make install clean
Step 3: 配置rsyncd.conf
freebsd-1#vi /usr/local/etc/rsyncd.conf //加入以下内容[www]comment = web server backuppath = /usr/local/www/data-distauth users = tonnyuid = nobodygid = nogroupsecrets file = /usr/local/etc/rsyncd.secretsread only = no
Step 4: 配置rsyncd.secrets
freebsd-1#vi /usr/local/etc/rsyncd.secrets //加入以下内容tonny:123456 // 认证所需的用户名/密码freebsd-1#chmod 600 rsyncd.secrets
Step 5: 配置rc.conf
freebsd-1#vi /etc/rc.conf //加入以下内容rsyncd_enable="YES"
Step 6: 启动 Rsync daemon模式
freebsd-1#vi /usr/local/etc/rc.d/rsyncd.sh //加入以下内容command_args="-4 --daemon" <<<--- 启用ipv4 协议freebsd-1#/usr/local/etc/rc.d/rsyncd.sh start
Step 7: 检查Rsync daemon启动状态
freebsd-1# sockstat | grep rsyncroot rsync 440 3 dgram -> /var/run/logroot rsync 440 4 tcp4 *:873 *:*
二,Rsync Client
Step 1: 安装
freebsd-2#cd /usr/ports/net/rsyncfreebsd-2#make install clean
Step 2: 建立备份目录
freebsd-2#cd /freebsd-2#mkdir -p backup/www
Step 3: 配置rsyncd.secrets
freebsd-2#vi /usr/local/etc/rsyncd.secrets //加入以下内容123456 //Rsync Server上的认证密码,不用输入用户名freebsd-2#chmod 600 rsyncd.secrets
Step 4: 检查备份同步状态
freebsd-2#/usr/local/bin/rsync -avzP --delete--password-file=/usr/local/etc/rsyncd.secrets tonny@172.18.5.251::www/backup/www/
--->>> 将Rsync Server的Web页面,备份或同步到了Rsync Client的/backup/www下
Step 5: Auto Rsync Shell:
freebsd-2#cd /usr/local/etc/rc.d/freebsd-2#chmod a-x rsyncd.shfreebsd-2#vi rsync.sh //加入以下内容#!/bin/sh/usr/local/bin/rsync -avzP --delete--password-file=/usr/local/etc/rsyncd.secrets tonny@172.18.5.251::www/backup/www/freebsd-2#chmod a+x rsync.shfreebsd-2#crontab -e //加入以下内容(每天下午5点半自动备份同步)30 17 * * * /usr/local/etc/rc.d/rsync.sh
三,高级应用(Rsync With SSH)
Rsync Server
freebsd-1#/usr/bin/ssh-keygen -d
Rsync Client
freebsd-2#/usr/bin/ssh-keygen -dfreebsd-2#scp ~/.ssh/id_dsa.pub 172.18.5.251:/root/.ssh/authorized_keysfreebsd-2#ssh-agent csh 或 (ssh-agent bash) --->>> #echo $SHELL查看当前SHELLfreebsd-2#ssh-add id_dsa --->>> 输入 passphasefreebsd-2#/usr/local/bin/rsync -avzP --delete -e ssh172.18.5.251:/usr/local/www/data-dist/ /backup/www/
PS: 参数说明
-a, --archive archive mode, equivalent to -rlptgoD
//档案模式
-v, --verbose
//详细模式
-z, --compress compress file data
//压缩文件
-P equivalent to --partial --progress
//显示进度
--delete
This tells rsync to delete any files on the receiving side
that
aren't on the sending side.
//保持远程机器的文件同步性
-e ssh use SSH connection
//使用SSH连接,保证数据安全
http://rsync.samba.org/ rsync 网站
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/openssh.html
freebsd handbook手册
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10748419/viewspace-944396/ ,如需转载,请注明出处,否则将追究法律责任。