A brief short linux how to and problem solving. This blog is intended to be a reference by summarizing from reliable data source and my experience. Readers should have a basic understanding about linux.
วันพุธที่ 27 ตุลาคม พ.ศ. 2553
split /var/log/message log
วันอังคารที่ 19 ตุลาคม พ.ศ. 2553
terminal key map
วันพุธที่ 6 ตุลาคม พ.ศ. 2553
find command with -exec options
วันศุกร์ที่ 10 กันยายน พ.ศ. 2553
Gentoo prebuilt package installation
วันอังคารที่ 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
reference
1. ms-font package installation [here]
วันจันทร์ที่ 30 สิงหาคม พ.ศ. 2553
mtime, ctime, and atime timestamp Linux
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.
วันพุธที่ 4 สิงหาคม พ.ศ. 2553
Gentoo migration to raid
วันศุกร์ที่ 23 เมษายน พ.ศ. 2553
Mounting file as filesystem
วันศุกร์ที่ 12 มีนาคม พ.ศ. 2553
The linux documentation project
Here is a good link that worth a look.
Link:
http://tldp.org/guides.html
วันพุธที่ 10 มีนาคม พ.ศ. 2553
Configuring gentoo apache with fcgi
AddHandler fcgid-script .php .fcgiDefaultInitEnv PHPRC "/etc/php/cgi-php5"IdleTimeout 60BusyTimeout 120ProcessLifeTime 360SpawnScoreUpLimit 2100MaxProcessCount 2100DefaultMaxClassProcessCount 2100IPCConnectTimeout 120IPCCommTimeout 120FCGIWrapper /usr/bin/php-cgi .php
วันอังคารที่ 9 มีนาคม พ.ศ. 2553
Monit : debuging monit process
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
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
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
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
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
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
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
#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
วันพฤหัสบดีที่ 11 กุมภาพันธ์ พ.ศ. 2553
Understanding apache config order in debian/ubuntu
/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
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 :
- introduction to xcache http://www.ibm.com/developerworks/opensource/library/os-php-fastapps1/
- set xcache adminpage http://www.linuxtuts.net/
ubuntu-webserver-tutorials/ 228-how-install-xcache- administration-page-ubuntu- linux.html - xcaching tunning http://serveradmins.net/tuning-xcache-for-fun-and-profit/
- xcache ini document http://xcache.lighttpd.net/wiki/XcacheIni
วันอังคารที่ 9 กุมภาพันธ์ พ.ศ. 2553
rrdtool tune rra file
/cacti/rra
show file info to see the limitation of value
#rrdtool info filename.rrd
tunning it
#rrdtool tune filename.rrd
วันจันทร์ที่ 8 กุมภาพันธ์ พ.ศ. 2553
gentoo SNMP
#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
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.
nginx :
http://wiki.nginx.org/NginxModules
lighttpd
http://redmine.lighttpd.net/wiki/lighttpd
วันพุธที่ 20 มกราคม พ.ศ. 2553
webserver http-caching header
http://www.mnot.net/cache_docs/
http://www.web-caching.com/
User & group management : uid, gid user
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
วันอังคารที่ 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/hdaIf 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
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 |
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
To optimize the disk usage...
- Right-click on your desktop and select "TortoiseSVN -> Settings..."
- In the tree view, find the "Look and Feel/Icon Overlays" branch.
- 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. - 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:
- Click OK to apply the changes.
- 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
#/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
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
tcp_max_syn_backlog
somaxconn
วันจันทร์ที่ 4 มกราคม พ.ศ. 2553
Hardisk upgrade/Replace
http://www.losurs.org/docs/LDP/HOWTO/Hard-Disk-Upgrade/index.html