Linux下rsync安装与配置

rsync可用于同步文件,一般架设在一台机器上备份文件到另外一台主机上。

rsync服务器端架设

安装rsync

下载解压并install

wget https://download.samba.org/pub/rsync/src/rsync-3.0.6.tar.gz
tar -zxvf rsync-3.0.6.tar.gz
./configure --prefix=/usr/local/rsync
make
make install

配置rsyncd.conf,不存在就手工创建/usr/local/rsync/rsyncd.conf

内容如下:

uid = root
gid = root
use chroot = yes
strict modes = false
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
####
log file = /var/log/rsyncd.log
transfer logging = true
log format= "%o [%a] %m (%u) %f %l %b %c"
##
reverse lookup = no
ignore errors = true
read only = false
hosts allow = 192.168.254.130
hosts deny = 0.0.0.0/0.0.0.0
strict modes = yes
list = false
max connections = 100
timeout = 1800
[www]
path = /data/www/
auth users = root
secrets file = /usr/local/rsync/rsyncd.secrets

这里的hosts allow我设置192.168.254.130,也就是我的客户端机器ip,auth users这里我设置成root(客户端的用户),path为同步文件存放目录。

配置rsyncd.secrets 不存在就手动创建 touch /usr/local/rsync/rsyncd.secrets
内容如下:

root:12345678

格式为用户:密码
注意:此文件权限必须设置:600 命令如下

[root@localhost rsync]# chmod 600 /usr/local/rsync/rsyncd.secrets

配置rsyncd.motd 不存在就手动创建 touch /usr/local/rsync/rsyncd.motd 该步骤可以省略
配置内容:

welcome use rsync service  huangbaokang

启动rsyncd
查看rsyncd进程,命令如下:

ps -aux |grep rsyncd

启动命令如下:

/usr/local/rsync/bin/rsync --daemon --config=/usr/local/rsync/rsyncd.conf

配置rsync开机启动

vi /etc/rc.local
在末尾加上 /usr/local/rsync/bin/rsync --daemon --config=/usr/local/rsync/rsyncd.conf

client端安装配置

安装rsync

yum -y install rsync

客户端建立密码文件
vi /etc/rsyncd.passwd 没有的话就自己创建
将其修改成12345678
注意:1、这里的密码,与服务端设置的密码相同,就是通过这个密码连接服务端的
2、然后切记修改改密码文件的权限(密码文件权限属性要设得只有属主可读)
修改命令如下:

chmod 600 /etc/rsyncd.passwd

同步文件

在客户端执行如下命令进行文件同步:

[root@localhost www]# rsync -RaP huangbaokang.txt [email protected]::www --password-file=/etc/rsyncd.passwd
sending incremental file list
huangbaokang.txt
             13 100%    0.00kB/s    0:00:00 (xfr#1, to-chk=0/1)

以上命令就把huangbaokang.txt发送到了服务器192.168.254.144对应的www目录下了。
这里的::www应该是一个module,我尝试修改www,从报错信息看到的。

在服务器端查看,确实接收到了

[root@localhost www]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.254.144  netmask 255.255.255.0  broadcast 192.168.254.255
        inet6 fe80::c813:ac4c:c09e:e9ad  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:19:88:40  txqueuelen 1000  (Ethernet)
        RX packets 27252  bytes 8605495 (8.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8852  bytes 1524899 (1.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 64  bytes 5568 (5.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 64  bytes 5568 (5.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost www]# pwd
/data/www
[root@localhost www]# ls
huangbaokang.txt

在服务器端/data/www/下新建一个test.txt文件
在客户端中同步服务器中的文件,执行如下命令:

[root@localhost www]# rsync -avz --progress --password-file=/etc/rsyncd.passwd [email protected]::www /data/www
receiving incremental file list
./
test.txt
              4 100%    3.91kB/s    0:00:00 (xfr#1, to-chk=0/2)

sent 75 bytes  received 158 bytes  466.00 bytes/sec
total size is 4  speedup is 0.02

猜你喜欢

转载自blog.csdn.net/huangbaokang/article/details/83748832
今日推荐