rsync服务器搭建
时间:2015-10-06 08:46 来源:linux.it.net.cn 作者:IT
目录[-]
-
一 什么是rsync
-
二 搭建rsync服务器
-
1.rsync的安装
-
a. 源码编译安装
-
b. 软件包安装
-
2.rsync的配置
-
3.启动脚本
-
4.测试连接
rsync在进行文件备份时是如此的方便,以至于我觉得必须在自己的服务器上安装它。这里对rsync的服务器进行了简单粗暴的搭建和配置(直接上代码),对于细节不做深入讨论,但是可以肯定是,服务器一定能run起来,对于新手这才是最重要的,不是吗?
一 什么是rsync
rsync,remote synchronize顾名思意就知道它是一款实现远程同步功能的软件,它在同步文件的同时,可以保持原来文件的权限、时间、软硬链接等附加信息。 rsync是用 “rsync 算法”提供了一个客户机和远程文件服务器的文件同步的快速方法,而且可以通过ssh方式来传输文件,这样其保密性也非常好,另外它还是免费的软件。
rsync 包括如下的一些特性:
1. 能更新整个目录和树和文件系统;
2. 有选择性的保持符号链链、硬链接、文件属于、权限、设备以及时间等;
3. 对于安装来说,无任何特殊权限要求;
4. 对于多个文件来说,内部流水线减少文件等待的延时;
5. 能用rsh、ssh 或直接端口做为传输入端口;
6. 支持匿名rsync 同步文件,是理想的镜像工具;
二 搭建rsync服务器
1.rsync的安装
a. 源码编译安装
下载地址:https://rsync.samba.org/
1
2
3
4
5
6
7
[root@yearnfar install]# tar xvf rsync-3.1.1.tar.gz
[root@yearnfar install]# cd rsync-3.1.1
[root@yearnfar rsync-3.1.1]# ./configure --prefix=/usr/local
[root@yearnfar rsync-3.1.1]# make && make install
[root@yearnfar rsync-3.1.1]# cd /usr/local/bin
[root@yearnfar bin]# ll|grep rsync
-rwxr-xr-x. 1 root root 1368856 9月 21 12:01 rsync
b. 软件包安装
1
2
3
4
5
sudo apt-get install rsync ##注:在debian、ubuntu 等在线安装方法;
yum install rsync ##注:Fedora、Redhat 等在线安装方法;
rpm -ivh rsync ##注:Fedora、Redhat 等rpm包安装方法;
##其它Linux发行版,请用相应的软件包管理方法来安装。
2.rsync的配置
rsync的主要有以下三个配置文件rsyncd.conf(主配置文件)、rsyncd.secrets(密码文件)、rsyncd.motd(rysnc服务器信息)
服务器配置文件(/etc/rsyncd.conf),该文件默认不存在,请创建它。
具体步骤如下:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@yearnfar local]# cd /etc/
[root@yearnfar etc]# mkdir rsync.d
[root@yearnfar etc]# cd rsync.d/
[root@yearnfar rsync.d]# touch rsyncd.conf
[root@yearnfar rsync.d]# touch rsyncd.secrets
[root@yearnfar rsync.d]# touch rsyncd.motd
[root@yearnfar rsync.d]# chmod 600 rsyncd.secrets ##将rsyncd.secrets这个密码文件的文件属性设为root拥有, 且权限要设为600
[root@yearnfar rsync.d]# ll
总用量 0
-rw-r--r--. 1 root root 0 9月 21 12:14 rsyncd.conf
-rw-r--r--. 1 root root 0 9月 21 12:14 rsyncd.motd
-rw-------. 1 root root 0 9月 21 12:14 rsyncd.secrets
以下是rsyncd.conf的配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Distributed under the terms of the GNU General Public License v2
# 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 = 115.28.34.xxx #修改为自己的ip
uid = root
gid = root
use chroot = yes
read only = yes
#limit access to private LANs
hosts allow=*
hosts deny=*
max connections = 5
motd file = /etc/rsync.d/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
[mysql_backup]
path = /data/mysql_backup
list=yes
ignore errors
auth users = yearnfar
secrets file = /etc/rsync.d/rsyncd.secrets
comment = backup mysql
exclude = git/
以下是rsyncd.secrets的配置
1
yearnfar:123456
以下是rsyncd.motd的配置
1
2
3
4
++++++++++++++++++++++++++++++++++++++++++++++
Welcome to use the mike.org.cn rsync services!
centos6.3 yearnfar
++++++++++++++++++++++++++++++++++++++++++++++
3.启动脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
[root@yearnfar rsync.d]# vi /etc/init.d/rsync
#!/bin/bash
#
# rsyncd This shell script takes care of starting and stopping
# standalone rsync.
#
# chkconfig: - 99 50
# description: rsync is a file transport daemon
# processname: rsync
# config: /etc/rsync.d/rsyncd.conf
# Source function library
. /etc/rc.d/init.d/functions
RETVAL=0
rsync="/usr/local/bin/rsync"
prog="rsync"
CFILE="/etc/rsync.d/rsyncd.conf"
start() {
# Start daemons.
[ -x $rsync ] || \
{ echo "FATAL: No such programme";exit 4; }
[ -f $CFILE ] || \
{ echo "FATAL: config file does not exist";exit 6; }
echo -n $"Starting $prog: "
daemon $rsync --daemon --config=$CFILE
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
echo
return $RETVAL
}
stop() {
# Stop daemons.
echo -n $"Stopping $prog: "
killproc $prog -QUIT
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
return $RETVAL
}
# call the function we defined
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 2
esac
exit $RETVAL
[root@yearnfar rsync.d]# chmod +x /etc/init.d/rsync
[root@yearnfar rsync.d]# /etc/init.d/rsync start
正在启动 rsync: [确定]
[root@yearnfar rsync.d]# chkconfig --add /etc/init.d/rsync ## 添加到开机启动
[root@yearnfar rsync.d]# chkconfig --level 235 rsync on ## 添加到开机启动
4.测试连接
1
2
3
4
5
6
7
8
[root@yearnfar rsync.d]# rsync --list-only yearnfar@115.28.34.xxx::mysql_backup
++++++++++++++++++++++++++++++++++++++++++++++
Welcome to use the mike.org.cn rsync services!
centos6.3 yearnfar
++++++++++++++++++++++++++++++++++++++++++++++
Password:
drwxr-xr-x 4096 2015/09/20 15:24:06 .
drwxr-xr-x 4096 2015/09/21 04:00:01 201509
(责任编辑:IT)
目录[-]
rsync在进行文件备份时是如此的方便,以至于我觉得必须在自己的服务器上安装它。这里对rsync的服务器进行了简单粗暴的搭建和配置(直接上代码),对于细节不做深入讨论,但是可以肯定是,服务器一定能run起来,对于新手这才是最重要的,不是吗? 一 什么是rsyncrsync,remote synchronize顾名思意就知道它是一款实现远程同步功能的软件,它在同步文件的同时,可以保持原来文件的权限、时间、软硬链接等附加信息。 rsync是用 “rsync 算法”提供了一个客户机和远程文件服务器的文件同步的快速方法,而且可以通过ssh方式来传输文件,这样其保密性也非常好,另外它还是免费的软件。 rsync 包括如下的一些特性: 1. 能更新整个目录和树和文件系统; 2. 有选择性的保持符号链链、硬链接、文件属于、权限、设备以及时间等; 3. 对于安装来说,无任何特殊权限要求; 4. 对于多个文件来说,内部流水线减少文件等待的延时; 5. 能用rsh、ssh 或直接端口做为传输入端口; 6. 支持匿名rsync 同步文件,是理想的镜像工具; 二 搭建rsync服务器1.rsync的安装a. 源码编译安装下载地址:https://rsync.samba.org/
b. 软件包安装
2.rsync的配置rsync的主要有以下三个配置文件rsyncd.conf(主配置文件)、rsyncd.secrets(密码文件)、rsyncd.motd(rysnc服务器信息) 服务器配置文件(/etc/rsyncd.conf),该文件默认不存在,请创建它。 具体步骤如下:
?
以下是rsyncd.conf的配置
以下是rsyncd.secrets的配置
以下是rsyncd.motd的配置
3.启动脚本
4.测试连接
(责任编辑:IT) |