These steps are to synchronize a remote directory to a local directory.
1. Install the xinted daemon (local machine)
[root@centos6pg1 syncdir]# yum install xinetd
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
* base: mirror.yongbok.net
* extras: mirror.optus.net
* updates: mirror.yongbok.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package xinetd.x86_64 2:2.3.14-29.el6 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================
Package Arch Version Repository Size
==================================================================================================================
Installing:
xinetd x86_64 2:2.3.14-29.el6 base 120 k
Transaction Summary
==================================================================================================================
Install 1 Package(s)
Upgrade 0 Package(s)
Total download size: 120 k
Installed size: 257 k
Is this ok [y/N]: y
Downloading Packages:
xinetd-2.3.14-29.el6.x86_64.rpm | 120 kB 00:06
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : 2:xinetd-2.3.14-29.el6.x86_64 1/1
Installed:
xinetd.x86_64 2:2.3.14-29.el6
Complete!
-------------------------------------------------------------------------------------------
[root@centos6pg1 syncdir]# vi /etc/xinetd.d/rsync
change disable=no to yes
2. On centospg1 run the following
[root@centos6pg1 syncdir]# rsync -r -a -v -e "ssh -l root" --delete /var/syncdir/ centos6pg2:/var/syncdir/
root@centos6pg2's password:
sending incremental file list
./
gandu
sent 106 bytes received 34 bytes 21.54 bytes/sec
total size is 3487834112 speedup is 24913100.80
3.
This will synchronize the centospg2 directory with your local directory.
This will synchronize the centospg2 directory with your local directory.
There are two problems with this approach
1. You will be asked for a password each time. To solve this establish a trust relation between the two hosts
2. You need to run this each time to get it synchronized. You automation capabilities as in cron
To establish a trust relation:-
[root@centos6pg1 syncdir]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
ed:4e:1f:4c:fc:19:47:49:c7:3d:04:af:43:b0:fc:c5 root@centos6pg1
The key's randomart image is:
+--[ RSA 2048]----+
| .ooo.+|
| .+o.+.|
| .o.+oo|
| . o...Eo|
| S + ooo .|
| + . .. |
| . . |
| |
| |
+-----------------+
[root@centos6pg1 syncdir]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@centos6pg2
root@centos6pg2's password:
Now try logging into the machine, with "ssh 'root@centos6pg2'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
[root@centos6pg1 syncdir]# ssh root@centos6pg2
[root@centos6pg2 ~]# exit
To put this in crontab:-
[root@centos6pg1 syncdir]# crontab -e
*/15 * * * * rsync -r -a -v -e "ssh -l root" --delete /var/syncdir centos6pg2:/var/syncdir/
No comments:
Post a Comment