| How to sync data between 2 servers automatically |
|
|
|
| Monday, 11 August 2008 22:14 |
|
Have you ever wanted to know how to easily synchronize the data between multiple servers automatically? Let’s call the 2 servers ‘SOURCESERVER’ and ‘DESTSERVER’ for
First, we need to make sure the DESTSERVER has the ability to use key authentication enabled. Find your sshd configuration file (usually ‘/etc/ssh/sshd_config’) and enable the following options if they are not already set. RSAAuthentication yes If you edit the file be sure to restart sshd afterwards. # /etc/init.d/sshd restart Next, on the SOURCESERVER we will create the public / private key pair to be used for authentication with the following command. # ssh-keygen -t rsa *Note: Do not enter a passphrase for this, just hit enter when prompted. This should create 2 files, a public key file and a private key file. Now we will plant the public key we created on to the DESTSERVER. ssh-rsa sourceuser@SOURCESERVER Save the file and change the permissions to 600 for the file and 700 for the ‘.ssh’ directory. Now to test that the keys are working. # ssh destuser@DESTSERVER If all is working you should not be prompted for a password but instead connected directly to a shell on the DESTSERVER. Now for the rsync script. ——————————————- #!/bin/bash SOURCEPATH=’/source/directory’ echo $’\n\n’ >> $LOGFILE ——————————————- Copy this file into the home directory of the sourceuser on the SOURCESERVER Now you should be able to run the script, have it connect to the DESTSERVER, and transfer the files all without your interaction. Assuming everything has worked so far all that’s left is to setup a cron job to run the script automatically at a predefined interval. As the same sourceuser use the ‘crontab’ command to create a new cron job. # crontab -e This will open an editor where you can schedule the job. ——————————————- Your 2 servers should now be syncing the chosen directory once every hour.
also added a LIST variable so it would handle multiple dirs and list in the log dirs and time of completion for LIST in “`cat list.txt`”; echo $’\n\n’ >> $LOGFILE |
Produk Safety
Kacamata Safety (72) Sepatu Safety (Safety Shoes) (216) Sarung Tangan (Hand Gloves) (14) Head & Face Protection (24) Hearing Protection (14) Safety Clothes & Vest (26) Masker & Hood (40) Full Body Harness & Safety Belt (16) Safety Sign (9) Miscellaneous (5) Metal Detector (6) Coveralll Nomex (3)Usefull Site
Contact Us
Another Menu
| Blog |
| Old Shop |
| Javascript |
| PHP |
| Linux |












