Showing posts from April, 2008

Linux - Methods to mount Samba

smbmount -o username="Username",password="Password" //IP/share /mnt/smb
smbumount /mnt/smb

mount -t smbfs -o username="Username",password="Password" //IP/share /mnt/smb
umount /mnt/smb

mount -t cifs -o username="Username",password="Password" //IP/share /mnt/smb
umount /mnt/smb

mount.cifs -o username="Username",password="Password" //IP/share /mnt/smb
umount.cifs /mnt/smb

Linux - network monitor (iftop)

iftop does for network usage what top does for CPU usage. It listens to network traffic on a named interface and displays a table of current bandwidth usage by pairs of hosts. Handy for answering the question "why is our ADSL link so slow?".

$ iftop -i ppp0

$ iftop -B

直接顯示IP, 不進行DNS反解:
$ iftop -n

直接顯示連接埠編號, 不顯示服務名稱:
$ iftop -N

其他參數可下 iftop -h 看說明.

進入iftop畫面時, 可按 p 切換是否顯示連接埠, n 切換顯示IP或主機的domain name, N切換顯示連接埠代號或名稱, p暫停顯示, b切換是否顯示長條, B切換計算幾秒內的平均流量, 其他按鍵可以按h觀看說明.

設定檔的位置在~/.iftoprc , 關於設定檔的寫法可以參考 iftop 的 info page.

Open Source Guide

Open Source Guide is a site that is here to share the amazing open source software currently around the net. We offer a directory of open source software so we can all benefit from what the open source community has to offer.

Open Source Hardware Inventory Management Software

OCS Inventory NG, Open Computers and Software Inventory Next Generation is an application designed to help administrator keep track of the computers configuration and installed softwares. Low network traffic HTTP communications between agents and server. I’m currently testing this software and I will update all of you about my results.

PcInventory Web-based system to track the Pc and the installed peripherals.

phpMyInventory is a web-based hardware, software, and peripheral inventory system using PHP & MySQL. Currently stable on PHP version 4xx only!

Windows Inventory. A Computer Hardware and Software Inventory system. Based around wmi, vbscript, mysql & php. Expandable via modules to include software distribution, remote control, event viewer, disk monitoring, etc.

Using Samba to join a Windows Domain

SAMP (Solaris, Apache 2, MySQL 5, and PHP 5) Setup for Solaris

OpenSSH for Windows

Western, do you know what you are fighting for?

As a Chinese in Hong Kong, I don't realize the situation of Tibet indeed.
I just saw from news that the Tibetans attacked the civilians. It was not demonstration, but insurrection and crime.

How do you think about the situation of Ireland in Britain, and Basque in Spain?

Is it any double standard?

Tibet under China

Linux - Apache DoS/DDoS mod

mod_evasive is an evasive maneuvers module for Apache to provide evasive action in the event of an HTTP DoS or DDoS attack or brute force attack.

Linux - redirect/rewrite http to https for a specified directory

<Location "/cacti">
RewriteEngine on
Options +FollowSymLinks
Allow from all
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

Linux - Restart NFS server when network link down

WARNING!Using restart option (i.e. service nfs restart) may crash / freeze your Linux computer if executed.

start service in following order:# service nfslock stop
# service nfs stop
# service portmap stop
# umount /proc/fs/nfsdstart service in following order:
# service portmap start
# service nfs start
# service nfslock start
# mount -t nfsd nfsd /proc/fs/nfsd


在溫室泛舟 誰又記得奮鬥
走出門口 原來越冷越長壽
逆流便向上游 微笑者可得救

*逆境出對手 時運也講節奏
高手能守 然後自有然後
上游亦勝下流 能吃苦都不瘦


MySQL Proxy Load balancing and Failover Tutorial

Linux - monitor MySQL Tools

$ mysql -u admin -p 123456
mysql> show status;

mytop is a console-based (non-gui) tool for monitoring the threads and overall performance

$ mytop -u admin -p 123456
$ mytop -u admin -p 123456 -d phpbb

