Friday, August 29, 2008

Resizing your xen DomU using LVM

To resize the disk space of a xen DomU that is using Logical Volume Manager(LVM) is very easy. Below is step by step on how to do the resizing process.
  1. Create a new image with the size that you require. Just give any meaningful name to the image. In this case I will use the name extended.img
    • # dd if=/dev/zero of=extended.img bs=1 count=1 seek=20G conv=notrunc
  2. Add the new image to the configuration file of your DomU. In this example, the name of the domU is xen0
    • # vi /etc/xen/xen0
    • Add these line to it
      • disk = [ 'tap:aio:/path/to/xen/xen0.img,xvda,w','file:/path/to/xen/extended.img,xvdb,w' ]
    • Save
  3. Start your domU
    • # xm create xen0
  4. Access your domU
    • # xm console xen0
  5. Once inside, check whether the new image is detected
    • # fdisk -lu
  6. After confirm that your new hard disk image is detected, it is time we have to work on the lvm
    • Create new physical volume (PV) using the new hard disk image
      • # pvcreate -v /dev/xvdb
    • Check that you have successfully added the PV
      • # pvdisplay
    • Extend your existing volume group (VG) to include the new PV
      • # vgextend -v VolGroup00 /dev/xvdb
    • Check that you have successfully add the PV into the VG
      • # vgdisplay
    • Extend your logical volume (LV)
      • # lvextend -L +20G -v /dev/VolGroup00/LogVol00
    • Check that the extension has been added
      • # lvdisplay
    • If all the steps are successfully done, you have to resize the / partition
      • # resize2fs /dev/mapper/VolGroup00-LogVol00
  7. You are done. Check your new hard disk space :)
    • # df -lh

Monday, August 25, 2008

NFS quick howto for centos 5

To use nfs successfully, you have to configure the server and the client. In this example, the client is 192.168.0.3 and the server is 192.168.0.1. The folder to be shared is /home/sharing, and to be mounted to /mnt on the client

On the server
  1. Make directory that you want to use.
    • # mkdir /home/sharing
  2. Edit /etc/exports, insert the client machine's ip
    • # vi /etc/exports
      • Add this line:
        • /home/sharing 192.168.0.3/255.255.255.255(rw,sync)
      • Save
  3. Edit /etc/hosts.allow
    • # vi /etc/hosts.allow
      • Add this line:
        • portmap: 192.168.0.0/255.255.255.0
      • Save
  4. Start nfs and portmap
    • # /etc/init.d /nfs start
    • # /etc/init.d/portmap start
On the client
  1. Start portmap
    • # /etc/init.d/portmap start
  2. Mount the nfs folder
    • # mount 192.168.0.1:/home/sharing /mnt
  3. Check /var/log/messages for any error that might occur
    • # tailf /var/log/messages
  4. Use mount to check if the folder is mounted properly
    • # mount
      • This should be the output:
        • 192.168.0.1:/home/sharing on /mnt type nfs (rw,addr=192.168.0.1)
  5. Edit /etc/fstab to mount the shared folder on boot
    • # vi /etc/fstab
      • Add this line
        • 192.168.0.1:/mnt/sdb1/backup /mnt nfs rw,hard,intr 0 0
      • Save
You can use 'man exports' to see the options available for /etc/exports

Wednesday, August 20, 2008

Installing backuppc in centos 5

I have been given the task of setting up one backuppc server, and below are the steps on how I did it :)

