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

Posted on in Categories Backup, Networking, Windows, Windows server last updated March 30, 2006

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.

How do I stop a Linux kernel module from loading automatically?

Posted on in Categories Debian Linux, Gentoo Linux, Howto, Linux, RedHat/Fedora Linux last updated March 30, 2006

A module (device driver) is causing Linux server to hang, so we replace Ethernet card with Intel LAN card. The old module still gets loaded. It is causing problem. So I decided to turn off module forever (I am not going to recompile kernel to get rid of this shity module).

The Linux kernel v2.6.xx queries /etc/modules.conf file to load modules for hardware device (old 2.4.xx version uses /etc/modprobe.conf file). If you are using Debian Linux look for /etc/modutils/aliases file.

Just locate name of module and turn it off using following syntax (or add/append line):
alias modulename off

Example
Open file /etc/modules.conf or /etc/modprobe.conf (RHEL 4/5) file:
# vi /etc/modules.conf
Now turn off 8139too module:
alias 8139too off
Read man page of update-modules.modutils/update-modules for more information. I am not sure what to do on Sun Solaris box if such situation popups. If anyone has more info/idea about Sun Solaris UNIX, please add in comments!

How does query caching in MySQL works and how to find find out my MySQL query cache is working or not?

Posted on in Categories News last updated March 29, 2006

Few days back I wrote about how to improve performance with query caching in MySQL. Someone email me about more questions.

How does query caching in MySQL helps improve performance of dynamic web site?
First query cache is new and added in MySQL v4.x.x version only so if you are using old version of MySQL server it will not work.

When MySQL server recives a request it will parse it and retrives data from database/table and sent back to client browser. If same query request (in case of dynamic content) comes repeatedly and server will just sent them result from cache (thus saving disk I/O and other associated cost with each query).

Please note that when data stored in table is modified, any related cached entries in the query cache are flushed.

How do I find out my MySQL query cache is working or not…
Very simple, MySQL provides the stats of same just type following command at mysql> prompt:

mysql> show status like ‘Qcache%’;

Output:

+-------------------------+----------+
| Variable_name           | Value    |
+-------------------------+----------+
| Qcache_free_blocks      | 1        |
| Qcache_free_memory      | 16766912 |
| Qcache_hits             | 3        |
| Qcache_inserts          | 1        |
| Qcache_lowmem_prunes    | 0        |
| Qcache_not_cached       | 6        |
| Qcache_queries_in_cache | 1        |
| Qcache_total_blocks     | 4        |
+-------------------------+----------+

For more information see the MySQL Query Cache documentation.

How do I sync data between two Load balanced Linux / UNIX servers?

Posted on in Categories Backup, FreeBSD, Linux, RedHat/Fedora Linux, Solaris, Tips, UNIX last updated March 29, 2006

Load balancing is way to provide to handle the load of the large number of visitors particular website or network service receives. It helps provide redundancy to your website. There are several ways to accomplish load balancing:
* Use of Linux Virtual Server
* Use of layer 4 routers
* Round robin DNS with squid cache
* Proprietary clustering solution from vendor such as Microsoft or HP/IBM, Cisco, Nortel etc

However, one frequently asked question is how to keep your webpages (HTML/PHP/PERL scripts) synchronized with each server. For example if you create a new web page called viewnews.php on one www2 server, how does new page get copied over to the second server www1?

You can use rsync – a network file distribution/synchronization utility on Unixish (Linux, FreeBSD, Solaris etc) systems. It does not simply send new files; it updates all files by sending only changed files. This saves time.

Install the rsync

Debian Linux user type the following command:# apt-get install rsyncFedora Linux user, user type the following command:# yum install rsyncRed Hat Linux user, user type the following command:# up2date rsyncFreeBSD user, user type the following command:# pkg_add -r -v rsyncALTERNATIVELY, use FreeBSD ports collection:# cd /usr/ports/net/rsync
# make; make install; make clean

How do I use rsync command?

You do not need to run rsync as a service or daemon. For example, if you would like to sync’d between www1 and www2 servers, type the following command on www1 server:rsync -avrR --links --rsh=/usr/bin/ssh 202.54.1.11:/var/html/ /var/htmlWhere,

  • -avrR : archive mode (a), verbose (v), recurse into directories (r), use relative path names (R)
  • –links : copy symlinks as symlinks
  • –rsh=/usr/bin/ssh : Use to specify the remote shell ssh to use (secure copy).
  • 202.54.1.11:/var/html/ : WWW2 server IP address and path to synchronize to www1 server
  • /var/html : WWW1 server path

A sample shell script for same job

#!/bin/bash
MASTER="master-server-ip"
DIR="/var/www/change-me"
LDIR="/local/dir"
SSH="/usr/bin/ssh"
rsync -avrR --links --rsh=$SSH $MASTER:$DIR $LDIR

See also:

  • If you are going to use rsync command from cron job/shell script, generate ssh keys for password less login over ssh.
  • See official rsync site for more complex examples.

How can I enable or setup log message in the iptables firewall?

Posted on in Categories News last updated March 28, 2006

Linux firewall, iptables has the capability to log network activity to the syslog system. This is very useful to detect problems as well as to generate reports of network activity. You can also use this to detect all intrusion detection or unwanted incoming/outgoing connections etc.

LOG module
To enable logging option you need to use LOG iptables/kernel module. It turn on kernel logging of matching packets. When this option is set for a rule, the Linux kernel will print some information on all matching packets (like most IP header fields) via the kernel log.

For example, drop all connection coming from hacker/cracker IP address 202.54.10.202 and log them to syslog:

iptables -A INPUT -s 202.54.10.202 -m limit –limit 5/m –limit-burst 7 -j LOG –log-prefix ‘** FW-DROP-HACKER **’

iptables -A INPUT -s 202.54.10.202 -j DROP

Firewall rules are checked in a sequential manner So first you logged message with first rule and second rule drops the connection.

Where,

  • -m limit –limit 5/m: This will prevent excessive log data to /var/log/message file from being granted. The limit specified is 5/minute (it is maximum average matching rate). And a burst rate of 7 is specified (it is maximum initial number of packets to match).
  • –log-prefix ‘** FW-DROP-HACKER **’: This is nothing but log prefix to dropped rule. Useful to search using grep command:

# grep ‘** FW-DROP-HACKER **’ /var/log/message

LOG module supports other options, read man page of iptables for more information.

How To Monitor Linux / BSD System Over Time Without Scrolling Output Using watch Command

Posted on in Categories Linux, UNIX last updated June 25, 2017

YYou can use the watch command to execute a program or shell script periodically, display its output on screen repeatedly. That allows you to look at the program output change over time. By default, the program runs every 2 seconds. Aforementioned is useful to monitor memory utilization, RAID rebuilds progress or disk space usage over time without having to look at scrolling output.

Retrieve php's configure options from the shell prompt

Posted on in Categories News last updated March 27, 2006

As a system administrator you need to admin not just Apache web server but other stuff like PHP. PHP has some cool command line options. These options are very useful for system administrators. I am sure it will save time while debugging php config problems:

Display PHP version:

$ php -v

Retrieve php’s configure options from the shell prompt:

$ php -i
$ php –i | less

Display list of compiled in modules

$ php –m

Read man page of php for more options.