Skip to content

Instantly share code, notes, and snippets.

@phaelfp
Created March 17, 2016 15:25
Show Gist options
  • Save phaelfp/4fd5c2e8538c6d52b930 to your computer and use it in GitHub Desktop.
Save phaelfp/4fd5c2e8538c6d52b930 to your computer and use it in GitHub Desktop.
Vagrantfile e bootstrap.sh para subir um Ubuntu com MongoDB já configurado para acesso externo em ambiente de desenvolvimento.
#!/bin/bash
MONGODB_RELEASE="2.6.7"
# Functions
function installMongoDB() {
# http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
# import the public key used by the package management system
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
# create a list file for MongoDB
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
# reload local package database
apt-get -y update
# install the MongoDB packages
apt-get install -y mongodb-org=$MONGODB_RELEASE mongodb-org-server=$MONGODB_RELEASE mongodb-org-shell=$MONGODB_RELEASE mongodb-org-mongos=$MONGODB_RELEASE mongodb-org-tools=$MONGODB_RELEASE
}
function configuringMongoDB() {
sed -i "s/bind_ip = 127.0.0.1/bind_ip = 0.0.0.0/" /etc/mongod.conf
sed -i "s/#port/port/" /etc/mongod.conf
service mongod restart
}
function configuringFirewall() {
ufw allow 22
ufw allow 27017
ufw --force enable
}
# Bootstrap
if [ ! -e ~/.firsttime ]; then
# fix "dpkg-preconfigure: unable to re-open stdin"
export DEBIAN_FRONTEND=noninteractive
installMongoDB
configuringFirewall
configuringMongoDB
touch ~/.firsttime
fi
IP = "10.0.33.34"
Vagrant.configure("2") do |config|
config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.provision :shell, :path => "bootstrap.sh"
config.vm.network :private_network, :ip => IP
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment