Skip to content

Instantly share code, notes, and snippets.

Last active July 10, 2018 23:43
  • Star 23 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Install Golang 1.4.1 on Ubuntu 14.04 AWS EC2
# -geoip true
# this will install maxmind geoip and auto update crontab file
# -cloudwatch true
# this will install aws cloud watch metrics and send them to aws dashboard
# -imagemagick true
# this will install imagemagick and magickwand
# process command line args
while echo $1 | grep -q ^-; do
eval $( echo $1 | sed 's/^-//' )=$2
# Install Golang 1.4 and Arc65 + dependencies on fresh Amazon AWS EC2 Ubuntu 14.04 LTS
echo "install correct language pack"
cat <<EOF > /etc/default/locale
. /etc/default/locale
echo "set correct timezone"
dpkg-reconfigure tzdata
echo "install basic requirements"
apt-get update && upgrade
apt-get install build-essential mercurial git libssl-dev pkg-config tree
echo "download Go and install it, as well as create GOPATH directory"
cd ~
tar -xf go1.4.1.linux-amd64.tar.gz && rm go1.4.1.linux-amd64.tar.gz
mv go /usr/local && mkdir -p /usr/local/gopath
echo "set enviornment variables required for Go"
export GOROOT=/usr/local/go
export GOPATH=/usr/local/gopath
cat <<EOF >> ~/.bashrc
export GOROOT=/usr/local/go
export GOPATH=/usr/local/gopath
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
export GORACE=log_path=$GOPATH/racereport
export w=$GOPATH/src/
. ~/.bashrc
# install Go tools
echo "installing go tool ... golint"
go get
echo "installing go tool ... errcheck"
go get
echo "installing go tool ... benchcmp"
go get
echo "installing go tool ... impl"
go get
echo "installing go tool ... goimports"
go get
echo "installing go tool ... goreturns"
go get
echo "installing go tool ... godef"
go get
echo "installing go tool ... gocode"
go get
echo "installing go tool ... oracle"
go get
echo "installing go tool ... gorename"
go get
echo "installing go tool ... godepgraph"
go get
echo "install arc65 external dependencies"
apt-get install zlib1g-dev nodejs npm
npm install less -g
npm install clean-css -g
npm install uglify-js -g
npm install html-minifier -g
npm install autoprefixer -g
npm install bower-installer -g
ln -s /usr/bin/nodejs /usr/bin/node
echo "install wrk benchmark tool (apache bench (ab) alternative)"
cd ~
git clone
cd wrk
cp wrk /usr/local/bin
cd ~
rm -rf wrk
echo "tuning ubuntu for high concurrent connections"
cat <<EOF >> /etc/security/limits.conf
root soft nofile 40000
root hard nofile 40000
* soft nofile 40000
* hard nofile 40000
cat <<EOF >> /etc/pam.d/su
session required
echo "-cloudwatch flag will enable pushing ec2 metrics to aws dashboard"
if $cloudwatch == "true"; then
cd ~
echo "install Amazon AWS command line client"
apt-get install awscli
echo "set enviornment variables for getting ec2 instance id and region"
cat <<EOF >> ~/.bashrc
export INSTANCE_ID="`wget -q -O -`"
export EC2_REGION="`wget -q -O - | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'`"
. ~/.bashrc
echo "install custom cloudwatch metrics"
git clone
cd cwput
echo "register with crontab to ensure metrics are sent every minute"
cat <<EOF > /etc/cron.d/cloudwatch
* * * * * root . $HOME/.bashrc; /usr/bin/cwput.bash
chmod 755 /etc/cron.d/cloudwatch
if $imagemagick == "true"; then
echo "install image magick and magickwand"
echo "useful for advanced image manipulation in go using 3rd party golang packages with C bindings using cgo"
echo "e.g."
apt-get install imagemagick libgif-dev libmagickwand-dev
if $geoip == "true"; then
echo "maxmind geoip mmdblookup c library install"
echo "useful for converting IP to city/country data structure in go using 3rd party golang packages with C bindings using cgo"
echo "e.g."
cd ~
git clone --recursive
cd libmaxminddb
apt-get install dh-autoreconf
make check
make install
cd ~
rm -rf ./tmp/
rm -rf ./libmaxminddb/
echo "install maxmind geoip update command line tool"
add-apt-repository ppa:maxmind/ppa
apt-get update
apt-get install geoipupdate
cat <<EOF >> /etc/GeoIP.conf
# GeoIP.conf file - used by geoipupdate program
# to update databases from
# UserId, LicenseKey, ProductIds from account
UserId 94685
ProductIds 106 133 GeoIP2-City GeoIP2-Country
echo "update GeoIP for the first time"
echo "register with crontab to ensure auto update"
cat <<EOF > /etc/cron.d/geoip
56 8 * * 5 root /usr/bin/geoipupdate
chmod 755 /etc/cron.d/geoip
echo "install done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment