March 2011 Archives

Cfengine 3 tutorial

No support for open source projects

Many believe that open source projects cannot be used in the enterprise because of the lack of support. This is untrue.

Enterprise system administration using configuration management

To maintain the large quantity of servers typically found in enterprise organizations, systems administration must move beyond manual and custom scripts toward a centralized configuration management service. This move can save an organization considerable time and money.

Subversion cheatsheet

Add to working copy svn add <file>
Backup to hot copy /opt/svn /opt/svn-backup
Change log view svn log file:///opt/svn/scripts/firewall/firewall-new
Checkout svn checkout file:///opt/svn/profile
Commit changes svn commit --message "Your log message"
Copy to working copy svn copy <file> <file>
Create respository svnadmin create --fs-type fsfs /opt/svn
Delete from working copy svn delete <file>
Diff changes svn diff
Initial Import svn import . file:///opt/svn --message "Initial import"
Merging to current directory svn merge <merge to@REV> <merge from@REV>
Move file in working copy svn move <file1> <file2>
Remote Checkout svn checkout svn+ssh://<user>@<hostname>/opt/svn/<project>
Revert all changes svn revert <file>
Review changes svn status
Review commit log svn log
Update working copy svn update <file> (may overwrite changes)
View file svn cat file:///opt/svn/profile/.profile
View repository tree svnlook tree /opt/svn

Solaris and Sun/Oracle sheetsheet

init levels
0 Go into boot prompt (OK).
1 Put the system in system administrator mode. All file systems are mounted. Only a small set of essential kernel processes are left running. This mode is for administrative tasks such as installing optional utility packages. All files are accessible and no users are logged in on the system.
2 Put the system in multi-user mode. All multi-user environment terminal processes and daemons are spawned. This state is commonly referred to as the multi-user state.
3 Start the remote file sharing processes and dae mons. Mount and advertise remote resources. Run level 3 extends multi-user mode and is known as the remote-file-sharing state.
4 Is available to be defined as an alternative multi-user environment configuration. It is not necessary for system operation and is usually not used.
5 Shut the machine down so that it is safe to remove the power. Have the machine remove power, if possible.
6 Stop the operating system and reboot to the state defined by the initdefault entry in /etc/inittab.
reboot -- -x
Reboot and issue boot -x (boot to non-cluster mode) at boot prompt.
reboot -- -xs
Reboot and issue boot -xs (single user, non-cluster mode) at boot prompt.
reboot -- -r
Reboot and issue boot -r (reconfigure) at boot prompt.

elom and ilom commands
Upload elom firmware
cd /SP/TftpUpdate
set ServerIP=<tftp IP address>
set Filename=Telom_X6250-053_040.ROM
stop /SYS
set Update=action
# wait for upload and reboot
Upload ilom firmware
load -source tftp://<tftp IP address>/file.pkg
Sun Cluster (under review)
Backup cluster confuration cluster export > clusterconfig.xml
Offline device group. cldg offline <group>
Offline resource group. clrg offline <group>
Onine device group. cldg online <group>
Onine resource group. clrg online <group>
Restore cluster configuration clintr delete --force +
clinst add clusterconfig.xml +
Show cluster configuration cluster show
Status of cluster. scstat or cluster status
Status of device group. cldg status
Status of resource group. clrg status
Swtich device group to another node. cldg switch -n <node> <group>
Swtich resource group to another node. clrg switch -n <node> <group>

Shell cheatsheet

The following may not apply to all shells.

Job control
List jobs jobs
Resume job after suspend ctrl-q
Resume job in background bg <%string>
Resume job in background bg <job number>
Resume job in foreground fg <%string>
Resume job in foreground fg <job number>
Suspend delay (suspend at stdin) ctrl-y
Suspend ctrl-z

Command line laziness
Recall history line 66 !66
Recall last command !!
Recall last arguement from last command !$
Recall all arguements from last command !*
Clear shell history history -c
Delete shell history entry history -d <number>
Rename rpmnew files find -type f -name "*.rpmnew" |\
sed 's/\(^.*\)\(\.rpmnew\)$/mv -f \1\2 \1/' |sh
Search and replace files in place find /path -name "*.*" -exec \
perl -pi -e 's///g' {} \;
vi cli editing set -o vi Now <esc> enter command mode where vi keys work. Pressing <enter> returns to normal mode.

GNU screen cheatsheet

Change to other region ctrl-a tab
Change to other screen ctrl-a 0-9
Dettach ctrl-a d
Help ctrl-a ?
Kill screen ctrl-a \
Kill region ctrl-a x
New screen ctrl-a c
Reattach screen -r
Serial connection screen /dev/ttyUSB0 9600
Split ctrl-a s

POSIX regular expressions cheatsheet

Alphabetic [:alpha:]
Alphanumeric [:alnum:]
Control characters [:cntrl:]
Hex numbers [:xdigit:]
Lowercase [:lower:]
Nonespace characters [:graph:]
Numbers [:digit:]
Printable [:print:]
Punctuation [:punct:]
Tab or space [:blank:]
Uppercase [:upper:]
White space [:space:]

