Archive for the ‘Linux’ Category

Timeout error occurred trying to start MySQL Daemon.

Friday, May 18th, 2007

I came across mysql error — “Timeout error occurred trying to start MySQL Daemon.”

Mysql will not restart —

[root@vps init.d]# ./mysqld restart
Stopping MySQL: [FAILED]
Timeout error occurred trying to start MySQL Daemon.
Starting MySQL: [FAILED]

Server Details :
Linux VPS — Plesk Installed.
Mysql Version : 4.1

——

Solution : Add this line in /etc/my.cnf

skip-innodb under socket=/var/lib/mysql/mysql.sock

vi /etc/my.cnf
——–

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-innodb
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
———

Thanks,
Sachin
ThinkSupport.net

Basic Linux commands.

Friday, May 18th, 2007

I often forget commands ;) I decided to post them at one place (cheers to websites from which I copied the details ) – now I don’t have to google everytime — I am sorry google you missed few of my hits :D

ls

List files/directories in a directory, comparable to dir in windows/dos.

ls -la

Shows all files (including ones that start with a period), directories, and details attributes for each file.

cd

Change directory (e.g cd /usr/local/bin)

cd ~

Go to your home directory

cd -

Go to the last directory you were in

cd ..

Go up a directory

cat

Print file contents to the screen

cat filename.txt

Print the contents of filename.txt to your screen

tail

Similar to cat, but only reads the end of the file

tail /var/log/messages

See the last 20 (by default) lines of /var/log/messages

tail -f /var/log/messages

Watch the file continuously, while it’s being updated

tail -200 /var/log/messages

Print the last 200 lines of the file to the screen

head

Similar to tail, but only reads the top of the file

head /var/log/messages

See the first 20 (by default) lines of /var/log/messages

head -200 /var/log/messages

Print the first 200 lines of the file to the screen

more

Llike cat, but opens the file one screen at a time rather than all at once

more /etc/userdomains

Browse through the userdomains file. hit Spaceto go to the next page, q to quit

less

Page through files

od

View binary files and data

xxd

Also view binary files and data

gv

View Postscript/PDF files

xdvi

View TeX DVI files

nl

Number lines

touch

Create an empty file

touch /home/burst/public_html/404.html

Create an empty file called 404.html in the directory /home/burst/public_html/

file

Attempts to guess what type of file a file is by looking at it’s content.

file *

Prints out a list of all files/directories in a directory

cp

Copy a file

cp filename filename.bak

Copies filename to filename.bak

