Amazon ec2 and automated deployments

Contents

Elastic IP

Using Amazon’s elastic IPs means that when the instance is restarted the IP remaps meaning that you don’t have to change configuration.

When an EC2 instance queries the external DNS name of an Elastic IP, the EC2 DNS server returns the internal IP address of the instance to which the Elastic IP address is currently assigned.

[ec2-user@ip-172-31-13-108 ~]$ host ec2-54-67-44-243.us-west-1.compute.amazonaws.com
ec2-54-67-44-243.us-west-1.compute.amazonaws.com has address 172.31.15.62

SSH Config

Adding the instances to the ssh config means that they can then be referenced in the Ansible inventory and all authentication is handled behind the scenes.

Host ec2-boapp
    User ec2-user
    IdentityFile /home/jmorgan/.ssh/jmorgan_openbet_ca.pem
    ProxyCommand ssh -q rosalind nc -q0 ec2-54-67-42-13.us-west-1.compute.amazonaws.com 22

Adding an extra volume for Centos

Centos AMI images don’t seem to preserve the volume information on startup. In addition the root volume is limited to 8GB.

I asked about this on Stack Overflow. Currently the way i’m trying to fix it is to mount a second partition to /opt and leave the root as 8GB

The information below is taken from the AWS Guide

[ec2-user ~]$ lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  20G  0 disk
├─xvda1 202:1    0   8G  0 part /
└─xvda2 202:2    0   7G  0 part [SWAP]
xvdb    202:16   0  30G  0 disk    <----------- needs to be formatted and mounted

Check whether we need to create a file system, data indicates no filesystem

sudo file -s /dev/xvdb
/dev/xvdb: data

Create ext4 filesystem

[ec2-user ~]$ sudo mkfs -t ext4 device_name
[ec2-user ~]$ sudo mkfs -t ext4 /dev/xvdb

mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1966080 inodes, 7864320 blocks
393216 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
240 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
	4096000
...
[ec2-user ~]$ sudo file -s /dev/xvdb
/dev/xvdb: Linux rev 1.0 ext4 filesystem data (extents) (large files) (huge files)

Mount the new filesystem, in this instance its mounted as /opt where the majority of our software is to be installed

sudo mount -t ext4 -o rw /dev/xvdb /opt/
[ec2-user@ip-172-31-1-58 ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  1.1G  6.4G  15% /
tmpfs                  15G     0   15G   0% /dev/shm
/dev/xvdb              30G  172M   28G   1% /opt          <----- new mount is available

Ansible playbook for checking, formatting and mounting a filesystem

comments powered by Disqus