Slide 1

Slide 1 text

Scripting your servers @coldclimate CANDDi.com

Slide 2

Slide 2 text

Put your pens down @coldclimate CANDDi.com

Slide 3

Slide 3 text

There once was a man... @coldclimate CANDDi.com

Slide 4

Slide 4 text

And then there was a document... @coldclimate CANDDi.com

Slide 5

Slide 5 text

Which became a wiki... @coldclimate CANDDi.com

Slide 6

Slide 6 text

Which finally because a script @coldclimate CANDDi.com

Slide 7

Slide 7 text

Which mostly worked... @coldclimate CANDDi.com

Slide 8

Slide 8 text

And then the madness had to stop @coldclimate CANDDi.com

Slide 9

Slide 9 text

You wouldn’t treat code like this (hopefully) @coldclimate CANDDi.com

Slide 10

Slide 10 text

Man => Document => Wiki => Script => Images @coldclimate CANDDi.com

Slide 11

Slide 11 text

Encoding Version controlling (automating) @coldclimate CANDDi.com

Slide 12

Slide 12 text

Man => Document Removing the bus factor “The man we can’t fire” @coldclimate CANDDi.com

Slide 13

Slide 13 text

Document => Wiki The fucker *might* stay up to date @coldclimate CANDDi.com

Slide 14

Slide 14 text

Wiki => Script Because script in documentation is stupid @coldclimate CANDDi.com

Slide 15

Slide 15 text

@coldclimate CANDDi.com

Slide 16

Slide 16 text

Why are you not talking about chef, puppet, ansible etc? @coldclimate CANDDi.com

Slide 17

Slide 17 text

http://widgetsandshit.com/teddziuba/2010/10/taco-bell-programming.html @coldclimate CANDDi.com

Slide 18

Slide 18 text

Build once or build twice? @coldclimate CANDDi.com

Slide 19

Slide 19 text

Build once Raw OS Base Instance Script Working Instance @coldclimate CANDDi.com

Slide 20

Slide 20 text

Kick-off instance Install packages Configure them Install your software Hope it all works @coldclimate CANDDi.com

Slide 21

Slide 21 text

Build Twice Raw OS Base Instance Script “Base Box” Make AMI “Base Box” “Instance Box” Script Base AMI @coldclimate CANDDi.com

Slide 22

Slide 22 text

Build once or build twice? @coldclimate CANDDi.com

Slide 23

Slide 23 text

Kick-off instance Install packages -------------------------------------------- Configure them Install your software @coldclimate CANDDi.com

Slide 24

Slide 24 text

Kick-off instance Install packages -------------------------------------------- Configure them Install your software Changes rarely Changes frequently

Slide 25

Slide 25 text

Kick-off instance Install packages -------------------------------------------- Configure them Install your software AMI Instance

Slide 26

Slide 26 text

Stability @coldclimate CANDDi.com

Slide 27

Slide 27 text

Speed @coldclimate CANDDi.com

Slide 28

Slide 28 text

The game: always runs, no manual fixes @coldclimate CANDDi.com

Slide 29

Slide 29 text

A script to built an AMI https://gist.github.com/coldclimate/5ff56c96dac116f3234e @coldclimate CANDDi.com

Slide 30

Slide 30 text

ec2-run-instances --region 'eu-west-1' -g TEMP -k TEMP -f install.sh -t t1.micro ami-ce7b6fba @coldclimate CANDDi.com

Slide 31

Slide 31 text

install.sh limited size (16kb) runs as root cock to debug @coldclimate CANDDi.com

Slide 32

Slide 32 text

/var/log/cloud-init.log @coldclimate CANDDi.com

Slide 33

Slide 33 text

set -ex @coldclimate CANDDi.com

Slide 34

Slide 34 text

Add any sources Update the APT repository Install core packages @coldclimate CANDDi.com

Slide 35

Slide 35 text

Add any sources @coldclimate CANDDi.com

Slide 36

Slide 36 text

echo "deb http://archive.canonical.com/ precise partner" | sudo tee -a /etc/apt/sources.list @coldclimate CANDDi.com

Slide 37

Slide 37 text

