Linux Web Server Tuning
- 06/06/2020 8:01 PM
Web Server Optimization Guide for CentOS - RedHat |
I am sure that all web hosts would like to lower the CPU load of their servers, shorten page load times, and boost overall performance. Whether it be to increase profit margin by packing in more customers or to get a Celeron 1.7Ghz handle a popular forum, we can all benefit from server optimization. Below is a compilation of some methods one may use to optimize a web server to serve web pages faster and lower the overall CPU load on the box. The following are some of the best procedures a web host can do to optimize his or her web server 1. Basic Config File Editing Make a backup of your /etc/my.cnf file by simply typing copy /etc/my.cnf /etc/my.cnf.back , and then perform the following via SSH: pico /etc/my.cnf [mysqld] [mysql.server] [safe_mysqld] [mysqldump] [mysql] [isamchk] [myisamchk] Hit CTRL + X to exit and save the file Now to edit the httpd.conf: pico /usr/local/apache/conf/httpd.conf (or wherever your httpd.conf is located) Set "Timeout" value to "Timeout 300" CTRL + X to exit and save the file Restart Apache and MySQL with: Some people may need to restart the services with /etc/rc.d/init.d/httpd restart and /etc/rc.d/init.d/mysql restart The above changes can be altered and played around with to suit your server's needs (i.e. if your server is fast or not). 2. Installing Mod_Perl Mod_Perl description: "mod_perl gives you a persistent Perl interpreter embedded in your web server. This lets you avoid the overhead of starting an external interpreter and avoids the penalty of Perl start-up time, giving you super-fast dynamic content. " Run these commands via SSH: wget http://perl.apache.org/dist/mod_perl-1.0-current.tar.gz tar zxvf tar zxvf mod_perl-1.0-current.tar.gz cd mod_perl-1.29 (or whatever folder is generated) perl Makefile.PL If you see any errors about missing dependencies (such as CGI.pm, LWP::UserAgent & HTML::HeadParser required by mod_perl) you may install them with: perl -MCPAN -e shell If you had to install any dependencies you must re-run "perl Makefile.PL". Back to setting up mod_perl, after perl Makefile.PL run: make Congratulations, you've just installed mod_perl. Restart Apache with: service httpd restart
Description: "Turck MMCache is a free open source PHP accelerator, optimizer, encoder and dynamic content cache for PHP. It increases performance of PHP scripts by caching them in compiled state, so that the overhead of compiling is almost completely eliminated. Also it uses some optimizations to speed up execution of PHP scripts. Turck MMCache typically reduces server load and increases the speed of your PHP code by 1-10 times. " Turck MMCache requires: apache 1.3, mod_php 4.1, autoconf, automake, libtool, m4. You should already have most of these on your server if not use the "apt-get install " command to get them installed. I won't go into detail about this here, you should easily be able to search the net to get them installed. To install Turck MMCache, perform the following commands via SSH: wget http://aleron.dl.sourceforge.net/sou...e-2.4.6.tar.gz export PHP_PREFIX="/usr" $PHP_PREFIX/bin/phpize ./configure --enable-mmcache=shared --with-php-config=$PHP_PREFIX/bin/php-config (You must specify the real prefix where PHP is installed in the "export" command. It may be "/usr" "/usr/local", or something else.) make make install Turck MMCache can be installed both as Zend or PHP extension, so you need to edit your php.ini file (usually /etc/php.ini). zend_extension="/usr/lib/php4/mmcache.so" To install as PHP extension: extension="mmcache.so" You may need to copy the mmcache.so file to the directory specified to the above paths in the configuration entries. Create the cache directory: Restart Apache with: service httpd restart
The sysctl.conf of a server is something that is seldom optimized for performance. You can get a tremendous boost in throughput by adjusting these settings. This configuration has been written by Steve from Rack911. I have applied this configuration to servers ranging from Celeron 1.7Ghz to Dual Xeon 2.8Ghz servers, and on the whole, the load on each lowered after making the changes. First make a backup of your old /etc/sysctl.conf file by running the following command, logged in as root: cp /etc/sysctl.conf /etc/sysctl.conf.bak Now enter: and replace the contents of the file with the following:
# Disables packet forwarding # Disables IP source routing # Enable IP spoofing protection, turn on source route verification # Disable ICMP Redirect Acceptance # Enable Log Spoofed Packets, Source Routed Packets, Redirect Packets # Disables IP source routing # Enable IP spoofing protection, turn on source route verification # Disable ICMP Redirect Acceptance # Disables the magic-sysrq key # Decrease the time default value for tcp_fin_timeout connection # Decrease the time default value for tcp_keepalive_time connection # Turn off the tcp_window_scaling # Turn off the tcp_sack # Turn off the tcp_timestamps # Enable TCP SYN Cookie Protection # Enable ignoring broadcasts request # Enable bad error message Protection # Log Spoofed Packets, Source Routed Packets, Redirect Packets # Increases the size of the socket queue (effectively, q0). # Increase the tcp-time-wait buckets pool size # Allowed local port range CTRL + X to exit and save the file To make your changes take effect immediately, type this command: You can watch your server load by entering "uptime" command via SSH. There you have it, a quick few things you can do to your server to boost performance and lower CPU load. Please feel free to post any comments or suggestions in the forum. |