一、服务器端rsync的安装和配置
服务器上的rsync安装
在此已本地虚拟机192.168.1.113为服务器做例子,客户端192.168.1.114作为备份同步的客户端。
直接yum安装:
yum install rsync
rsync的主要有以下三个配置文件rsyncd.conf(主配置文件)、rsyncd.secrets(密码文件)、rsyncd.motd(rysnc服务器信息)
服务器配置文件,该文件默认不存在,请创建它.现在我在/etc目录下创建rsync.d目录,再创建
rsyncd.conf、rsyncd.secrets、rsyncd.motd
具体步骤如下:
[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的配置
# 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的配置
tjj:123456
ps:tjj是登陆用户,后面是密码
以下是rsyncd.motd的配置
+++++++++++++++++++++++++++++++++++++++++++++
Welcome to use the mike.org.cn
rsync
services!
centos6.3 tjj
++++++++++++++++++++++++++++++++++++++++++++++
3.编写启动脚本
[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.测试链接
++++++++++++++++++++++++++++++++++++++++++++++
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
|
二、在客户机(192.168.1.114)上同步服务器
也要装上rsync,直接yum install rsync即可
编写密码文件
vi /home/psw/rsync.secrets
chmod 600 /home/psw/rsync.secrets(必须赋予600权限)
编写链接备份的脚本sh
vi /home/shell/rsync.sh
chmod+x /home/shell/rsync.sh
./home/shell/rsync.sh
ps:sync -avzP --delete --password-file=密码文件 tjj@119.146.203.245::mysql_backup 备份目录
4.同步成功