HOWTO

HOW TO : Check status of bond interface in Linux

For my notes.. If you ever wanted to check the status of a bonded interface configure in Linux (esp RHEL), you can check the status by running the following command

[root@serverxyz bin]# cat /proc/net/bonding/bond0

i.e. assuming the name of your bond interface is bond0.

Output from the command

Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: eth3 (primary_reselect always)
Currently Active Slave: eth3
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth3
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:10:18:6e:b8:1a

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:21:5e:11:34:32

The configuration files involved are

/etc/sysconfig/network-scripts/ifcfg-bond0 (Bond Interface)

DEVICE=bond0
IPADDR=10.10.40.26
NETMASK=255.255.255.0
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
GATEWAY=10.10.40.1
NETWORK=10.10.40.0
BROADCAST=10.10.40.255
TYPE=Ethernet

/etc/sysconfig/network-scripts/ifcfg-eth3 (Primary Interface)

DEVICE=eth3
BOOTPROTO=none
ONBOOT=yes
HWADDR=00:10:18:6e:b8:1a
MASTER=bond0
SLAVE=yes
TYPE=Ethernet
USERCTL=no

/etc/sysconfig/network-scripts/ifcfg-eth0 (Secondary Interface)

DEVICE=eth0
HWADDR=00:21:5e:11:34:32
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
TYPE=Ethernet

HOW TO : Configure mime type mappings in Jboss

Instructions for configuring the mime type mappings in Jboss. Mime types essentially tells the application processing the content (typically a browser), what the content is. More information here (http://en.wikipedia.org/wiki/Internet_media_type).

  • Locate the web.xml file for your Jboss instance. It is usually in $JBOSS_HOME/server/INSTANCE/deploy/jboss-web.deployer/conf/web.xml
  • Locate the setting <mime-mapping> and make the required edits. For example, the code for defining the mime type for javascript looks like this



js
application/javascript

  • Restart Jboss

HOW TO : Improve Jboss startup times

We run multiple applications in Jboss at my work and one of the applications used to take an inordinate time to come up. A typical application would take < 1 minute to get deployed and this particular application for some reason was taking ~7-8 minutes. We initially thought it was a bug in the code and gave hell to our development team :).. But on closer investigation, we found out that a feature we enabled in the Jboss server settings which allows content to be hosted on network storage was causing the issue.

I blogged the feature in Jboss to follow sym links here (https://kudithipudi.org/2008/07/25/howto-configure-jboss-to-follow-symbolic-links/). So essentially when Jboss was started, it was checking all the content in these network path to check for applications to deploy. And traversing a network share with 1000s of directories isn’t fun :)..

We fixed it by making a simple edit to the start up script. Here’s the psuedo code for the script

  1. Remove soft links to network share
  2. Start Jboss
  3. Put soft links to network share

And now the application starts in less than a minute :).

I guess there might be other elegant ways to do this. i.e. Configure Jboss to only deploy certain applications, but this did the trick for us :).

HOW TO : Advanced search and replace in Notepad++

Jhanvi asked me to help with editing a text file recently. She had a file in the format


'512'
'345'
'876'

and needed to convert it into the format below


INSERT INTO BLAH VALUE ('512');
INSERT INTO BLAH VALUE ('345');
INSERT INTO BLAH VALUE ('876');

There are multiple ways, one can do this. Here is how I did this using Notepad++, an open source text editor. I used the regular expression capability of Notepad++ it’s search and replace function.

  • Press “Ctrl + h” to bring up the search and replace window.
  • Replace the single quote at the beginning of the line by using ” ^’ “
  • Replace the single quote at the end of the line by using ” ‘$ “

Screenshots from the operation

The data in it’s original format

Replacing the first quote mark

Data after the first search and replace operation

Replacing the second quote mark

Data in the final format

HOW TO : Load/Stress test a Linux based server

We ran into an issue at work recently, which prompted us to do some performance testing on some of our Linux servers. The requirement was to stress test the key components of the server (CPU, RAM, HDD, Network) and prove that different servers with the same configuration were capable of performing identically. Pretty simple right :).. The challenge was to find tools that could be run to stress test each of the components. There were a lot of tools for CPU and memory (RAM) testing, but not a lot for network and hard drive (HDD) testing. After searching high and low, we found a couple of tools, that I wanted to document here for future reference.

HDD Testing :

