Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Last active April 18, 2020 10:18
Show Gist options
  • Save wilmoore/1615295 to your computer and use it in GitHub Desktop.
Save wilmoore/1615295 to your computer and use it in GitHub Desktop.
# Cookbook Name:: mongodb
# Recipe:: default
case node['platform']
when "ubuntu"
execute "apt-get update" do
action :nothing
end
execute "add gpg key" do
command "apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10"
action :nothing
end
file "/etc/apt/sources.list.d/mongodb-10gen.list" do
owner "root"
group "root"
mode "0755"
action :create
content "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen"
notifies :run, resources("execute[apt-get update]"), :immediately
end
package "autoconf" do
action :install
options '--force-yes'
end
package "mongodb-10gen" do
action :install
options '--force-yes'
end
else
Chef::Log.error "no platform support."
end
#!/usr/bin/env sh
VBOX_LATEST_VERSION=$(curl http://download.virtualbox.org/virtualbox/LATEST.TXT)
wget -c http://download.virtualbox.org/virtualbox/${VBOX_LATEST_VERSION}/VBoxGuestAdditions_${VBOX_LATEST_VERSION}.iso -O /tmp/VBoxGuestAdditions_${VBOX_LATEST_VERSION}.iso
sudo mkdir -p /media/guestadditions ; sudo mount -o loop /tmp/VBoxGuestAdditions_${VBOX_LATEST_VERSION}.iso /media/guestadditions
sudo /media/guestadditions/VBoxLinuxAdditions.run
sudo umount /media/guestadditions && sudo rm -rf /tmp/VBoxGuestAdditions_$VBOX_VERSION.iso /media/guestadditions
echo 'You may safely ignore the message that reads: "Could not find the X.Org or XFree86 Window System."'
#!/usr/bin/env sh
VBOX_LATEST_VERSION=$(curl http://download.virtualbox.org/virtualbox/LATEST.TXT)
VBOX_LATEST_FILE_OSX=$(wget -q http://download.virtualbox.org/virtualbox/${VBOX_LATEST_VERSION}/MD5SUMS -O- | grep -i "OSX.dmg" | cut -d"*" -f2)
wget -c http://download.virtualbox.org/virtualbox/${VBOX_LATEST_VERSION}/${VBOX_LATEST_FILE_OSX} -O /tmp/${VBOX_LATEST_FILE_OSX}
hdiutil mount /tmp/${VBOX_LATEST_FILE_OSX}
sudo installer -pkg /Volumes/VirtualBox/VirtualBox.mpkg -target /Volumes/Macintosh\ HD
hdiutil unmount /Volumes/VirtualBox
wget -c http://download.virtualbox.org/virtualbox/${VBOX_LATEST_VERSION}/Oracle_VM_VirtualBox_Extension_Pack-${VBOX_LATEST_VERSION}.vbox-extpack -O /tmp/Oracle_VM_VirtualBox_Extension_Pack-${VBOX_LATEST_VERSION}.vbox-extpack
VBoxManage extpack uninstall "Oracle VM VirtualBox Extension Pack"
VBoxManage extpack cleanup
VBoxManage extpack install /tmp/Oracle_VM_VirtualBox_Extension_Pack-${VBOX_LATEST_VERSION}.vbox-extpack
# SEE: http://download.virtualbox.org/virtualbox/rpm/rhel/
#!/usr/bin/env sh
INSTALL_UBUNTU_DISTRO=${UBUNTU_VERSION-lucid}
VBOX_LATEST_VERSION=$(curl http://download.virtualbox.org/virtualbox/LATEST.TXT)
sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian ${INSTALL_UBUNTU_DISTRO} contrib" > /etc/apt/sources.list.d/virtualbox.list'
wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -
sudo apt-get update ; sudo apt-get install dkms virtualbox-${VBOX_LATEST_VERSION}
wget -c http://download.virtualbox.org/virtualbox/${VBOX_LATEST_VERSION}/Oracle_VM_VirtualBox_Extension_Pack-${VBOX_LATEST_VERSION}.vbox-extpack -O /tmp/Oracle_VM_VirtualBox_Extension_Pack-${VBOX_LATEST_VERSION}.vbox-extpack
VBoxManage extpack uninstall "Oracle VM VirtualBox Extension Pack"
VBoxManage extpack cleanup
VBoxManage extpack install /tmp/Oracle_VM_VirtualBox_Extension_Pack-${VBOX_LATEST_VERSION}.vbox-extpack
usermod -a -G vboxusers nodemanager
#!/usr/bin/env bash
set -e
################################################################################
# NOT RECOMMENDED TO MODIFY UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING!
################################################################################
# virtual disk image root directory (a dedicated user/admin account is recommended)
VDI_ROOT=~/.vm/hdds
VDI_TEMP=/tmp
################################################################################
# argument handling
################################################################################
# correct # of arguments?
if (($# != 1)); then
echo "Usage : createvm <vm-name>"
echo "Example: createvm localdev"
exit 1
fi
################################################################################
# Template VM Name (probably should be based on provided argument but good for now)
################################################################################
# template virtual machine disk image
USE_VM_NAME=nodebuilder-ubuntu-lucid64
################################################################################
# Calculate effective VDI file name/path
################################################################################
USE_VDI_FILE=$USE_VM_NAME.vdi
USE_VDI_PATH=$VDI_TEMP/$USE_VDI_FILE
################################################################################
# Setup a proper name for the new virtual machine
################################################################################
# name of virtual machine to manage/create
NEW_VM_NAME=$1
NEW_VDI_FILE=$NEW_VM_NAME.vdi
NEW_VDI_PATH=$VDI_ROOT/$NEW_VDI_FILE
################################################################################
# Check that we aren't trying to clobber an existing VDI file
################################################################################
# quit if the disk image file exists (should we allow a switch to force overwrite?)
if [ -s $NEW_VDI_PATH ]; then
echo "'$NEW_VDI_PATH' already exists!"
echo "Please try again after correcting the situation."
echo "You might try the command 'VBoxManage unregistervm $NEW_VM_NAME --delete'"
exit 1
fi
################################################################################
# download disk image (continues partial downloads)
################################################################################
if [ ! -d $VDI_ROOT ]; then
mkdir -p $VDI_ROOT
fi
# if file already exists, "wget" will skip retrieving it by default
wget --timeout=1 --wait=1 -c http://nodebuilder.s3.amazonaws.com/$USE_VM_NAME.tgz -O $VDI_TEMP/$USE_VM_NAME.tgz
tar -xvf $VDI_TEMP/$USE_VM_NAME.tgz -C $VDI_TEMP/
################################################################################
# use template image to create a new disk image
################################################################################
# copy the template disk image to the new image location and assign a new UUID
echo "Creating new virtual disk image: '$NEW_VDI_PATH' from base file: '$USE_VDI_PATH'"
rsync -Pv $USE_VDI_PATH $NEW_VDI_PATH
VBoxManage internalcommands sethduuid $NEW_VDI_PATH
# create a new virtual machine
echo "Creating new virtual machine: '$NEW_VM_NAME'"
VBoxManage createvm --name $NEW_VM_NAME --register
# modify the VM using sane linux server defaults
VBoxManage modifyvm $NEW_VM_NAME --ostype Ubuntu_64 --clipboard disabled --memory 512 --cpus 1 --acpi on --ioapic off --rtcuseutc on --hwvirtex on --nestedpaging on --bioslogofadein off --bioslogofadeout off --boot1 disk
# setup an internal network via the primary interface
VBoxManage modifyvm $NEW_VM_NAME --nictype1 82540EM --nic1 hostonly --hostonlyadapter1 vboxnet0
# setup NAT (need to run "sudo dhclient" on host before this works)
VBoxManage modifyvm $NEW_VM_NAME --nictype2 82540EM --nic2 nat --natpf2 "ssh,tcp,,2222,,22"
# expose machine's to the internet via port forwarding (this + iptables is quite secure)
VBoxManage modifyvm $NEW_VM_NAME --natpf2 "http,tcp,,80,,80"
VBoxManage modifyvm $NEW_VM_NAME --natpf2 "https,tcp,,443,,443"
# setup bridged networking using the first virtual network interface (assumes a GB adapter)
# if [ "$(uname -s)" == "Darwin" ]; then
# use vnic0 if host is Mac OSX
# ADAPTER_NAME=vnic0
# else
# ADAPTER_NAME=eth0
# fi
# setup bridged networking using the first virtual network interface (assumes a GB adapter)
# uncomment only for nodes that need to have an external presence
# VBoxManage modifyvm $NEW_VM_NAME --nictype2 82540EM --nic2 bridged --bridgeadapter2 $ADAPTER_NAME
# define a SATA controller, and attach HDD image to the SATA controller
VBoxManage storagectl $NEW_VM_NAME --name "SATA Controller 1" --add sata --controller IntelAHCI --hostiocache on
VBoxManage storageattach $NEW_VM_NAME --storagectl "SATA Controller 1" --type hdd --port 0 --device 0 --medium $NEW_VDI_PATH
# define an IDE controller
VBoxManage storagectl $NEW_VM_NAME --name "IDE Controller 1" --add ide --controller PIIX4 --hostiocache on
# set the remote display port and set off VRDE (Remote Display/RDP) by default (FYI, VBoxHeadless turns it on for that session regardless of this setting)
VBoxManage modifyvm $NEW_VM_NAME --vrdeport "5000-6000" --vrde off --vrdeauthtype null --vrdemulticon on
# start the virtual machine with VRDE (Remote Display) enabled (you should see output similar to: "VRDE server is listening on port 3389")
# NOTE: VBoxHeadless turns on VRDE regardless of the "-vrde on|off"
echo "About to start '$NEW_VM_NAME' with remote RDP enabled"
VBoxHeadless --startvm $NEW_VM_NAME -e "TCP/Ports=5000-6000" || exit 1
# Cookbook Name:: nodejs
# Recipe:: default
case node[:platform]
when "ubuntu"
execute "apt-get update" do
action :nothing
end
package "git-core curl build-essential openssl libssl-dev" do
action :install
options '--force-yes'
end
bash "install nodejs from source" do
code <<-EOH
rm -rf $HOME/local/node/0.6.11 ; \
mkdir -p $HOME/local/node/0.6.11/src && \
cd $HOME/local/node/0.6.11/src && \
curl -# -L http://nodejs.org/dist/v0.6.11/node-v0.6.11.tar.gz | tar -xz --strip 1 && \
./configure --prefix=/usr/local && \
make && make install
EOH
end
else
Chef::Log.error "no platform support."
end
# REF: http://wiki.opscode.com/display/chef/Chef+Solo#ChefSolo-ConfigureChefSolo
# sudo chef-solo -c provisioners/chef/bin/solo.rb
# sudo chef-solo -c provisioners/chef/bin/solo.rb -j servers/$(hostname -s)/provisions.json
base_directory = File.expand_path("../../", __FILE__)
file_cache_path '/tmp/chef-solo'
cookbook_path ['cookbooks', 'site-cookbooks'].map{|value| File.expand_path(value, base_directory) }
role_path File.expand_path('roles', base_directory)
log_level :info
log_location STDOUT
ssl_verify_mode :verify_none

Remote OS Installation

Press enter|return to start base system installation

  1. From the "Installer boot menu" select "Install"
  2. Choose Language
  • English
  1. Choose a Country
  • United States
  1. Keyboard (Origin of the Keyboard / Keyboard layout)
  • No
  • USA
  • USA
  1. Hostname
  • nodebuilder-ubuntu-lucid64
  1. Choose a mirror of the Ubuntu archive
  • United States
  • us.archive.ubuntu.com (default)
  1. HTTP proxy
  • (blank/none)
  1. TimeZone
  • No (is your time zone correct?)
  • UTC (select your time zone)
  1. Partition Disks
  • Guided - use entire disk (press enter twice to accept disk selection)
  • Yes (write changes to disks?)

NOTE: the base system software will be downloaded and installed at this point...it could take a while.

  1. Non-administrative
  • {Project Name}
  • {username}
  • {password}
  1. Encrypt home directory
  • No
  1. Automatic Updates
  • No automatic updates
  1. Software Selection
  • OpenSSH server
  1. Install the GRUB boot loader to the master boot record?
  • Yes
  1. Is the system clock set to UTC?
  • Yes

Default packages and configuration

bootstrapping (bootstraps provisioners like chef-solo, puppet, etc.)

Note

these commands must be run after login (likely via RDP but you may be able to use SSH via password authentication as well at this point)

  1. dhclient
$   sudo dhclient
  1. Install ACPID, GCC, WGET, CURL, and VIM (make VIM the default system editor):
$   yes | sudo aptitude install acpid gcc wget curl vim molly-guard
$   sudo update-alternatives --config editor
NOTE: select "vim.basic"
  1. Retrieve public key
$   mkdir -p ~/.ssh
$   cat your-public-key.pub > ~/.ssh/authorized_keys
$   chmod 700 ~/.ssh ; chmod 600 ~/.ssh/*

Note

or simply use password authentication for initial SSH access

Note

or use a different public key where only you have access to the private key

  1. Install Ruby and friends, ruby gems, and chef
    $ yes | sudo apt-get install ruby1.9.1 ruby1.9.1-dev libopenssl-ruby1.9.1 rdoc1.9.1 ri1.9.1 irb1.9.1 build-essential wget ssl-cert git-core rubygems1.9.1 $ sudo ln -s /usr/bin/ruby1.9.1 /usr/bin/ruby $ cd /tmp $ wget http://production.cf.rubygems.org/rubygems/rubygems-1.6.0.tgz $ tar xvzf rubygems-1.6.0.tgz $ cd rubygems-1.6.0 $ sudo ruby setup.rb $ sudo ln -s /usr/bin/gem1.9.1 /usr/bin/gem $ sudo gem install rubygems-update $ sudo gem update gem $ sudo gem install chef --no-ri --no-rdoc
  2. Configure SSHD
$   sudo editor /etc/ssh/sshd_config

    PasswordAuthentication yes
    PermitRootLogin no
    PubkeyAuthentication yes
    PermitEmptyPasswords no
    X11Forwarding no
    UsePAM no
    UseDNS no
  1. RESTART THE SSHD SERVICE
$   sudo service ssh restart
  1. Install Guest Additions
$   VBOX_LATEST_VERSION=$(curl http://download.virtualbox.org/virtualbox/LATEST.TXT)
$   wget -c http://download.virtualbox.org/virtualbox/${VBOX_LATEST_VERSION}/VBoxGuestAdditions_${VBOX_LATEST_VERSION}.iso -O /tmp/VBoxGuestAdditions_${VBOX_LATEST_VERSION}.iso
$   sudo mkdir -p /media/guestadditions ; sudo mount -o loop /tmp/VBoxGuestAdditions_${VBOX_LATEST_VERSION}.iso /media/guestadditions
$   sudo /media/guestadditions/VBoxLinuxAdditions.run
$   sudo umount /media/guestadditions && sudo rm -rf /tmp/VBoxGuestAdditions_$VBOX_VERSION.iso /media/guestadditions

Note

The following message is expected and is benign: "Could not find the X.Org or XFree86 Window System."

  1. "dhclient" should run every time the OS is restarted
$   sudo -i
$   cat > /etc/init/dhclient.conf <<EOF

# dhclient - configure all network interfaces # This task is run on startup to reconfigure all network interfaces

description "identify all network interfaces, eliminate non-broadcast interfaces, and attempt to configure each interface." start on startup

task exec dhclient EOF

$ exit
  1. Reset network interface rules (must be done just before cloning the disk image)
$   sudo rm /etc/udev/rules.d/70-persistent-net.rules
$   sudo shutdown -r now
#/etc/init/vbox-node1.conf
description "node1"
author "node1"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [016]
console output
respawn
respawn limit 5 10
pre-stop script
su instancemanager -c "VBoxManage controlvm node1 savestate"
end script
exec su instancemanager -c "VBoxHeadless –startvm node1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment