Thursday, August 4, 2016

Bill Cain Notes - AWS Setup

One time only Setup CLI into AWS:
    http://docs.aws.amazon.com/cli/latest/userguide/installing.html#cli-test-the-setup
        $ curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
        $ unzip awscli-bundle.zip
        $ sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

One time only:  "aws configure"

Each Day run this to get current day login string:   "aws ecr get-login --region us-east-1"

----------------------------------------------------------------------------------------------------

If all your AWS instances do not have BTRFS file system formatting, then the default max disk space
size for docker containers will be 10GB.  This is too small for the IBM Dash Docker container.

Steps to setup docker service on rhel7 to have large enough to support the IBM Dash docker container
    1. stop docker
    2. remove directory /var/lib/docker (this will remove any pulled images)
    3. edit /usr/lib/systemd/system/docker.service
            update line starting with ExecStart to :
            ExecStart=/usr/bin/docker daemon -H fd://  --storage-driver devicemapper --storage-opt dm.basesize=50G
        save the file
    4. systemctl daemon-reload
    5. start docker

----------------------------------------------------------------------------------------------------

Steps to upload NOI Docker containers:

Example to connect:
    docker login  -u AWS  -p <big_long_encrypted_hash>  -e none   https://093244773991.dkr.ecr.us-east-1.amazonaws.com

Example to tag an existing container:
    run - to tag Dash container       "docker tag noi1401-ifix/dash:latest 093244773991.dkr.ecr.us-east-1.amazonaws.com/itsm01:dash"
    run - to tag Impactcore container "docker tag noi1401-ifix/impactcore:latest 093244773991.dkr.ecr.us-east-1.amazonaws.com/itsm01:impactcore"

Example to load an existing local container after it has been tagged using AWS syntax
    docker push 093244773991.dkr.ecr.us-east-1.amazonaws.com/itsm01:dash

----------------------------------------------------------------------------------------------------

Create your AWS instance (virtual machine)

----------------------------------------------------------------------------------------------------

Connecting to your AWS instance
    https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html

# Setup the aws command line environment (aws configure)

# Get info about specific instance (validate its existence)
    aws ec2 get-console-output --instance-id i-0ea22089a33d69cdd
                or
                aws ec2 get-console-output --headers --instance-id i-0ea22089a33d69cdd

# Obtain the PEM certificate file (Private Key File when Instance was created)

# ssh in Linux
    chmod 400 /root/Desktop/itsm-noi-14.pem
    ssh -i /root/Desktop/itsm-noi-14.pem ec2-user@ec2-54-235-4-35.compute-1.amazonaws.com

----------------------------------------------------------------------------------------------------

Docker setup Once logged into AWS instance

- setup docker repo - https://docs.docker.com/engine/installation/linux/rhel/
                             sudo tee /etc/yum.repos.d/docker.repo <<-EOF
                                    [dockerrepo]
                                    name=Docker Repository
                                    baseurl=https://yum.dockerproject.org/repo/main/centos/7
                                    enabled=1
                                    gpgcheck=1
                                    gpgkey=https://yum.dockerproject.org/gpg
                                    EOF
- install docker-engine (sudo yum install docker-engine)
- download AWS command line tool
- Install AWS command line tools
- run "aws configure"
- run "aws ecr get-login --region us-east-1"  <-- this produces the next line for "docker login"
- run "docker login  -u AWS  -p <big_long_encrypted_hash>  -e none   https://093244773991.dkr.ecr.us-east-1.amazonaws.com"
- run - download Omnibus container  "docker pull 093244773991.dkr.ecr.us-east-1.amazonaws.com/itsm01:omnibus"
    (This pulls the docker container from the AWS repository to local host)
    Now tag the pulled AWS container to have the same name which the IBM deployment scripts use:
        run "docker tag 093244773991.dkr.ecr.us-east-1.amazonaws.com/itsm01:omnibus noi1401-ifix/omnibus:latest"

- run (if not using the IBM deployment scripts) ...  "docker run -d -i --ulimit nofile=8192:8192 --ulimit nproc=16384:16384 -p 4100:4100 -p 45037:45037 -p 162:162 -p 162:162/udp -p 9002:9001 -p 9093:9090 -p 9098:9095 -p 9998-9999:9998-9999 -h omnibus --name=omnibus -u netcool c6cae41ef50b"  #( This is not including the other parameters to build the /etc/hosts file for this container which is part of an NOI install - eg multiple docker containers)

----------------------------------------------------------------------------------------------------

Copy IBM Created docker images into AWS instance (as needed - this is not needed if "docker push" steps were performed above
    scp -i /root/Desktop/itsm-noi-14.pem database.tgz  ec2-user@ec2-54-164-87-185.compute-1.amazonaws.com:/home/ec2-user/database

----------------------------------------------------------------------------------------------------

Ensure there is sufficient disk space in your AWS instance
     -AND-
The filesystem space must be formatted "btrfs"
Create BTRFS file system for docker images
    (recall an additional storage block space has been allocated to our AWS instance)
    (recall also Docker loads its file system in /var/lib/docker)
        lsblk  (lists device files)
        mkfs.btrfs /dev/xvdb
        mkdir /opt/IBMDocker
        Edit /etc/fstab , add entry
              --->  /dev/xvdb                                 /opt/IBMDocker                  btrfs   defaults        0 0
        mount -a

----------------------------------------------------------------------------------------------------

Copying files from AWS S3 storage into your AWS instance
    - setup aws authentication session
    - run "aws s3 cp s3://noidockerimages/dash.tgz My_dash.tgz"

----------------------------------------------------------------------------------------------------

Uploading DB2 docker tarball - this is the case if not using AWS Docker service (basically we build our own private docker hub within our AWS instance)

    Ensure all unix commands required by IBM deployment script are present
       
  mkdir /tmp/database ( This becomes full path /home/ec2-user/database )
        (perform the scp copy for each IBM docker instance tarball file)
  scp -i /root/Desktop/itsm-noi-14.pem   database.tgz   ec2-user@ec2-54-164-87-185.compute-1.amazonaws.com:/home/ec2-user/database

----------------------------------------------------------------------------------------------------

Using existing IBM docker deployment script. (So this ignores the AWS Docker service)
    Setup passwordless ssh for "root" account in your AWS instance
        cd /root/.ssh
        cp authorized_keys authorized_keys.OLD
        cat id_rsa.pub >> authorized_keys
        ssh root@172.31.8.223   (validation step)

    Ensure all unix commands required by IBM deployment script ( ./noi-docker.sh ) are present
        yum install bind-utils.x86_64   

    Start AWS container networking in proper order required for Docker port maps
        systemctl stop docker
        systemctl restart firewalld
        iptables -I INPUT 1 -i docker0 -j ACCEPT   <---- You might need to run this after starting the docker service
        systemctl start docker
        ./noi-docker.sh -start database omnibus impactcore impactgui dash