Server setup
  1. Download the backuppc 3.1.0 srpm from dev.centos.org
  2. Rebuild the srpm using rpmbuild. If the command is not there in your pc, install it first using 'yum install rpm-build'
    • # rpmbuild --rebuild backuppc-3.1.0-1.el5.centos.src.rpm
  3. Get your rpm file at /usr/src/redhat/RPMS/i386 and install it. Install all the perl module needed using yum
    • # yum install perl-Compress-Zlib perl-Archive-Zip perl-File-RsyncP perl-XML-RSS httpd
    • # rpm -Uvh backuppc-3.1.0-1%{dist}.i386.rpm
  4. User backuppc will be created upon installation. Change apache user to backuppc.
    • # vi /etc/httpd/conf/httpd.conf
    • Change 'User apache' to 'User backuppc'
    • Save
  5. Edit file /etc/httpd/conf.d/backuppc.conf
    • # vi /etc/httpd/conf.d/backuppc.conf
    • change 'Allow from 127.0.0.1' to 'Allow from all'
    • Save
  6. Create password for cgi-bin admin user
    • # htpasswd -c /var/lib/backuppc/passwd/htpasswd admin
  7. Edit backuppc config file
    • # vi /etc/BackupPC/config.pl
    • Find and change accordingly
      • $Conf{ServerHost} = 'localhost';
      • $Conf{SplitPath} = '/usr/bin/split';
        $Conf{CatPath} = '/bin/cat';
        $Conf{GzipPath} = '/bin/gzip';
        $Conf{Bzip2Path} = '/usr/bin/bzip2';
      • $Conf{BackupPCUser} = 'backuppc';
      • $Conf{TopDir} = '/var/lib/backuppc';
        $Conf{ConfDir} = '/etc/BackupPC';
        $Conf{LogDir} = '/var/log/BackupPC';
        $Conf{InstallDir} = '/usr';
        $Conf{CgiDir} = '/usr/share/backuppc/cgi-bin';
      • $Conf{ServerInitdPath} = '/etc/init.d/backuppc';
        $Conf{ServerInitdStartCmd} = '$sshPath -q -x -l root $serverHost$serverInitdPath start';
      • $Conf{SshPath} = '/usr/bin/ssh';
      • $Conf{NmbLookupPath} = '/usr/bin/nmblookup';
      • $Conf{PingPath} = '/bin/ping';
      • $Conf{CgiAdminUsers} = 'admin';
    • Save
  8. Grant passwordless sudo for user backuppc to run /bin/gtar and /bin/tar
    • # visudo
    • Add these entries
      • Defaults !lecture # to disable lecture
      • backuppc ALL=NOPASSWD:/bin/gtar,/bin/tar # enable user backuppc to run /bin/tar and /bin/gtar without authentication.
    • Comment this entry
      • #Defaults requiretty
    • Save
  9. Restart apache and backuppc service
    • # /etc/init.d/http restart
    • # /etc/init.d/backuppc restart
  10. Open your browser and point it to 'http://backuppc_server_ip/backuppc' and you should see the backuppc web interface
  11. After this, you have to do almost all the configuration through the web interface. To test, you can run localhost backup first. You have to create the host, fill up all the setting and you are ready to go. Record the host and ip in /etc/hosts.
Client setup
  1. Create new user
    • # useradd backupuser
    • # passwd backupuser
  2. Grant passwordless sudo for user backupuser
    • # visudo
    • Add these entries
      • Defaults !lecture # to disable lecture
      • backupuser ALL=NOPASSWD:/bin/gtar,/bin/tar # enable user backuppc to run /bin/tar and /bin/gtar without authentication.
    • Comment this entry
      • #Defaults requiretty
    • Save
  3. From the server using backuppc user, create ssh public key
    • # su -s /bin/bash backuppc
    • $ mkdir .ssh
    • $ chown backuppc.backuppc .ssh
    • $ chmod 700 .ssh
    • $ ssh-keygen -t rsa
    • $ ssh-copy-id -i .ssh/id_rsa.pub backupuser@client
  4. To make sure that the 3rd step is a success, try to ssh to backupuser@client using backuppc user from the server. If no password is asked, then you are ready.
    • # su -s /bin/bash backuppc
    • $ ssh backupuser@client
  5. You can start entering the client to the list of host and start backing up :)
Update: Precompiled rpm can be downloaded here

Monday, August 18, 2008

Saving website on local machine

Sometimes you found a website that is very interesting, but you just do not have enough time to read it on that particular time. You wish you could save it so that you can view it offline without connecting to the internet. This can be done using wget;

$ wget -m -k -K -E http://www.tldp.org/HOWTO/LVM-HOWTO/index.html

where -m for mirror, -k for convert the links so that it will be suitable for local viewing, -K for backup converted files and -E for adding html extension to the files downloaded. This is the result of the above command;

$ ls
www.tldp.org

Use any web browser to view the files offline by opening the .html file inside the above folder