" Real coders don't blog, or at least not very often! " A.R.

CentOS Virtual Machine : datadisk with httpd, mysql and tomcat


Notes sur le configuration d'une Virtual Machine sous CentOS utilisant un data disk externe séparé du disque systeme, et contenant les parties configuration et data des applications.
Dans le cas présent, il s'agit des applications httpd, mysql et tomcat.
(l'objectif d'une telle configuration et de pouvoir backuper / restaurer seulement le disque externe et de pouvoir reconstruire un nouveau serveur fonctionnel à partir d'une nouvelle machine virtuelle et d'un backup)


Setup DATADISK

shutdown the VM and update its configuration: add a new 40GB disk and attach it to the VM
start the VM
verify the name of the new disk by comparing the size
fdisk -l

with fdisk create new partition covering whole disk, of type LVM (assuming new disk is /dev/sdc)
fdisk /dev/sdc
: n - p - 1 - CR - CR

change type to LVM
: t - 8e

save new partition table
: w

install disk as LVM
pvcreate /dev/sdc1
vgcreate lg1 /dev/sdc1

check it
vgdisplay

create then extend logical volume
lvcreate -L 1G /dev/lg1 -n lv1
lvextend -l 100%VG /dev/lg1/lv1

check it
lvdisplay

format logical volume
mkfs.ext3 /dev/lg1/lv1

update fstab so that the new disk is mounted automatically at boot
vim /etc/fstab
    /dev/lg1/lv1 /datadisk ext3 defaults 1 1

or
    /dev/mapper/lg1-lv1 /datadisk ext3 defaults 1 1

mount disk
mkdir /datadisk
mount /datadisk

update monitoring to monitor /datadisk instead of /boot AFTER monitoring has been setup
vim /etc/snmp/snmpd.conf
vim /etc/mrtg/server-info-num.cfg

replace occurences of "boot" with "datadisk" in those 2 files


httpd on DATADISK

httpd can be installed on the datadisk

  • Configuration

    for simplicity, do not install httpd before preparing the datadisk!
    create configurations folders
    cd /datadisk
    mkdir -p var/log/httpd
    mkdir -p etc/httpd/conf
    mkdir -p etc/httpd/conf.d
    mkdir -p var/www

    Be careful: first check what is under /etc/httpd/conf.d and /var/www if httpd has already been installed

    move existing web applications already present in /var/www to datadisk (such as mrtg)
    cd /var/www
    cp -a mrtg/ /datadisk/var/www/
    rm -rf /var/www

    prepare httpd folders to point to datadisk
    cd /etc
    rm -rf httpd
    mkdir httpd
    cd /etc/httpd
    ln -s /datadisk/etc/httpd/conf/ conf
    ln -s /datadisk/etc/httpd/conf.d/ conf.d
    cd /var
    ln -s /datadisk/var/www/ www
        
    cd /var/log
    ln -s /datadisk/var/log/httpd/ httpd
        

    install httpd and make it start automatically at startup
    yum install httpd
    chkconfig --levels 2345 httpd on
    chkconfig --list httpd
        

    enable HTTP in firewall (check WEB entry)
    system-config-securitylevel-tui


  • Virtual Hosting

    create virtual hosting for virtual domains
    mkdir /datadisk/www
    mkdir /www
    cd /
    ln -s /datadisk/www www

    update basic httpd config for virtual hosting at the bottom of the config file
    cd /etc/httpd/conf
    vim httpd.conf
        NameVirtualHost *:80

    for each virtual server add an entry like this one
        <VirtualHost *:80>
         <Directory "/www/www.mydomain.com/">
        # Options +Includes
        # XBitHack Full
         </Directory>
        ServerName www.mydomain.com
        ServerAlias mydomain.com
        DocumentRoot /www/www.mydomain.com
        ErrorLog logs/vhost_mydomain_com_error_log
        CustomLog logs/vhost_mydomain_com_access_log combined
        #ScriptAlias /cgi-bin/ /www/www.mydomain.com/cgi-bin/
        </VirtualHost>


    mysqld on DATADISK

    install mysql server
    yum install mysql-server

    BEFORE starting mysqld, move config file and folders to datadisk
    cd /etc
    cp -a my.cnf /datadisk/etc/
    rm my.cnf
    ln -s /datadisk/etc/my.cnf my.cnf

    update configuration in /etc/my.cnf based on "huge" configuration settings
    (or from /usr/share/mysql/my-huge.cnf)
    update configuration file to use datadisk for data
    vim /etc/my.cnf
        [mysqld]
        datadir=/datadisk/mysql

    start mysqld
    service mysqld start

    change root password
    /usr/bin/mysqladmin -u root password '<newpassword>'

    update timeout settings for connection pool
    vim my.cnf
        [mysqld]
        wait_timeout=604800


    tomcat6 on DATADISK

    install java 1.6 if needed (so that it doesn't only install java 1.5)
    yum install java-1.6.0

    install tomcat, java and all (lot of files will be installed)
    yum install tomcat6

    move /var/lib/tomcat6 to datadisk
    cd /var/lib/
    cp -a tomcat6 /datadisk/
    mv tomcat6 __tomcat6
    ln -s /datadisk/tomcat6/ tomcat6
        
    cd /etc
    cp -a tomcat6 /datadisk/etc/
    mv tomcat6 __tomcat6
    ln -s /datadisk/etc/tomcat6/ tomcat6

    install tomcat6 webapps
    yum install tomcat6-webapps

    start it and test it (monitor /var/log/tomcat6/catalina.out)
    service tomcat6 start

    open firewall (select "customize" and add 8080:tcp in other ports)
    system-config-securitylevel-tui

    test it opening http://<server>:8080/jsp-examples/
    install admin webapps
    yum install tomcat6-admin-webapps

    add an admin account to access the admin webapp
    vim /etc/tomcat6/tomcat-users.xml
         ...
         <user username="admin" password="<#admin password#>" roles="admin,manager"/>
         ...

    restart and test the manager interface logging with the user account just added
    service tomcat6 restart

    browse http://<server>:8080/manager/

    OK
  • January 15, 2012
    676 words


    Categories
    Tags
    centos esxi vmware httpd mysql tomcat

    Connect. Socialize.