Sunday, April 17, 2011

VPS Guide to improving

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:

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

2. Access to your Web Host Support for installation of

3. Root access to your VPS via SSH

4. FTP Access to your server

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

6. How to restart mysql & apache in your server operating environment

7. Access to WHM

Viewing your PHPinfo
Create a file called phpinfo.php & include the follow in it:
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 180Uncheck 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_connectionswait_timeoutthread_cache_sizetable_cachekey_buffer_sizequery_cache_sizetmp_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:
[mysqld]max_connections = 300key_buffer = 32Mmyisam_sort_buffer_size = 32Mjoin_buffer_size = 1Mread_buffer_size = 1Msort_buffer_size = 2Mtable_cache = 4000thread_cache_size = 286interactive_timeout = 25wait_timeout = 7000connect_timeout = 10max_allowed_packet = 16Mmax_connect_errors = 10query_cache_limit = 2Mquery_cache_size = 12Mquery_cache_type = 1tmp_table_size = 16Mskip-innodb[mysqld_safe]open_files_limit = 8192[mysqldump]quickmax_allowed_packet = 16M[myisamchk]key_buffer = 64Msort_buffer = 64Mread_buffer = 16Mwrite_buffer = 16M[mysqlhotcopy]interactive-timeout
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:
KeepAlive OnMaxKeepAliveRequests 100KeepAliveTimeout 1MinSpareServers 5MaxSpareServers 10StartServers 5MaxClients 150MaxRequestsPerChild 1000
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
top - 19:56:30 up 27 days,  4:11,  1 user,  load average: 0.04, 0.07, 0.09Mem:    524288k total,   386432k used,   137856k free,        0k buffers
View the original article here

No comments: