Difference between revisions of "Main Page"

From wiki.mikejung.biz
Jump to navigation Jump to search
Line 480: Line 480:
==Hardware Checks and Commands==
Check for disk age:
smartctl -a /dev/sda | grep Power_On_Hours

Revision as of 21:07, 24 November 2011



"Can you take a look at my server and tell me what's going on?"

Starting Points

Who is on the server?


Show top processes.

top -c

Load averages.

sar -q

Ram usage.

sar -r

I/O wait

sar -s

After you get a good idea of what is causing load / unresponsiveness, you can start narrowing things down.


Apache Status

/usr/bin/lynx -dump -width 500 | less

Apache connection

/usr/bin/lynx -dump -width 500 | awk '{print $11" "$12}'| awk NF |grep [0-9].[0-9].[0-9].[0-9]|sort|uniq -c|sort -n|tail -50

Check settings in httpd.conf. Added +160 usually located around that line number.

vim /usr/local/apache/conf/httpd.conf +160

Think Apache is causing server to go OOM? Check PHP memory limit. If it's above 32M ask client if they need it this high.

grep memory_limit /usr/local/lib/php.ini

Find all users php.ini files.

find /home/*/public_html/* -name php.ini


Useful for seeing what queries are doing what.

watch -n 1 'mysqladmin proc stat'

Check /tmp for sess_* files. Can mean tables are corrupt.

ll /tmp/

Check the logs.


Then check MySQL settings

vim /etc/my.cnf

Network Stuff

New server missing some IPs it was supposed to come with?

 service ipaliases restart


One Liners

See MySQL status. Updates every 1 s.

watch -n 1 'mysqladmin proc stat'

Optimize Tables.

for i in $(mysql -e "show databases;" | sed 's/Database//') ; do for each in $(mysql -e "use $i; show tables;" \
| sed 's/Tables.*//' ;) ; do mysql -e "use $i ; optimize table $each" ; done ; done

MySQL check that will: check all databases, analyze, optimize and repair. Pretty useful, usually safe.

mysqlcheck -Aaor

Dump a database.

mysqldump database > database.sql

Import a database.

mysql database < database.sql

Connect to a database.

mysql -u user -h ip -p databasename

Viewing and Deleting Tables and Databases

Look at databases and tables.

> use databasename;
> show tables;

Drop (delete) a database. Can be useful if importing a database and it gives you an error.

> drop database databasename;

Optimization Scripts

While the default configs here are a good starting point. These scripts will help in finding any issues with the users current MySQL config.

Note: I like to run these like : '/scripts/tuning-primer.sh > /root/tuning-primer.txt[n]' This saves the output, so you don't feel compelled to add it as a note to a ticket or admin comments. You can also use it to compare the results after 48 hours. This is a great way to document these changes.

wget -O /scripts/tuning-primer.sh http://day32.com/MySQL/tuning-primer.sh
chmod +x /scripts/tuning-primer.sh

If day32.com is down, try:

wget -O /scripts/tuning-primer.sh http://mysql-tuner.didfor.me

wget -O /scripts/mysqltuner.pl http://mysqltuner.com/mysqltuner.pl
chmod +x /scripts/mysqltuner.pl

Upgrading MySQL

Template:Box Warning

If pre-MySQL 5.0:

 mysqlcheck -Aaor

If MySQL 5.0 to 5.1:

 mysqlcheck -Agr

And back up all the databases:

 mkdir -p /backup/mysqldumps
 cd /backup/mysqldumps
 for i in $(mysql -e "show databases;" | cut -d ' ' -f2 | grep -v Database); do `mysqldump $i > $i.sql`; done

Enabling a Slow Query Log

How to enable a slow query log

touch /var/lib/mysql/slow.log

chown mysql. /var/lib/mysql/slow.log

In the my.cnf file under the mysqld section add this:


Then restart mysql and you have a slow query log.

If you want to specify the number of seconds that indicates a long or slow query, use this line in /etc/my.cnf :

long_query_time = 5

changing 5 to whatever number of seconds you want.


Parse Error

Parse error: syntax error, unexpected T_STRING

Check the file and remove <?xml version="1.0" encoding="utf-8"?>

Force PHP5

Add to .htaccess:

AddType application/x-httpd-php5 .html .htm

Apache PHP Handlers

Can use this command to change owner and group

chown -R user:group /directory/


Ownership - permissions should be 755



Ownership - permissions should be 755



