Check Linux server status

vmstat, iostat, top…etc are useful to check server load, I/O or memory usage.

iostat
r/s and w/s
the number of read and write requests sent to the device per second
await
the number of requests waiting in the device’s queue
svctm
the number of miliseconds spent servicing requests, from beginning to end
util
the percentage of the device utilization

vmstat
procs
r: processes are waiting for the CPU time
b: processes are in sleep (means they are waiting for I/O)
io
bi/bo: how many blocks reading in/out the device
system
in: number of interrupts per second
cs: context switches per second

Here are some good sites showing how to use them

http://www.cyberciti.biz/tips/linux-disk-performance-monitoring-howto.html
http://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html
http://www.linuxforums.org/articles/using-top-more-efficiently_89.html
http://software.intel.com/en-us/blogs/2011/02/09/using-linux-top-to-troubleshoot-multi-core-scalability-issues-at-dreamworks-animation/

Good article about I/O scheduler
http://www.linuxjournal.com/article/6931

manipulating strings

1. cut

Ex. #echo “192.168.1.10:8080″| cut -d: -f1
192.168.1.10

Ex. User with uniq & sort

Ex. #netstat -nap|less|grep ‘192.168’| awk ‘{print $5}’|uniq -c|sort -nr -k 1

2. sed

match a string and replace it

echo “I love poem”|sed ‘s/peom/music/’

ldconfig — change lib path

Sometimes it’s preferred to install libraries into non-default locations, such as /usr/local/,
but how to let the system know where to find them?

ldconfig can be used to change the lib path,

Ex. To have the system be able to find libraries under /usr/local/lib for myapp

vi /etc/ld.so.conf.d/myapp.conf
/usr/local/lib
#ldconfig

To check result
#ldconfig -v

# ldconfig -l /path/to/lib/missing.lib.so

Great articles about shared libraries.
http://www.cyberciti.biz/faq/linux-setting-changing-library-path/
http://www.cyberciti.biz/tips/linux-shared-library-management.html

Linux Network command –tcpdump

Examples:

Show details of packets
#tcpdump -nnvvXS

tcpdump

show specific type of connection
#tcpdump icmp/tcp/udp

Add more options with source/destination IP/port, write to file
tcpdump -nnvvXS src 1.2.3.4 and port 3306 -w /tmp/test.pcap

Read tcpdump log from the file
tcpdump -qns -0 A -r /tmp/test.pcap

tcpick -C -yP -r /tmp/test.pcap

ngrep
ngrep -d any -W byline dst 1.2.3.4 > /tmp/test.pcap

Install ubuntu to EeePC

1. Create a USB image to install Ubuntu to EeePC.
problem:
Got error: “Unknown keyword in configuration file”

How to fix:
This page is very helpful
http://alexsleat.co.uk/2010/11/27/how-to-fix-unknown-keyword-in-configuration-file-ubuntu-usb-boot/

2. choose partition
delete old /dev/sda7
then “Add” on “Free Space” -> new /dev/sda7
ext3
mount point -> /
Then install

bg

To suspend the command just run

Ctrl + Z

Then use bg command to put in the background

Ex.
find / -name “syslog”

>Ctrl + z

[1]+ Stopped find / -name “syslog”

>jobs
[1]+ Stopped find / -name “syslog”

>bg %1
[1]+ find / -name “syslog” &

Setup Lighttpd for Vedio Streaming

Lighttpd is said that much lighter that Apache. I tried to set it up for flv and H.264 streaming. The configuration is relatively easy.

1. Download lighttpd-1.4.29.tar.gz

2. Download lighttpd-1.4.18_mod_h264_streaming-2.2.0.tar.gz
(This is the patch for mod_h264)

3. Open tar ball of lighttpd
tar zxvf lighttpd-1.4.29.tar.gz

4. Patch h264-mod
mv lighttpd-1.4.29 lighttpd-1.4.18
tar zxvf lighttpd-1.4.18_mod_h264_streaming-2.2.0.tar.gz

5. config /etc/lighttpd.conf
basic setup:

server.port = 80
server.username = “lighttpd”
server.groupname = “lighttpd”
server.document-root = “/var/www”
server.tag = “lighttpd”
server.pid-file = “/var/run/lighttpd.pid”
server.errorlog = “/var/log/lighttpd/error.log”
include “conf.d/access_log.conf”
index-file.names += (
“index.html”, “index.htm”, “index.php”
)
include “conf.d/mime.conf”

6. module.conf
server.modules = (
“mod_access”,
“mod_fastcgi”,
“mod_h264_streaming”,
“mod_flv_streaming”,
“mod_rewrite”,
“mod_auth”,
)
h264-streaming.extensions = ( “.mp4” )
flv-streaming.extensions = ( “.flv” )

7. Setup vhost
There’re many samples out there for this part already, so I won’t write any here.

8. FCGI
I had FCGI installed in advance. To have lighttpd uses FCGI, edit

conf.d/fastcgi.conf

fastcgi.server = (
“.php” =>
(( “host” => “127.0.0.1”,
“port” => 81,
“bin-path” => “/usr/local/bin/php”
)),
)
9. restart lighttpd
Then you can see the lighttpd started fcgi process

10. Use jwplayer
download mediaplayer.zip
unzip it and copy “jwplayer.js” and “player.swf” to a folder under docroot of the site
check the “JW Player Quick Start Guide.pdf” in the zip file for how to use javascript to embed jwplayer to stream.

Yum Repo

Setup /etc/yum.conf
“man yum.conf” is useful to learn all the options

Yum repos are located under
/etc/yum.repos.d

$releasever is decided by distroverpkg in /etc/yum.conf
distroverpkg=redhat-release is set as default
how to get value of distroverpkg
yum whatprovides redhat-release

how to change $arch
man setarch

Yum with multiple repos
http://blog.chrisramsay.co.uk/2009/08/14/yum-with-multiple-repos-yum-plugin-priorities-on-centos/

RPMforge yum repo

To install RPMforge repo in yum,

http://wiki.centos.org/AdditionalResources/Repositories/RPMForge

#wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
#rpm –import http://apt.sw.be/RPM-GPG-KEY.dag.txt
#rpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm

#rpm -i rpmforge-release-0.5.2-2.el5.rf.i386.rpm