Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Now You Too Can Install Nventory on Amazon AWS

DZone's Guide to

Now You Too Can Install Nventory on Amazon AWS

Free Resource

Are you joining the containers revolution? Start leveraging container management using Platform9's ultimate guide to Kubernetes deployment.

This post is more of a reference for myself than anything else, however I thought it might come in handy for some others.  It’s bastardised from the install.sh which comes with nventory and will configure an Amazon Linux AMI for you.

The install script below installs nventory, rubygems and nginx from source and everything else from either the Amazon repo or Epel.

This means that you can install and configure this system on the Amazon Free Usage Tier using the “tiny” Amazon Linux ( amzn-ami-2011.09.1.x86_64-ebs ) and get a complete inventory server and puppetmaster for a year at zero cost!

Before we get to the install script, a few caveats:

  1. THIS SCRIPT IS INTENDED TO BE RUN ON A FRESH INSTANCE WITH NO OTHER SERVICES INSTALLED, CONFIGURED OR RUNNING – I will not be held responsible if it breaks stuff!
  2. There is no warranty or guarantee with this script – if it breaks stuff, you get to keep both pieces.
  3. I haven’t tested this at any great scale – in this particular setup I only have three puppet agents, however the resources on the server seem to be more than adequate to deal with them
  4. The installation of the rubygems takes a long time (like over half an hour!)
  5. The entire script could take up to an hour to run
  6. Nventory itself is still not 100% production ready, however I have it working nicely, YMMV.

Install Instructions:

  1. Update the variables at the top of the script to set the various versions of RAILS, RubyGems, NGinx and NVentory
  2. Change the MySQL Password to something that is secure
  3. Run the script
  4. Point a hostname (/etc/hosts or DNS) “nventory” at the IP of the server
  5. Log in using a username of “admin” and a password of “admin”
  6. If it works, buy me a beer the next time you see me… ;)

 

#!/bin/sh

# nventory installation script for Amazon Linux

MYSQL_CONFIG_DIR="/usr/bin/mysql_config"
RAILS_VER="2.3.14"
GEMS_VER="1.8.10"
NGINX_VER="1.0.8"
NV_VERSION="0.86"
NV_MYSQL_PASSWORD="password"



## SETUP INSTALL PATH
echo -e "Setting up installation directories\n==============="
INSTALL_PATH="$HOME/nventory-install-$(date +%s)"
mkdir $INSTALL_PATH
cd $INSTALL_PATH

# get the nventory source code
echo -e "Fetching the nventory source code\n==========================="
wget -q http://downloads.sourceforge.net/project/nventory/nventory/$NV_VERSION/nventory-$NV_VERSION.tar.gz
echo -e "Unpacking the archive\n==============="
tar -zxf nventory-$NV_VERSION.tar.gz
## OPERATING SYSTEM PRE-REQUISITES
echo -e "Installing Operating System Requirements\n================="
yum install ruby -y 2>&1 > /dev/null
yum install mysql-server -y 2>&1 > /dev/null
### for rubygems
yum install -y ruby-devel ruby-docs ruby-ri ruby-irb ruby-rdoc 2>&1 > /dev/null
### for gems (hpricot & fastthread)
yum install -y gcc make 2>&1 > /dev/null
### for graphviz gem
yum install graphviz -y 2>&1 > /dev/null
### for mysql gem
yum install mysql-devel -y 2>&1 > /dev/null
### for nginx
yum install -y openssl-devel 2>&1 > /dev/null
yum install -y gcc-c++ 2>&1 > /dev/null
yum install -y zlib-devel 2>&1 > /dev/null
yum install -y pcre-devel 2>&1 > /dev/null

# install rubygems
echo -e "Downloading Rubygems\n===================="
wget -q http://production.cf.rubygems.org/rubygems/rubygems-$GEMS_VER.tgz
echo -e "Upacking Rubygems\n===================="
tar zxf rubygems-$GEMS_VER.tgz
cd rubygems-$GEMS_VER
echo -e "Installing Rubygems\n========================="
ruby setup.rb

# Install NGinx
echo -e "Getting the NGinx Source Code\n========================="
wget http://www.nginx.org/download/nginx-$NGINX_VER.tar.gz
echo -e "Unpacking the archive\n===================="
tar zxf nginx-$NGINX_VER.tar.gz
cd nginx-$NGINX_VER
echo -e "Building NGinx with HTTPS support and installing\n==========================="
./configure --sbin-path=/sbin/nginx --prefix=/opt/nginx --with-http_ssl_module
make && make install

## generate self signed keys & certs for nginx ssl
echo -e "Creating SSL Certificates\n**** PLEASE ANSWER THE QUESTIONS WHEN PROMPTED****\n========================="
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
openssl rsa -in server.key -out cert.key
openssl x509 -req -days 365 -in server.csr -signkey cert.key -out cert.pem

## move your nventory-0.<version>/server directory to /opt/nventory (this is your rails app)
echo -e "Moving from $INSTALL_PATH to /opt\n======================"
mv $INSTALL_PATH/nventory-$NV_VERSION/server /opt/nventory

## copy nginx.conf template overwriting original
echo -e "Overwriting NGinx Config\n==============================="
cp /opt/nventory/config/nginx.conf /opt/nginx/conf
sed -i 's/localhost/nventory/g' /opt/nginx/conf/nginx.conf

## startup nginx
echo -e "Starting Nginx\n============================="
/sbin/nginx

### install gems
echo -e "Installing the required gems (this will take quite a while!)\n======================="
gem install rails -v $RAILS_VER --no-ri --no-rdoc
gem install RedCloth -v 3.0.4 --no-ri --no-rdoc
gem install ruby-net-ldap -v 0.0.4 --no-ri --no-rdoc
gem install ruport --no-ri --no-rdoc
gem install acts_as_reportable --no-ri --no-rdoc
gem install starling --no-ri --no-rdoc
gem install fast_xs --no-ri --no-rdoc
gem install fastercsv --no-ri --no-rdoc
gem install facter --no-ri --no-rdoc
### If hpricot gem install fails, try lower version
### Example: gem install hpricot -v 0.7
gem install hpricot --no-ri --no-rdoc
gem install mongrel --no-ri --no-rdoc
gem install mislav-will_paginate --source http://gems.github.com/ -v 2.3.2 --no-ri --no-rdoc
gem install mongrel -v 1.1.5 --no-ri --no-rdoc
gem install mysql -- --with-mysql-config=$MYSQL_CONFIG_DIR --no-ri --no-rdoc
gem install ruby-graphviz --no-ri --no-rdoc
gem install unicorn --no-ri --no-rdoc
gem install workling --no-ri --no-rdoc
gem install ruby-debug --no-ri --no-rdoc

echo "Checking if any gems failed to install...\n============================="
for i in rails RedCloth ruby-net-ldap ruport acts_as_reportable starling fast_xs fastercsv facter hpricot mongrel mislav-will_paginate mongrel mysql ruby-graphviz unicorn workling; do
gem list $i |grep $i > /dev/null 2>&1
 if [ $? != 0 ]; then echo "!! $i not installed." ; fi
done

# create nventory database
echo -e "Starting MySQL\n===================="
service mysqld start
echo -e "Creating Database and granting privilieges\n==============================="
mysql -u root -p -e "create database nventory;GRANT ALL PRIVILEGES ON nventory.* to nventory@localhost IDENTIFIED BY '$NV_MYSQL_PASSWORD';flush privileges;"

echo -e "Updating the RAILS config for the database\n==================="
### THE CONFIG WHICH COMES WITH RAILS WON'T WORK WITH LOCALHOST CONNECTIONS SO WE JUST REPLACE THE ENTIRE FILE HERE...
(cat <<EOF
development:
adapter: mysql
database: nventory
username: nventory
password: '$NV_MYSQL_PASSWORD'
host: 127.0.0.1
port: 3306

# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
adapter: mysql
database: nventory_test
username: nventory
password: '$NV_MYSQL_PASSWORD'
socket: /var/lib/mysql/mysql.sock
# Used for both staging and production
production:
adapter: mysql
database: nventory
username: nventory
password: '$NV_MYSQL_PASSWORD'
socket: /var/lib/mysql/mysql.sock
EOF
) > /opt/nventory/config/database.yml


# run nventory's initial db migration to create database schema
echo -e "Running the initial migration\n==========================="
cd /opt/nventory && rake db:migrate

# Startup Rails
echo -e "Starting the webrick-based rails server\n======================="
cd /opt/nventory && ruby script/server -d -p 8080

Source:  http://www.threedrunkensysadsonthe.net/2011/10/installing-nventory-on-amazon-aws/

Using Containers? Read our Kubernetes Comparison eBook to learn the positives and negatives of Kubernetes, Mesos, Docker Swarm and EC2 Container Services.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}