I found a pretty interesting tool called Iozone written by William Norcott (Oracle) and Don Capps. You can get the source code and builds for major OSs at http://iozone.org . Despite installing the program using RPM, we were not able to  run the program without specifying the complete path.

There are a ton of options for the program, but the easiest method to run it was in automated mode with the output going to an Excel spreadsheet (more like a glorified CSV file 🙂 ). Here is the command we used

/opt/iozone/bin/iozone -a -Rb output_excel_file.xls

The “-a” is to tell the program in automated mode and the “-Rb” is to tell the program to format the output in Excel format. And you can then go ahead and open the spreadsheet in Excel and create 3D graphs to check and compare the output.

Network Testing :

Most of the information out there in terms of testing the network stack of a machine is either to copy large files over a network share or via FTP. We didn’t find that was enough to really max out a Gigport since there were protocol limitations that didn’t allow us to saturate the network port. After some searching, we stumbled across a tool called “ettcp” on Sourceforge. ettcp itself is an offshoot of ttcp. ttcp (stands for test tcp) was created to test network performance between two nodes. I couldn’t find any place to download ttcp itself, but you can download ettcp at http://ettcp.sourceforge.net/.

We used a server, to act as a common receiver for all the servers we intended to do a performance test on. Here are the commands we used to run the test

RECEIVER (Common Server)
./ettcp -r -s -f M

The options are

  • “-r” for designating the machine as receiver
  • “-f M” for showing the output in Mega Bytes.

TRANSMITTER (Test Servers)
./ettcp -t -s receiver_hostname -n 10000000 -f M

the options are

  • “-t” for designating the machine as transmitter
  • “-s receiver_hostname” to define the receiver
  • “-n” to define the number of packets to send to the receiver

HOW TO : Install Wireshark on Windows 7

[UPDATE] Wireshark works without any issues as of version 1.2.3. This release includes WinPcap 4.1.1, which has support for Windows 7 and 2008. Looks like the issue was with the drivers not being signed digitally.

I recently upgraded my laptop to Windows 7 RC from the beta version I was testing earlier. As part of installing my standard set of tools, I tried to install Wireshark (open source network capture tool), and ran into an error due to the UAC security settings. Essentially, Windows was blocking the install of WinPcap (network capture driver). I solved it by enabling compatibility mode on the install executable. Here are the steps to install Wireshark on Windows 7.

  • Download the install file from http://www.wireshark.org/download.html
  • Right click on the install file (I happened to download the 64 bit install) and click on properties
  • In the properties window, click on the compatibility tab and change the option for “Run this program in compatibility mode for” to “Windows Vista (Service Pack 2)” and click on OK. Here’s a screenshot for reference

  • Right click on the install and click on “Run as Administrator”
  • Make sure you choose the option to install the NPF as a service during the install prompts. This will allow all users on the machine to use Wireshark without admin privileges.

P.S : WinPCap is apparently going to come out with a new version soon that is compatible with Windows 7.

HOW TO : Convert mpg files to flv format using ffmpeg

For my documentation. Here is the command line parameters, I used to convert a video file in mpg format to flv (flash video) format using ffmped (open source format converter)

ffmpeg -i Original_Video.mpg -deinterlace -ar 44100 -r 25 -qmin 3 -qmax 6 Converted_Video.flv

I will post details on where to get software and such, when I have time :).

HOW TO : Find which interface a particular IP address is configured on

There are a ton of scripts to find how many IP addresses  are configured on a system, but I could not find one, whic would show me which particular network interface an IP address was configured on. Here is a one liner, that will give you this information in Linux

/sbin/ifconfig | grep -B1 10.10.10.10 | awk '{if (NR==1) print $1}'

The same script can be changes a bit to support other operating systems too. Essentially, I am doing a grep (search) of the output of ifconfig, which shows all the network information on the system for a particular IP. At the same time, I am using the -B1 option, which will show the line above the matching line. Finally, I am piping this to awk and printing the first row in the first column.

HOW TO : Pass environment variables when using sudo

Say you need to sudo as a particular user and run a command and at the same time you need to pass an environmental variable to the command, you can do it by passing the command in doublequotes.

For example, I want to start Oracle while I am logged in as another user (vinay), I can start the database using dbstart by issues

"sudo su - oracle -c "dbstart /$ORACLE_HOME"

$ORACLE_HOME is an environmental variable listed under user oracle’s environment.

Needless to say, you need to ensure that you have sudo configured to allow your userID to su to oracle.