Difference between revisions of "Main Page"

From wiki.mikejung.biz
Jump to navigation Jump to search
(Blanked the page)
Line 1: Line 1:
 +
== "Can you take a look at my server and tell me what's going on?"==
  
 +
===Starting Points===
 +
 +
'''Who is on the server?'''
 +
<pre>
 +
w
 +
</pre>
 +
 +
'''Show top processes.'''
 +
<pre>
 +
top -c
 +
</pre>
 +
 +
'''Load averages.'''
 +
<pre>
 +
sar -q
 +
</pre>
 +
 +
'''Ram usage.'''
 +
<pre>
 +
sar -r
 +
</pre>
 +
 +
'''I/O wait'''
 +
<pre>
 +
sar -s
 +
</pre>
 +
 +
After you get a good idea of what is causing load / unresponsiveness, you can start narrowing things down.
 +
 +
===Apache===
 +
 +
'''Apache Status'''
 +
<pre>
 +
/usr/bin/lynx -dump -width 500  http://127.0.0.1/whm-server-status | less
 +
</pre>
 +
 +
'''Apache connection'''
 +
<pre>
 +
/usr/bin/lynx -dump -width 500 http://127.0.0.1/whm-server-status | awk '{print $11" "$12}'| awk NF |grep [0-9].[0-9].[0-9].[0-9]|sort|uniq -c|sort -n|tail -50
 +
</pre>
 +
 +
'''Check settings in httpd.conf. Added +160 usually located around that line number.'''
 +
<pre>
 +
vim /usr/local/apache/conf/httpd.conf +160
 +
</pre>
 +
 +
'''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.'''
 +
<pre>
 +
grep memory_limit /usr/local/lib/php.ini
 +
</pre>
 +
 +
'''Find all users php.ini files.'''
 +
<pre>
 +
find /home/*/public_html/* -name php.ini
 +
</pre>
 +
 +
===MySQL===
 +
 +
'''Useful for seeing what queries are doing what.'''
 +
<pre>
 +
watch -n 1 'mysqladmin proc stat'
 +
</pre>
 +
 +
'''Check /tmp for sess_* files. Can mean tables are corrupt.'''
 +
<pre>
 +
ll /tmp/
 +
</pre>
 +
 +
'''Check the logs.'''
 +
<pre>
 +
/var/lib/mysql/examplehostname.err
 +
</pre>
 +
 +
 +
'''Then check MySQL settings'''
 +
<pre>
 +
vim /etc/my.cnf
 +
</pre>
 +
 +
== Network Stuff ==
 +
 +
New server missing some IPs it was supposed to come with?
 +
 +
<pre>
 +
service ipaliases restart
 +
</pre>
 +
 +
<pre>
 +
/scripts/rebuildippool
 +
</pre>
 +
 +
 +
 +
 +
== MySQL ==
 +
 +
=== One Liners ===
 +
 +
See MySQL status. Updates every 1 s.
 +
 +
<pre>
 +
watch -n 1 'mysqladmin proc stat'
 +
</pre>
 +
 +
Optimize Tables.
 +
 +
<pre>
 +
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
 +
</pre>
 +
 +
MySQL check that will: check all databases, analyze, optimize and repair. Pretty useful, usually safe.
 +
 +
<pre>
 +
mysqlcheck -Aaor
 +
</pre>
 +
 +
Dump a database.
 +
<pre>
 +
mysqldump database > database.sql
 +
</pre>
 +
 +
Import a database.
 +
<pre>
 +
mysql database < database.sql
 +
</pre>
 +
 +
===Viewing and Deleting Tables and Databases===
 +
Look at databases and tables.
 +
 +
<pre>
 +
mysql
 +
> use databasename;
 +
> show tables;
 +
</pre>
 +
 +
Drop (delete) a database. Can be useful if importing a database and it gives you an error.
 +
 +
<pre>
 +
mysql
 +
> drop database databasename;
 +
</pre>
 +
 +
=== 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
 +
/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
 +
/scripts/mysqltuner.pl
 +
 +
 +
===Upgrading MySQL===
 +
{{Box Warning| '''If they are upgrading from 4.0 to 5.0 or 5.1 or from 4.1 to 5.1 please incrementally upgrade and then run a mysqlcheck -Agr during the upgrade to the next version''' (If old current MySQL version is pre-5.x, just do mysqlcheck -Ar)}}
 +
 +
If pre-MySQL 5.0:
 +
 +
<pre>
 +
mysqlcheck -Aaor
 +
</pre>
 +
 +
If MySQL 5.0 to 5.1:
 +
 +
<pre>
 +
mysqlcheck -Agr
 +
</pre>
 +
 +
And back up all the databases:
 +
 +
<pre>
 +
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
 +
</pre>
 +
 +
=== 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:
 +
 +
log-slow-queries=/var/lib/mysql/slow.log
 +
 +
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.
 +
 +
 +
==PHP==
 +
 +
===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

Revision as of 02:46, 28 October 2011

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

Starting Points

Who is on the server?

w

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

Apache Status

/usr/bin/lynx -dump -width 500  http://127.0.0.1/whm-server-status | less

Apache connection

/usr/bin/lynx -dump -width 500 http://127.0.0.1/whm-server-status | 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

MySQL

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.

/var/lib/mysql/examplehostname.err


Then check MySQL settings

vim /etc/my.cnf

Network Stuff

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

 service ipaliases restart
 /scripts/rebuildippool



MySQL

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.

mysql
> use databasename;
> show tables;

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

mysql
> 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
/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
/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:

log-slow-queries=/var/lib/mysql/slow.log

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.


PHP

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