python-setuptools add-apt-repository -y ppa:ondrej/php5 @coldclimate CANDDi.com

Slide 38

Slide 38 text

apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/10gen.list @coldclimate CANDDi.com

Slide 39

Slide 39 text

Update the APT repository @coldclimate CANDDi.com

Slide 40

Slide 40 text

apt-get update @coldclimate CANDDi.com

Slide 41

Slide 41 text

Install core packages @coldclimate CANDDi.com

Slide 42

Slide 42 text

apt-get -y install zip unzip xmlstarlet sysstat iftop ntp sysvbanner build- essential python-setuptools nginx nodejs @coldclimate CANDDi.com

Slide 43

Slide 43 text

easy_install -U boto @coldclimate CANDDi.com

Slide 44

Slide 44 text

wget https://github.com/nicolasff/phpredis/archive/2.2.4.zip -P /tmp/ mkdir -p /opt/code unzip /tmp/2.2.4.zip -d /opt/code/ cd /opt/code/phpredis-2.2.4 phpize ./configure make make install @coldclimate CANDDi.com

Slide 45

Slide 45 text

banner “*** DONE BABY ***” @coldclimate CANDDi.com

Slide 46

Slide 46 text

ec2-create-image -n instance_id @coldclimate CANDDi.com

Slide 47

Slide 47 text

Making running instance @coldclimate CANDDi.com

Slide 48

Slide 48 text

ec2-run-instances --region 'eu-west-1' -g sg-bb18b66c -k LIVE-PEM-KEY -p Instance_Profile -f install.sh -t m1.small --availability-zone eu-west-1a --disable-api-termination ami-XXXXXX @coldclimate CANDDi.com

Slide 49

Slide 49 text

Roles http://docs.aws.amazon.com/cli/latest/reference/iam/create-role.html Instance Profiles http://docs.aws.amazon.com/cli/latest/reference/iam/create-instance-profile.html Adding a Role to an Instance Profile http://docs.aws.amazon.com/cli/latest/reference/iam/add-role-to-instance-profile.html @coldclimate CANDDi.com

Slide 50

Slide 50 text

Download from S3 Setup directories Setup config Install code Start it up Register it @coldclimate CANDDi.com

Slide 51

Slide 51 text

Download from S3 python <

Slide 52

Slide 52 text

Setup directories Your script is running as root so remember to chown @coldclimate CANDDi.com

Slide 53

Slide 53 text

Setup config Copy it from the download into place Restart the service @coldclimate CANDDi.com

Slide 54

Slide 54 text

Install code https://github.com/jordansissel/fpm @coldclimate CANDDi.com

Slide 55

Slide 55 text

Start it up Supervisord Ubuntu service Avoid own scripts @coldclimate CANDDi.com

Slide 56

Slide 56 text

Register it @coldclimate CANDDi.com

Slide 57

Slide 57 text

Monitoring (zabbix) @coldclimate CANDDi.com

Slide 58

Slide 58 text

Load Balancer (ec2 call) @coldclimate CANDDi.com

Slide 59

Slide 59 text

Logging (papertrail) @coldclimate CANDDi.com

Slide 60

Slide 60 text

DNS (R53 call) @coldclimate CANDDi.com

Slide 61

Slide 61 text

And it works! @coldclimate CANDDi.com

Slide 62

Slide 62 text

@coldclimate CANDDi.com

Slide 63

Slide 63 text

Need to change the code or config? @coldclimate CANDDi.com

Slide 64

Slide 64 text

JFDI and roll a fresh one @coldclimate CANDDi.com

Slide 65

Slide 65 text

You need to change the base AMI @coldclimate CANDDi.com

Slide 66

Slide 66 text

It’s simple, it just doesn’t feel it @coldclimate CANDDi.com

Slide 67

Slide 67 text

Update the scripts until you can “launch clean” @coldclimate CANDDi.com

Slide 68

Slide 68 text

Lastly @coldclimate CANDDi.com

Slide 69

Slide 69 text

@coldclimate CANDDi.com

Slide 70

Slide 70 text

speakerdeck. com/coldclimate/scripting-creating- aws-based-servers @coldclimate canddi.com/blog @coldclimate CANDDi.com