วันพุธที่ 27 ตุลาคม พ.ศ. 2553

split /var/log/message log

I'm using gentoo and vixie-cron as a system cron. After using it for a while, I found that gentoo store cron log in to /var/log/message. And, I just kind of like to split this for monitoring easily. Here is what I have done.

edit this :
/etc/syslog-ng/syslog-ng.conf

add the following lines :
filter f_cron { facility (cron); };
destination cron { file("/var/log/cron.log"); };
log { source(src); filter(f_cron); destination(cron); };

reload syslog-ng :
/etc/init.d/syslog-ng reload

you may need to setting the logrotate. Please see the example in /etc/logrotate.d/ for example

วันอังคารที่ 19 ตุลาคม พ.ศ. 2553

terminal key map

Some ssh client need config for special button.
You can use this value to map the keyboard button to this value perform function properly.

Home \033[1~
Delete \033[3~
End \033[4~
Page Up \033[5~
Page Down \033[6~

วันพุธที่ 6 ตุลาคม พ.ศ. 2553

find command with -exec options

find command is quite a handy tool for file searching. It can also include an command to execute for matched file with

1) -exec command ;
2) -exec command {} +

Both are different.
Let say you have 3 files, a b c in the directory.

#find . -exec echo '{}' >> tmp1 \;
output in tmp1 will be :
.
./b
./a
./c
./tmp1

#find . -exec echo '{}' >> tmp2 \+;
output in tmp2 will be :
a b c

with + all matched file will be append and execute once.
with ; all matched file will be execute for each matching.

วันศุกร์ที่ 10 กันยายน พ.ศ. 2553

Gentoo prebuilt package installation

With gentoo, you can customize every packages you want because gentoo give that choices to you. Emerge, package manager, will built package for you from source code. However, compiling package in gentoo can be very time-consuming task, Especially, when you have more gentoo system. I have found option of emerge that can build package and you can use this prebuilt package to other system.

(1) build package
#quickpkg mysql
- This will build package from files on your system. If the package you wanna built are on the system already.


#emerge -b mysql
-the -b(--buildpkg) option tell emerge to do additional task when installing package to the system.

*In this case(mysql), the prebuilt package will be available in /usr/portage/packages/dev-db/ directory.

(2) use prebuilt package
Place the prebuilt package in appropriate directory, in this case : /usr/portage/packages/dev-db/
#emerge --usepkgonly mysql

For more information please consult the man page :
#man emerge
#man quickpkg
#man make.conf

วันอังคารที่ 7 กันยายน พ.ศ. 2553

Install windows font in linux(ubuntu)

Linux user cannot avoid living with windows user. That make linux users to adjust ourselves to read file from windows including fonts they using.

(1) using font package
#sudo apt-get install msttcorefonts

#sudo fc-cache -fv


(2) copying font files from windows
copy *.ttf font to /usr/share/fonts/truetype/thai

#fc-cache -fv

reference
1. ms-font package installation [here]

วันจันทร์ที่ 30 สิงหาคม พ.ศ. 2553

mtime, ctime, and atime timestamp Linux

Recently, I've implemented a caching system. This involve removing old file from the cache. One important factor for making a decision is a file timestamp. There are many timestamp implemented in the file system here are method for viewing timestamp info.

mtime, ctime, and atime

atime - access time
mtime - if modify time
ctime - of change time

To view atime

ls -lu

To view ctime

ls -lc

To view mtime

ls -lt

Access time is when last time data from the file was access.

Modify time is when last change was done to the file.

Change time id when you change owner.

Or

Use stat command

stat filename

stat newname2.txt
File: `newname2.txt'
Size: 13 Blocks: 8 IO Block: 4096 regular file
Device: 805h/2053d Inode: 2338058 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2011-01-28 16:01:10.000000000 +0700
Modify: 2011-01-28 16:02:35.000000000 +0700
Change: 2011-01-28 16:06:26.000000000 +0700

to verify with ls command
--
References :

วันพุธที่ 4 สิงหาคม พ.ศ. 2553

Gentoo migration to raid

At some point, high availability become more essential to your server. Raid1(mirror) can help server to be able to continue even the disk go wrong. This blog is intend to be a complete just-type-guide for system admin. I hope that you guy succeeded in this migration

Background my system is gentoo on sda. The new disk will be sdb. After finishing copying data to sdb. The another new disk will be replace as sda. sda and sdb will be raid1 mirroring each other.

#0 move running service to another system
- make sure that the system can be down for maintainance


#1 shutdown system
shutdown -h now

#2 install new hdd as sdb
some vendor disable port B (for sdb) please make sure that it is enable so it can be visible from linux.

#3 boot system with live cd
modprobe raid1

#4 format disk and create raid on sdb
available 500GB
-> sdb1 boot 1GB ext2
-> sdb5 root entire ext3
-> sdb6 swap 4GB swap
cfdisk /dev/sdb
cd /dev && MAKEDEV md
mdadm --create /dev/md1 --level=1 --raid-devices=2 missing /dev/sdb1
mdadm --create /dev/md5 --level=1 --raid-devices=2 missing /dev/sdb5
mke2fs /dev/md1
mke2fs -j /dev/md5
mkswap /dev/sdb6
swapon /dev/sdb6


#5 copy data from sda to raid
mkdir /mnt/gentoo1
mount /dev/sda5 /mnt/gentoo1
mount /dev/md5 /mnt/gentoo
mount /dev/sda1 /mnt/gentoo1/boot
mkdir /mnt/gentoo/boot
mount /dev/md1 /mnt/gentoo/boot
cp -dpRx /mnt/gentoo1/* /mnt/gentoo/


#6 install boot loader to raid
mount -t proc none /mnt/gentoo/proc
mount -o bind /dev /mnt/gentoo/dev
chroot /mnt/gentoo /bin/bash
env-update
source /etc/profile
export PS1=”(chroot) $PS1”
#Edit grub.conf change root=/dev/sdaxx to mdxx
nano /boot/grub/grub.conf
#install boot loader to the disk
grub –no-floppy
- device (hd0) /dev/sdb
- root (hd0,0)
- setup (hd0)

#7 edit fstab to mount disk on raid instead // or just copy from preedit @ /home/username/fstab
nano /etc/fstab

#8 shutdown & replace sda with new disk
exit
cd /
umount /mnt/gentoo/boot /mnt/gentoo/proc /mnt/gentoo/dev /mnt/gentoo
umount /mnt/gentoo1/boot /mnt/gentoo1
shutdown -h now
-replace new disk


#9 sync disk and install boot loader
-change bios priority to start boot from sdb
sfdisk -d /dev/sdb | sfdisk /dev/sda
mdadm --add /dev/md1 /dev/sda1
mdadm --add /dev/md5 /dev/sda5
#edit fstab add sda as swap
nano /etc/fstab
mkswap /dev/sda6
swapon /dev/sda6
grub –no-floppy
- device (hd0) /dev/sda
- root (hd0,0)
- setup (hd0)


#wait until sync finish
- reboot test
- restore bios boot priority
- restore sevice back to the server.

วันศุกร์ที่ 23 เมษายน พ.ศ. 2553

Mounting file as filesystem

Linux provide various and flexible file system for user to choose.

Here are an example

Create empty 10 Mb file.
#dd if=/dev/zero of=file.img bs=1k count=10000

Attach the file to loopback file system
#losetup /dev/loop0 file.img

Create file system on loopback device
#mke2fs -c /dev/loop0 10000

Mount loopback device
#mount -t ext2 /dev/loop0 /mnt/point1

So you can have any file system on any file system.

To find out more detail about file system please visit the following links :
-Anatomy of file system

-Cryptographic File Systems Performance

-Loopback Tricks

วันศุกร์ที่ 12 มีนาคม พ.ศ. 2553

วันพุธที่ 10 มีนาคม พ.ศ. 2553

Configuring gentoo apache with fcgi

mod php and worker are not stable as PHP official page.

Gentoo user might not aware this because we can compile PHP with threads use flag without realizing the warning.

Before get start with apache-worker fcgid and php. You need the following :
1) installed PHP with cgi use flag.
2) installed mod_fcgid (emerge mod_fcgid)

PHP configuration :
- modify /etc/php/cgi-php5/php.ini to suite your need.

apache configuration :
- modify /etc/apache2/modules.d/20_mod_fcgid.conf adding the following in
AddHandler fcgid-script .php .fcgi
DefaultInitEnv PHPRC "/etc/php/cgi-php5"

IdleTimeout 60
BusyTimeout 120
ProcessLifeTime 360
SpawnScoreUpLimit 2100
MaxProcessCount 2100
DefaultMaxClassProcessCount 2100
IPCConnectTimeout 120
IPCCommTimeout 120

FCGIWrapper /usr/bin/php-cgi .php

Please change the /usr/bin/cgi/ to your path. And don't forget to add +ExecCGI to option directive.

- edit /etc/conf.d/apache2 add -D FCGID to APACHE2_OPTS

restarting apache.

วันอังคารที่ 9 มีนาคม พ.ศ. 2553

Monit : debuging monit process

Misconfiguration on apache can lead monit false alet and do wrong action. I found that some monit process in one of my servers always complaining about apache cannot connect port 80. which is not right cause I can still access the pages.

Here are tip for debugging what goes wrong:

1) stop monit as a daemon
2) smart monit in foreground
#monit -Iv
3) see the message

From my experience, the server response with 403 http code cause monit alert cannot connect host port 80.
So, I change apache config to get 200 code and everything back to work :)

Monit : server monitoring tools

If you have a web server, have you ever experience apache process not responding to http request?

or

How to make sure that apache are running? and If server load go too high please restart it for me.

Monit can help you monitoring common for system admin.


It can monitoring server process, file size, memory server load. And, you can set the appropriate action to those events: sending email, restart process etc.

To install monit
for gentoo :
#emerge -av monit
for debian:
#apt-get install monit

Configuring monit
Locate configuration file : /etc/monitrc or /etc/monit/monitrc
Here is the example configuration for apache with these condition
1) check whether apache is running : if not restart
2) check http:80 is working : if not restart
3) if server go to high : restart apache process
set daemon 120

set mailserver smtp.localhost


set mail-format { from: admin@localhost.com }

set alert systemadmin@localhost.com


check process apache with pidfile /var/run/apache2.pid
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if failed port 80 protocol http then restart
if loadavg(5min) greater than 100 for 2 cycles then restart
alert extrapeople@localhost.com

If you are interested in monit for advance feature please visit monit official site.
check out monit document

วันศุกร์ที่ 5 มีนาคม พ.ศ. 2553

Advance php error handling

PHP server need different configuration for production and development server.

This article help you understanding php.ini configuration better and applicable to your server.

- display_errors
echo error to the browser this should be turn off for production but should be enable for test server.

- log_errors
instead of displaying error to stderr, you can choose to enable error logging to the file instead for production.

More option can be study here :
http://perishablepress.com/press/2008/01/30/advanced-php-error-handling-via-php/

apache with fcgid

Once, I used gentoo with apache(worker) + phpmod as a webserver. After switching to ubuntu, I've found that phpmod is not stable with apache(worker), this is not a problem with gentoo b'coz u can customize everything by yourself.

Up to this point ,there are 2 choice for ubuntu apache works with php
1) use apache prefork + phpmod
2) use apache worker + cgi + php

More description about fcgid/fastcgi http://www.seaoffire.net/fcgi-faq.html

I found the following study show that fcgid might be a good choice. And, it is.
http://2bits.com/articles/apache-fcgid-acceptable-performance-and-better-resource-utilization.html

For fcgid reference for apache :
http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html

วันพฤหัสบดีที่ 4 มีนาคม พ.ศ. 2553

monitoring mysql with cacti

By default, cacti don't come with mysql graphing template. Here is the plugin that help you graphing mysql important data.

The installation is like the other plugins.
1) copy php script to cacti host /script directory
2) import template using web interface
3) add mysql user to mysql host
4) have fun :)


plugin document/download :
http://code.google.com/p/mysql-cacti-templates/wiki/InstallingTemplates

author blog:
http://www.xaprb.com/blog/2009/10/25/version-1-1-4-of-improved-cacti-templates-released/

วันพุธที่ 17 กุมภาพันธ์ พ.ศ. 2553

Apache Mod setenvif

Some software/browser didn't follow the standard or have some bugs. I found that MSIE 6 have problem with richtext editor -javascript. Mod setenvif can be used to set special variable to correct the problem.



In file: /etc/apache2/mods-enabled/setenvif.conf
BrowserMatch "MSIE 4\.0b2;" gzip-only-text/html
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0

With this line apache the user with MSIE6 will be:
-send gzip format for text/html only
-disable keepalive
-downgraded request to HTTP 1.0
-response with HTTP 1.0

To find our more directive of this mod.
http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html

There are more interesting variable that can be set.
http://httpd.apache.org/docs/2.2/env.html

วันศุกร์ที่ 12 กุมภาพันธ์ พ.ศ. 2553

Ubuntu package management & package installed for web server

Update list of package
#apt-get update

Upgrade all package in system
#apt-get upgrade

To install package
#apt-get install foo

To remove package
#apt-get remove foo
-remove configuration on the system
#apt-get --purge remove for

To upgrade all packages on the system
#apt-get dist-upgrade

apt-cache : query package list tool

To find packages whose description contain word:
#apt-cache search word

To print the detailed information of a package:
#apt-cache show package

To print the packages a given package depends on:
#apt-cache depends package

#To print detailed information of the versions available for a package and the packages
that reverse-depends on it:
apt-cache showpkg package



PHP package
php5
php5-cgi
php5-cli
php5-curl
php4-common
php5-gd
php5-imagick
php5-memcache
php5-mysql
php5-xcache
libapache2-mod-fcgid
nfs-kernel-server


Apache package
apache2
apache2-mpm-worker
apache2-utils
apache2.2-bin
apache2.2-common
libapache2-mod-fcgid


Apache Ubuntu vs Apache gentoo
add user apache with uid81 (gentoo)
#useradd -r -u 81 apache

edit /etc/apache2/envvars to run apache with user apache

Reference :
A Debian Package Primer: Part One
Aptitude :part two
Ubuntu Community Doc.

วันพฤหัสบดีที่ 11 กุมภาพันธ์ พ.ศ. 2553

Understanding apache config order in debian/ubuntu

In ubuntu, i've found a lot of config file for apache. To identify the problem, you need to know which config loading sequence which might overwrite another one.

/etc/apache2

1) apache2.conf - define #process, timeout etc...
2) mods-enabled/*.conf - module configuration
3) httpd.conf (user configuration)
4) ports.conf - port listening
5) conf.d/*- generic snippet statement - charset localized-error-pages, security
6) sites-enable/* -all vhost

xcache opcode/optimizer for php tunning

Installing xcache can help php-apache app responding faster.

1) installing xcache
gentoo :
#emerge cache
ubuntu/debian
#apt-get install php5-xcache

after installing you will see path for xcache admin
2) set xcache config and admin password
#echo -n "yourpassword" | md5sum
edit xcache.ini this line :
xcache.admin.pass="" (from previous command)
http://xcache.lighttpd.net/wiki/XcacheIni

3) point apache to xcache admin path

4) browse xcache admin with browser

use this admin page to see what variable need to be adjusted.

I'll point some importtatn config

xcache.size
- set just fit, not too low or too high. see OOM(out of memory column) from admin page. If there are lots of OOM, please consider increasing.

xcache.count
- set to number of your cpu : cat /proc/cpuinfo | grep -c processor

xcache.slots
- the more slot, the faster PHP code accessing


More reading here :

วันอังคารที่ 9 กุมภาพันธ์ พ.ศ. 2553

rrdtool tune rra file

Using SNMP and cacti, you need to adjust rrd file manually for displaying graph correctly.

/cacti/rra
show file info to see the limitation of value
#rrdtool info filename.rrd

tunning it
#rrdtool tune filename.rrd --maximum cpu_user:800

วันจันทร์ที่ 8 กุมภาพันธ์ พ.ศ. 2553

gentoo SNMP

Installing SNMP in gentoo for system monitoring.


#emerge net-snmp

edit /etc/snmp/snmpd.conf add the following
com2sec Mybox localhost public
com2sec cacti 192.168.1.0/24 public

group RWGroup v2c Mybox
group ROGroup v1 cacti
group ROGroup v2c cacti

view all included .1 80
view system included system fe

access ROGroup "" any noauth exact all none none
access RWGroup "" v2c noauth exact all all all

#rc-update add snmpd default

วันพฤหัสบดีที่ 21 มกราคม พ.ศ. 2553

timer shell script

To measure performance, you might want to know how much does it take to complete the task.
Here are shell script to help you.

The following measure hard disk performance by creating 10 GB file.
#!/bin/bash
START=$(date +%s)
# do something
# start your script work here

dd if=/dev/zero of=/home/user/hd2/file.img bs=1M count=1000

# your logic ends here
END=$(date +%s)
DIFF=$(( $END - $START ))

echo "It took $DIFF seconds"

Nginx / lighttpd light weight web server.

Apache is a standard for web server. But, you can help apache and utilize computing resource by using lighttpd and nginx as a helper for static content/load balancer for your website.

nginx :
http://wiki.nginx.org/NginxModules
lighttpd
http://redmine.lighttpd.net/wiki/lighttpd

วันพุธที่ 20 มกราคม พ.ศ. 2553

webserver http-caching header

Here are link to speed up your http server :

http://www.mnot.net/cache_docs/
http://www.web-caching.com/

User & group management : uid, gid user

If you share file about variety distro of linux, you might experience with permission error.

The following command help to change uid, gid of user apache group apache to 81 :
#usermod -u 81 apache
#groupmod -g 81 apache
#id apache


Read more:

วันอังคารที่ 12 มกราคม พ.ศ. 2553

How to monitor harddisk with smartmontools

Now let's install the smartmontools package:

# emerge -av smartmontools

Finally, you have to check if your hard disk(s) support SMART:

# smartctl -i /dev/hda

For SATA drives:

# smartctl -i -d ata /dev/sda

Using smartctl

SMART Health Status

Let's check the SMART Health Status:

# smartctl -H /dev/hda

If you read PASSED it's ok, but if you read FAILED you have to backup your data now: the disk has already failed or it's predicted to fail within 24 hours!


To recover from bad block :

http://smartmontools.sourceforge.net/badblockhowto.html

smartmontool document:

http://sourceforge.net/apps/trac/smartmontools/wiki/TocDoc

วันศุกร์ที่ 8 มกราคม พ.ศ. 2553

swappiness tuning linux

vm.swappiness is a tunable kernel parameter that controls how much the kernel favors swap over RAM. At the source code level, it’s also defined as the tendency to steal mapped memory. A high swappiness value means that the kernel will be more apt to unmap mapped pages. A low swappiness value means the opposite, the kernel will be less apt to unmap mapped pages. In other words, the higher the vm.swappiness value, the more the system will swap.

More to read : http://www.linuxvox.com/2009/10/what-is-the-linux-kernel-parameter-vm-swappiness/

The following is the test. It seems that the higher swapiness the slower i/o rate. More to read : http://lwn.net/Articles/100978/

linux memory management

Overview of memory management

Traditional Unix tools like 'top' often report a surprisingly small amount of free memory after a system has been running for a while. For instance, after about 3 hours of uptime, the machine I'm writing this on reports under 60 MB of free memory, even though I have 512 MB of RAM on the system. Where does it all go?

The biggest place it's being used is in the disk cache, which is currently over 290 MB. This is reported by top as "cached". Cached memory is essentially free, in that it can be replaced quickly if a running (or newly starting) program needs the memory.

The reason Linux uses so much memory for disk cache is because the RAM is wasted if it isn't used. Keeping the cache means that if something needs the same data again, there's a good chance it will still be in the cache in memory. Fetching the information from there is around 1,000 times quicker than getting it from the hard disk. If it's not found in the cache, the hard disk needs to be read anyway, but in that case nothing has been lost in time.

To see a better estimation of how much memory is really free for applications to use, run the command free -m:

Code: free -m
             total       used       free     shared    buffers     cached
Mem: 503 451 52 0 14 293
-/+ buffers/cache: 143 360
Swap: 1027 0 1027

The -/+ buffers/cache line shows how much memory is used and free from the perspective of the applications. Generally speaking, if little swap is being used, memory usage isn't impacting performance at all.

Notice that I have 512 MB of memory in my machine, but only 52 is listed as available by free. This is mainly because the kernel can't be swapped out, so the memory it occupies could never be freed. There may also be regions of memory reserved for/by the hardware for other purposes as well, depending on the system architecture. However, 360M are free for application consumption.


The difference among VIRT, RES, and SHR in top output

VIRT stands for the virtual size of a process, which is the sum of memory it is actually using, memory it has mapped into itself (for instance the video card's RAM for the X server), files on disk that have been mapped into it (most notably shared libraries), and memory shared with other processes. VIRT represents how much memory the program is able to access at the present moment.

RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. (This also corresponds directly to the %MEM column.) This will virtually always be less than the VIRT size (there are only very rare cases that they will be equal, and RES will never be more than VIRT).

SHR indicates how much of the VIRT size is actually sharable (memory or libraries). In the case of libraries, it does not necessarily mean that the entire library is resident. For example, if a program only uses a few functions in a library, the whole library is mapped and will be counted in VIRT and SHR, but only the parts of the library file containing the functions being used will actually be loaded in and be counted under RES.

The difference between buffers and cache

Buffers are allocated by various processes to use as input queues, etc. Most of the time, buffers are some processes' output, and they are file buffers. A simplistic explanation of buffers is that they allow processes to temporarily store input in memory until the process can deal with it.

Cache is typically frequently requested disk I/O. If multiple processes are accessing the same files, much of those files will be cached to improve performance (RAM being so much faster than hard drives), it's disk cache.



More to read : http://www.gentoo-wiki.info/FAQ_Linux_Memory_Management

http://forums.gentoo.org/viewtopic-t-175419-postdays-0-postorder-asc-start-0.html

optimize Tortoise SVN cache

From : http://www.paraesthesia.com/archive/2007/09/26/optimize-tortoise-svn-cache-tsvncache.exe-disk-io.aspx


To optimize the disk usage...

  1. Right-click on your desktop and select "TortoiseSVN -> Settings..."
  2. In the tree view, find the "Look and Feel/Icon Overlays" branch.
  3. In the "Exclude Paths" box, put C:\* to exclude the entire C drive. If you have more drives than that, exclude them all at the top level. Separate the values by newlines.
  4. In the "Include Paths" box, list all of the locations you have working copies, separated by newlines. Again, this is easier if you keep all of your working copies in a specific folder or set of folders. Using my example, this is what I put in the "Include Paths" box:
    C:\dev\*
    C:\Documents and Settings\tillig\My Documents\Visual Studio 2005\*
    C:\Documents and Settings\tillig\My Documents\Visual Studio Projects\*


    And here's a screen shot:
    TortoiseSVN icon overlay options - set the "Exclude paths" and "Include paths" values
  5. Click OK to apply the changes.
  6. Either reboot or open Task Manager and kill "TSVNCache.exe" so it restarts when needed. You have to restart it for these options to take effect.

After I did this, the icon overlays still worked great but the disk I/O went down to nearly nothing. YMMV.

วันพุธที่ 6 มกราคม พ.ศ. 2553

Apache Segmentation fault

Recently, I've found the message in
#/var/log/apache2/error_log
[notice] child pid 20295 exit signal Segmentation fault (11)

Getting core dump file : http://www.question-defense.com/2009/07/15/apache-notice-child-pid-27609-exit-signal-segmentation-fault-11

debugin apache : http://httpd.apache.org/dev/debugging.html

Apache document directive for coredump : http://httpd.apache.org/docs/2.0/mod/mpm_common.html

CoreDumpDirectory Directive

Description:Directory where Apache attempts to switch before dumping core
Syntax:CoreDumpDirectory directory
Default:See usage for the default setting
Context:server config
Status:MPM
Module:beos, leader, mpm_winnt, perchild, prefork, threadpool, worker

This controls the directory to which Apache attempts to switch before dumping core. The default is in the ServerRoot directory, however since this should not be writable by the user the server runs as, core dumps won't normally get written. If you want a core dump for debugging, you can use this directive to place it in a different location.

วันอังคารที่ 5 มกราคม พ.ศ. 2553

TCP/networking tunning

Kernel TCP Networking tunning .
You can achieve a high network performance by adjusting some value to to the kernel
From http://www.gentoo-wiki.info/HOWTO_TCP_Tuning
http://blogs.techrepublic.com.com/opensource/?p=62
http://www.freebsd.org/doc/en/books/handbook/index.html

Variables to Change, and suggested Values

net.core.rmem_max="16777216"
This setting changes the maximum network receive buffer size to 16777216 bytes.
net.core.wmem_max="16777216"
The same thing for the send buffer
net.ipv4.tcp_rmem="4096 87380 16777216"
This sets the kernel's minimum, default, and maximum TCP receive buffer sizes. You might be surprised, seeing the maximum of 16M, that many Unix-like operating systems still have a maximum of 256K!
net.ipv4.tcp_wmem="4096 65536 16777216"
A similar setting for the TCP send buffer. Note that the default value is a little lower. Don't worry about this, the send buffer size is less important than the receive buffer.
net.ipv4.tcp_no_metrics_save=1
Moreover, There are a couple of kernel value you should adjust
tcp_max_syn_backlog
somaxconn

วันจันทร์ที่ 4 มกราคม พ.ศ. 2553