UnixServerAdmin

Server Administration & Management

Magic SysRq key to Reboot Server

# reboot
bash: /sbin/reboot: Input/output error
# shutdown -r now
bash: /sbin/shutdown: Input/output error

I am sure most of has seen this issue earlier, Whats the rescue – call the data center guy and hard reboot. WAIT!! **Just try this. There is some issue with your disc for sure and thats why the kernel is unable to access the ‘/sbin/reboot’ and ‘/sbin/shutdown’ binaries from the disk so that it could execute them.

A fsck in next boot is mandatory now BUT what you need right away is – some way to reboot this BOX. Do we have something to tell the kernal bypassing anything or any command on disc. Yes! There is this “magic SysRq key” for your rescue. First you must activate the magic SysRq option by type following command :-

# echo 1 > /proc/sys/kernel/sysrq

When you are ready to reboot the machine simply run the following:

# echo b > /proc/sysrq-trigger

Note: This will reboot your server, without trying to umount any file system), BUT please remember this should only be used in dire situation as it wont do any umount of the currently mounted file systems. BUT if your drive is already failing then that may not be a concern.

Make the Sysrq setting permanent –
# echo “kernel.sysrq = 1” >> /etc/sysctl.conf

Advertisements

December 28, 2012 Posted by | Tips & Tricks, Unix/Linux | , | 1 Comment

Webmail error:Warning: main(../config/config.php): failed to open stream in cPanel

I got the following error in webmail

===============================================================
Warning: main(../config/config.php): failed to open stream: No such file or directory in /usr/local/cpanel/base/3rdparty/squirrelmail/functions/global.php on line 18
Fatal error: main(): Failed opening required ‘../config/config.php’ (include_path=’/usr/local/cpanel/3rdparty/lib/php/:.’) in /usr/local/cpanel/base/3rdparty/squirrelmail/functions/global.php on line 18
===============================================================

To Fix this issue, type the following command:-

# /scripts/fixwebmail

After running /scripts/fixwebmail you may get error like this:-

===============================================================
chown: failed to get attributes of `/usr/local/etc/cpanel/base/webmail/data’: No such file or directory
chmod: failed to get attributes of `/usr/local/etc/cpanel/base/webmail/data’: No such file or directory
===============================================================

For fixing this just issue the following command:-

# cp -p /usr/local/cpanel/base/3rdparty/squirrelmail/config/config_default.php /usr/local/cpanel/base/3rdparty/squirrelmail/config/config.php

December 23, 2012 Posted by | cPanel, Mail | , , | Leave a comment

How to use special string to save time in Cron

Instead of the first five fields, you can use any one of eight special strings. It will not just save your time but it will improve readability.

Special string    Meaning

@reboot ——> Run once, at startup.
@yearly ——> Run once a year, “0 0 1 1 *”.
@annually –> (same as @yearly)
@monthly —> Run once a month, “0 0 1 * *”.
@weekly —–> Run once a week, “0 0 * * 0”.
@daily ——–> Run once a day, “0 0 * * *”.
@midnight –> (same as @daily)
@hourly —–> Run once an hour, “0 * * * *”.

Run ntpdate every hour:

@hourly /path/to/ntpdate

December 18, 2012 Posted by | Cron | , , , | Leave a comment

How to Setup Anacron in CentOS/RHEL 6.x

Anacron is the cron for desktops and laptops. Anacron does not expect the system to be running 24 x 7 like a server. When you want a background job to be executed automatically on a machine that is not running 24 x 7, you should use anacron.

CentOS/RHEL 6.x has changed how the default system maintenance cronjobs are scheduled. These are the cron jobs responsible for things like rotating logs and indexing files on the filesystem. That is routine jobs that are best scheduled to run at off peak times when the server is not busy doing more important things like serving money making websites. First, a look at how the jobs are scheduled. We just follow the trail:

* Previously, in CentOS/RHEL 5.x system maintenance cronjobs were scheduled using the /etc/crontab file. This is no longer the case in CentOS 6.x. /etc/crontab is empty by default.
* Anacron is installed by default and is responsible for maintenance cron jobs. Anacron was originally created for running cron jobs on systems that aren’t switched on 24/7 i.e. desktop or workstation PCs. So why Redhat chose to include it by default in an enterprise operating system designed for servers that are always on is anyone’s guess.
* Anacron is run by crond via the 0anacron file in /etc/cron.hourly. Anacron does NOT run as it’s own daemon.
* Anacron is configured using /etc/anacrontab and executes the commands in the cron.daily/weekly/monthly directories:
* Just like how cron has /etc/crontab, anacron has /etc/anacrontab, /etc/anacrontab file has the anacron jobs mentioned in the following format.

————————————————————————————–
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=20-22
 
#period in days   delay in minutes   job-identifier       command
1                   5                cron.daily      nice run-parts /etc/cron.daily
7                   25               cron.weekly     nice run-parts /etc/cron.weekly
@monthly        45             cron.monthly    nice run-parts /etc/cron.monthly
————————————————————————————–