Email accounts not showing up in cPanel.

Check /home/user/etc Make sure the passwd file and shadow file have proper permissions also make sure they are located in



Can't find file: 'horde_sessionhandler.MYI'

/etc/init.d/mysqld stop
rm /var/lib/mysql/horde/horde_sessionhandler.frm
/etc/init.d/mysqld start

>CREATE TABLE horde_sessionhandler (session_id VARCHAR(32) NOT NULL, session_lastmodified INT NOT NULL, session_data LONGBLOB, PRIMARY KEY 
(session_id)) ENGINE = InnoDB;

>GRANT SELECT, INSERT, UPDATE, DELETE ON horde_sessionhandler TO [email protected];


Find top sending IPs in exim logs:

grep "SMTP connection from" /var/log/exim_mainlog |grep "connection count" |awk '{print $7}' |cut -d ":" -f 1 |cut -d "[" -f 2 |cut -d "]" -f 1 |sort -n |uniq -c | sort -n

Find authenticated users who may be spamming:

find /var/spool/exim/input/ -name '*-H' | xargs grep 'auth_id'

Spam comming from scripts:

grep cwd=\/home\/ /var/log/exim_mainlog| cut -d' ' -f4 | sort | uniq -c | sort -n

Removing all queued messages at once in a safe way:

exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | sh

Or you can do the same from the mail queue manager in WHM.

APF SMTP tweak enables mail to be sent only from the mail or mailman GID, and blocks all outbound SMTP, except through the sendmail binary. Add this bold line of code to /etc/init.d/apf , right underneath the start) case:

/usr/local/sbin/apf --start >> /dev/null 2>&1
'''/scripts/smtpmailgidonly on'''


Add relaying from another server:

Add the IP to the "remote service IPs" in cPanel


Find Spam in the queue:

egrep -l "user" /var/spool/clientmqueue/Q* | wc -l


To search for available packages:

yum search example

Find packages and where they lead to:

rpm -qa | grep example
rpm -ql example

Java + Tomcat

Regular install:

yum install java-1.6.0-openjdk.x86_64
yum install tomcat5


Configuration file, lots of settings can be changed here:

vim /usr/local/apache/conf/httpd.conf

Includes (external settings that Apache reads in case the conf was rebuilt)

cd /usr/local/apache/conf/includes

Check for a basic Dos, or heavy traffic:

netstat -tn 2>/dev/null | grep ':80 ' | awk '{print $5}' | cut -f1 -d: | sort | uniq -c | sort -rn | head  

Count the processes:

ps aux | grep httpd | wc -l
ps aux | grep php | wc -l


cPanel not working for some accounts on some servers:

chgrp user /var/cpanel/users/username
vim /etc/proftpd/username


PureFTP using FTPES

Edit /etc/pure-ftpd.conf and uncomment (enable) the PassivePortRange line, like below.

# Port range for passive connections replies. - for firewalling.
PassivePortRange          30000 50000

APF - /etc/apf/conf.apf

# Common ingress (inbound) TCP ports

# Common egress (outbound) TCP ports

CSF - /etc/csf/csf.conf

# Allow incoming TCP ports
TCP_IN = "20,21,22,25,53,80,110,143,443,465,953,993,995,2077,2078,2082,2083,2086,2087,2095,2096,30000:50000"

# Allow outgoing TCP ports
TCP_OUT = "20,21,22,25,37,43,53,80,110,113,443,587,873,953,2087,2089,2703,30000:50000"

Packages / Yum

Install clamd on a coremanaged server:

yum --disablerepo=\* --enablerepo=epel install clamd

Load Balanced Troubleshooting

Reboot Process

Check to make sure SAN is mounted:

netstat -lpn | grep 192.168

Stop OCFS2 before reboot:

/etc/init.d/ocfs2 stop

Start OCFS2:

/etc/init.d/ocfs2 start

Make sure man is mounted:

mount | grep san

Restart Apache:

service httpd restart


Find all index.* files then remove bad things

find /home/*/public_html/ -name index.* > /root/list
for each in `cat /root/list` ; do sed -i.lwbak 's/Badthing\/script>//g' $each ; done


Conflicting Server Name Error

Check for duplicates/system users:

grep -i domain.com /var/cpanel/users/*

If there is a domain entry owned by "system" remove this file:

rm /var/cpanel/users/system

Then run:


Hardware Checks and Commands

Check for disk age:

smartctl -a /dev/sda | grep Power_On_Hours