为了实现多个服务器负载均衡,我们需要这几个服务器之间进行数据同步,而rsync软件也能胜任,下面我们来介绍如何架设rsync服务器来达到文件增量备份和数据同步的功能。
什么是rsync
rsync 是一个快速增量文件传输工具,它可以用于在同一主机备份内部的备分,我们还可以把它作为不同主机网络备份工具之用。本文主要讲述的是如何自架rsync服务器,以实现文件传输、备份和镜像。相对tar和wget来说,rsync 也有其自身的优点,比如速度快、安全、高效。
rsync的安装
在CentOS服务器,我们可以执行以下命令安装
yum install rsync
对于debian、ubuntu服务器,则是以下命令
sudo apt-get install rsync
rsync服务器的配置文件rsyncd.conf
下面我们将涉及到三个文件 rsyncd.conf,rsyncd.secrets 和rsyncd.motd。
rsyncd.conf 是rsync服务器主要配置文件。
rsyncd.secrets是登录rsync服务器的密码文件。
rsyncd.motd是定义rysnc 服务器信息的,也就是用户登录信息。
下面我们分别建立这三个文件。
mkdir /etc/rsyncd
注:在/etc目录下创建一个rsyncd的目录,我们用来存放rsyncd.conf 和rsyncd.secrets文件;
touch /etc/rsyncd/rsyncd.conf
注:创建rsyncd.conf ,这是rsync服务器的配置文件;
touch /etc/rsyncd/rsyncd.secrets
注:创建rsyncd.secrets ,这是用户密码文件;
chmod 600 /etc/rsyncd/rsyncd.secrets
注:为了密码的安全性,我们把权限设为600;
touch /etc/rsyncd/rsyncd.motd
注:创建rsyncd.motd文件,这是定义服务器信息的文件。
下一就是我们修改 rsyncd.conf 和rsyncd.secrets 和rsyncd.motd 文件的时候了。
rsyncd.conf文件内容:
复制代码
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help
# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid
port = 873
address = 192.168.1.171
#uid = nobody
#gid = nobody
uid = root
gid = root
use chroot = yes
read only = yes
#limit access to private LANs
hosts allow=192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0
hosts deny=*
max connections = 5
motd file = /etc/rsyncd/rsyncd.motd
#This will give you a separate log file
#log file = /var/log/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
#transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
[linuxsirhome]
path = /home
list=yes
ignore errors
auth users = linuxsir
secrets file = /etc/rsyncd/rsyncd.secrets
comment = linuxsir home
exclude = beinan/ samba/
[beinan]
什么是rsync
rsync 是一个快速增量文件传输工具,它可以用于在同一主机备份内部的备分,我们还可以把它作为不同主机网络备份工具之用。本文主要讲述的是如何自架rsync服务器,以实现文件传输、备份和镜像。相对tar和wget来说,rsync 也有其自身的优点,比如速度快、安全、高效。
rsync的安装
在CentOS服务器,我们可以执行以下命令安装
yum install rsync
对于debian、ubuntu服务器,则是以下命令
sudo apt-get install rsync
rsync服务器的配置文件rsyncd.conf
下面我们将涉及到三个文件 rsyncd.conf,rsyncd.secrets 和rsyncd.motd。
rsyncd.conf 是rsync服务器主要配置文件。
rsyncd.secrets是登录rsync服务器的密码文件。
rsyncd.motd是定义rysnc 服务器信息的,也就是用户登录信息。
下面我们分别建立这三个文件。
mkdir /etc/rsyncd
注:在/etc目录下创建一个rsyncd的目录,我们用来存放rsyncd.conf 和rsyncd.secrets文件;
touch /etc/rsyncd/rsyncd.conf
注:创建rsyncd.conf ,这是rsync服务器的配置文件;
touch /etc/rsyncd/rsyncd.secrets
注:创建rsyncd.secrets ,这是用户密码文件;
chmod 600 /etc/rsyncd/rsyncd.secrets
注:为了密码的安全性,我们把权限设为600;
touch /etc/rsyncd/rsyncd.motd
注:创建rsyncd.motd文件,这是定义服务器信息的文件。
下一就是我们修改 rsyncd.conf 和rsyncd.secrets 和rsyncd.motd 文件的时候了。
rsyncd.conf文件内容:
复制代码
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help
# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid
port = 873
address = 192.168.1.171
#uid = nobody
#gid = nobody
uid = root
gid = root
use chroot = yes
read only = yes
#limit access to private LANs
hosts allow=192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0
hosts deny=*
max connections = 5
motd file = /etc/rsyncd/rsyncd.motd
#This will give you a separate log file
#log file = /var/log/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
#transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
[linuxsirhome]
path = /home
list=yes
ignore errors
auth users = linuxsir
secrets file = /etc/rsyncd/rsyncd.secrets
comment = linuxsir home
exclude = beinan/ samba/
[beinan]










