How To Format Disk in linux

In the previous post we discussed how to re-size disk space,
Now lest say you want to add additional disk to your machine.

Follow the commands: 

step 1 -  Partition
# fdisk -l | grep Disk
Disk /dev/sda: 549.7 GB, 549755813888 bytes
Disk /dev/sdb: 107.3 GB, 107374182400 bytes 

you'll see the disks on your machine, we want to partition the new disk /dev/sdb

# fdisk /dev/sdb
n - add new partition - follow the instruction
p - print the partition table - check the partition
w - write table to disk and exit

step 2 - Format

mkfs.ext3 /dev/sdb1

step 3 - Mount
# mkdir /New-Disk
# mount /dev/sdb1 /New-Disk

step 4 - Update /etc/fstab
# vi /etc/fstab
add the next line to the file:
/dev/sdb1     /New-Disk     ext3     defaults     1 2
Save and close the file.

Now check the changes:
# df -h

How To display Timestamp in History command

By default, the history command shows just the command number and the command.
it could be very useful to add a timestamp to be shown, this can help you to monitor things by the time you run something.

To add the timestamp you need to export the next command:
#  export HISTTIMEFORMAT='%F %T '

if you want, you can add this line to your profile, so next you boot your machine, it will run automatic:
just edit /etc/profile  and add the line above.

Best Regards

How to resize ext3 partition - GPartEd

Hi, couple of days ago was asked to increase ext3 partition without LVM.
After searching the web I found a cool Linux Live CD called GPatrEd.
because it has just one partition  " /dav/sda1 on / "  i could not unmount it the resize it with the new space.
I was had to used a live CD.
I'm talking about virtual machine, so first I increased the disk space of the virtual machine
then I restart and boot from GPartEd live CD.
The UI is very simple and fun actually, 
all you need to do is to resize the partition with the mouse the click APPLY.

After finishing, I restart the machine again and WALLA I had new partition space on my server.


How To install Load Balancer with HAProxy on Debian

Hi, today I want to discuss on how to install a LB for web servers base on http (linux or windows) on debian.

First we need to add the source of the installation to sources.list
# vi /etc/apt/sources.list

and add the following lines:
deb etch main
deb-src etch main

deb lenny main

deb etch/updates main contrib
deb-src etch/updates main contrib

Next we need to update the sources and install the HAproxy

# apt-get update
# apt-get install haproxy

First we backup the original configuration
# cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.orig
# cat /dav/null > /etc/haproxy/haproxy.cfg

and new we create a new configuration for our Round Robin LB.
edit the haproxy.cfg file and add the following lines:
# vi /etc/haproxy/haproxy.cfg
        log   local0
        log   local1 notice
        maxconn 4096
        user haproxy
        group haproxy

        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        maxconn 2000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

listen webfarm LB-IPAddress:80
       mode http
       stats enable
       stats auth someuser:somepassword
       balance roundrobin
       cookie JSESSIONID prefix
       option httpclose
       option forwardfor
       server webA serverA-IP:80 cookie A check
       server webB serverB-IP:80 cookie B check

make sure you change the RED lines to your settings.
and now we need to ENABLE the haproxy in /etc/default/haproxy
# vi /etc/default/haproxy
and set ENABLE=1

to start haproxy just run:
# /etc/init.d/haproxy start

that's it you have a Load Balancer Installed and work.

HAproxy Statistics:
In this configuration we enable the statistics of haproxy, you can acsses from you browser by enter http://LB-IPAddress/haproxy?stats

The user and the password is like you type in the configuration in "stats auth someuser:somepassword"

Enjoy and please comment !!!


How To install Apache MySQL and PHP

The easy way to install a web server with apache MySQL and PHP is by a project called XAMPP
XAMPP is a project of apache friends how let you the easy way to install Apache distribution containing MySQL, PHP and Perl.

I was trying to create a new WordPress blog on one of my servers. and I found this project very helpful.
All you have to do is to download a tar file from from XAMPP website untar him and thats it.
I will show you how it goes:

