Difference between revisions of "Main Page"

From wiki.mikejung.biz
Jump to navigation Jump to search
Line 292: Line 292:
'''/scripts/smtpmailgidonly on'''
'''/scripts/smtpmailgidonly on'''
To search for available packages:
yum search example
Find packages and where they lead to:
rpm -qa | grep example
rpm -ql example

Revision as of 23:40, 31 October 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

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


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'''


To search for available packages:

yum search example

Find packages and where they lead to:

rpm -qa | grep example
rpm -ql example