20090422

snippets used to research low disk space

Simple snippets useful for troubleshooting low disk space.

Using 'du' against a directory and single filesystem and sorting i
du -hxc --max-depth=1 / | sort -n

Find command that displays the 10 largest files within the defined directory
find /tmp -mount -type f -ls | sort -k 7 -r -n | head -10

snippets used to identify cause of high CPU usage

Snippets useful for investigating high CPU usage

Top 10 CPU consuming processes
ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

Identify device encountering IO wait (x is optional and will display more details)
iostat -x 5

Identify processes encountering IO wait (and usually causing the IO)
ps -eo pid,stat,args,wchan | grep ' D'

And of course the awesome tool of 'sar' that is provided within the 'sysstat' package.

simple snippets to identify memory usage

Simple snippets to identify general memory usage.

Show top 10 memory consuming processes
ps xuaw --sort -rss | head

Display general memory summary
free -m

Display detailed memory breakdown
cat /proc/meminfo

simple mysql health check page

Simple? Yes. Useful? Yes.

Although the below is very simple it can be a very useful and effective way to regularly check apache functionality and its ability to communicate with mysql.

<html>
<head>
<title>Test mysql communications</title>
</head>
<body>
<!--test-->
<?php
$dbhost = 'localhost:3306';
$dbuser = 'trunty';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn)
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($conn);
?>
</body>
</html>

A URL that this can be seen in action is http://dev.linuxismybff.com/test/mysql/mysqltestconnect.php

how to add a new mysql user

How to add a mysql user, define permissions, and set password in one command.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
-> IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
-> IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost';
mysql> GRANT USAGE ON *.* TO 'dummy'@'localhost';

I primarily use the first method, however, obviously different circumstances (permissions) call for different commands.

After you make any permission or user changes be sure to run 'flush privileges;' to apply your changes. (Note: when you restart mysql new changes are applied at this time as well).

Link where information was taken from: http://dev.mysql.com/doc/refman/5.1/en/adding-users.html