Sunday, January 31, 2010

Preparing a CentOS 5.4 AMI for LAMP server

I used the RightScale AMI with id ami-f8b35e91, which has a pretty minimalistic installation of CentOS 5.4. Here are the steps I did to make it ready to run my sites
  • install rpmforge
    yum install yum-priorities
    Edit the .repo files in /etc/yum.repos.d/ and set up priorities by adding the line:
    priority=1 in the [base], [addons], [updates], [extras] sections, and the line
    priority=2 in the [centosplus],[contrib]
    rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
    wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm
    rpm -K rpmforge-release-0.5.1-1.el5.rf.i386.rpm
    rpm -ivh rpmforge-release-0.5.1-1.el5.rf.i386.rpm
    
    Edit /etc/yum.repos.d/rpmforge.repo and add the line
    priority=10
    Edit /etc/yum.repos.d/rpmforge-testing.repo and add the line
    priority=15
  • update the system
    yum update
    
  • install apache, mysql, php and some other packages
    yum install httpd php mysql mysql-server php-cli php-gd php-mbstring php-pdo php-pecl-fileinfo php-mysql php-imap php-ldap php-pear php-xml php-xmlrpc
     mod_ssl ImageMagick elinks emacs fetchmail mod_python netpbm netpbm-progs nmap ntp strace webalizer rdiff-backup trac
    
  • install amazon's AMI tools
    rpm -Uvh http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.noarch.rpm
    
  • turn off some services
  • chkconfig rightscale off
    chkconfig jexec off
    chkconfig --level 06 jexec off
    chkconfig ip6tables off
    chkconfig iptables off
    chkconfig netfs off
    chkconfig nfslock off
    chkconfig portmap off
    chkconfig xfs off
    chkconfig mcstrans off
    
  • install EC2 API tools
    wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip
    cd /usr/local/ec2
    unzip /root/ec2-api-tools.zip
    ln -s ec2-api-tools-* apitools
    
  • get rid of some unneeded packages
  • yum remove cups gcc-gnat libgnat cups-libs libobjc gcc-objc++ kernel-2.6.18-164.11.1.el5 kernel-headers-2.6.18-164.11.1.el5
  • add back c, c++ compilers
    yum install gcc gcc-c++
  • turn on services we need
    chkconfig httpd on
    chkconfig mysqld on
    chkconfig ntpd on
    
  • change /etc/sysconfig/network-scripts/ifcfg-eth0 to contain
    DEVICE=eth0
    BOOTPROTO=dhcp
    ONBOOT=yes
    TYPE=Ethernet
    USERCTL=yes
    PEERDNS=yes
    IPV6INIT=no
    

  • change /etc/sysconfig/network to contain
    HOSTNAME=yourhost.yourdomain
    NETWORKING=yes
    NETWORKING_IPV6=no
    

  • My site is an old legacy php site, which needs register_globals and register_long_arrays. So edit /etc/php.ini to set
    register_globals = On
    register_long_arrays = On
    memory_limit = 128M
    

  • edit /etc/logrotate.d/httpd and add /var/www/logs/*log

  • add user USER
    groupadd -g GID USER
    useradd -g GID -u UID USER
    

  • change passwords for root and USER
    passwd USER
    passwd
    

  • add crontab for USER

  • create the directory where EBS LVM will be mounted
    mkdir /vol
    

  • edit /etc/fstab to add
    /dev/vg1/lv1          /vol              ext3    defaults,noatime        0 0
    /vol/home             /home             none    bind                    0 0
    /vol/etc/httpd        /etc/httpd        none    bind                    0 0
    /vol/etc/pki          /etc/pki          none    bind                    0 0
    /vol/var/www          /var/www          none    bind                    0 0
    /vol/var/trac         /var/trac         none    bind                    0 0
    /vol/var/lib/mysql    /var/lib/mysql    none    bind                    0 0
    

  • edit /etc/ssh/sshd_config and set
    PasswordAuthentication yes
    

  • install the QuickForm pear package
    pear install HTML_QuickForm
    
  • get rid of the RightScale motd
    echo -n > /etc/motd
    

  • use the re-bundle script from my previous post to create the AMI