Howto: change Port OR Network Interface Speed?

November 22, 2009    |   Posted by admin   |    Category: Linux Administration

How to change Port speed OR Network Interface Speed?

To set a specific speed limit on a Network Interface say 10mbps, edit the file network interface file and set the limit which will make the changes permanent even after a reboot.

Edit the file:

root@server [~]# pico /etc/sysconfig/network-scripts/ifcfg-eth0

Add the following line at the end of the file:

ETHTOOL_OPTS=”speed 10 duplex full autoneg off”

Save the file and restart the network service.

root@server [~]# service network restart

This way you can set the duplex or auto negotiation as well. Once done, you can check the network speed using the ethtool command

root@server [~]# ethtool eth0

Script to change IP address of all the accounts.

November 20, 2009    |   Posted by admin   |    Category: cPanel Management

How to change IP address of all the accounts on a cPanel server?

The “Change Site IP Address” option is WHM is not feasible in case you need to change IP address of all the accounts on a server. In order to change IP address of all the domains on a cPanel server, you have to use the “swapip” script provided by cPanel.

The following script will do the needful:

for i in `cat /etc/trueuserdomains | cut -d: -f1`
do
/usr/local/cpanel/bin/swapip OLDIP NEWIP $i;
done;

where,

OLDIP is the current IP assigned to the domain.
NEWIP is the new IP which you would like to assign.
$i is the domain names read per line from the /etc/trueuserdomains file.

Comments Off on Script to change IP address of all the accounts.

How to recompile kernel?

November 20, 2009    |   Posted by admin   |    Category: Linux Administration

How to compile a kernel on a CentOS server?

Compiling a kernel on a CentOS server is probably easy than other Operating Systems but still you should take care while selecting modules else the server won’t boot up on the new kernel. New System admins find it difficult to compile a kernel, however, the following steps should help them a bit.

1) Download the kernel:

cd /usr/local/src/
wget http://www.kernel.org/pub/linux/kern…x.xx.xx.tar.gz

2) Extract the kernel:

tar -zxf linux-2.xx.xx.tar.gz

3) Here you can use previous config during compilation and select the new required modules:

cd linux-*
cp /boot/config-`uname -r` .config

This will copy the current kernel config in the extracted directory of the new kernel.

4) Now configure the kernel using “make menuconfig”. It will present a graphical display with all the available modules.

make menuconfig

Most of them are already selected since you are using the previous config. You need to make sure you select the new modules for example, the ones related to iptables. Each module provides a HELP module which will help you to understand what the module is all about.

5) Compile the kernel:

make

6) Compile the modules:

make modules

7) Install the modules:

make modules_install

8 ) Install the kernel:

make install

This will place the required files of the new kernel under the /boot directory.

Now, the /etc/grub/grub.conf file will have “default=1” where, ‘1’ is the old kernel. You now need to change “default” value to ‘0’ i.e. from

default=1
to
default=0

Save the file and reboot the server. The server will boot up with the new kernel. However, if the kernel is not compiled properly, your server won’t come online and you will have to change the “default” value back to ‘1’ to boot the server using a single usermode and investigate the issue further.

To overcome this issue, you can use the following steps to test the new kernel.  Once you complete the kernel installation using the “make install” command, execute the command:

root@server[#]# grub

At the grub prompt, execute:

savedefault –default=0 –once
quit

You now need to reboot the server to pick up the new kernel just once i.e. even if the server won’t boot up on the new kernel, you just need another reboot and the server will come online on the old kernel. This will save time and will allow you to work immediately on the issue.

Comments Off on How to recompile kernel?

How to turn off Innodb engine?

November 17, 2009    |   Posted by admin   |    Category: Linux Administration

How to turn off Innodb Engine in Mysql?

When Mysql is installed, Innodb Engine is set to ON by default. You can verify whether Innodb is set to On or Off by using ‘mysqladmin variables’. Login to the server as root and execute:

root@host [~]# mysqladmin variables | grep have_innodb
| have_innodb                     | ENABLED

To turn off Innodb, you need to edit the Mysql Configuration file at /etc/my.cnf and add the following line:

skip-innodb

Save the file and restart the mysql service. You now execute the ‘mysqladmin variables’ to check the status of Innodb engine.

Comments Off on How to turn off Innodb engine?

Shell Script for Disk Space Notification

November 13, 2009    |   Posted by admin   |    Category: Scripts

Shell Script for Disk Space Notification

The Disk Space Notification script can be scheduled to run once in a week which will check the Disk Space Usage on the server. The Shell script will send out an email to the admin if the Disk Space Usage is greater than the Threshold.

Create a file /home/diskspace.sh and paste the following code in it:

#!/bin/sh

#Threshold is set to 70 here.
THRESHOLD=70
MAILTO=”youremailaddress”
TEMPFILE=/tmp/diskspace.temp
HOSTNAME=`hostname`

rm -f $TEMPFILE

#Calculate the Current Disk Usage with the below command.
CDU=$(df -h | tail -1 | awk ‘{print $5}’ | sed ‘s/%//’)

#Compare the current value with the threshold one.
if [ $(expr $CDU “>=” $THRESHOLD) -ne 0 ]
then
echo “Warning!!! Disk Space usage on server $HOSTNAME is ${CDU}%” >> $TEMPFILE
fi

#Send an email if /tmp/diskspace.temp is present.
if [ -e $TEMPFILE ]
then
mail -s “Disk Space Notification” $MAILTO < $TEMPFILE
fi

rm -f $TEMPFILE

Save the file. Now you need to schedule a cron to execute the script once in a week.

crontab -e

and set the following cronjob:

0 1 * * 0  /bin/sh  /home/diskspace.sh

Save the file and restart the crond service. The cronjob will now execute on Sunday at 1.00AM and will send a notification if the disk space usage on the server is above the threshold.