cp -a /etc/* /root/etc/

Copies all files, retaining permissions form one directory to another.

cp -av * ../newdirectory

Copies all files and directories recurrsively in the current directory INTO newdirectory

mv

Move a file command

mv oldfilename newfilename

Move a file or directory from oldfilename to newfilename

rm

delete a file

rm filename.txt

deletes filename.txt, will more than likely ask if you really want to delete it

rm -f filename.txt

deletes filename.txt, will not ask for confirmation before deleting.

rm -rf tmp/

recursively deletes the directory tmp, and all files in it, including subdirectories.

chmod

changes file access permissions. The set of 3 go in this order from left to right:
USER – GROUP – EVERONE

0 = — No permission
1 = –X Execute only
2 = -W- Write only
3 = -WX Write and execute
4 = R– Read only
5 = R-X Read and execute
6 = RW- Read and write
7 = RWX Read, write and execute

chmod 000

No one can access

chmod 644

Usually for HTML pages

chmod 755

Usually for CGI scripts

chown

Changes file ownership permissions
The set of 2 go in this order from left to right:
USER – GROUP

chown root myfile.txt

Changes the owner of the file to root

chown root.root myfile.txt

Changes the owner and group of the file to root

stat

Display file attributes

grep

Llooks for patterns in files

grep root /etc/passwd

Shows all matches of root in /etc/passwd

grep -v root /etc/passwd

Shows all lines that do not match root

ln

Create’s “links” between files and directories

ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf

Now you can edit /etc/httpd.conf rather than the original. changes will affect the orginal, however you can delete the link and it will not delete the original.

wc

Word count

wc -l filename.txt

Tells how many lines are in filename.txt

find

Utility to find files and directories on your server.

find / -name “filename”

Find the file called “filename” on your filesystem starting the search from the root directory “/”.

locate filename

Find the file name and path of which contains the string “filename”. Run ‘updatedb’ to build index.

EDITORS

Most popular editors available on UNIX platforms.

pico

Friendly, easy to use file editor

pico /home/burst/public_html/index.html

Edit the index page for the user’s website.

vi

Popular editor, tons of features, harder to use at first than pico

vi filename.txt

Edit filename.txt. All commands in vi are preceded by pressing the escape key. Each time a different command is to be entered, the escape key needs to be used. Except where indicated, vi is case sensitive. Fore more commands go to: http://www.intellink.net/vi-qref.htm

H — Upper left corner (home)
M — Middle line
L — Lower left corner
h — Back a character
j — Down a line
k — Up a line
^ — Beginning of line
$ — End of line
l — Forward a character
w — Forward one word
b — Back one word
fc — Find c
; — Repeat find (find next c)

:q! — This force quits the file without saving and exits vi
:w — This writes the file to disk, saves it
:wq — This saves the file to disk and exists vi
:LINENUMBER : EG :25 — Takes you to line 25 within the file
:$ — Takes you to the last line of the file
:0 — Takes you to the first line of the file

emacs

Another popular editor. For more commands go to http://www.hsrl.rutgers.edu/ug/emacs_qref.html

C-\ t — Tutorial suggested for new emacs users.
C-x C-c exit emacs

emacs filename.txt

Edit filename.txt. While you’re in emacs, use the following quickies to get around:

C-x C-f — read a file into emacs
C-x C-s — save a file back to disk
C-x i — insert contents of another file into this buffer
C-x C-v — replace this file with the contents of file you want
C-x C-w — write buffer to specified file

C-f — move forward one character
C-b — move backward one character
C-n — move to next line
C-p — move to previous line
C-a — move to beginning of line
C-e — move to end of line
M-f — move forward one word
M-b — move backword one word
C-v — move forward one screen
M-v — move backward one screen
M-< --- go to beginning of file
M-> — go to end of file

NETWORK

Some of the basic networking utilities.

w

Shows who is currently logged in and where they are logged in from.

who

This also shows who is on the server in an shell.

netstat

Shows all current network connections.

netstat -an

Shows all connections to the server, the source and destination ips and ports.

netstat -rn

Shows routing table for all ips bound to the server.

netstat -an |grep :80 |wc -l

Show how many active connections there are to apache (httpd runs on port 80)

top

Shows live system processes in a formatted table, memory information, uptime and other useful info.

While in top, Shift + M to sort by memory usage or Shift + P to sort by CPU usage

top -u root

Show processes running by user root only.

route -n

Shows routing table for all ips bound to the server.

nslookup yahoo.com

Query your default domain name server (DNS) for an Internet name (or IP number) host_to_find.

top

Shows live system processes in a formatted table, memory information, uptime and other useful info.

While in top, Shift + M to sort by memory usage or Shift + P to sort by CPU usage

top -u root

Show processes running by user root only.

route -n

Shows routing table for all ips bound to the server.

nslookup yahoo.com

Query your default domain name server (DNS) for an Internet name (or IP number) host_to_find.

traceroute yahoo.com

Have a look how you messages travel to yahoo.com

ifconfig

Display info on the network interfaces.

ifconfig -a

Display into on all network interfaces on server, active or inactive..

ping

Sends test packets to a specified server to check if it is responding properly

tcpdump

Print all the network traffic going through the network.

arp

Command mostly used for checking existing Ethernet connectivity and IP address

SYSTEM TOOLS

Many of the basic system utilities used to get things done.

ps

ps is short for process status, which is similar to the top command. It’s used to show currently running processes and their PID.
A process ID is a unique number that identifies a process, with that you can kill or terminate a running program on your server (see kill command).

ps

ps is short for process status, which is similar to the top command. It’s used to show currently running processes and their PID.
A process ID is a unique number that identifies a process, with that you can kill or terminate a running program on your server (see kill command).

ps U username

Shows processes for a certain user

ps aux

Shows all system processes

ps aux –forest

Shows all system processes like the above but organizes in a hierarchy that’s very useful!

kill

terminate a system process

kill -9 PID

Immediately kill process ID

killall program_name

Kill program(s) by name. For example to kill instances of httpd, do ‘killall httpd’

du

Shows disk usage.

du -sh

Shows a summary of total disk space used in the current directory, including subdirectories.

du / -bh | more

Print detailed disk usage for each subdirectory starting at the “/”.

last

Shows who logged in and when

last -20

Shows only the last 20 logins

last -20 -a

Shows last 20 logins, with the hostname in the last field

pwd

Print working directory, i.e., display the name of my current directory on the screen.

hostname

Print the name of the local host. Use netconf (as root) to change the name of the machine.

whoami

Print my login name.

date

Print or change the operating system date and time

time

Determine the amount of time that it takes for a process to complete + other info.

uptime

Show the number days server has been up including system load averages.

uname -a

Displays info on about your server such as kernel version.

free

Memory info (in kilobytes).

lsmod

Show the kernel modules currently loaded. Run as root.

dmesg | less

Print kernel messages.

man topic

Display the contents of the system manual pages (help) on the topic. Do ‘man netstat’ to find all details of netstat command including options and examples.

reboot / halt

Halt or reboot the machine.

mount

Mount local drive or remote file system.

mount -t auto /dev/fd0 /mnt/floppy

Mount the floppy. The directory /mnt/floppy must exist.

mount -t auto /dev/cdrom /mnt/cdrom

Mount the CD. The directory /mnt/cdrom must exist.

sudo

The super-user do command that allows you to run specific commands that require root access.

fsck

Check a disk for errors

COMPRESSION UTILITIES

There are many other compression utilities but these are the default and most widely utilized.

tar

Creating and Extracting .tar.gz and .tar files

tar -zxvf file.tar.gz

Extracts the file

tar -xvf file.tar

Extracts the file

tar -cf archive.tar contents/

Takes everything from contents/ and puts it into archive.tar

gzip -d filename.gz

gzip -d filename.gz

zip

Compress files into.zip

unzip file.zip

Extracting .zip files shell command

compress

Compress files. compress filename

uncompress

Uncompress compressed files. uncompress filename.Z

bzip2

Compress files in bzip2 format

THE (DOT) FILES

The good old dot files. Let’s clear up some confusion here by defining each.

.bash_login

Treated by bash like .bash_profileif that doesn’t exist.

.bash_logout

Sourced by bash login shells at exit.

.bash_profile

Sourced by bash login shells after /etc/profile

.bash_history

The list of commands executed previously.

.profile

Treated by bash like ~/.bash_profile if that and .bash_login don’t exist.

.vimrc

Default “Vim” configuration file.

.emacs

Read by emacs at startup

CONFIGURATION FILES

Listing everything is beyond the scope of this article.

/etc

This directory contains most of the basic Linux system-configuration Files.

/etc/init.d

Contains the permanent copies of System V–style run-level scripts. These scripts are often linked to files in the /etc/rc?.d directories to have each service associated with a script started or stopped for the particular run level. The ? is replaced by the run-level number (0 through 6). (Slackware puts its run-level scripts in the /etc/rc.d directory.)

/etc/cron*

Directories in this set contain files that define how the crond utility runs applications on a daily (cron.daily), hourly (cron.hourly), monthly (cron.monthly), or weekly (cron.weekly) schedule.

/etc/cups

Contains files used to configure the CUPS printing service.

/etc/default

Contains files that set default values for various utilities. For example, the file for the useradd command defines the default group number, home directory, password expiration date, shell, and skeleton directory

/etc/skel

Any files contained in this directory are automatically copied to a user’s home directory when that user is added to the system.

/etc/mail

Contains files used to configure your sendmail mail service.

/etc/security

Contains files that set a variety of default security conditions for your computer.

/etc/sysconfig

Contains important system configuration files that are created and maintained by various services (including iptables, samba, and most networking services).

/etc/passwd

Holds some user account info including passwords (when not “shadowed”).

/etc/shadow

Contains the encrypted password information for users’ accounts and optionally the password aging information.

/etc/xinetd.d

Contains a set of files, each of which defines a network service that the xinetd daemon listens for on a particular port.

/etc/syslogd.conf

The configuration file for the syslogd daemon. syslogd is the daemon that takes care of logging (writing to disk) messages coming from other programs to the system.

/var

Contains variable data like system logging files, mail and printer spool directories, and transient and temporary files.

/var/log

Log files from the system and various programs/services, especially login (/var/log/wtmp, which logs all logins and logouts into the system) and syslog (/var/log/messages, where all kernel and system program message are usually stored).

/var/log/messages

System logs. The first place you should look at if your system is in trouble.

/var/log/utmp

Active user sessions. This is a data file and as such it can not be viewed normally.

/var/log/wtmp

Log of all users who have logged into and out of the system. The last command can be used to access a human readable form of this file.

Apache Shell Commands

Some of the basic and helpful apache commands.

httpd -v

Outputs the build date and version of the Apache server.

httpd -l

Lists compiled in Apache modules

httpd status

Only works if mod_status is enabled and shows a page of active connections

service httpd restart

Restarted Apache web server

MySQL Shell Commands

Some of the basic and helpful MySQL commands.

mysqladmin processlist

Shows active mysql connections and queries

mysqladmin processlist |wc -l

Show how many current open connections there are to mysql

mysqladmin drop database

Drops/deletes the selected database

mysqladmin create database

Creates a mysql database

mysql -u username -p password databasename < data.sql

Restores a MySQL database from data.sql

mysqldump -u username -p password database > data.sql

Backup MySQL database to data.sql

echo “show databases” | mysql -u root -p password|grep -v Database

Show all databases in MySQL server.

mysqldump -u root -p password database > /tmp/database.exp

Dump database including all data and structure into /tmp/database.exp

Thank You,
Preeti S
ThinkSupport.net

How to increase file limit

Sunday, May 13th, 2007

Get current limit:

ulimit -n

cat /proc/sys/fs/file-nr

The default limit is 1024.

Get current number of open file descriptors:

lsof [-p pid] | wc -l

Increase the limit:

Edit /etc/security/limits.conf:

username hard nofile 32768

Enjoy

Ninad

CGI is down on the server!

Saturday, May 12th, 2007

First check the Apache error logs.

—————————————————
[Sat Mar 31 21:24:19 2007] [error] [client 65.254.32.50] Premature end of script headers: /home/youngerb/public_html/cgi-bin/at3/admin.cgi
admin.cgi: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory
[Sat Mar 31 21:24:29 2007] [error] [client 59.95.36.168] Premature end of script headers: /home/youngerb/public_html/cgi-bin/at3/admin.cgi
—————————————————

It seems shared libraries libstdc++.so.5 is missing or courrpted on the server.

Just do this

yum install compat-lib*

How To use Yum

Friday, May 11th, 2007
  • To seach for a application

Yum will search all your enabled repos and tell you where you can obtain the package from

yum search application_name
  • Yum can list all available packages from your enabled repos and tell you where you can obtain the package from:
yum list available
  • To find out more info about some package
yum info application_name
  • Installing applications

Inastalling is as easy as

yum install application_name
  • Listing rpms

yum can list installed rpms for you from the repos you have enabled

yum list extras
  • Removing rpms

Yum can remove a application and the dependenciesit installed with tat application. it will not remove depenencies if another application installed needs them.

yum remove application_name
  • Updating the system

Yum can update the system for you with out user interact if you want it to.

yum update
  • Not sure if you have upates?
yum check-update
  • Local install

downloaded a rpm and cannot install it with rpm because of dependencies?

yum localinstall /path/to/the/rpm

Enjoy

Ninad

Postfix + ClamAV + MailScanner in OpenSuse 10.2

Friday, May 11th, 2007

1) Install the anti virus software (Clamav) –> (here) http://rpm.pbone.net/
rpm -ivh clamav-db-0.88.2-1.i386.rpm
rpm -ivh clamav-devel-0.88.2-1.i386.rpm
rpm -ivh clamav-server-0.88.2-1.i386.rpm
rpm -ivh clamav-0.88.2-1.i386.rpm

/etc/init.d/clamd start

2. Once the anti-virus is install then we need to install the MailScanner software the RPM along with the source files can be found at
http://www.sng.ecs.soton.ac.uk/mailscanner/downloads.shtml

Now get ready to install the mailscanner, this is going to take a long time.

gzip -d MailScanner-4.46.2-2.rpm.tar.gz
tar -xvf MailScanner-4.46.2-2.rpm.tar
cd MailScanner-4.46.2-2
./install.sh

3. In your MailScanner.conf file in /etc/MailScanner, there are 5 settings you need to change. The settings are:

Run As User = postfix
Run As Group = postfix
Incoming Queue Dir = /var/spool/postfix/hold
Outgoing Queue Dir = /var/spool/postfix/incoming
MTA = postfix

4. You will need to ensure that the user “postfix” can write to

/var/spool/MailScanner/incoming and /var/spool/MailScanner/quarantine

chown postfix:postfix /var/spool/MailScanner/incoming
chown postfix:postfix /var/spool/MailScanner/quarantine

5. Edit file MailScanner.conf
Virus Scanners = clamav

6. Edit virus.scanners.conf
clamav /usr/lib/MailScanner/clamav-wrapper /var/lib/clamav

7. Now we need to edit the postfix main.cf file, go all the way to the bottom of the file and add the following
header_checks = regexp:/etc/postfix/header_checks

8. In the file /etc/postfix/header_checks add this line:
/^Received:/ HOLD

9. Set the servers to run on startup and then start them

chkconfig MailScanner on
chkconfig postfix on
chkconfig clamd on

/etc/init.d/Mailscanner start
/etc/init.d/postfix start
/etc/init.d/clamd start

Enjoy

Ninad

zlib installation

Thursday, May 10th, 2007

wget http://www.zlib.net/zlib-1.2.3.tar.gz
tar -zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
make
make install

Enjoy

Ninad

Not able to view JSP pages

Wednesday, May 9th, 2007

If you are getting code instead of JSP page then you need to install servlets.

To install servlet go to the WHM >> Account Functions >> Install Servlets. Select domain and install.

After doing this you need to restart tomcat.

Now you will be able to view JSP pages.

Enjoy

Ninad

Install Ruby on Rails (ROR)

Sunday, May 6th, 2007

Here are some usefull links for installing ROR –

Installing on Linux –

http://wiki.rubyonrails.org/rails/pages/HowtoInstallAndRunRubyOnRailsOnCpanel


Installing Rails on Windows –

http://wiki.rubyonrails.org/rails/pages/RailsOnWindows

Nagios Installation and Configuration

Thursday, May 3rd, 2007

You can use the following steps to install and configure Nagios.

Create the base directory where you would like to install Nagios.
mkdir /usr/local/nagios

Add a new user (and group) to your system.
adduser nagios

Download Nagois 1.0.
wget http://internap.dl.sourceforge.net/sourceforge/nagios/nagios-1.0.tar.gz
tar -zxvf nagios-1.0.tar.gz
cd nagios-1.0

Run the configure script.
./configure –prefix=/usr/local/nagios –with-cgiurl=/nagios/cgi-bin
–with-htmurl=/nagios/ –with-nagios-user=nagios –with-nagios-grp=nagios

Compile Nagios and the CGIs.
make all

Install the binaries and HTML files (documentation and main web page).
make install

Install the sample init script to /etc/rc.d/init.d/nagios.
make install-init

Installing the Plugins
——————————-

In order for Nagios to be of any use to you, you’re going to have to download
and install some plugins. Plugins are scripts or binaries which perform all
the service and host checks that constitute monitoring

Download and install the Nagios Plugins.
wget

http://aleron.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.3.1-1.9.i386.rpm

rpm -Ivh nagios-plugins-1.3.1-1.9.i386.rpm

Configuring Nagios
—————————

Nagios is compiled and installed. Now we have to configure it or in other
words define objects (hosts, services, etc.) that should be monitored.

The main configuration file (/usr/local/nagios/etc/nagios.cfg) contains a
number of directives that affect how Nagios operates. This config file is
read by both the Nagios process and the CGIs. This is a sample nagios.cfg

—————————————————————————————————————–
log_file=/usr/local/nagios/var/nagios.log
cfg_file=/usr/local/nagios/etc/checkcommands.cfg
cfg_file=/usr/local/nagios/etc/misccommands.cfg
cfg_file=/usr/local/nagios/etc/contactgroups.cfg
cfg_file=/usr/local/nagios/etc/contacts.cfg
cfg_file=/usr/local/nagios/etc/dependencies.cfg
cfg_file=/usr/local/nagios/etc/escalations.cfg
cfg_file=/usr/local/nagios/etc/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/hosts.cfg
cfg_file=/usr/local/nagios/etc/services.cfg
cfg_file=/usr/local/nagios/etc/timeperiods.cfg
resource_file=/usr/local/nagios/etc/resource.cfg
status_file=/usr/local/nagios/var/status.log
nagios_user=nagios
nagios_group=nagios
check_external_commands=1
command_check_interval=45s
command_file=/usr/local/nagios/rw/nagios.cmd
comment_file=/usr/local/nagios/var/comment.log
downtime_file=/usr/local/nagios/var/downtime.log
lock_file=/usr/local/nagios/var/nagios.lock
temp_file=/usr/local/nagios/var/nagios.tmp
log_rotation_method=d
log_archive_path=/usr/local/nagios/archives
use_syslog=0
log_notifications=1
log_service_retries=1
log_event_handlers=1
log_initial_states=1
log_external_commands=1
log_passive_service_checks=1
inter_check_delay_method=s
service_interleave_factor=s
max_concurrent_checks=0
service_reaper_frequency=1
sleep_time=1
service_check_timeout=30
host_check_timeout=30
event_handler_timeout=30
notification_timeout=30
ocsp_timeout=5
perfdata_timeout=5
retain_state_information=1
state_retention_file=/usr/local/nagios/var/status.sav
retention_update_interval=60
use_retained_program_state=0
interval_length=20
use_agressive_host_checking=0
execute_service_checks=1
accept_passive_service_checks=1
enable_notifications=1
enable_event_handlers=1
process_performance_data=0
obsess_over_services=0
check_for_orphaned_services=0
check_service_freshness=1
freshness_check_interval=60
aggregate_status_updates=1
status_update_interval=15
enable_flap_detection=1
low_service_flap_threshold=5.0
high_service_flap_threshold=20.0
low_host_flap_threshold=5.0
high_host_flap_threshold=20.0
date_format=us
illegal_object_name_chars=`~!$%^&*|’”<>?,()=
illegal_macro_output_chars=`~$&|’”<>
admin_email=you@yourdomain.com
admin_pager=you@yourdomain.com
——————————————————————————————

Add the list of servers that you want to monitor in
/usr/local/nagios/etc/hosts.cfg

——————————————————————————————
# ‘server42′ host definition
define host{
use generic-host
host_name (server hostname)
alias (hostname)
address IP Address
check_command check-host-alive
max_check_attempts 10
notification_interval 120
notification_period 24×7
notification_options d,u,r
}
# ‘server43…..

——————————————————————————————

Edit /usr/local/nagios/etc/hostgroups.cfg to add all the servers.

——————————————————————————————
define hostgroup{
hostgroup_name tchosting
alias TotalChoice
contact_groups tchosting
members server40,server41,server42
}
—————————————————————————————–

To setup email and pager notifications edit
/usr/local/nagios/etc/contacts.cfg to add your contact info.

—————————————————————————————–
define contact{
contact_name Ninad
alias ninad
service_notification_period 24×7
host_notification_period 24×7
service_notification_options n
host_notification_options d,u,r
service_notification_commands notify-by-email
host_notification_commands host-notify-by-email
email ninad@thinksupport.net
}
—————————————————————————————–

The contact name must be a member of contact group. Edit
/usr/local/nagios/etc/contactgroups.cfg to add your name.

Enjoy

Ninad