2009-01-04

When you get to the level where you start needing VPS’ (Virtual Private Servers) it’s important to understand how they work & how you can get the most out of them. Poorly set up servers can cause you all sorts of problems like Downtime, Slow MYSQL or not withstanding the force of something like Digg.

This article will cover everything you need to do to ensure that your VPS is performing as fast as possible, which mostly focuses on optimizing your memory usage. Please ensure you make backups of your existing my.cnf & httpd.conf we will not be held responsible for any problems.

What you will need to action this guide:

Your server specs (most importantly Guaranteed RAM & Burst RAM)

Access to your Web Host Support for installation of

Root access to your VPS via SSH

FTP Access to your server

A brief knowledge of an editior (i.e. VI) if not I’ll provide the commands you need to know

How to restart mysql & apache in your server operating environment

Access to WHM

Viewing your PHPinfo

Create a file called phpinfo.php & include the follow in it:

[coolcode]
[/coolcode]

Navigate to that file on your server i.e. http://www.yourserver.com/phpinfo.php, you should see something like this:



What you need to ask your host to do:

Ensure that you have the latest PHP version (currently 5.28)

Make sure that PHP is compiled with the latest version of Zend Optimizer, Eaccelerator & Ioncube Accelerator.

Ensure that you have the latest apache version (currently 2.0.63)

Viewing your current resource usage

Log in via SSH, I normally use the Putty client for this.

Commands:

top: your current server load & resource usage.

ps aux: all your processes & which ones are using the most memory/cpu

free -m: allocated memory, usage & free memory



If you use the top command you can get an overview of the load on the server & memory usage. You can see in the screenshot above my VPS has a load of 0.02 during the last 1minute, 5 minutes & 10 minutes.

No-one really knows what the ideal “load average” should be but my general rule is that anything over below 1 is good & above 1 is average. Above 3 & you may start to notice performance issues.

With memory usage you should ideally have 100MB or so free (if not more), you really need that buffer for large traffic spikes. If you’re coming close to your allocated memory usage then any allocated burst ram will kick in. On my server I have no burst ram, just guaranteed which means I don’t have that buffer, but my system is more stable (as everyone on the VPS can make use of the burst ram).

Removing & Tweaking Unnecessary Services

There’s a number of services that you can remove or tweak to increase performance. To remove any of these services log into WHM & go to Service Configuration > Service Manager or Cpanel > Plugins in the left menu.

Clamd: This is a virus scanning service, it uses up a ton of memory do generally I’ll remove it.

Entropy Chat: Disable this.

Spamd: This uses a lot of processes & memory. You shouldn’t remove this, instead we can tweak it. Go to Cpanel > Plugins & install spamdconf, once done go to the bottom of WHM & click on Setup Spamd Startup Configuration. Change the maximum children to 1 or 2. This will stop spamd spawning too many child processes.

Cpanel Tweak Settings

In WHM under Server Configuration > Tweak Settings:

Make sure default catch-all mail address is set to FAIL, this will use the least CPU time.

Untick Mailman, this is a resource hog.

Change the number of minutes between mail server queues to 180

Uncheck Analog Stats, I also usually uncheck Webalizer.

Make sure you tick delete each domains access logs after run, otherwise you’ll start using heaps of Disk Space.

Mysql Optimisation

You can edit your mysql configuration (/etc/my.cnf) by typing vi /etc/my.cnf

In order to add something in vi you need to hit insert, once completed hit esc then :wq to save & quit. If you want to save without quitting type :q!

There’s a few important variables that we’re going to tweak:

max_connections

wait_timeout

thread_cache_size

table_cache

key_buffer_size

query_cache_size

tmp_table_size

Via ssh you can type ‘mysqladmin variables’ to see their current values & you can also see a refreshed processlist by using the command ‘mysqladmin –i10 processlist extended-status’.

The settings below should work well for a server with 512MB Guaranteed RAM (also leaving you enough free for traffic spikes), if you have burstable then you can probably look at increasing the number of max_connections to 400 & possibly the key_buffer to 64M:

[coolcode]

[mysqld]

max_connections = 300

key_buffer = 32M

myisam_sort_buffer_size = 32M

join_buffer_size = 1M

read_buffer_size = 1M

sort_buffer_size = 2M

table_cache = 4000

thread_cache_size = 286

interactive_timeout = 25

wait_timeout = 7000

connect_timeout = 10

max_allowed_packet = 16M

max_connect_errors = 10

query_cache_limit = 2M

query_cache_size = 12M

query_cache_type = 1

tmp_table_size = 16M

skip-innodb

[mysqld_safe]

open_files_limit = 8192

[mysqldump]

quick

max_allowed_packet = 16M

[myisamchk]

key_buffer = 64M

sort_buffer = 64M

read_buffer = 16M

write_buffer = 16M

[mysqlhotcopy]

interactive-timeout[/coolcode]

Apache Optimisation

Apache settings are located in httpd.conf, you can use ‘locate httpd.conf’ or ‘whereis httpd.conf’ to find it.

Optimal settings for apache should look something like this, I like to keep the min & start servers slightly lower to stop too many child processes spawning & using memory:

[coolcode]

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 1

MinSpareServers 5

MaxSpareServers 10

StartServers 5

MaxClients 150

MaxRequestsPerChild 1000[/coolcode]

Restarting Mysql & Apache

Once you’re done you’ll want to restart mysql & apache. You can do this via the command line or via WHM.

Restart Mysql: /etc/init.d/mysql restart (if mysql doesn’t restart consider commenting out skip-innodb in my.cnf)

Restart Apache: /etc/init.d/httpd restart

These commands may vary depending on what your server is running.

Monitoring Changes

Use the ‘top’ command, ‘free – m’ & ‘ps aux’ to get an idea of how the server is responding. Pay attention to how much RAM you have left & also how much CPU Mysql & Apache is using. You may need to leave Mysql running for 24-48 hours to get a true picture here.

Thinking about upgrading to a VPS but not sure who to choose, let us help you with our VPS Web Hosting Reviews, tailored specifically for Affiliate Marketers or check out some VPS Coupons also check out PhotonVPS

[coolcode]top – 19:56:30 up 27 days, 4:11, 1 user, load average: 0.04, 0.07, 0.09

Mem: 524288k total, 386432k used, 137856k free, 0k buffers[/coolcode]

---
Related Articles at Affiliate Marketing Blog | How to Earn Money Online - Earners Blog:

Seo Book Review, Search Engine Optimization Book

Diggproof & Speed up Your WordPress Blog

Ebay ditches Commission Junction

SEO Blogs Don’t Make Money

Link Building Guide Part 1 – Thank You Mr Yahoo

Get Coupons, Deals & Reviews for your favourite online stores at StoreCrowd

Show more