Chris Paquin

AI, Virtualization, Containers, Infrastructure, Linux

Category: Redhat

  • Redirect Linux Console to HP ILO via SSH

    Constipation Sometimes the ILO web interface is painfully slow to use when you are just trying to get on the console of a server. To get around this I have been taking advantage of the fact that you can SSH to the ILO and access the server console from there.

    In order to do this you must add the following to the bottom of /etc/inittab.

    S1:2345:respawn:/sbin/agetty 115200 ttyS1 vt100

    Then you must add ttyS1 to the bottom of /etc/securetty. If you don’t you will not be able to log in as root from the serial console. So don’t forget this step.

    Then ssh into the ilo console — and run the following command.

    </>hpiLO-> VSP

    Note that this works on the ILO2, and possibly on the ILO3. It does not work on ILO1.

     

     

     

     

  • RedHat Performance Tuning: The Man Pages

    OTF365091S This my first post following my week long Redhat Monitoring and Performance Tuning Course (RH442). This course was rather intense and dealt mostly with concepts and theories rather and was not at all a how-to on performance tuning. I am going to do my best to document some of what I learned.  Lets start with the documentation…

    Man Pages, are the extensive documentation that comes installed by default on a linux system. They are seperated into 9 books or sections.

    1. General Commands
    2. System Calls
    3. C Library Functions
    4. Special FIles and Drivers
    5. FIle Formats
    6. Games/Screensavers
    7. Protocols
    8. System Admin Commands and Daemons

    To access a particular book you specify the book name after the man command. For example:

    #man 1 printf

    which is different than…

    #man 3 printf

    To find all the man pages related to printf, you run a the following

    #man -k printf

    Which gives you the output below listing all man pages related to printf. These specific ones are all on the the printf command specifically. Similarly you can use the apropos command and get the same output

    To see only the man pages for printf run the command below

    #man -f printf

    Which will return only what you see below.

    printf (1)           – format and print data
    printf (1p)          – write formatted output
    printf (3)           – formatted output conversion
    printf (3p)          – print formatted output

     

  • Simple Bash Scripting – Case Statement

    Angry-bird-red-toy For the RHCE test you are probably going to want to know how to write a simple bash script which employs a simple case statement.

    Note that the ")" symbol is used to separate the list of selections from the action to be taken. Fall through is done using *, which catches all input that has not been specificed previously. Also ;; acts as a case break.

    Note that the statement is started with “case” and closed with “esac

    [code language=”css”]
    #!/bin/bash
        case "$1" in
    this)  echo "this"
    ;;
    that) echo "that"
    ;;
    *) echo "Type this or that"
    esac

    [/code]

  • RHEL – How to Encrypt a Partition using Cryptsetup and LUKS

    EUTScglkIUlpZsV Cryptsetup uses dm-crypt to encrypt a disk at the partition level.  In RHEL, cryptsetup is used with Linux Unified Key Setup (LUKS), a disk encryption specification. Mounting a LUKS encrypted partiton requires a passphrase, which can either be passed in a file or via the command line. Read more about dm-crypt here.

    Anyway to use crypsetup, you first must have a free partiton on a disk. In this instance I am using /dev/sdc1, which is a freeagent external usb drive.

    First initialize the LUKS partition. My target is /dev/sdc1

    #cryptsetup luksFormat /dev/sdc1

    Then open the LUKS partition setup the dev mapper device. The command below creates /dev/mapper/freeagent

    #cryptsetup luksOpen /dev/sdc1 freeagent

    Create a passkey file if you want the device to be able to automount at boot. 

    #touch /root/freeagent_passkey && chmod 600 /root/freeagent_passkey

    Make cryptsetup aware of the key

    #cryptsetup luksAddKey /dev/sdc1 /root/freeagent_passkey

    #echo "mypasskey" > /root/freeagent_passkey

    Dont forget to make a filesystem

    #mkfs -t ext4 /dev/mapper/freeagent

    Then add the following to /etc/fstab…

    /dev/mapper/freeagent   /freeagent              ext4    _netdev         1 1

    And add the following to /etc/crypttab. Note that the first entry is the name of the /dev/mapper device

    freeagent       /dev/sdc1       /freeagent

    To get a status on a device and to see the mappings between /dev/mapper and /dev/sdc1

    #cryptsetup status

    /dev/mapper/freeagent
    /dev/mapper//dev/mapper/freeagent is active:
      cipher:  aes-cbc-essiv:sha256
      keysize: 128 bits
      device:  /dev/sdc1
      offset:  1032 sectors
      size:    2930270970 sectors
      mode:    read/write

    Make sure you keep track of when to use /dev/mapper/freeagent vs /dev/sdc1 in the commands above.

  • Bind – Zone File Serial Number Reset

    Lemo-the-worm Each and every zone file has a unique serial number and that serial number should increment with each subsequent revision

    A serial number is traditionally in the format (YYYYMMDDSS) where SS the sequence number. For example, today is 1/21/2011, so the serial number in a zone file modified today would be… 201101210.

    So lets say that you pushed that zone today and when you went back to make an additional change, you accidentally added an additional number to your serials and instead of  201101211 you ended up with 2201101211.

    In order to get everything back in order you will need to manually reset the zone file’s serial number by setting it to the number below. Its highest number you can get using 32 bits.

    4294967295

    To to reset your serial number, update your zone file with the serial number listed above and push it out to the slaves. Then change your zone files serial number back to the correctserial number, which will be considered to be greater than the magic number above. Then push dns again.

    Check your slave servers and verify the the zone file now has the correct serial.

     

     

  • How to use SAR on Redhat

    Eyeball Sar is a system monitor command used to display system activity. Sar ts installed via the sysstat rpm. Use the command below to install sysstat.

    [root@fedora ~]# yum -y install sysstat

    Once installed you can check out the sysstat config file (/etc/sysconfig/sysstat) and configure how long to sar will keep your logfiles, on my system the default was 7 days. I changed this to 30 days.

    The cron job for sar is located here (/etc/cron.d/sysstat) if you want to modify it as well.

    Once installed and configured to your liking you must ensure that it starts and runs at boot time. I accomplished this via the command below.

    [root@fedora ~]# chkconfig sysstat on && service sysstat start

    Once up and running it will write its logs out to /var/log/sa, and you can read those files with the following command (sar -d <filename>, where filename is the name of the file that you want to read). Note that in the examples below, 3 is the interval, and 10 is the count.

    Additionally you may run sar interactively, below are a few sample commands.

    View disk i/o and transfer rate stats:

    sar -b 3 10

    View memory and swap space stats:

    sar -r 3 10

    View swapping stats:

    sar -W 3 10

    View network stats:

    sar -n DEV 3 10

    View CPU stats:

    sar -P ALL 3 10

  • Quick and Dirty Sed Replace Command

    Prodshot_170x190 Had to move my corporate kickstart server to a new vlan and re-ip it this past week. As a result I needed to update my kickstart config files so that they know where to look for the install media. Instead of editing each file directly I did the following to change the IP address in a kickstart config

    sed -i ‘s/10.100.x.x/10.1.x.x/g’ centos5-u4_x86_64.cfg.

    Once I saw that the command above worked as anticipated, I then ran the same command but on each cfg file in the directory. Syntax below

    find . -type f -exec sed -i ‘s/10.100.x.x/10.1.x.x/g’ {} \;