Difference between revisions of "Aws-create"

From Bashlinux
Jump to: navigation, search
(Redirected page to Creating an AMI)
 
Line 1: Line 1:
  +
#REDIRECT [[Creating an AMI]]
__NOTOC__
 
= Creating an AMI =
 
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
 
 
<pre><nowiki>
 
# mkdir -p /usr/local/src/EC2
 
</nowiki></pre>
 
 
* Create a file to host the CentOS AMI
 
 
<pre><nowiki>
 
# 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
 
</nowiki></pre>
 
 
 
== Create a Root File System Inside the File ==
 
Create an ''ext3'' file system
 
 
<pre><nowiki>
 
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.
 
</nowiki></pre>
 
 
 
== Mount the File through Loopback ==
 
# Create a mount point in the file system where the image will be attached:
 
 
<pre><nowiki>
 
# mkdir -p /mnt/EC2-FS
 
</nowiki></pre>
 
 
# Mount the file system image:
 
 
<pre><nowiki>
 
mount -o loop /usr/local/src/EC2/bashlinux-server.fs /mnt/EC2-FS/
 
</nowiki></pre>
 
 
 
== Prepare for the Installation ==
 
# Create a `/dev` directory and populate it with a minimal set of devices. You can ignore the errors in the output
 
 
<pre><nowiki>
 
# 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
 
</nowiki></pre>
 
 
# Create the `/etc` directory
 
 
<pre><nowiki>
 
# mkdir -p /mnt/EC2-FS/etc
 
</nowiki></pre>
 
 
# Create the `fstab` file within the `/mnt/EC2-FS/etc` directory and add the following:
 
 
<pre><nowiki>
 
/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
 
</nowiki></pre>
 
 
# Create a temporary yum configuration file `/usr/local/src/EC2/yum-ec2.conf`
 
 
<pre><nowiki>
 
[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
 
</nowiki></pre>
 
 
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
 
# Hide system repositories for AMI installation
 
 
<pre><nowiki>
 
# mkdir /root/tmp-yum
 
# mv /etc/yum.respos.d/* /root/tmp-yum/
 
</nowiki></pre>
 
 
This avoids the use of system repositories that requires a specific value for `$releasever` and `$basearch`, also avoids the duplicated repository error messages.
 
# Mount the `proc` filesystem manually
 
 
<pre><nowiki>
 
# mkdir -p /mnt/EC2-FS/proc
 
# mount -t proc none /mnt/EC2-FS/proc
 
</nowiki></pre>
 
 
# Create log folder
 
 
<pre><nowiki>
 
# mkdir -p /mnt/EC2-FS/var/log
 
</nowiki></pre>
 
 
 
== Install the Operating System ==
 
* Install the Base operating system
 
 
<pre><nowiki>
 
# 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!
 
</nowiki></pre>
 
 
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:
 
# Insert "CentOS 5.1 Final" DVD
 
# If the sytem didn't mount automatically the DVD under `/media` folder, then run the command:
 
 
<pre><nowiki>
 
# mount /dev/cdrom /media/CentOS_5.1_Final
 
</nowiki></pre>
 
 
# Install the rest of the packages using the DVD as repository, try to get done by parts, in case something goes wrong:
 
 
<pre><nowiki>
 
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
 
</nowiki></pre>
 
 
Due compatibility issues with `glib` package, `nautilus-sendto` package should be excluded.
 
 
* Restore yum repositories
 
 
<pre><nowiki>
 
# mv /root/tmp-yum/* /etc/yum.repos.d/
 
</nowiki></pre>
 
 
 
== 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:
 
 
<pre><nowiki>
 
DEVICE=eth0
 
BOOTPROTO=dhcp
 
ONBOOT=yes
 
TYPE=Ethernet
 
USERCTL=yes
 
PEERDNS=yes
 
IPV6INIT=no
 
</nowiki></pre>
 
 
 
<pre><nowiki>#!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.
 
</nowiki></pre>
 
 
# Ensure that networking starts by making sure the following line appears in the `/mnt/EC2-FS/etc/sysconfig/network` file:
 
 
<pre><nowiki>
 
NETWORKING=yes
 
</nowiki></pre>
 
 
# Create `/etc/hosts` file with default configuration
 
 
<pre><nowiki>
 
# echo "127.0.0.1 localhost.localdomain localhost" > /mnt/EC2-FS/etc/hosts
 
</nowiki></pre>
 
 
# Ensure that SELinux is disabled
 
 
<pre><nowiki>
 
# perl -pi -e 's/SELINUX=enforcing/SELINUX=disabled/' /mnt/EC2-FS/etc/selinux/config
 
</nowiki></pre>
 
 
# 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`:
 
 
<pre><nowiki>
 
/dev/sda2 /mnt ext3 defaults 0 0
 
/dev/sda3 swap swap defaults 0 0
 
</nowiki></pre>
 
 
 
<pre><nowiki>#!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]]
 
</nowiki></pre>
 
 
# Change base root to `/mnt/EC2-FS`
 
 
<pre><nowiki>
 
# chroot /mnt/EC2-FS
 
</nowiki></pre>
 
 
# Make sure all of your required services start at system startup by allocating them appropriate system run levels:
 
 
<pre><nowiki>
 
# chkconfig --level 2345 sshd on
 
# chkconfig --level 345 monit
 
</nowiki></pre>
 
 
# In order to setup MySQL first startup the network, then fire up MySQL
 
 
<pre><nowiki>
 
# /etc/init.d/network start
 
# /etc/init.d/mysqld start
 
</nowiki></pre>
 
 
# Create your user account:
 
 
<pre><nowiki>
 
# useradd myuser
 
# passwd myuser
 
</nowiki></pre>
 
 
# Stop services and umount the image:
 
 
<pre><nowiki>
 
# /etc/init.d/mysqld stop
 
# /etc/init.d/network stop
 
# umount /mnt/EC2-FS/proc
 
# umount -d /mnt/EC2-FS
 
</nowiki></pre>
 

Latest revision as of 22:50, 9 June 2015

Redirect to: