• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

How to use Rsync- To Sync Two Apache Web Servers

64


Steps to Sync Two Apache Web Servers/Websites Using Rsync

In this article we will explained the various way to Sync Two Apache Web Servers/Websites Using Rsync. The main use of generating a mirror of Web Server with Rsync, suppose if the main web server fails, the backup server will take over it in order to reduce downtime of the website.

Merits of Syncing Web Servers

  • It controls over the ownerships, permissions and special attributes during the data copy remotely.
  • Transfers data by compression and decompression method resulting in lesser bandwidth.
  • Verifies and deletes the files and directories which are deleted from the main web server.
  • It synchronizes the bytes and blocks of changed data.
  • Supports SSH protocol that transfer data in an encrypted manner.

How To Sync Two Apache Web Servers

Main Server used:

IP Address : 192.168.5.189
Hostname : server.linuxhelp1.com

Backup Server used:

IP Address : 192.168.5.190
Hostname : backup.linuxhelp1.com

To Install Rsync Tool

On Debian based systems

#apt-get install rsync

Use the following command to install Rsync on both the servers.

[root@backup ~]# yum install rsync
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.webwerks.com
* extras: centos.webwerks.com
* updates: centos.webwerks.com
Resolving Dependencies
-->  Running transaction check
--->  Package rsync.x86_64 0:3.0.9-15.el7 will be updated
.
.
.
Updated:
rsync.x86_64 0:3.0.9-17.el7

Complete!


To Create a User to run Rsync

Either use rsync with root user or create an unprivileged user on main webserver to Rsync for security reasons

[root@server ~]# useradd linux
[root@server ~]# passwd linux
Changing password for user linux.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.


To Test Rsync Setup

Run the following command to test Rsync on the backup server.

[root@backup ~]# rsync -avzhe ssh linux@192.168.5.189:/var/www /var/www
The authenticity of host ' 192.168.5.189 (192.168.5.189)'  can' t be established.
ECDSA key fingerprint is 03:b1:88:9e:3d:c6:eb:fe:38:6c:3f:90:06:51:4b:c9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ' 192.168.5.189'  (ECDSA) to the list of known hosts.
linux@192.168.5.189' s password:
receiving incremental file list
www/
www/cgi-bin/
www/html/
www/html/index.html

sent 42 bytes received 263 bytes 21.03 bytes/sec
total size is 247 speedup is 0.81


Automate Sync with SSH Passwordless Login

To setup passwordless ssh logins for rsync

To use corn setup for rsync in ssh without login credentials. To do this generate a public and private key by executing the following commands on backups server

[root@backup ~]# ssh-keygen -t rsa -b 2048
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:
c9:a4:59:9e:32:39:f7:14:92:1b:57:99:79:a0:98:c5 root@backup
The key' s randomart image is:
+--[ RSA 2048]----+
| .. o= |
| =Eo+ . |
| O + . |
| O B . |
| B S . |
| = o |
| . |
| |
| |
+-----------------+


Press Enter for Empty passphrase to synchronizing it without using password.

Share the public and private key to the main server so that the sync can be accessed in ssh without password.

[root@backup ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.5.189
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.5.189' s password:

Number of key(s) added: 1

Now try logging into the machine, with: " ssh ' root@192.168.5.189' " 
and check to make sure that only the key(s) you wanted were added.


Open and log in to system using " ssh root@192.168.5.189" ,and verify for the .ssh/authorized_keys.

[root@backup ~]# ssh root@192.168.5.189
Enter passphrase for key ' /root/.ssh/id_rsa' :
Last login: Fri May 6 14:49:28 2016
[root@server ~]#


To Schedule Cron To Automate Sync

Run the following command to open and setup crontab file

[root@backup ~]# crontab &ndash e
5 * * * * rsync -avzhe root@192.168.5.189:/var/www /var/www


Above command opens /etc/crontab file and edit with the default editor.

Tags:
benjamin
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

What is the purpose of need two apache server for same website ?

A

if the main web server fails, the backup server will take over it in order to reduce downtime of the website.

Q

How to generate the mirror of serevr ?

A

Transferring the data by compression with help of using rsync command

Q

How to access the SSH protocol in Ubuntu?

A

Before accessing the SSH protocol, need to install OpenSSH-server package on Ubuntu system

Q

How to set synchronize data updating for both servers?

A

To set cron setup for rsync the data from the main server to the mirror server.

Q

I have already set the cron job for my server. But every time it will ask the credential of SSH user?

A

Need to set automatic sync with SSH passwordless login as shown as a document.

Related Tutorials in How to use Rsync- To Sync Two Apache Web Servers

Related Tutorials in How to use Rsync- To Sync Two Apache Web Servers

rsync Command in Linux with Examples
rsync Command in Linux with Examples
Mar 22, 2016
How to use Rsync- To Sync Two Apache Web Servers
How to use Rsync- To Sync Two Apache Web Servers
May 28, 2016
How to Sync Files/Directories Using Rsync with Non-standard SSH Port
How to Sync Files/Directories Using Rsync with Non-standard SSH Port
Jun 8, 2016

Related Forums in How to use Rsync- To Sync Two Apache Web Servers

Related Forums in How to use Rsync- To Sync Two Apache Web Servers

Rsync
isaac class=
How to fix corrupt packet error for with rsync for (relatively) large files
Nov 19, 2018
Rsync
jacob class=
Rsync: failed to set permissions on..
Oct 22, 2021
CentOS
samson class=
rsync: Failed to exec ssh: No such file or directory (2)
Oct 21, 2017
Ubuntu
mason class=
Backup files with rsync: error 23
Feb 25, 2021
Rsync
nicholas class=
Removing source files after send to destination in Linux
Feb 9, 2017
Rsync
rio class=
How to transfer multiple file in single command
Feb 17, 2017
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Isaiah ?
What is the use of SUID & SGID commands

How to set the special permissions to the files and folders using SUID and SGID commands...

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.