Posts

Showing posts from 2009

[Level 3] Clone ZFS Permissions

One day, someone ask me how to clone ZFS permissions from one ZFS file system to another ZFS file system. It seems that zfs command doesnot support the permission like getfacl setfacl to clone the file system permissions. Therefore I try to write a script to implement that, please refer to the following code. #!/usr/bin/bash showUsage() {   cat <<EOF Usage:   $0 source_zfs target_zfs Ex.   $0 rpool/fs1 karajon/fs2 EOF } ##################################### main sSZFS=$1 sTZFS=$2 declare -i fPermSet=0 declare -i fLocalPerm=0 zfs allow $sSZFS | while read s do   ( echo $s | grep "^---- Permissions on " > /dev/null ) && continue   ( echo $s | grep "^Permission sets:$" > /dev/null ) && fPermSet=1 && fLocalPerm=0 && continue   ( echo $s | grep "^Local+Descendent permissions:$" > /dev/null ) && fLocalPerm=1 && fPermSet=0 && continue   if [ $fPermSet -eq 1 ] ...

[Level 2] MySQL Query with Regular Expression.

If you  want to let your query more powerful, you can use regular expression to enhance your SQL query. mysql> create table testRegExp (name varchar(32)); mysql> insert into testRegExp values('Stanley'),('Christy'),('Joseph'),('Chantelle'); Query OK, 4 rows affected (0.00 sec) Records: 4  Duplicates: 0  Warnings: 0 mysql> select * from testRegExp where name regexp '^(S|C)'; +-----------+ | name      | +-----------+ | Stanley   | | Christy   | | Chantelle | +-----------+ 3 rows in set (0.00 sec) mysql>  Ref: http://dev.mysql.com/doc/refman/5.1/en/regexp.html Wish this helps. regards, Stanley Huang

[Level 2] MySQL XML Functions.