$–> Field 1 is Recurrence period: This is a numeric value that specifies the number of days.

1 – daily
7 – weekly
30 – monthly
N – This can be any numeric value. N indicates number of days
@monthly’ for a job that needs to be executed monthly.

$–> Field 2 is Delay: This indicates the delay in minutes. i.e X number of minutes anacron should wait before executing the job after the the machine starts.

$–> Field 3 is Job identifier: It is the name for the job’s timestamp file. It should be unique for each job. This will be available as a file under the /var/spool/anacron directory. This file will contain a single line that indicates the last time when this job was executed.

$–> Field 4 is command: Command or shell script that needs to be executed.

START_HOURS_RANGE :- Interval, when scheduled jobs can be run, in hours, In case the time interval is missed, for example due to a power failure, the scheduled jobs are not executed that day.

RANDOM_DELAY :- maximum number of minutes that will be added to the delay in minutes variable which is specified for each job, The minimum delay value is set, by default, to 6 minutes. If RANDOM_DELAY is, for example, set to 12, then between 6 and 12 minutes are added to the delay in minutes for each job in that particular anacrontab. RANDOM_DELAY can also be set to a value below 6, including 0. When set to 0, no random delay is added. This proves to be useful when, for example, more computers that share one network connection need to download the same data every day.

So if you want to schedule system maintenance cron jobs to run at off peak times you will have to tweak the START_HOURS_RANGE in /etc/anacrontab Or if you want more fine grained control you could just ditch anacron altogether and use /etc/cron.d/dailyjobs

# yum remove cronie-anacron

# yum install cronie-noanacron sysstat

Don’t forget to start crond!

# vim /etc/cron.d/dailyjobs

# service crond start

# chkconfig crond on

December 13, 2012 Posted by | Cron, Tips & Tricks, Unix/Linux | , , , , | Leave a comment

How to stop USB Mass Storage device in RHEL/CentOS

I’d like to disable all USB devices connected to our Red Hat Linux based workstations. I’d like to disable USB flash or hard drives, which users can use with physical access to a system to quickly copy sensitive data from it. How do I disable USB device support under RHEL/CentOS 5.x workstation operating systems. The USB storage drive automatically detects USB flash or hard drives. You can easily force and disable USB storage devices under any Linux distribution. The modprobe program used for automatic kernel module loading and can be configured to not load the USB storage driver upon demand. This will prevent the modprobe program from loading the usb-storage module, but will not prevent root (or another program) from using the insmod program to load the module manually.

In linux it’s even more easily done, by unloading the usb_storage module: for disable :-

# modprobe -r usb_storage

for enable :-

# modprobe -i usb_storage
================================================================================
The easiest way to disable usb storage device in linux is create following file And add following line inside the file

# touch /etc/modprobe.d/no-usb

install usb-storage /bin/true

================================================================================
Grub option

You can get rid of all USB devices by disabling kernel support for USB via GRUB. Open grub.conf or menu.lst (Under Debian / Ubuntu Linux) and append “nousb” to the kernel line as follows:

kernel /vmlinuz-2.6.18-128.1.1.el5 ro root=LABEL=/ console=tty0 console=ttyS1,19200n8 nousb

Save and close the file. Once done just reboot the system:

================================================================================
Type the following command:

# echo ‘install usb-storage : ‘ >> /etc/modprobe.conf

You can also remove USB Storage driver, enter:

# ls /lib/modules/$(uname -r)/kernel/drivers/usb/storage/usb-storage.ko

# mv /lib/modules/$(uname -r)/kernel/drivers/usb/storage/usb-storage.ko /root

December 8, 2012 Posted by | Tips & Tricks, Unix/Linux | , , | Leave a comment

How to bind to multiple IP Address in MySQL Server

The MySQL server listens on a single network socket for TCP/IP connections. This socket is bound to a single address, but it is possible for an address to map onto multiple network interfaces. The default address is 0.0.0.0. To specify an address explicitly, use the bind-address=addr option at server startup, where addr is an IPv4 address or a host name. If addr is a host name, the server resolves the name to an IPv4 address and binds to that address. The server treats different types of addresses as follows:

* If the address is 0.0.0.0, the server accepts TCP/IP connections on all server host IPv4 interfaces.
* If the address is a “regular” IPv4 address (such as 127.0.0.1), the server accepts TCP/IP connections only for that particular IPv4 address.

Configuration

You can set bind-address directive in my.cnf. Edit /etc/my.cnf or /usr/local/etc/my.cnf, run:

# vim /etc/my.cnf

bind-address  = 0.0.0.0

Make sure you delete the following line or comment out the following line:

#skip-networking

Save and close the file. Next setup the firewall and allows connection from or to select IPs only.

December 3, 2012 Posted by | MySQL | | Leave a comment