Pages

Bài đăng phổ biến

Wednesday, November 30, 2011

How do I sync data between two Load balanced Windows 2003 servers?


For UNIX/Linux server you can use rsync command to keep data sync'd between two servers. rsync also works under Windows NT/2003 server but it will take lots of time to setup.
For Microsoft Windows 2003 server use robocopy tool, to sync files between two windows server. You can download robocopy.exe and other files from Windows 2003 Resource Kit Tools set.
Once tool is downloaded, install the Resource Kit. By default robocopy located at c:\Program Files\Windows Resource Kits\Tools\robocopy.exe. Now let us assume that you want to sync d:\Inetpub\wwwroot\ directory between two Windows server. First create hidden share on www2 (secondary server)
  1. Login to www2
  2. Select d:\Inetpub\wwwroot\
  3. Right click > Properties > Sharing tab > Share this folder > Add $ at the end of share name and save the changes.

How do I use robocopy command?

=> Login to primary server (www1)
=> Click on stat > run > type cmd
=> At command prompt type command:
c:>"c:\program files\windows resource kits\tools\robocopy.exe d:\inetpub\wwwroot www2\\inetpub\wwwroot\"ALTERNATIVELY, use IP address of www2 server :
c:>"c:\program files\windows resource kits\tools\robocopy.exe d:\inetpub\wwwroot 202.54.10.200\\inetpub\wwwroot\"robocopy has many more options and lots of other information available in Robocopy.DOC file.
(cyberciti)

How to sync data between 2 servers automatically


Have you ever wanted to know how to easily synchronize the data between multiple servers automatically?

In this article I’ll explain how to setup 2 Linux servers to automatically synchronize data between a specific directory on each server. To do this we will use rsync, ssh key authentication, and a cron job.
Let’s call the 2 servers ‘SOURCESERVER’ and ‘DESTSERVER’ for
SOURCESERVER = Source server (the server we’re connecting from to upload the data)
DESTSERVER = Destination server (the server we’re connecting to receive the data)

Part 1 - Setting up SSH key authentication

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
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

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.
The public key file (usually [homedir]/.ssh/id_rsa.pub) we will upload to the DESTSERVER.
The private key file (usually [homedir]/.ssh/id_rsa) we will keep on the SOURCESERVER.
*Be sure to keep this private key safe. With it anyone will be able to connect to the DESTSERVER that contains the public key.
Now we will plant the public key we created on to the DESTSERVER.
Choose the user account which you will use to connect to on DESTSERVER, we’ll call this user ‘destuser’ for now.
In that account’s home directory, create a ‘.ssh’ subdirectory, and in that directory create a new text file called ‘authorized_keys’. If it already exists, great, use the existing file.
Open the ‘authorized_keys’ file and paste in the contents of the public key you created in the previous step (id_rsa.pub). It should look something like the following
ssh-rsa <lots and lots of characters…> 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.
From the SOURCESERVER try logging in as normal using ssh to the DESTSERVER.
# 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.

Part 2 - Creating the rsync script

Now for the rsync script.
I use a simple script such as the following
——————————————-
#!/bin/bash
SOURCEPATH=’/source/directory’
DESTPATH=’/destination’
DESTHOST=’123.123.123.123′
DESTUSER=’destuser’
LOGFILE=’rsync.log’
echo $’\n\n’ >> $LOGFILE
rsync -av –rsh=ssh $SOURCEPATH $DESTUSER@$DESTHOST:$DESTPATH 2>&1 >> $LOGFILE
echo “Completed at: `/bin/date`” >> $LOGFILE
——————————————-
Copy this file into the home directory of the sourceuser on the SOURCESERVER
and modify the first 4 variables in the file.
SOURCEPATH (Source path to be synced)
DESTPATH (Destination path to be synced)
DESTHOST (Destination IP address or host name)
DESTUSER (User on the destination server)
Save it as something like ‘rsync.sh’
Set the permissions on the file to 700.
# chmod 700 rsync.sh
Now you should be able to run the script, have it connect to the DESTSERVER, and transfer the files all without your interaction.
The script will send all output to the ‘rsync.log’ file specified in the script.

Part 3 - Setting up the cron job

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.
Enter the following to have the script run once every hour
——————————————-
# Run my rsync script once every hour
0 * * * * /path/to/rsync.sh
——————————————-
Your 2 servers should now be syncing the chosen directory once every hour.
Hope this helped, let me know if you have any questions.

(howtomonster.)

Tuesday, November 29, 2011

Cpanel : A fatal error has occurred DB Error: connect failed


Problem happen when password of database in file config difference with current password  of database horde.

Resolution: Change current password to same password in file config of horde.

/usr/local/cpanel/base/horde/config/conf.php
$conf['sql']['username'] = 'horde';
$conf['sql']['password'] = 'xxxxxxx';


mysql> UPDATE mysql.user SET Password=PASSWORD('YOUR-NEW-MYSQL-PASSWORD') WHERE User='horde';
mysql> FLUSH PRIVILEGES;
mysql> exit
 Nguyễn Sĩ Nhàn