One day, a friends of mine asked me if MySQL support XML? Actually, MySQL havs two XML functions, called "ExtractValue" and "UpdateValue". You can use these two function as the following samples: mysql> CREATE TABLE persons ( id int auto_increment primary key, data text ); mysql> INSERT INTO persons(data) values (' <person>   <name>stanley</name>   <sex>m</sex>   <addr>taipei</addr>   <tels>     <tel>12340001</tel>     <tel>12340002</tel>     <tel>12340003</tel>   </tels> </person> '), (' <person>   <name>joseph</name>   <sex>m</sex>   <addr>taipei</addr>   <tels>     <tel>12350001</tel>     <tel>12350002</tel>     <tel>12350003</tel> ...

[Level 1] MySQL 5.5 new features -- Semisynchronous Replication.

MySQL 5.5 m2 has released. In m2, MySQL 5.5 has a great called "Semisynchronous Replication". How the semi works? 1. First, the client connect to server and be indicated that is semi or not. 2. If semi is enable on server site and there is at least one client and waits untilone semi client acknowledges that it has received. please refer to the following link for more info. http://dev.mysql.com/doc/refman/5.5/en/replication-semisync.html Wish this helps. regards, Stanley Huang

[Level 3] Using DTrace for MySQL DB.

I'm glade to here that, in MySQL 5.4 beta, it supports that to use Solaris DTrace to monitor MySQL SQL statement. About the probe for MySQL, please refer to the following link: http://dev.mysql.com/doc/refman/5.4/en/dba-dtrace-mysqld-ref.html I use one of the scripts to demo the result of DTrace, http://dev.mysql.com/doc/refman/5.4/en/dba-dtrace-ref-query.html The result as below: Sessin 1: [stanley@Stanley-NB]:/usr/mysql# mysql Enter password: Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.4.3-beta MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. stanley@localhost:stanley mysql> show tables; Empty set (0.00 sec) stanley@localhost:stanley mysql> Sessin 2: root@Stanley-NB:/tmp# ./MySQL_query.d Who                  Database     ...

[Level 3] Script for clone VirtualBox 3.1.0 .

Before, I wrote a script to clone VirtualBox with ZFS technology. After new VirtualBox release, because of the architecture and command changed, the previous script will occur error while running. Therefore, I modify the script for version 3.1.0 later of VirtualBox. #!/usr/bin/bash showUsage() {   cat <<EOF Usage:   $0 [c]reate/[d]elete New_Machine_Name Source_Machine_Name interface begin_index end_index Ex.   $0 [c]reate OS128a_MySQL OS128a yge0 1 10   $0 [d]elete OS128a_MySQL OS128a yge0 1 10   $0 [d]elete OS128a_MySQL OS128a yge0 VMMachine: `showVMS | sed -e 's/^/  /'` EOF } ## Usage: ##   setUUID vdi_file ## Ex. ##   setUUID /Karajon/VBoxes/Guest/guest.vdi setUUID() {   sVDI=$1   VBoxManage -q internalcommands setvdiuuid $sVDI } ## Usage: ##   createVM vm_name os_type. ## Ex. ##   createVM S10u8_MySQL Solaris_64 ## PS. ##   OS Type: Solaris Solaris_64 Open...

Gnome-commander in OpenSolaris

If you like to use the utility on Windows called "Total Commander", you would like "Gnome-commander" in OpenSolaris. You can download the Gnome-commander in opensolaris.org repository. The package name called "SUNWgnome-commander". Wish this helps. regards, Stanley Huang

[Level 3] Get process pid which open port!

How to get your process that open port. The following will help you to check it! #!/usr/bin/bash showUsage() {   cat <<EOF Usage:   $0 [port/pid/program](sort column, default is sort by 'port'.) Ex.   $0 1/port   $0 2/pid   $0 3/program EOF } ####################################### main typeset -i nSortKey case $1 in 1|port|"")   sFlag="-n"   nSortKey=1   ;; 2|pid)   sFlag="-n"   nSortKey=2   ;; 3|program)   nSortKey=3   ;; *)   showUsage   exit 0   ;; esac echo "port\tpid\tcmd" ps -eo pid,comm | while read pid cmd do   pfiles $pid 2> /dev/null | grep port: | awk "{printf(\"%s\t%s\t%s\n\",\$5,\"$pid\",\"$cmd\")}" done | sort $sFlag -u -k $nSortKey  Wish this helps. regards, Stanley Huang

[Level 2] Enhance the performance with MySQL checksum table with MyISAM engine.

You can create MyISAM table with the option "checksum=1", to let MyISAM table store the checksum value. Otherwise, checksum table, will need to do a full table scan. PS. This only support on MyISAM engine. mysql> create table t (id int) engine=MyISAM checksum=1; mysql> checksum table t; Wish this helps. regards, Stanley Huang Publish Post

VirtualBox 3.1 released

Sun Microsystems release VirtualBox 3.1 at 11/30. The new version has new features that people looking forward to: 1. Teleportaion (aka live migration): It supports that to let virtual machine to migration between different platform, it enhances the virtual server with HA and flexibility. 2. Snapshots flexibility: The guest can rollback from different revision, and also can have branched snapshots. 3. Network attachement on the fly: The guest can modify the network interace on line. More information, please refer to: http://www.virtualbox.org/wiki/Changelog Wish this helps. regards, Stanley Huang

[Level 3] 1A2B shell game

Another game. # !/usr/bin/bash showUsage() {   cat <<EOF Usage:   $0 Ex.   $0 EOF } getNum() {   #set -vx   sNum="0|1|2|3|4|5|6|7|8|9"   sAns=""   declare -i n1=$RANDOM*10/32767+1   declare -i n2=$RANDOM*9/32767+1   declare -i n3=$RANDOM*8/32767+1   declare -i n4=$RANDOM*7/32767+1   s=`echo $sNum | cut -d'|' -f$n1` && sAns=$sAns$s && sNum=`echo $sNum | sed -e "s/$s//" | sed -e 's/||/|/g' | sed -e 's/^|//g' | sed -e s'/|$//'`   s=`echo $sNum | cut -d'|' -f$n2` && sAns=$sAns$s && sNum=`echo $sNum | sed -e "s/$s//" | sed -e 's/||/|/g' | sed -e 's/^|//g' | sed -e s'/|$//'`   s=`echo $sNum | cut -d'|' -f$n3` && sAns=$sAns$s && sNum=`echo $sNum | sed -e "s/$s//" | sed -e 's/||/|/g' | sed -e 's/^|//g' | sed -e s'/|$//'`   s=`echo $sNum | cut -d'|' -f$n4` && ...

[Level 3] OX shell game.

Today, I deliver the shell programming course. And I think, why not to write a simple shell script game. The script should be to fun. #!/usr/bin/bash showUsage() {   cat<<EOF Usage:   $0 init/load 0/X Ex.   $0 init 0/X   $0 load O/X EOF } checkLine() {   sDisp=$1   s1=`echo $sDisp | cut -d'|' -f1`   s2=`echo $sDisp | cut -d'|' -f2`   s3=`echo $sDisp | cut -d'|' -f3`   s4=`echo $sDisp | cut -d'|' -f4`   s5=`echo $sDisp | cut -d'|' -f5`   s6=`echo $sDisp | cut -d'|' -f6`   s7=`echo $sDisp | cut -d'|' -f7`   s8=`echo $sDisp | cut -d'|' -f8`   s9=`echo $sDisp | cut -d'|' -f9`   if [ $s1 == $s2 ] && [ $s2 == $s3 ]   then     echo "$s1 wins..." && return 0   elif [ $s4 == $s5 ] && [ $s5 == $s6 ]   then     echo "$s4 wins..." && return 0   elif [ $s7 == $s8 ] && [ $s8 == $s9 ]   then ...

[Level 3] The script for demo creating mass zones on OpenSolaris

Days ago, my colleague will demo about the virtualization techniques on OpenSolari. So I share the script for him to demo fast creating zones on OpenSolaris. After test, my lap will create a zone per 3 seconds. That impress him, and he decided to demo on that session. The same script that I'd like to share to you, please refer the following script code. Any question, and suggestion, please feel free to let me know. #!/usr/bin/bash showUsage() {   cat< <EOF Usage:   $0 [c]reate  [original index] [start index] [end index]   $0 [d]estroy [start index]    [end index]   [always yes]   $0 [l]ist Ex.   $0 c 1 2 10   => create  zone2, zone3, ... ,zone10   $0 c 1 3 8    => create  zone3, zone4, ... ,zone8   $0 d 2 10 [F] => destroy zone2, zone3, ... ,zone10   $0 l PS.   for solaris 11 only   all indexes must greater then 1, less then 255 Zones: ...

[Level 3] Script for create VirtualBox VM quickly.

This script is for quickly create VirtualBox VM, it base on ZFS snapshot/clone technique. The description for the script is as the following: The step as below: 1. create a ZFS filesystem first. Ex. # zfs create -p rpool/vbox/sourceOS 2. create a VirtualBox VM for source and put the vdi on the above ZFS filesystem. 3. use the script: Usage:   $0 create New_Machine_Name Source_Machine_Name interface begin_index end_index Ex.   ./createVBoxClientByClone.sh create NewVM SourceVM yukonx0 3 5 the above command will create 3 VMs (NewVM_3, NewVM_4, NewVM_5): The actions of create are, . snapshot origin ZFS . clone from origin ZFS snapshot to new ZFS . re-new vdi uuid on new ZFS . create new vm . modify new vm . modify new vm nic 4. If you want to delete VMs, use the command as below: Usage:   $0 delete New_Machine_Name Source_Machine_Name interface begin_index end_index Ex.   ./createVBoxClientByClone.sh delete NewVM SourceVM yukonx0 3 5 Above coma...

[Level 2] How to get ZFS clone file system?

Now I have use VirtualBox with ZFS clone file system. So sometimes, I have to figure out which file system is native, which file system is clone. Therefore, I write a script to list the ZFS clone file system. #!/usr/bin/bash showUsage() {   cat < <EOF Usage:   $0 pool_name Ex.   $0 rpool EOF } ######################################################## main [ $# -lt 1 ] && echo "Error without parameters, exit program..." && showUsage && exit 1 sPoolname=$1 #sPoolname=${1:-rpool} echo "get pool($sPoolname)..." zfs get -r origin $sPoolname | egrep -v -- 'origin[ ]+-[ ]+-$' The you can use the command to find out the clone file system. # getCloneFS.sh rpool get pool(rpool)... NAME                                          PROPERTY ...

[Level 1] Install freemind on OpenSolaris

These days, my colleague want to find the freemind tool which can run on OpenSolaris, finally, we got one. And you can download it from the following link: http://freemind.sourceforge.net/wiki/index.php/Download After downloaded, you can got a zip file. then de-compress it. # cd /src # mkdir freemind # cd freemind; unzip ../freemind-bin-max-0_8_1.zip < lengthy output omitted > # chmod u+x ./freedmind.sh # ./freemind.sh # ps -ef | grep freemind  stanley  1155   810   0 14:25:00 pts/2       0:05 /usr/java/bin/java -Dfreemind.base.dir=. -cp ::./lib/freemind.jar:./lib/ant/lib Wish this helps. regards, Stanley Huang

[Level 2] Tips on ZFS.

1. Is that possible to migrate root filesytem from smaller hard disk to larger one without shutdown the operation system? The answer is "Yes", if you use OpenSolaris. You can use a larger disk to attach into the pool and make the hard disk be a part of mirror disk of the root file system. After join the pool, the zfs pool will reslivering the data from origin one to new hard disk. After reslivered, then deatch the old hard disk, then the zfs capacity will also increased. The simulation output as the following. # mkdir /temp # mkfile 128m /temp/128m # mkfile 256m /temp/256m # ls /temp/*m -rw-------   1 stanley  staff    134217728 Nov 19 09:06 /temp/128m -rw-------   1 stanley  staff    268435456 Nov 19 09:06 /temp/256m # # pfexec zpool create myPool /temp/128m # zpool status myPool   pool: myPool  state: ONLINE  scrub: none requested config:     NAME     ...

[Leve 1] Use usb to com to connect SPARC machine in OpenSolaris.

Today, I try to use my colleage's usb to com cable, to connect SPARC machine. 1. check /dev/term folder first. # ls -al /dev/term total 8 drwxr-xr-x   2 root root   2 2009-11-10 18:20 . drwxr-xr-x 252 root sys  252 2009-11-10 18:20 .. 2. connect cable then try again. # ls -al /dev/term total 9 drwxr-xr-x   3 root root   3 2009-11-10 18:00 . drwxr-xr-x 253 root sys  253 2009-11-10 18:00 .. lrwxrwxrwx   1 root root  48 2009-11-10 18:00 0 -> ../../devices/pci@0,0/pci1043,8263@1d/device@1:0 3. use tip command to connect SPRAC machine. PS. you have to set baud rate to 9600. # tip -9600 /dev/term/0 4. Start the SPARC machine then you will get the console. Wish this helps. regards, Stanley Huang

[Level 1] How to let our source code display with colors in Vim.

In TWOSUG , someone ask about how to display colors in shell. 1. Setting TERM variables. # export TERM=xterm-color; 2. Use Vim to open the source. # vim ./test.c; 3. Turn on the syntax mode in Vim. In last line mode, type the following command. :syntax on Wish this helps. regards, Stanley Huang

[Level 3] Clone multi-server on VirtualBox guest by ZFS clone.

How to save your disk space while you need multi VirtualBox guest? You can use ZFS clone to clone ZFS filesystem. But while you import the vdi, you willgot an error message with duplicated disk uuid. So you need to modify the disk uuid by command VBoxManage. The complete steps as the following: 1. create zfs pool for VirtualBox VDI. # zpool create vdiPool c1t0d0s0; # default folder is /vdiPool 2. create zfs filesystem for Source VDI. # zfs create vdiPool/vdiSource; # default folder is /vdiPool/vdiSource 3. create VirtualBox guest, and create vdi on /vdiPool/vdiSource/OpenSolaris.vdi 4. clone vdi source # zfs snapshot vdiPool/vdiSource@installed # zfs clone vdiPool/vdiSource@installed vdiPool/vdiTarget1 # VBoxManage internalcommands setvdiuuid /vdiPool/vdiTarget1/OpenSolaris.vdi Wish this helps. regards, Stanley Huang

chm reader in OpenSolaris

If you want to install chm reader on OpenSolaris, you can install xchm from Blastwave repository. Wish this helps. regards, Stanley Huang

ScaleDB storage engine for MySQL.

Image
Here comes a new commercial storage engine for MySQL called "ScaleDB". The architecture ScaleDB just similar like "Oracle RAC", but now, ScaleDB only support Linux and Windows. All the db instant are active and supports shared storage. Expecting the storage engine be mature. PS. If you don't have shared storage, and you just use VirtualBox as I do, you can use "DRBD" to simulate the shared storage, but now, DRDB only supoort Linux. The architecture of SacleDB as below. (All pictures rights belows to www.scaledb.com) Ref: http://www.scaledb.com The DRDB architecture as below. (All picture rights below to DRDB.org) Ref: http://www.drbd.org Wish this helps. regards, Stanley Huang

[Level 3] Solaris 10 Technical Conference ( 2009/10/25,11/13,12/4 ) -- Advanced ZFS hands-on lab

The following is my lab file, please refer to it.  Wish this helps. regards, Stanley Huang **************************************************************************************************** The purpose of this lab is to let you have advanced ZFS filesystem administration skill. And then you will have the following capabilities. Lab 1: * replace zpool disk. Lab 2: * take ZFS filesystem snapshot, rollback ZFS filesystem. * clone ZFS filesystem. Lab 3: * use ZFS L2ARC * use ZFS ZIL Lab 1: 1. replace zpool disk. # cd /labs/ZFS/files; # zpool create mypool mirror `pwd`/f1 `pwd`/f2 spare `pwd`/f3; # zpool replace mypool `pwd`/f2 `pwd`/f3; # zpool status mypool; -------------------------------------------------------------------------------   pool: mypool  state: ONLINE  scrub: resilver completed after 0h0m with 0 errors on Sun Oct 18 11:13:15 2009 config:     NAME          ...

[Level 2] Solaris 10 Technical Conference ( 2009/10/25,11/13,12/4 ) -- Basic ZFS hands-on lab

The following is my lab file, please refer to it.  Wish this helps. regards, Stanley Huang **************************************************************************************************** The purpose of this lab is to let you have basic ZFS administration skill. And then you will have the following capabilities. Lab 1: * create ZFS pool. * check ZFS pool status. * set ZFS pool properties. * destroy ZFS pool. Lab 2: * create ZFS filesystem. * check ZFS filesystem status. * set ZFS filesystem properties. * destroy ZFS filesystem. Lab 1: 1. prepare files with command mkfile. # mkdir -p /labs/ZFS/files; # cd /labs/ZFS/files; # mkfile 128m f1 f2 f3 f4 f5 f6 f7 f8 f9; 2. create ZFS pool. # zpool create mypool mirror `pwd`/f1 `pwd`/f2 spare `pwd`/f3; # zpool create myraidz raidz `pwd`/f4 `pwd`/f5 `pwd`/f6 spare `pwd`/f7; 3. list ZFS pools, and check pool status. # zpool list; --------------------------------------------------- # zpool list mypool...