Multipathd testing

  1. Format and mount the SAN LUN.
  2. Start a write to the mounted filesystem cat /dev/zero >> /pathto/mnt/testfile &
  3. Now connect to the multipath daemon in interactive mode multipathd -k
  4. View current paths with show maps topology
    multipathd> show maps topology
    reload: mpath5 (360060e801045249004f2a5f900000031) dm-7 HITACHI,DF600F
    \_ round-robin 0 [prio=1][active]
     \_ 1:0:0:4 sdb 8:16  [active][ready]
    \_ round-robin 0 [prio=0][enabled]
     \_ 2:0:0:4 sdc 8:32  [active][ready]
  5. There are two paths shown as sdb and sdc. Delete one path.
    del path sdb
  6. Suspend with ctrl-z and check that the write is still happening.
    ls -l /pathto/mnt If testfile is still growing then the path sdc is working.
  7. Resume multipath with fg 2. Re-add the path.
    add path sdb
  8. Now remove the other path.
    del path sdc
  9. Again suspend iwth ctrl-z and check that the test file is growing. If so then resume multipath and re-add the path.
    add path sdc
  10. Testing complete. Exit with ctrl-c. Kill the write job with kill %1. Remove the test file.

Miscellaneous cheatsheet

Burn DVD growisofs -J --iso-level 4 -v -Z dev/dvdrw -R /path/to/dir/
growisofs -dvd-compat -Z /dev/sr0 myimage.iso
Burn CD mkisofs -J --iso-level 4 -R path/to/dir/ | \
cdrecord driveropts=burnfree dev=/dev/cdrom -
cdrecord driveropts=burnfree dev=/dev/sr0 mydisk.iso
Image manipulation convert -rotate 90 -resize 800x600 input.jpg output.jpg
Linux Qlogic HBA configuration
# loading module for failover and load balancing:
options qla2xxx ql2xfailover=1 ql2xlbType=2
# The RAM disk image may need to be rebuilt with
mkinitrd <image file> <kernel version>

Linux networking cheatsheet

Network calculation
Show network info ipcalc
Segment network into 2 50 node subnets ipcalc -s 50 50

Net-tools versus Iptroute2
List interfaces ip addr list
ifconfig -a
ip addr list eth0
ifconfig eth0
Link status ip link list
ifconfig -a
ip link list eth0
ifconfig eth0
Route table ip route
netstat -rn
Adding routes ip route add default via
Add/delete IP addresses ip addr add dev eth0
ifconfig eth0 netmask
ip addr del dev eth0
ifconfig eth0 del

Linux Ethernet bonding

# Loading module:
# for Red Hat AS4, may work with other 2.6 Linuxes.
install bond0 /sbin/modprobe bonding -o bond0 mode=0 miimon=100
# for Red Hat AS3, may work with other 2.4 Linuxes.
alias bond0 bonding
options bond0 -o bonding mode=0 miimon=100
# For Redhat distributions
# ifcfg-ethx

# ifcfg-bond0
Click for more Ethernet bonding information.

OSI model diagram


Debian Apt cheatsheet

Download and build source package apt-get -b source <package name>
Download and install dependencies for source package apt-get build-dep <package name>
Download source package apt-get source <package name>
Install package “on demand” auto-apt run <program>
List contents of a package apt-file list <package name>
List installed packages dpkg -l
Remove package and configuration files apt-get --purge remove <package name>
Search for Debian Packages
Search for packages apt-cache search <string>
Show package dependencies apt-cache depends <string>
Show package information apt-cache show <string>
Show package that supplies a given file apt-file search <file name>
Show package that supplies a given file COLUMNS=132 dpkg -S <file name>
Show source package information apt-cache showsrc <package name>
Update apt-file and auto-apt database apt-file update

Heartbeat 2 cheatsheet

List cluster resources. crm_resource -L
Dump cluster configuration as xml to stdout. cibadmin -Q
Place node in standby (maintenance mode). Technically this is adding the standby property. crm_standby -U <hostname> -v true
Place local node in standby. crm_standby -v true
Place node online or remove the standby property. crm_standby -D -U <hostname>
Place local node online or remove standby property. crm_standby -D
View cluster status. One time to stdout. crm_mon -1
View cluster status. Refresh every 3s. crm_mon -i3
One line simple output. crm_mon -s
Show inactive resources. crm_mon -r
Stop resource. crm_resource -r <resource> -p target_role -v stopped
Start resource. crm_resource -r <resource> -p target_role -v started
Clear failed resource. crm_resource -C -H <host> -r <resource>
Query running cluster for current state (STDOUT). cibadmin -Q --obj_type resources
Other resources. XML definition

Choosing a host naming convention

Whether realizing it or not every organization goes through the process of selecting a naming convention. Often this is done without much forward planing resulting in unwieldy host and service names. In the worst cases host names are dropped completely and either by habit or lack of a proper DNS service only ip addresses are used.

In the following I will talk about the different types of naming conventions that I’ve experienced or read about. I’ll discuss the pros and cons of each. Before we get to that we’ll need to have a small refresher on domain name services.