VPS Troubleshooting

From DreamHost
Jump to: navigation, search

VPS

Symptoms of an Overloaded VPS

If you experience any of the following symptoms, most likely you will need to increase the resource allocation (Memory) on your VPS:

  1. Out of memory
  2. Restarts
  3. Inability to log in ("ssh_exchange_identification: Connection closed by remote host")

Checking your Daily & Monthly Resource Usage

You can check the daily & monthly usage graph in the Control Panel under (VPS > Manage Resources). The graphs record usage every 5 minutes. This means that if there are any spikes in usage they more then likely will not show up in these graphs.

Changing your Memory Allocation

You can increase or decrease your resource allocation by moving the blue slider in the Control Panel under (VPS > Manage Resources). As you move it the amount of memory will update automatically, along with the rate you'll be charged for that setting. Once you're happy with the setting click on the "Change {servername}'s resources now!" button to push the change into place. It will take a short period of time for the setting change to be reflected. Typically no reboot is necessary.

Rebooting your VPS

If you have a problem you can try rebooting your VPS yourself in the Control Panel under (VPS > Reboot Server).

No need to contact support for that! Isn't that cool?! It may temporarily fix things, but if it doesn't provide a long-term solution, you may want to contact support to see what is causing the problem!

Overloaded VPS

It is recommended that you start out by doubling your current resource allocation to see if it's enough. Once you've verified that things are running properly you can reduce your resource allocation to the point where your peaks just barely exceed what you have allocated. Of course you'll want to routinely monitor your usage and increase the resource allocation as your needs increase. It's best to over allocate then under allocate! You don't want to find out that you've under allocated by your visitors/customers complaining about your sites not working properly.

Note that you're only charged for the period of time that you have the slider in a particular position. So it's safe to experiment. In fact, we recommend it. You can increase or decrease your resource allocation at any time. You can even use a 3rd party memory manager that utilizes the DreamHost API to automatically adjust your memory based on usage. Keep in mind this is not something DreamHost can support for you.

You will typically see Apache processes running on your server and appearing to consume all of the memory. This is generally not the case because Apache processes share a significant amount of memory between one another. Additionally, we automatically configure Apache to work well within the memory allocation of your PS server. It is still possible for a busy website to overwhelm a VPS server, but it is not generally the fault of the Apache web server itself. The processes you should be most concerned with would be the PHP processes. PHP sites that are not optimized can use an extremely large amount of memory.

Of course you may also want to try to reduce your load on the server as well so you can reduce the resource allocation and save some money.

Changing web server

Apache web server on DH is configured in process-based mode. This means that each process serves one simultaneous connection and uses significant amount of memory for that, thus limiting concurrent user count. Dreamhost now has the option to change your web server to (lighttpd) or (nginx) right within the panel. These servers use async i/o and can handle large count of concurrent connections without consuming much RAM, especially when serving static files. Most of the time Apache is more than sufficient, but if your site is receiving very heavy traffic you may wish to look into Nginx or Lighttpd.

Linux Commands to troubleshoot your VPS

There are many ways to keep track of your VPS' Memory and CPU usage. If you start to notice that your VPS went from 60MB of memory usage a day to 250MB of memory usage a day, you should probably take a good look at what is going on behind the scenes. You can always do a Reboot of the server (please remember that your website will be down temporarily while your server restarts) but when there is an underlying issue that you are having a hard time figuring out what is really going on, might as well dig into the log files and see what is really eating up the memory. Here are a few commands that will help pin-point high memory usage and high CPU usage.

Please note that these commands are used to help pin-point any high usage processes and are just used to help you in your journey of troubleshooting your server.

Running TOP to see CPU Utilization and Memory Usage per Process

top

Top has a few shortcut keys that are available:

Shortcut Key Description
t Displays summary information on and off.
m Displays memory information on and off.
A Sorts the display by top consumers of various system resources. Useful for quick identification of performance-hungry tasks on the system.
f Enters an interactive configuration screen for top. Helpful for setting up top for a specific task.
o Enables you to interactively select the ordering within top.
r Issues renice command.
k Issues kill command.
z Turn color/mono on and off.

Linux CPU utilization with mpstat and other Linux Tools

apt-get install sysstat

If you are using SMP (Multiple CPU) system, use mpstat command to display the utilization of each CPU individually. It report processors related statistics. Basic usage:

mpstat

The mpstat command display activities for each available processor, processor 0 being the first one. Global average activities among all processors are also reported. The mpstat command can be used both on SMP and UP machines, but in the latter, only global average activities will be printed.:

mpstat -P ALL

Report CPU utilization

sar

Comparison of CPU utilization.The sar command writes to standard output the contents of selected cumulative activity counters in the operating system. The accounting system, based on the values in the count and interval parameters. For example display comparison of CPU utilization; 2 seconds apart; 5 times, use:

sar -u 2 5

To get multiple samples and multiple reports set an output file for the sar command. Run the sar command as a background process using.

sar -o output.file 12 8 >/dev/null 2>&1 &

Better use nohup command so that you can logout and check back report later on:

nohup sar -o output.file 12 8 >/dev/null 2>&1 &

All data is captured in binary form and saved to a file (data.file). The data can then be selectively displayed ith the sar command using the -f option.

sar -f ~/log/data.file

Find out what process is troublesome

Display the top 10 processes that are using memory on your VPS.

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

or

ps -eo pcpu,pid,user,args | sort -r -k1 | less

Display memory usage and details of specific process

top -b -n 1 | grep -i [EnterProcessName]

or by username:

top -U [EnterUsername]

Display Memory Usage with /proc/meminfo

ps aux --sort pmem

Use the following command to view memory usage over time (would require you to repeat the command or usage of a CRONJOB):

ps ev --pid=[EnterPID]

To display all currently running processes and detailed information, use:

ps -ef

and on most systems:

ps -aux

You can find a memory leak by running:

ps aux --sort pmem
ps ev --pid=[HighestEnterPID]

iostat to view CPU usage, Disk activity and Network Filesystems

iostat

Log File Details for Troubleshooting

Now, after a conversation with Dreamhost Technical Support they did provide a few helpful commands to dig through your log files to find troublesome IP Addresses and issues. This command shows what domain/sub-domain is getting the most hits:

for k in `ls -S /home/*/logs/*/http/access.log`; do wc -l $k |
sort -r -n; done | head

Followed by the next command that will find out what is being accessed the most on the domain or sub-domain:

/home/[EnterYourUsername]/logs/[EnterYourDomain]/http# awk '{print
$7}' access.log|cut -d? -f1|sort|uniq -c|sort -nk1|tail -n10

or you can create a simple bash script to do so as shown below, which I have called mostviewed.sh:

#!/bin/bash

echo "Show files that are being accessed the most on the domain specified $2"
/home/$1/logs/$2/http# awk '{print
$7}' access.log|cut -d? -f1|sort|uniq -c|sort -nk1|tail -n10

exit

with the Usage of that script being (Don't forget to chmod +x ./mostviewed.sh):

./mostviewed.sh username domain

then check for IP Abuse by running:

/home/[EnterYourUsername]/logs/[EnterYourDomain]/http# cat
access.log| awk '{print $1}' | sort | uniq -c |sort -n | tail

To learn more about how to block IP Addresses and Hostnames you can visit the following websites:

See also

External link