Aws-create

From Bashlinux
Revision as of 02:23, 18 June 2010 by Manpaz (talk)
Jump to: navigation, search

Creating a CentOS AMI through a Loopback File

The image created here is based on CentOS Linux.

Create a File to Host the CentOS AMI

A base CentOS Linux installation requires about 1.2 GB, but custom installation for a server environment might require up to 3.0 GB.

  • Create a location to place the CentOS AMI
 # mkdir -p /usr/local/src/EC2
 
  • Create a file to host the CentOS AMI
 # dd if=/dev/zero of=/usr/local/src/EC2/bashlinux-server.fs bs=1M count=3072
 3072+0 records in
 3072+0 records out
 3221225472 bytes (3.2 GB) copied, 118.687 seconds, 27.1 MB/s
 


Create a Root File System Inside the File

Create an ext3 file system

 mke2fs -F -j /usr/local/src/EC2/bashlinux-server.fs
 mke2fs 1.39 (29-May-2006)
 Filesystem label=
 OS type: Linux
 Block size=4096 (log=2)
 Fragment size=4096 (log=2)
 393216 inodes, 786432 blocks
 39321 blocks (5.00%) reserved for the super user
 First data block=0
 Maximum filesystem blocks=805306368
 24 block groups
 32768 blocks per group, 32768 fragments per group
 16384 inodes per group
 Superblock backups stored on blocks:
 	32768, 98304, 163840, 229376, 294912

 Writing inode tables: done
 Creating journal (16384 blocks): done
 Writing superblocks and filesystem accounting information: done

 This filesystem will be automatically checked every 30 mounts or
 180 days, whichever comes first.  Use tune2fs -c or -i to override.
 


Mount the File through Loopback

  1. Create a mount point in the file system where the image will be attached:
 # mkdir -p /mnt/EC2-FS
 
  1. Mount the file system image:
 mount -o loop /usr/local/src/EC2/bashlinux-server.fs /mnt/EC2-FS/
 


Prepare for the Installation

  1. Create a `/dev` directory and populate it with a minimal set of devices. You can ignore the errors in the output
 # mkdir -p /mnt/EC2-FS/dev
 # MAKEDEV -d /mnt/EC2-FS/dev -x console
 # MAKEDEV -d /mnt/EC2-FS/dev -x null
 # MAKEDEV -d /mnt/EC2-FS/dev -x zero
 
  1. Create the `/etc` directory
 # mkdir -p /mnt/EC2-FS/etc
 
  1. Create the `fstab` file within the `/mnt/EC2-FS/etc` directory and add the following:
 /dev/sda1  /         ext3    defaults        1 1
 none       /dev/pts  devpts  gid=5,mode=620  0 0
 none       /dev/shm  tmpfs   defaults        0 0
 none       /proc     proc    defaults        0 0
 none       /sys      sysfs   defaults        0 0
 
  1. Create a temporary yum configuration file `/usr/local/src/EC2/yum-ec2.conf`
 [base]
 name=CentOS-5.1 - Base
 mirrorlist=http://mirrorlist.centos.org/?release=5.1&arch=i386&repo=os
 baseurl=http://mirror.centos.org/centos/5.1/os/i386/
 gpgcheck=0

 [updates]
 name=CentOS-5.1 - Updates
 mirrorlist=http://mirrorlist.centos.org/?release=5.1&arch=i386&repo=updates
 baseurl=http://mirror.centos.org/centos/5.1/updates/i386/
 gpgcheck=0
 
This ensures all the required basic packages and utilities are installed.  This file can be located on image location `/usr/local/src/EC2`, and is used only during installation
  1. Hide system repositories for AMI installation
 # mkdir /root/tmp-yum
 # mv /etc/yum.respos.d/* /root/tmp-yum/
 
This avoids the use of system repositories that requires a specific value for `$releasever` and `$basearch`, also avoids the duplicated repository error messages.
  1. Mount the `proc` filesystem manually
 # mkdir -p /mnt/EC2-FS/proc
 # mount -t proc none /mnt/EC2-FS/proc
 
  1. Create log folder
 # mkdir -p /mnt/EC2-FS/var/log
 


Install the Operating System

  • Install the Base operating system
 # yum -c /usr/local/src/EC2/yum-ec2.conf --installroot=/mnt/EC2-FS --exclude=sysreport -y groupinstall Core Base
 Core Base
 Repository base is listed more than once in the configuration
 Repository updates is listed more than once in the configuration
 Setting up Group Process
 Setting up repositories
 extras                    100% |=========================| 1.1 kB    00:00
 updates                   100% |=========================|  951 B    00:00
 base                      100% |=========================| 1.1 kB    00:00
 addons                    100% |=========================|  951 B    00:00
 yumgroups.xml             100% |=========================| 9.7 kB    00:00
 comps.xml                 100% |=========================| 912 kB    00:05
 Setting up repositories
 Reading repository metadata in from local files
 primary.xml.gz                                                  113 kB 00:02
 ################################################## 421/421
 primary.xml.gz            100% |=========================| 278 kB    00:01
 ################################################## 502/502
 primary.xml.gz            100% |=========================| 834 kB    00:06
 ################################################## 2400/2400
 primary.xml.gz            100% |=========================|  157 B    00:00
 Excluding Packages in global exclude list
 ...
 Complete!
 
Due compatibility errors with `sos` package, `sysreport` package should be excluded.
  • Install the packages and files needed for a server
