Centos 5.x

Archived posts from this Category

Installing clamav

Posted by admin on 06 May 2008 | Tagged as: Centos 5.x, exim

I wanted to install an anti-virus scanner to work with my smtp server (exim) and since I couldn’t find a centos repository that included clamav and didn’t want to spend hours searching I just downloaded the source and installed from scratch. To do this you will need to have a compiler and development libraries installed. The steps I followed were:

  • Create the clamav user and group

    sudo groupadd clamav
    sudo useradd -g clamav -c "clamav user" -d /var/clamav -s /sbin/nologin -m clamav

  • Download the source from http://www.clamav.net into a working directory and unpack (eg. tar zxvf clamav-0.93.tar.gz) which will create a source code directory called clamav-0.93 under your working directory.
  • cd into the source code directory and execute ./configure in my case I didn’t want to change any of the defaults and wanted to install clamav into /usr/local which is the default location. The output will tell you if there are any missing prerequisites such as zlib. If there are any missing prerequisites then I recommend that you install them first and then start to build and install clamav.
  • Execute make which will compile the clamav source with the configuration options from above.
  • Install clamav

    sudo make install

  • Edit the clamd.conf file in /usr/local/etc and set appropriate values for the various configuration items. My clamd.conf has the following settings:

    LogFile /tmp/clamd.log
    LogFileUnlock yes
    LogFileMaxSize 2M
    LogTime yes
    LogClean yes
    LogSyslog yes
    PidFile /var/run/clamd.pid
    LocalSocket /var/run/clamd.exim/clamd.sock
    FixStaleSocket yes
    MaxRecursion 128
    MaxFileSize 15M
    MaxFiles 1500

    for all other settings I accepted the defaults.

  • Configure /usr/local/etc/fresclam.conf - the settings I changed in my freshclam.conf were:

    UpdateLogFile /var/log/freshclam.log
    LogTime yes
    LogSyslog yes
    PidFile /var/run/freshclam.pid
    DatabaseMirror database.clamav.net
    NotifyClamd /usr/local/etc/clamd.conf

    all other settings were at their default values

  • Run freshclam once manually to seed the virus signatures in the database. Execute /usr/local/bin/freshclam
  • For normal operations I also set freshclam to run once per hour by adding it to my crontab

    8 0-23 * * * /usr/local/bin/freshclam 2>&1

  • Create a script to automatically start clamd on a system reboot in /etc/init.d. My /etc/init.d/clamd script is:


    #! /bin/sh
    #
    ### BEGIN INIT INFO
    # Provides: clamd
    # Required-Start: $syslog $network clamd
    # X-UnitedLinux-Should-Start:
    # Required-Stop: $syslog $network clamd
    # X-UnitedLinux-Should-Stop:
    # Default-Start: 3 5
    # Default-Stop: 0 1 2 6
    # Short-Description: anti virus scan mails
    # Description: Start clamd
    ### END INIT INFO
    #

    # Check for missing binaries (stale symlinks should not happen)
    # Note: Special treatment of stop for LSB conformance
    CLAMD_BIN=/usr/local/sbin/clamd
    CLAMD_CONFIG=/usr/local/etc/clamd.conf
    CLAMD_PID_FILE=/var/run/clamd.pid

    test -x $CLAMD_BIN || { echo "$CLAMD_BIN not installed";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 5; fi; }

    # Check for existence of needed config file and read it
    test -r $CLAMD_CONFIG || { echo “$CLAMD_CONFIG not existing”;
    if [ "$1" = "stop" ]; then exit 0;
    else exit 6; fi; }

    # Shell functions sourced from /etc/rc.status:
    # rc_check check and set local and overall rc status
    # rc_status check and set local and overall rc status
    # rc_status -v be verbose in local rc status and clear it afterwards
    # rc_status -v -r ditto and clear both the local and overall rc status
    # rc_status -s display “skipped” and exit with status 3
    # rc_status -u display “unused” and exit with status 3
    # rc_failed set local and overall rc status to failed
    # rc_failed set local and overall rc status to
    # rc_reset clear both the local and overall rc status
    # rc_exit exit appropriate to overall rc status
    # rc_active checks whether a service is activated by symlinks
    # rc_splash arg sets the boot splash screen to arg (if active)
    . /etc/rc.status

    # Reset status of this service
    rc_reset

    # Return values acc. to LSB for all commands but status:
    # 0 - success
    # 1 - generic or unspecified error
    # 2 - invalid or excess argument(s)
    # 3 - unimplemented feature (e.g. “reload”)
    # 4 - user had insufficient privileges
    # 5 - program is not installed
    # 6 - program is not configured
    # 7 - program is not running
    # 8–199 - reserved (8–99 LSB, 100–149 distrib, 150–199 appl)
    #
    # Note that starting an already running service, stopping
    # or restarting a not-running service as well as the restart
    # with force-reload (in case signaling is not supported) are
    # considered a success.

    case “$1″ in
    start)
    echo -n “Starting clamd”
    $CLAMD_BIN 2>&1

    # Remember status and be verbose
    rc_status -v
    ;;
    stop)
    echo -n “Shutting down clamd”
    CLAMD_PID=`/usr/bin/head -n 1 ${CLAMD_PID_FILE}`
    kill -TERM ${CLAMD_PID}

    # Remember status and be verbose
    rc_status -v
    ;;
    restart)
    ## Stop the service and regardless of whether it was
    ## running or not, start it again.
    $0 stop
    $0 start

    # Remember status and be quiet
    rc_status -v
    ;;
    reload)
    echo -n “Reload service clamd”
    $CLAMD_PID=`head -n 1 ${CLAMD_PID_FILEi}`
    kill -HUP ${CLAMD_PID}
    rc_status -v

    ## Otherwise:
    #$0 stop && $0 start
    #rc_status
    ;;
    *)
    echo “Usage: $0 {start|stop|restart|reload}”
    exit 1
    ;;
    esac
    rc_exit

  • Now make a link from the /etc/init.d/clamd script to the runlevel startup directories. Try

    chkconfig clamd on

    or possibly

    ln -s /etc/init.d/clamd /etc/rc3.d/S99clamd
    ln -s /etc/init.d/clamd /etc/rc5.d/S99clamd

  • Now start clamd

    /etc/init.d/clamd start

What is dmapi?

Posted by admin on 06 May 2008 | Tagged as: Centos 5.x, IT Stuff

dmapi is the data management api defined in the X/Open document “Systems Management Data Storage Management API dated Feb 1997. XFS, IBM JFS, VxFS, AdvFS and GPFS file systems support DMAPI for Hierarchical Storage Management

Enabling the CentOSPlus repository

Posted by admin on 06 May 2008 | Tagged as: Centos 5.x, IT Stuff

  • Open the /etc/yum.repos.d/CentOS-BASE.repo file in your favourite text editor.
  • Find the [centosplus] section and set (Note: Ignore quotes) “enabled=1” then add the line “includepkgs=kernel* xfs” kmod* dmapi*”
  • You can now list the available (eg. xfs related) packages using “yum list available *xfs*”

Adding an xfs partition to Centos 5

Posted by admin on 06 May 2008 | Tagged as: Centos 5.x

First off I should say that my test system is pretty ancient being an AMD Duron with 512MB ram so if you are installing onto something more modern your mileage on the actual commands may vary. If you are using an x86_64 system you will need to enable the CentosPlus repository. For i386/i686 the modules you need are in the extras repository so no changes to the /etc/yum.repos.d/CentOS-Base.repo file are required. Also I refer to directories and devices on my hardware, you should replace these references with those for your own system as appropriate.

(1) Obtaining the xfs modules

This assumes you are logged into Centos and have a command prompt…

At a command prompt execute

yum list available *xfs*

and you should see something like the following output

Loading "installonlyn" plugin
Setting up repositories
base 100% |=========================| 1.1 kB 00:00
updates 100% |=========================| 951 B 00:00
addons 100% |=========================| 951 B 00:00
extras 100% |=========================| 1.1 kB 00:00
Reading repository metadata in from local files
Available Packages
kmod-xfs.i686 0.4-1.2.6.18_53.1.14.e extras
kmod-xfs-PAE.i686 0.4-1.2.6.18_53.1.14.e extras
kmod-xfs-xen.i686 0.4-1.2.6.18_53.1.14.e extras
xfsdump.i386 2.2.46-1.el5.centos extras
xfsprogs.i386 2.9.4-1.el5.centos extras
xfsprogs-devel.i386 2.9.4-1.el5.centos extras
xorg-x11-xfs.i386 1:1.0.2-4 base
xorg-x11-xfs-utils.i386 1:1.0.2-4 base

The modules I loaded were kmod-xfs.i686, xfsdump.i386, xfsprogs.i386 and dmapi so execute the command

yum install kmod-xfs.i686 xfsdump.i386 xfsprogs.i386 dmapi

(2) Creating an XFS filesystem

  • Use fdisk or parted to create a new partition from unused space on your hard disk. You will need to check the man pages for exact details. If you are converting an existing partition to xfs then see (3) below.
  • Format the new filesystem for xfs with a command like mkfs.xfs <filesystem> eg. for a partition /dev/had3 the command would be
  • mkfs.xfs /dev/hda3

  • You can provide a number of parameters to mkfs.xfs to set various options so it may be worth reading the man pages for mkfs.xfs.
  • Create a mountpoint for the new filesystem
  • mkdir /mymount

  • Edit /etc/fstab and add a line something like
  • /dev/hda3 /mymount xfs defaults 1 1

    which basically means “mount the block special device /dev/hda3 on the /opt mountpoint”. This is an xfs filesystem which uses the default mount options, the filesystem does not need to be dumped but fsck can check the filesystem after it has checked the root filesystem”.

  • Mount your new filesystem
  • mount /mymount

    The mount command will read the mount options from the fstab line that refers to the /mymount mountpoint.

  • You can now access the new filesystem at /mymount

(3) Converting and existing filesystem to xfs. For the purposes of these notes we will assume that /dev/hda3 is mounted on /opt formatted as ext3.

  • Make a backup of any data currently on the partition you want to convert to xfs.
  • Unmount the /opt partition
  • umount /opt

  • Format the partition as XFS
  • mkfs.xfs -f /dev/hda3

  • edit /etc/fstab
    • If you are not using LVM or your system does not use volume labels to identify partitions find the entry for /dev/hda3 and change the third item on that line of the fstab file from ext3 to xfs.
    • If you have LVM2 partitions you are probably using volume labels in your fstab file in which case I suggest that you format the partition using the command mkfs.xfs -f -L /opt /dev/hda3 then find the line in fstab that starts with “LABEL=/opt” and change the third item on that line from ext3 to xfs
  • Remount the partition
  • mount /opt

  • Restore the data you backed up in the first point above.

Congratulations, you should now have a working XFS partition that will automatically mount during a system boot.