rsync备份服务配置流程

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rsync备份服务配置流程相关的知识,希望对你有一定的参考价值。

目录

1 rsync服务配置流程... 2

1.1 系统优化... 2

1.2 查看操作系统信息及rsync服务... 2

1.3 编辑rsync服务/etc/rsyncd.conf配置文件... 2

2 rsync服务搭建细节... 3

2.1 创建rsync用户,御用rsynd进程的登录... 3

2.2 创建备份目录并修改权限... 3

2.3 编辑rsync服务的密码文件并修改文件权限... 3

3检查服务配置结果... 3

3.1 开启并检查rsync服务... 3

3.2 写入开机自启动... 4

3.3 客户端rsync配置... 4

4 rsync实战测试... 4

4.1 标准rsync命令使用... 4

4.2 把服务启动写入开机启动... 5

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

第1章 rsync服务配置流程

1.1 系统优化

1.2 查看操作系统信息及rsync服务

[[email protected] /]# cat /etc/redhat-release

CentOS release 6.7 (Final)

[[email protected] /]# uname -r

2.6.32-573.el6.x86_64

[[email protected] /]# uname -m

x86_64

[[email protected] /]# rpm -qa rsync

rsync-3.0.6-12.el6.x86_64

1.3 编辑rsync服务/etc/rsyncd.conf配置文件

[[email protected] /]# vim /etc/rsyncd.conf        (下边的注释不能写在行的后面,会导致配置文件失效,错误)

#rsync_config______start

#created by crazy frog

##rsyncd.cong start##

uid=rsync                        ##virtual users uid

gid=rsync                        ##virtual users gid

use chroot=no                     ##safe system config

max connections=200               ##max  link users

timeout=300                      ##delay time

pid file=/var/run/rsyncd.pid          ##process file for rsync

lock file=/var/run/rsyncd.lock        ##lock file for file the same

log file=/var/log/rsyncd.log          ##rsync  log file

hosts allow=172.16.1.0/24          

[backup]                        ##modules  must##

path=/backup                    ##directory

ignore errors                     ##no check errors

read only=false

list=false

auth users=rsync_backup

secrets file=/etc/rsync.password ##virtual userspassword

##rsyncd.conf end##

"/etc/rsyncd.conf" [New] 21L, 854Cwritten           

第2章 rsync服务搭建细节

2.1 创建rsync用户,御用rsynd进程的登录     

[[email protected] /]# useradd -s /sbin/nologin -M rsync 远程命令使用该用户访问备份目录

[r[email protected] /]# tail -1 /etc/passwd

rsync:x:500:500::/home/rsync:/sbin/nologin

2.2 创建备份目录并修改权限

[[email protected] /]# mkdir /backup

[[email protected] /]# ls -ld /backup

drwxr-xr-x 2 root root 4096 Sep  8 08:20 /backup

[[email protected] /]# chown -R rsync.rsync /backup

[[email protected] /]# ls -ld /backup

drwxr-xr-x 2 rsync rsync 4096 Sep  8 08:20 /backup

2.3 编辑rsync服务的密码文件并修改文件权限

[[email protected] /]# vim  /etc/rsync.password

rsync_backup=oldboy

"/etc/rsync.password" [New] 1L, 20Cwritten                                          

[[email protected] /]# ls -ld /etc/rsync.password

-rw-r--r-- 1 root root 20 Sep  8 08:29 /etc/rsync.password

[[email protected] /]# chmod 600 /etc/rsync.password

[[email protected] /]# ls -ld /etc/rsync.password

-rw------- 1 root root 20 Sep  8 08:29 /etc/rsync.password

[[email protected] /]# cat /etc/rsync.password

rsync_backup=oldboy

第3章 检查服务配置结果

3.1 开启并检查rsync服务  

[[email protected] /]# rsync --daemon

[[email protected] /]# ps -ef|grep rsync|grep -v grep

root    10262     1  0 07:59 ?       00:00:00 rsync --daemon

[[email protected] /]# ps -ef|grep rsync

root    10262     1  0 07:59 ?        00:00:00 rsync –daemon    进程是在root

