Linux

HOW TO : Setup Global Redirect in Lighttpd

If you have ever managed a web application, you know you have to take it down at times :). And you usually want to show an simple page stating that you are down for maintenance. Here is a simple way to setup a “maintenance” splash page. The assumption is that you have a Linux server to host the maintenance page.

  • Configure lighttpd (HTTP Server) on the server using instructions from this article on Cyberciti.
  • Edit the lighttpd.conf file and add the following line in your site configuration

[bash] server.error-handler-404   = "index.html" [/bash]

  • Name your maintenance page as index.html and upload it to the document root (in this example, it is /var/www/html)

You are essentially telling the web server to display index.html whenever the user is trying to access content that is not present on the server. And since there is no content on the server other than the index.html, the web browser will always display the index.html page..

HOW TO : Dowload content from Oracle Metalink (Support) using wget

The usual process for a DBA to download files from Oracle Metalink (support) site is

  • Login to Metalink from his/her workstation
  • Download the file
  • Upload the file to the database server
  • Use the file

Say your database is in a data center and your workstation doesn’t have high speed connectivity to the data center, you can use the following trick to download content to a l[u]inux server in the data center that has Internet connectivity (and hopefully it is not your database server 🙂 ).

  • Log into Metalink from your workstation
  • Grab the link to the file/content you want to download (for example, we recently tried to download clusterware for Oracle 11G, and the link was http://download.oracle.com/otn/linux/oracle11g/linux.x64_11gR1_clusterware.zip)
  • Log into a server in your data center (it should have connectivity to the Internet and also to your database server)
  • Download the file using wget

[bash]wget http://download.oracle.com/otn/linux/oracle11g/linux.x64_11gR2_clusterware.zip –user ORACLE_ID –password ORACLE_ID_PASSWORD[/bash]

  • Replace the link with the link to your content and use your Oracle ID and password.
  • The file downloaded will have a strange name since wget  appends the sessionID to the end of the file. In the example I used above, the name of the file was “linux.x64_11gR2_clusterware.zip\?e\=1297470492\&h\=a66b265cc967a68c611052cb8e54356f
  • Rename the file and strip off the unnecessary data in the name using mv

HOW TO : Capture HTTP Headers using tcpdump

Quick how to on capturing HTTP headers using tcpdump on a web server (running Linux).

    • On the web server, issue the following command

      [bash] tcpdump -s 1024 -C 1024000 -w /tmp/httpcapture dst port 80 [/bash]

        • Stop the capture by issuing the break command (ctrl + c)
        • Open the capture file (httpcapture in this example) in wireshark and check out the headers under the  the HTTP protocol

        HOW TO : Find out which network port a program is using in linux

        Quick way to figure out, which ports a particular program is using in linux

        [bash] netstat -plan | grep -i PROGRAM_NAME [/bash]

        Example : Check which ports SSH is listening on

        [bash]

        samurai@samurai:~$ sudo /bin/netstat -plan | grep sshd
        tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      5257/sshd
        tcp        0     52 123.123.123.123:22      124.124.124.124:32846     ESTABLISHED 3551/sshd: samurai
        tcp6       0      0 :::22                   :::*                    LISTEN      5257/sshd
        unix  3      [ ]         STREAM     CONNECTED     5893     3551/sshd: samurai
        unix  2      [ ]         DGRAM                    5849     3551/sshd: samurai

        [/bash]

        HOW TO : Manage startup services in Ubuntu

        Most Redhat/Fedora users are used to chkconfig and service for controlling the services/programs that startup at boot time. Here is how you do it in Ubuntu

        • Check status of a particular service

        [bash] sudo SERVICE_NAME status [/bash]

        Example : Check the status of Apache Web Service

        [bash]samurai@samurai:~$ sudo service apache2 status
        Apache is running (pid 3496).[/bash]

        • Add a service to start on bootup

        [bash] update-rc.d SERVICE_NAME add [/bash]

        Example : Configure squid to start on bootup

        [bash] update-rc.d squid add [/bash]

        • Stop a service from starting on bootup

        [bash] update-rc.d SERVICE_NAME remove [/bash]

        Example : Configure squid to NOT start on bootup

        [bash] update-rc.d squid remove [/bash]

        NOTE : You need to have a startup script in /etc/init.d for the service to ensure update-rc.d works fine.

        HOW TO : Check IO speed on a Linux Machine

        For my notes.. if you ever want to check the IO capability of a disk (local or network) on a linux machine, use the following command

        [bash] dd if=/dev/zero of=test.file bs=4M count=1000 [/bash]

        The above command make a copy of the output from /dev/zero to a file called test.file (you can locate the file on the disk you want to measure) with a block size of 4M for a total file size of 4000Mb.

        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 : 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 : 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