To do a fast installation try to use the "CentOS 5.1 Final" DVD and the CentOS-Media repository locate in the temporary location we set at `/root/tmp-yum`.  To have done this do as follows:
  1. Insert "CentOS 5.1 Final" DVD
  2. If the sytem didn't mount automatically the DVD under `/media` folder, then run the command:
 # mount /dev/cdrom /media/CentOS_5.1_Final
 
  1. Install the rest of the packages using the DVD as repository, try to get done by parts, in case something goes wrong:
 yum -c /root/tmp-yum/CentOS-Media.repo --installroot=/mnt/EC2-FS --exclude=sysreport --exclude=nautilus-sendto -y groupinstall mysql editors system-tools text-internet gnome-desktop
 yum  --installroot=/mnt/EC2-FS clean all
 yum -c /root/tmp-yum/CentOS-Media.repo --installroot=/mnt/EC2-FS --exclude=sysreport --exclude=nautilus-sendto -y groupinstall ftp-server network-server
 yum  --installroot=/mnt/EC2-FS clean all
 yum -c /root/tmp-yum/CentOS-Media.repo --installroot=/mnt/EC2-FS --exclude=sysreport --exclude=nautilus-sendto -y groupinstall java java-development base-x graphics web-server
 yum  --installroot=/mnt/EC2-FS clean all
 yum -c /root/tmp-yum/CentOS-Media.repo --installroot=/mnt/EC2-FS --exclude=sysreport --exclude=nautilus-sendto -y groupinstall smb-server mail-server server-cfg sound-and-video
 yum  --installroot=/mnt/EC2-FS clean all
 yum -c /root/tmp-yum/CentOS-Media.repo --installroot=/mnt/EC2-FS --exclude=sysreport --exclude=nautilus-sendto -y groupinstall admin-tools development-tools graphical-internet
 yum -c /root/tmp-yum/CentOS-Media.repo --installroot=/mnt/EC2-FS -y install mod_auth_mysql php-mysql vim-X11 festival createrepo audit mrtg amanda-client iptraf lynx kexec-tools device-mapper-multipath vnc-server xorg-x11-server-Xnest xorg-x11-server-Xvfb libsane-hpaio tomcat5-admin-webapps php-pear tomcat5-webapps mod_auth_mysql tomcat5 dnsmasq ruby ruby-rdoc ruby-devel ruby-ri ruby-docs mysql-devel php-mysql php-bcmath php-gd php-mcrypt php-soap php-xml imake memtest86+ compat-libstdc++-33 compat-libstdc++-296 yum-cron libmcrypt
 
Due compatibility issues with `glib` package, `nautilus-sendto` package should be excluded.
  • Restore yum repositories
 # mv /root/tmp-yum/* /etc/yum.repos.d/
 


== Configure the Operating System ==

After successfully installing the the base operating system, you mus configure the networking and hard drives to work in the Amazon EC2 environment.

  • Configure the operating system
  • Create _/mnt/EC2-FS/etc/sysconfig/network-scripts/ifcfg-eth0_ and make sure it contains at least the following information:
 DEVICE=eth0
 BOOTPROTO=dhcp
 ONBOOT=yes
 TYPE=Ethernet
 USERCTL=yes
 PEERDNS=yes
 IPV6INIT=no
 


#!wiki note 
 '''Note'''
 The Amazon EC2 DHCP server ignores hostname requests. If you set _DHCP_HOSTNAME_, the local hostname will be set on the instance but not externally. Additionally, the local hostname will be the same for all instances of the AMI, which might be confusing.
 
  1. Ensure that networking starts by making sure the following line appears in the `/mnt/EC2-FS/etc/sysconfig/network` file:
 NETWORKING=yes
 
  1. Create `/etc/hosts` file with default configuration
 # echo "127.0.0.1  localhost.localdomain localhost" > /mnt/EC2-FS/etc/hosts
 
  1. Ensure that SELinux is disabled
 # perl -pi -e 's/SELINUX=enforcing/SELINUX=disabled/' /mnt/EC2-FS/etc/selinux/config
 
  1. Ensure that local disk storage on `/dev/sda2` and swap space on `/dev/sda3` are mounted at system startup by adding the following lines to `/mnt/EC2-FS/etc/fstab`:
 /dev/sda2  /mnt      ext3    defaults        0 0
 /dev/sda3  swap      swap    defaults        0 0
 


#!wiki note
 '''Note'''
 The `/dev/sda2` and `/dev/sda3` storage locations only apply to small instances.  For more information on instance storage, see [[http://docs.amazonwebservices.com/AWSEC2/2008-02-01/DeveloperGuide/instance-storage.html]]
 
  1. Change base root to `/mnt/EC2-FS`
 # chroot /mnt/EC2-FS
 
  1. Make sure all of your required services start at system startup by allocating them appropriate system run levels:
 # chkconfig --level 2345 sshd on
 # chkconfig --level 345 monit
 
  1. In order to setup MySQL first startup the network, then fire up MySQL
 # /etc/init.d/network start
 # /etc/init.d/mysqld start
 
  1. Create your user account:
 # useradd myuser
 # passwd myuser
 
  1. Stop services and umount the image:
 # /etc/init.d/mysqld stop
 # /etc/init.d/network stop
 # umount /mnt/EC2-FS/proc
 # umount -d /mnt/EC2-FS