root    [[email protected]/]# lsof -i :873

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

rsync  10262 root    3u IPv4 125661      0t0  TCP *:rsync (LISTEN)

rsync  10262 root    5u  IPv6 125662      0t0 TCP *:rsync (LISTEN)

[[email protected] /]# netstat -lntup|grep 873

tcp       0      0 0.0.0.0:873                 0.0.0.0:*                   LISTEN      10262/rsync        

tcp       0      0 :::873                      :::*                        LISTEN      10262/rsync 10302  9542  008:01 pts/0    00:00:00 grep rsync  

3.2 写入开机自启动

[[email protected] /]# echo “/usr/bin /nc --daemon">>/etc/rc.local

[[email protected] /]# tail -1 /etc/rc.local

rsync --daemon

3.3 客户端rsync配置

[[email protected] /]# mkdir /backup

[[email protected] /]# vim /etc/rsync.password

oldboy

"/etc/rsync.password" [New] 2L, 8Cwritten                                           

[[email protected] /]# cat /etc/rsync.password

oldboy

[[email protected] /]# chmod /etc//rsync.password

chmod: missing operand after`/etc//rsync.password‘

Try `chmod --help‘ for more information.

[[email protected] /]# chmod 600  /etc/rsync.password

[[email protected] /]# ls -ld  /etc/rsync.password

-rw-------. 1 root root 8 Sep  8 08:58 /etc/rsync.password

 

第4章 rsync实战测试

4.1 标准rsync命令使用

[[email protected] /]# rsync -avz /backup/  [email protected]::backup--password-file=/etc/rsync.password

sending incremental file list

./

oldboy.txt

sent 80 bytes received 30 bytes  73.33 bytes/sec

total size is 0 speedup is 0.00

[[email protected] backup]# ls -ld /backup

drwxr-xr-x 4 rsync rsync 4096 Sep  9 00:50 /backup

[[email protected] backup]# ls -ld /backup/oldboy

drwxr-xr-x 2 root root 4096 Sep  9 00:50 /backup/oldboy

[[email protected] backup]# chown -R rsync.rsync/backup/oldboy

[[email protected] backup]# ls -ld /backup/oldboy

drwxr-xr-x 2 rsync rsync 4096 Sep  9 00:50 /backup/oldboy

[[email protected] backup]# rsync -avz /backup/[email protected]::backup/oldboy --password-file=/etc/rsync.password   推送(这种方法比较简洁)

sending incremental file list

./

a

g

test1

{c..g]

.ICE-unix/

sent 131000 bytes received 186 bytes  37481.71bytes/sec

total size is 134217728  speedup is 1023.11

[[email protected] backup]# rsync -avz [email protected]::backup/oldboy /backup/    --password-file=/etc/rsync.password   客户端拉取

4.2 把服务启动写入开机启动

[[email protected] oldboy]# echo "/usr/bin/rsync--daemon" >>/etc/rc.local

[[email protected] oldboy]# tail /etc/rc.local

#!/bin/sh

#

# This script will be executed *after* all theother init scripts.

# You can put your own initialization stuff inhere if you don‘t

# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

>/etc/udev/rules.d/70-persistent-net.rules

/usr/bin/rsync –daemon

查看日志:

[[email protected] oldboy]# tail /var/log/rsyncd.log

2016/09/09 00:49:34 [2143] receiving file list

2016/09/09 00:49:34 [2143] ./

2016/09/09 00:49:34 [2143] sent 213 bytes  received 457 bytes  total size 134217728

2016/09/09 00:51:58 [2169] params.c:Parameter() -Ignoring badly formed line in configuration file: ignore errors


本文出自 “11566241” 博客,请务必保留此出处http://crazyfrog.blog.51cto.com/11566241/1851019

以上是关于rsync备份服务配置流程的主要内容,如果未能解决你的问题,请参考以下文章

centos 7配置rsync源服务器

Rsync备份服务

rsync备份服务

如何配置Rsync备份服务器

Centos 配置rsync远程同步及使用inotify+rsync实时备份

RSYNC备份服务