You can store this information in ~/.mytop file:

vi ~/.mytop

Add config text as follows:


mtop (MySQL top) monitors a MySQL server showing the queries which are taking the most amount of time to complete.
mkill (MySQL kill) monitors a MySQL server for long running queries and kills them after a specified time interval. Queries can be selected based on regexes on the user, host, command, database, state and query.

innotop is designed to monitor InnoDB transactions and internals, replication status, deadlocks, general queries and status values, and much more.

Linux - Procedure to convert a running single disk servers to software RAID1

Linux - rebuilding a RAID array after a disk fails

Assuming that new SCSI disk is /dev/sdb, type the following command:
# raidhotadd /dev/mdX /dev/sdb

Replace /dev/mdX with actual raid device name (e.g. /dev/md0). While array is under construction, you can see progress and other information by typing following command:
# cat /proc/mdstat

Linux - Setting up RAID 1 on running system.

Config was as follows:
/dev/hdb (/dev/hdb1 40 GB)
/dev/hdc (/dev/hdc1 40 GB)

Each partition has been 40 GB size ext3 formatted (make sure partition id is set to Linux raid auto).
RAID tools and software was installed. It is called mdadm.
Remember first software device will be /dev/md0, second will be /dev/md1 and so on

You need to type following command to setup /dev/md0:
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/hdb1 /dev/hdc1

You can see status, health of /dev/md0 at /proc/mdstat. Type the following command:
cat /proc/mdstat

Better uses watch command to refresh it automatically:
watch cat /proc/mdstat

Format /dev/md0 as ext3 fs:
mkfs.ext3 /dev/md0

Mount /dev/md0 at /data2 directory:
mkdir /data2
mount /dev/md0 /data2

Don't forget to add /dev/md0 to /etc/fstab:
vi /etc/fstab
Append following text:
/dev/md0 /data2 ext3 defaults 0 0

Linux - copy master boot record (MBR)

dd if=/dev/sda of=/dev/sdb bs=512 count=1

Linux - How do you take a single line of input from the user in a shell script?

One line is read from the standard input (keyboard), or from file descriptor FD if the -u option is supplied, and the first word is assigned to the first NAME, the second word to the second NAME, and so on, with leftover words assigned to the last NAME.


read {variable-name}
read -p {’Prompt text’} {variable-name}

Read single line of input from the user and store to variable called dbname:
read dbname
read -p 'Enter Database name : ' dbname

To display variable value, enter:
echo $dbname

Sample shell script

Linux - IP Address Allocation Table script

If you need a tabular representation of relationships and source of the various variables representing a chunk from /32 to /0 subnets use iptab command. This is useful if you are allocating IPs to end users.

$ iptab
Sample output:

| addrs bits pref class mask |
| 1 0 /32 |
| 2 1 /31 |
| 4 2 /30 |
| 8 3 /29 |
| 16 4 /28 |
| 32 5 /27 |
| 64 6 /26 |
| 128 7 /25 |
| 256 8 /24 1C |
| 512 9 /23 2C |
| 1K 10 /22 4C |
| 2K 11 /21 8C |
| 4K 12 /20 16C |
| …

Linux - Subnets Calculator

If you need to calculate subnet under Linux use an IP Netmask/broadcast calculator called ipcal & sipcalc.[a] ipcalc : ipcalc takes an IP address and netmask and calculates the resulting broadcast, network, Cisco wildcard mask, and host range. By giving a second netmask, you can design sub- and supernetworks. It is also intended to be a teaching tool and presents the results as easy to understand binary values.[b] sipcalc : Sipcalc is also an ip subnet calculator consisting of two parts. A plain text based console version, and web (cgi) based counterpart. Sipcalc, in it’s simplest form takes an ip-address and a subnet mask on the commandline and outputs information about the subnet. Sipcalc has support for both IPv4 and IPv6 addresses.Let us see how to calculate subnets for$ ipcalc 00000001Netmask: = 2411111111.11111111.11111111. 00000000Wildcard: 11…