Download the last version of XAMPP from here -
Run the command:
tar xvfz xampp-linux-1.7.3a.tar.gz -C /opt

That's all. XAMPP is now installed below the /opt/lampp directory.
All you need to do to start the XAMPP is:
# /opt/lampp/lampp start

You should now see something like this on your screen:Starting XAMPP 1.7.3a...
LAMPP: Starting Apache...
LAMPP: Starting MySQL...
LAMPP started.

Go to your server via you browser ~ http://localhost

for more information and tricks go to the main project website -

Apache Compile Wallpaper

A new Wallpaper I found
Discover Simple, Private Sharing at

How To make SSH Tunnel

In this post I'll discuss no how to make ssh tunnel
this how to will show you the basic, and I hope you will take the good from it to your needs.

the main configuration is:
edit /etc/ssh/ssh_config with your favorite editor
# vi /etc/ssh/ssh_config
and add flowing lines in the end

Host test
HostName localhost
User your_user_name
LocalForward 2022 SERVER1_IP:22
LocalForward 2080 SERVER2_IP:80
LocalForwars 2025 SERVER3_IP:25

save the file.
and run: # ssh test
now if you'll try to access to localhost on port 2080 you'll go to SERVER2 on port 80, you can test it from your browser - http://localhost:2080/ or try to ssh to locahost with port 2022
# ssh -p 2080 localhost

and you'll see you go to SERVER1.

You can run the ssh tunnel from one command line instead of edit the ssh_config.
# ssh -N -f User_Name@SERVER2_IP -L 2080/localhost/80
this script tell the server to forward all the traffic to port 2080 to SERVER2 on port 80

Or if you want to make REVERSE tunnel you can run the same command but with -R instead of -L
# ssh -N -f User_Name@SERVER2_IP -R 2022/localhost/22
(with this script you can access from the remote machine (SERVER2) via ssh to your machine with port 2022)
run # ssh -p 2022 localhost from SERVER2

I'm hoping this post will help you to understand the basic of ssh tunneling
Please comment

Ram Usage Per Application

Hi all,
I found a cool script that show you very nicely how many ram memory every application on your server used:

444.0 KiB +   0.0 KiB = 444.0 KiB       atd
536.0 KiB +   0.0 KiB = 536.0 KiB       portmap
620.0 KiB +   0.0 KiB = 620.0 KiB       ping
640.0 KiB +   0.0 KiB = 640.0 KiB       acpid
748.0 KiB +   0.0 KiB = 748.0 KiB       init
764.0 KiB +   0.0 KiB = 764.0 KiB       rpc.statd
788.0 KiB +   0.0 KiB = 788.0 KiB       dhcdbd
904.0 KiB +   0.0 KiB = 904.0 KiB       check_ping
956.0 KiB +   0.0 KiB = 956.0 KiB       xinetd
960.0 KiB +   0.0 KiB = 960.0 KiB       hald-addon-acpi
  1.0 MiB +   0.0 KiB =   1.0 MiB       cron
  1.0 MiB +   0.0 KiB =   1.0 MiB       dbus-daemon
  1.1 MiB +   0.0 KiB =   1.1 MiB       system-tools-ba
  1.1 MiB +   0.0 KiB =   1.1 MiB       hald-addon-inpu
  1.1 MiB +   0.0 KiB =   1.1 MiB       hald-runner
  1.2 MiB +   0.0 KiB =   1.2 MiB       kerneloops
  1.2 MiB +   0.0 KiB =   1.2 MiB       NetworkManagerD
  2.0 MiB +   0.0 KiB =   2.0 MiB       rsyslogd
  2.0 MiB +   0.0 KiB =   2.0 MiB       avahi-daemon (2)
  2.1 MiB +   0.0 KiB =   2.1 MiB       NetworkManager
  2.2 MiB +   0.0 KiB =   2.2 MiB       pickup
  2.2 MiB +   0.0 KiB =   2.2 MiB       master
  2.2 MiB +   0.0 KiB =   2.2 MiB       nagios (2)
  2.3 MiB +   0.0 KiB =   2.3 MiB       hald-addon-stor (2)
  2.3 MiB +   0.0 KiB =   2.3 MiB       cupsd
  2.3 MiB +   0.0 KiB =   2.3 MiB       udevd
  2.4 MiB +   0.0 KiB =   2.4 MiB       qmgr
  3.0 MiB +   0.0 KiB =   3.0 MiB       screen (2)
  3.0 MiB +   0.0 KiB =   3.0 MiB       hald
  3.4 MiB +   0.0 KiB =   3.4 MiB       getty (6)
  4.2 MiB +   0.0 KiB =   4.2 MiB       sshd (2)
  4.6 MiB +   0.0 KiB =   4.6 MiB       gdm (2)
  5.3 MiB +   0.0 KiB =   5.3 MiB       snmpd
  6.2 MiB +   0.0 KiB =   6.2 MiB       Xorg
  7.0 MiB +   0.0 KiB =   7.0 MiB       munin-node
  9.0 MiB +   0.0 KiB =   9.0 MiB
 17.6 MiB +   0.0 KiB =  17.6 MiB       bash (5)
 25.6 MiB +   0.0 KiB =  25.6 MiB       gdmgreeter
