Wednesday, November 28, 2012

Running Rsync as Daemon on Centos 6.2

Configuring /etc/rsyncd.conf
# mcedit /etc/rsyncd.conf
max connections = 2
motd file = /etc/rsync.motd
log file = /var/log/rsync.log
pid file = /var/run/rsync.pid
lock file = /var/run/rsync.lock
timeout = 300
[Test] comment = "Backup Testing" path = /mnt/share uid = root gid = root list = true use chroot = no read only = no list = yes auth users = root, merkurius, venus, jupiter secrets file = /etc/rsyncd.secrets hosts allow = 192.168.1.0/255.255.255.0
Creating the secrets file on /etc/rsyncd.secrets, and add the usernames and the passwords, one per line, separated by a colon (:)
# mcedit /etc/rsyncd.secrets
root:password merkurius:Password venus:passworD jupiter:PassWord
Finally, change the permission of this file so it can't be read or modified by other users.
# chmod 600 /etc/rsyncd.secrets
Edit /etc/xinetd.d/rsync
# mcedit /etc/xinetd.d/rsync
service rsync { disable = no socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID }
Testing from Localhost
# rsyncd root@localhost::
Test "Backup Testing"
or
#rsync rsync://root@localhost
Test "Backup Testing"
Testing from another computer
# rsync -avzr root@192.168.77.194::Test /tmp/test/
Password:******* receiving incremental file list ./ new.txt sent 76 bytes received 216 bytes 83.43 bytes/sec total size is 71 speedup is 0.24
As another user : merkurius
# rsync -avzr merkurius@192.168.77.194::Test /tmp/test/
Password:***** receiving incremental file list ./ install.log sent 81 bytes received 8707 bytes 2510.86 bytes/sec total size is 35011 speedup is 3.98
Check Result
# ls -al /tmp/test/
total 48 drwxr-xr-x 2 root root 4096 Nov 28 17:08 . drwxrwxrwt. 14 root root 4096 Nov 28 17:01 .. -rw-r--r-- 1 root root 34940 Nov 28 17:08 install.log -rw-r--r-- 1 root root 71 Nov 28 16:57 new.txt
As shown above, all file are belong to root, because we specify uid and gid as root, when rsync run as daemon, we can specify which user and group owns the files that are transfer from and to.

Done

No comments: