3月 232011
 

HOWTO : Home made NAS server with Ubuntu 8.04.1 – Part V
[HOWTO] 用Ubuntu 8.04.1搭建NAS服务器 – Part V

This part is optional. The web server with PHP and MySQL is already running. Now, we are going to fine tune the Apache and PHP to make it running as faster as possible. The kernel can also be optimized too.
这部分是可选的。使用PHP和MySQL的网站已经运行。现在,我们对Apache 和 PHP优化,让它们运行更快一些。内核也能优化的。

Apache

sudo a2enmod deflate
sudo /etc/init.d/apache2 force-reload

Edit the file /etc/apache2/conf.d/deflate.conf :
编辑文件/etc/apache2/conf.d/deflate.conf:
sudo nano /etc/apache2/conf.d/deflate.conf


DeflateCompressionLevel 6
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE application/x-httpd-eruby
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/postscript

Header append Vary User-Agent

Edit /etc/apache2/apache2.conf :
编辑/etc/apache2/apache2.conf :
sudo nano /etc/apache2/apache2.conf

Then change the value as the following :
修改下述行的值:
ServerSignature Off
ServerTokens Prod

Edit /etc/apache2/sites-available/default :
编辑 /etc/apache2/sites-available/default:
sudo nano /etc/apache2/sites-available/default

Then change the value as the following at /var/www section :
修改/var/www区的相应值:
Options -Indexes FollowSymLinks

Restart your Apache server :
重新启动Apache server:
sudo /etc/init.d/apache2 restart

PHP
To accelerate PHP, you need Zend but I will show you how to use eAccelerator.
要加速PHP,需要使用Zend。下面说如何使用它。

Download the eAccelerator :
下载eAccelerator:
wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2
tar xvf eaccelerator-0.9.5.3.tar.bz2

sudo apt-get install build-essential php5-dev

cd eaccelerator-0.9.5.3
phpize
./configure
make
sudo make install

sudo mkdir /tmp/eaccelerator
sudo chmod 0777 /tmp/eaccelerator

Add the following lines at the end of /etc/php5/apache2/php.ini :
在文件/etc/php5/apache2/php.ini末尾加上下述行:

extension=”eaccelerator.so”
; shm_size default is 16, you may change to 64 or 128 depends on your RAM
eaccelerator.shm_size=”16”
eaccelerator.cache_dir=”/tmp/eaccelerator”
eaccelerator.enable=”1”
eaccelerator.optimizer=”1”
eaccelerator.check_mtime=”1”
eaccelerator.debug=”0”
eaccelerator.filter=””
eaccelerator.shm_max=”0”
eaccelerator.shm_ttl=”0”
eaccelerator.shm_prune_period=”0”
eaccelerator.shm_only=”0”
eaccelerator.compress=”1”
eaccelerator.compress_level=”9”

Restart the Apache :
重新启动Apache:
sudo /etc/init.d/apache2 restart

Kernel

Please refer to my blog “Performance-tunning” at http://samiux.wordpress.com/2008/06/12/performance-tunning/ for details.

HOWTO : Performance tuning

Add the following lines to /etc/sysctl.conf if you have 512MB RAM or more :
如果内存多于512M,在/etc/sysctl.conf后增加以下行:

kernel.sem = 250 32000 100 128
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
# If you have more than 512MB RAM, use this setting (uncomment it and comment the setting just below)
#fs.file-max = 256000
# If you have 512MB RAM or less, use this setting
fs.file-max = 65535
vm.swappiness = 1
vm.vfs_cache_pressure = 50

If you have a fast broadband (UL 10Mbps / DL 10Mbps, my broadband connection speed) (other connection speed is not tested), use the following setting :
如果你用的是高速网络(上下行各10M,我的宽带速度,其他的速度没有试验过),使用下面的设置:

net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_no_metrics_save = 1

If you have a Wifi (such as IEEE 802.11 a/b/g) or a 3.5G modem, use the following setting :
如果你使用Wifi(IEEE 802.11 a/b/g)或3.5G modem,使用下面的设置:

net.core.rmem_default = 524288
net.core.rmem_max = 524288
net.core.wmem_default = 524288
net.core.wmem_max = 524288
net.ipv4.tcp_wmem = 4096 87380 524288
net.ipv4.tcp_rmem = 4096 87380 524288
net.ipv4.tcp_mem = 524288 524288 524288
net.ipv4.tcp_rfc1337 = 1
net.ipv4.ip_no_pmtu_disc = 0
net.ipv4.tcp_sack = 1
net.ipv4.tcp_fack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_ecn = 0
net.ipv4.route.flush = 1

Then make the setting effective :
让配置生效:

sudo /sbin/sysctl -p

Lightening Ubuntu!!!!

 回复

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>