120.5 MiB +   0.0 KiB = 120.5 MiB       apache2 (11)

 Private  +  Shared  =  RAM used        Program

download the script from HERE -
to run the script to need to type:
# python ./

Enjoy (-:

Please leave a comment if you like this post.

HowTo Install NRPE on Debian-Host

Later in my last post - How To Install Nagios
I want to show you how to install NRPE plugin on your Debian-Hosts to monitoring from Nagios.

Install NRPE-Daemon and Nagios-Plugins on Debian-Linux Host.

1. Make sure you have a C compiler installed
# apt-get install make gcc g++

2. Install SSL for secure communication between Nagios-Server and Debian-Host
# apt-get install libssl-dev

3. Install SNMP (in case you like to query some SNMP via NRPE)
# apt-get install snmpd
# apt-get install snmp scli tkmib

4. Create Nagios user
# useradd -p nagios nagios

5. Install Nagios-Plugins
# cd /usr/src
# wget
# tar -xzvf nagios-plugins-1.4.13.tar.gz
# cd nagios-plugins-1.4.13
# ./configure
# make
# make install

6. Fix permission for the Nagios director
# chown -R nagios:nagios /usr/local/nagios/

7. Install Xinetd
# apt-get install xinetd

8. Install and configure NRPE
# cd /usr/src
# wget
# tar -xzvf nrpe-2.12.tar.gz
# cd nrpe-2.12
# ./configure
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
# make install-xinetd

Edit /etc/xinetd.d/nrpe
# vi /etc/xinetd.d/nrpe
and add to only_from= your Nagios server IP
only_from =

Add the following entry for the NRPE daemon to the /etc/services file.
# echo "nrpe 5666/tcp #NRPE" >> /etc/services

Restart the NRPE service
# /etc/init.d/xinetd restart

Test if NRPE is listening:
# netstat -l | grep nrpe

The output out this command should show something like this:
tcp 0 0 *:nrpe *:* LISTEN

Next, check to make sure the NRPE daemon is functioning properly. To do this, run the check_nrpe plugin that was installed for testing purposes.
# /usr/local/nagios/libexec/check_nrpe -H localhost

If everything is fine you will see this output:
NRPE v2.12

9. Test the NRPE from the Nagios-Server
Now we want to test if we can query some information from the Debian-Host via NRPE from the Nagios-Server.
So switch into /usr/local/nagios/libexec on your Nagios Server and check if you have the check_nrpe plugin.
# ls - l check_ nrpe

In case you dont have the check_nrpe plugin you need to download and compile NRPE. (See Step 8)
run the next command:
# ./check_nrpe -H HostIPAddress -c check_users

You should get something like this back:
USERS OK - 1 users currently logged in |users=1;5;10;0

Great! Your Nagios server is able to communicate with the Debian-Host.

How To Install Nagios on Ubuntu

Nagios is a powerful monitoring system that enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes.

Download, install and Configure Apache
first we have to install some necessary compliers and Apache to run Nagios.
run the next commands:
# sudo apt-get install build-essential
# sudo apt-get install libgd2-xpm-dev
# sudo apt-get install apache2
# sudo apt-get install php5-common php5 libapache2-mod-php5

Configure Apache to use PHP:

Run in a terminal:
# sudo vi /etc/apache2/apache2.conf
Paste the following into the file:
DirectoryIndex index.html index.php index.cgi

and restart the server with the command
# sudo /etc/init.d/apache2 restart

Download, install, and configure Nagios
Create a user to run the service and a group to run external commands:

# sudo useradd -m nagios
# sudo passwd nagios
# sudo groupadd nagcmd
# sudo usermod -a -G nagcmd nagios
# sudo usermod -a -G nagcmd www-data

Download the current version of Nagios and Nagios Plugins from -

Extract the Nagios tar:
# sudo tar -zxvf nagios-3.1.2.tar.gz
and change to the nagios-3.1.2 directory
# cd  nagios-3.1.2
Now install the Nagios use the flowing commands :
# sudo ./configure --with-command-group=nagcmd
# sudo make all
# sudo make install
# sudo make install-init
# sudo make install-config
# sudo make install-commandmode
# sudo make install-webconf

Add a user for the Nagios interface:
# sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Extract and compile the Nagios-plugins:
# tar -zxvf nagios-plugins-1.4.14.tar.gz
# cd nagios-plugins-1.4.14
# sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# sudo make
# sudo make install

Create a link to start the service:
# sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Verify the config:
# sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Start Nagios:
# sudo /etc/init.d/nagios start

You should now be able to log into the Nagios web interface (http://localhost/nagios) using the nagiosadmin user and password.

How To, MySQL to CSV - Script

I wanted to share a new script that I was writing,
This script knows how to take SQL queries, convert them to csv files and send them by eMail.

the script is divided to 2 files:
the first one contain all the sql queries, and the second do all the amazing job.

The fist file called SQL.reports can be download from HERE, contain the sql queries, the syntax must be like the example:
ReportName your_report_name
sql your query

ReportName your_second_report_name
sql select * from tableA where [...]

The script file called can be download from HERE,
the only things you need to do for this to work is to fill the next parameters in the script:
DBname="your DB name"
DBuser="your DB user name"
DBpass="your DB password"
Mail_to='list of mail with space between them'
please do not touch the rest of the script.

After you have been download those 2 file, placed them in the same directory on your server lets say /opt/reports
and make sure you give them a permission
# chmod +x /opt/reports/*

now all left to do is to run the script
# /opt/reports/
and check you mailBox.
you can also add the script to corntab to run in your own scheduling

And please comment (-;

How To sort and find duplicate records

I'm was asked to sort a password file, to show all duplicate users and their UIDs.
For Example if you have a file like this:
UID    UserName   Password
----   --------   ----------
1236   john       oe93kf9034j
936    max        fkl03kf032j
9381   keren      fg38uf6124t
8988   john       fj3589gjf01
9834   roma       fgj390jf203
8915   max        gf23j09g305
341    john       mf9244t24t4
9841   david      f02jflp3053
43745  david      23hkfg03g35
4956   ron        04fk054f2e4
69595  max        kvf9035g022
7765   john       mg30gk30gkw

I want to show all the duplicate users and all their UIDs like this:
john - 1236 8988 341 7765
max - 936 8915 69595
david - 9841 43745

To find all duplicate users we'll use the next script:
$ cut -f2 yourFile | sort | uniq -d
it'll display:

Now we want to know all the UIDs of those users
create a new file with vi
$ vi
and copy the folloing lines:
dup=`cut -f2 yourFile | sort | uniq -d`

for a in $dup
        echo $a - `cat yourFlie | grep $a | cut -f1`

It will search for each user all UIDs he has and display them like the example on the top.

$ sort yourFlie | uniq -u # only the unique, non-repeated lines
$ sort yourFile | uniq -d # repeated lines
$ sort yourFile | uniq -c # all lines + count repeated lines


linux/kernel/panic.c Wallpaper

A New Wallpaper I found    
  Discover Simple, Private Sharing at 

How To change user name and UID

I was asked to change the ID of the mysql user and gourp on one of my servers.
this is a very simple to do.

first type
# id mysql
uid=101(mysql) gid=103(mysql) groups=103(mysql) 
to change the user id type:
# usermod -u 25 mysql
to change the group id run the next command under root user:
# vigr
search the mysql group mysql:x:103: the change it to 25 mysql:x:25:
(save with /wq like regular vi)
# groupmod -g 25 mysql
now run again:
# id mysql
uid=25(mysql) gid=25(mysql) groups=25(mysql)

to change user name run:
# usermod -l old_name new_name
to change home directory run:
# usermod -d /home/user_name user_name
to change group name run:
# groupmod -n old_name new_name

How to configure MySQL Cluster with Heartbeat

In this post we'll discuss how to set up a MySQL cluster with two serves, storage and Heartbeat.
I'm using CentOS 5 distribution on both machines, MySQL 5.1 and a mounted directory on both servers to /var/lib/mysql

You need to install MySQL on both machines.
Assign hostname dbserver01, dbserver02.
dbserver01 is the primary node with IP address to eth0.
and dbserver02 is the slave one with ip address is the virtual IP that will be used for MySQL.

Configuration (do those steps on both servers)
install the Heartbeat package:
# yum install heartbeat

copy the next configuration files to the /etc/ha.d directory:
# cp /usr/share/doc/heartbeat-version/authkeys /etc/ha.d
# cp /usr/share/doc/heartbeat-version/ /etc/ha.d
# cp /usr/share/doc/heartbeat-version/haresources /etc/ha.d

First we will edit the authkeys file,
# vi /etc/ha.d/authkeys
copy from here:
auth 2
2 sha1 test-HA
change the permission of the authkeys file:
# chmod 600 /etc/ha.d/authkeys

Now let's edit the most important file (
# vi /etc/ha.d/ha/cf
add the following lines into the file:
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
initdead 120
bcast eth0
udpport 694
auto_failback on
node dbserver01
node dbserver02 

The last file we need to edit is haresources:
# vi /etc/ha.d/haresources
add the following line:
dbserver01 netfs mysqld 

Now all we need to do is to start the hearbeat service on both machines:
# /etc/init.d/heartbeat start
the virtual IP address is now on dbserver01 and MySQL is up and running.
if dbserver01 will crashed from any reason the IP address will jump to dbserver02 the the MySQL service will start automatic.

And please comment (-;

How to mirror a folder among 2 servers

Hi, in this post I'll show you how to mirror ,synchronize a folder from serverA to serverB with rsync for a backup purpose or what ever you want and need.

First we have to install rsync on both machines for RedHat/Fedora/CentOS you would use:
# yum install rsync
for Debian systems:
# apt-get install rsync
or if you work with SuSE use: yast

Now we need to create a user that will be used by rsync on both servers:
# useradd -d /home/syncuser -m -s /bin/bash syncuser
and give this user a password:
# passwd syncuser

The next step is to make sure that serverA can log into serverB without password so we could create a crontab script which do the synchronization automatic without human interaction.
for this step please go read my post - how to ssh without password

After we test we can ssh from serverA to serverB without password, we can test the rsync,
make sure you have a folder on serverB that you want to backup all your data to and run the next command on serverA:
# rsync -raz --progress --size-only --delete /DirOnServerA/* syncuser@serverB:/DirOnServerB

Now go the serverB and check if you data are there.

All you left to do is to to add the rsync script to crontab and you can sleep well at night.