CentOS 6.6 rsync 的服务端和客户端配置
基本信息
系统版本 |
主机名 |
IP地址 |
角色 |
CentOS 6.6 |
backup |
10.0.0.10 |
rsync服务端 |
CentOS 6.6 |
lamp01 |
10.0.0.8 |
rsync客户端 |
CentOS 6.6 |
lnmp02 |
10.0.0.9 |
rsync客户端 |
服务端配置
- 创建rsync配置文件,并写入配置内容(默认rsync文件是不存在的,需要创建)
[[email protected] ~]# touch/etc/rsyncd.conf
[r[email protected] ~]# vim/etc/rsyncd.conf
[[email protected] ~]# cat/etc/rsyncd.conf
#Rsync server
#created by wangning 10:322017-6-8
##rsyncd.conf start##
uid = rsync
gid = rsync
use chroot = no
max connections = 2000
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 10.0.0.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file =/etc/rsync.password
#####################################
[backup]
comment = backup server by wangning 10:39 2017-6-8
path = /backup
2.创建rsync用户和/backup目录,并/backup目录将属主改为rsync用户
[[email protected] ~]# useradd rsync-s /sbin/nologin –M
[[email protected] ~]# mkdir /backup
[[email protected] ~]# chown -R rsync/backup/
3.创建rsync.password文件,设置权限为600,并将用户名和密码写入
[[email protected] ~]# echo"rsync_backup:123456" >>/etc/rsync.password
[[email protected] ~]# chmod 600/etc/rsync.password
4.启动rsync daemon进程,并检查是否启动成功
[[email protected] ~]# rsync –daemon
[[email protected] ~]# ps -ef|greprsync|grep -v grep
root 1942 1 0 04:31 ? 00:00:00 rsync –daemon
[[email protected] ~]# netstat-tulpn|grep rsync
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 1942/rsync
tcp 0 0 :::873 :::* LISTEN 1942/rsync
[[email protected] ~]# ss -tulpn|greprsync ###ss跟netstat差不多
tcp LISTEN 0 5 :::873 :::* users:(("rsync",1942,5))
tcp LISTEN 0 5 *:873 *:* users:(("rsync",1942,3))
5.将rsync的daemon进程加入到开机自启动
[[email protected] ~]# echo"rsync --daemon">>/etc/rc.local
6.如果只需要局域网连接rsync服务端,而不需要互联网连接,那么看可以绑定本机ip即可
[[email protected] ~]# netstat -tulpn|grep rsync
[[email protected] ~]# pkill rsync ###先杀死rsync进程
[[email protected] ~]# ps -ef|grep rsync ###进程是否已杀死
[[email protected] ~]# rsync --daemon --address=10.0.0.10 ###绑定本机IP
客户端配置(推和拉都是在客户端操作)
1.创建密码文件rsync.password,设置权限600,并将密码123456写入此文件
[[email protected] ~]# echo "123456">/etc/rsync.password
[[email protected] ~]# chmod 600 /etc/rsync.password
2.将客户端的/tmp目录下的内容推送到服务端的/backup目录下(这种推送方式比较好)
[[email protected] ~]# rsync -avz /tmp/ [email protected]::backup --password-file=/etc/rsync.password ###::后的backup是模块的名字,与/etc/rsyncd.conf里的[backup]对应
[[email protected] ~]# rsync -avz --delete /tmp/ [email protected]::backup --password-file=/etc/rsync.password ##加--delete表示无差异同步,本地和服务端目录内容保持一致,--delete尽量不要用
[[email protected] ~]# rsync -avz --exclude=1.txt /tmp/ [email protected]::backup --password-file=/etc/rsync.password ##加--exclude表示除了1.txt文件外,其他的文件都要推送。
[[email protected] ~]# rsync -avz --exclude={1,3,5} /tmp/ [email protected]::backup --password-file=/etc/rsync.password ##加--exclude={1,3,5}表示除了1.txt,3.txt,5.txt文件外,其他的文件都要推送。
3.将服务端的/backup目录里的内容拉到客户端的/tmp目录下
[[email protected] ~]# rsync -avz [email protected]::backup --password-file=/etc/rsync.password /tmp/