Changes

Jump to navigation Jump to search
8,155 bytes added ,  12:37, 3 March 2015
initial notes on attempt to add AWS cloud support
[[File:MediaWiki-Vagrant.screenshot.png | thumb | screenshot showing aspects of the MediaWiki-Vagrant system]]
 
 
== Deploy MediaWiki-Vagrant to Amazon ==
 
How to Deploy your MediaWiki-Vagrant instance to Amazon Web Services (AWS)
 
Using multiple providers ''with the same virtual machine'' is not a feature of Vagrant. Supposedly this limitation will be removed in a future version of Vagrant. But there is a work-around that you can use to accomplish this -- by creating a multi-machine environment. We are describing that work-around. There are some "cheap" solutions that tell you to either delete, or rename the hidden <code>.virtualbox</code> directory in your project source. Don't do that. That's just deleting the information that you'd need for using the existing provider. Or, only do that if you are trying to permanently switch the provider used in your project -- which is not the case here. To get a fully compatible MediaWiki-Vagrant setup that works for both localhost VirtualBox deployments and cloud Amazon AWS deployments, then read on.
 
=== Caveats ===
The MediaWiki-Vagrant setup is designed for local development and NOT for security, so it may not be suitable for running in the cloud.
 
The MediaWiki-Vagrant box is setup with NFS shares. The Vagrant-aws plugin has nominal support for shared folders using rsync, so sharing the ~/vagrant folder might work, but it's unkown how well this works. And it's unknown how to disable the sharing in <code>Vagrantfile-extra.rb</code>
 
=== Pre-requisites ===
 
==== AWS Account ====
You obviously need an AWS account, which you can get for free. So head over to Amazon and create one. You'll need to create a IAM user and a set of "Access" and "Secret" keys for this user at https://console.aws.amazon.com (Dashboard -> Users -> User Actions -> Manage Access Keys)
 
==== Console Tools ====
It may be helpful to have the command line tools for Elastic Cloud installed so that you can test your connection ability. For Ubuntu,
<source lang="bash">
sudo apt-get install ec2-api-tools
ec2-describe-regions -v --auth-dry-run --aws-access-key KEY --aws-secret-key KEY
</source>
Rather than specifying your keys on the command line, you may want to set them in <code>~/.bashrc</code> and <code>source</code> the file to bring them into your current shell session. <ref>For some reason, this didn't work for me the first time, so I regenerated keys, and it worked.</ref>
 
<source lang="bash">
export AWS_ACCESS_KEY=THISISJUSTANEXAMPLE
export AWS_SECRET_KEY=ThisIsNotARealSecretEnterYourSecretHere
</source>
 
 
==== Vagrant-AWS Plugin ====
You need the vagrant-aws plugin (https://github.com/mitchellh/vagrant-aws)
<source lang="bash">
cd ~/vagrant
vagrant plugin install vagrant-aws
</source>
 
== Status ==
When you do a <code>vagrant status</code> check of your current MediaWiki-Vagrant setup, you'll see something like this:
 
<pre>
Current machine states:
 
default poweroff (virtualbox)
 
The VM is powered off. To restart the VM, simply run `vagrant up`
 
</pre>
 
 
The machine is called '''default''' and the provider is '''virtualbox'''.
 
If your virtual machine is not powered off, then do so with <code>vagrant halt</code>
 
== Boxes ==
Each '[http://docs.vagrantup.com/v2/providers/basic_usage.html box]' in vagrant is specific to a provider, so we'll need to get a new box that will run on AWS.
 
 
<source lang="bash">
vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
vagrant box list
</source>
 
You need to create a custom stanza in <code>Vagrantfile-extra.rb</code><ref>Don't edit Vagrantfile since that is distributed by MediaWiki-Vagrant and you won't be able to upgrade your environment</ref>
 
The items you'll need are:
# aws.access_key_id
# aws.secret_access_key
# aws.keypair_name
# aws.ami
 
To get the access_key_id and secret_access_key, you login to your AWS account. Here are the instructions http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html
 
To get the keypair_name, you need to create (or upload) a keypair into your AWS Console for the region. It's easy to create a keypair in the AWS console, and as soon as you do, it will prompt you to download the .pem file. Save the .pem file to your ~/.ssh/ directory, and ensure the file mode is 400
<source lang="bash">
chmod 400 ~/.ssh/my-aws-keys.pem
</source>
 
Need to find the image (AMI) you want. You can search for Ubuntu images at http://cloud-images.ubuntu.com/locator/ec2/ The latest Ubuntu version used in MediaWiki-Vagrant as of March 2015 is Trusty-Tahr (or 14.04 LTS) You need to choose the region that you want to host in. So for example if you want to host in Oregon state, then you want the "US West" region for Amazon. Searching for "trusty 64 west" we can see several options for the AMD64 architecture
 
<pre>Instance Type hvm:ebs AMI-ID ami-a6b8e7ce</pre>
 
 
 
== Customize Vagrantfile-extra.rb ==
 
 
I tried to customize the Vagrantfile-extra.rb but couldn't quite understand the required structure
<source lang=ruby line>
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# Sample 'extra' configuration file for MediaWiki-Vagrant
# -------------------------------------------------------
# http://www.mediawiki.org/wiki/Mediawiki-Vagrant
#
# This file contains examples of some customizations you may wish to
# apply to your virtual machine. To use it, copy this file to its parent
# directory (i.e., the repository root directory).
#
# To apply a customization, uncomment its line by removing the leading
# '#'. Then save the file and run 'vagrant halt' followed by 'vagrant up'.
#
# Useful details about the structure and content of this file can be
# found in the Vagrant documentation, at:
# <http://docs.vagrantup.com/v2/vagrantfile/index.html>.
#
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provider :virtualbox do |vb|
# For a full list of options you can pass to 'modifyvm', see
# <http://www.virtualbox.org/manual/ch08.html>.
 
# Boot the VM in graphical mode:
# vb.gui = true
 
# Increase memory allocation from 768MB to 1GB:
# vb.customize ['modifyvm', :id, '--memory', '1024']
vb.customize ['modifyvm', :id, '--memory', '2048']
 
# But limit the virtual machine to 1 CPU core:
# vb.customize ['modifyvm', :id, '--cpus', '1']
 
# Fix dns resolution problem
vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'off']
vb.customize ['modifyvm', :id, '--natdnsproxy1', 'off']
end
# override the box used for MediaWiki-Vagrant with a box for AWS
# we added this box at the command-line with
# vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
config.vm.define "default_virtualbox"
config.vm.define "default_aws", autostart:false do |default_aws|
default_aws.vm.box = "dummy"
end
supported_providers = %w(virtualbox aws)
active_provider = ENV['VAGRANT_ACTIVE_PROVIDER'] # it'd be better to get this from the CLI --provider option
supported_providers.each do |provider|
next unless active_provider.nil? || active_provider == provider
config.vm.define "default_#{provider}" do |box|
box.vm.provider :aws do |aws, override|
aws.access_key_id = 'RedactedSecret'
aws.secret_access_key = 'RedactedSecret'
aws.keypair_name = "eqt-mw-keys"
 
aws.ami = "ami-7747d01e"
 
override.ssh.username = "ubuntu"
override.ssh.private_key_path = "/home/greg/.ssh/eqt-mw-keys.pem"
end
end
end
# config.vm.provider :aws do |aws, override|
# aws.access_key_id = 'RedactedSecret'
# aws.secret_access_key = 'RedactedSecret'
# aws.keypair_name = "eqt-mw-keys"
#
# aws.ami = "ami-7747d01e"
#
# override.ssh.username = "ubuntu"
# override.ssh.private_key_path = "/home/greg/.ssh/eqt-mw-keys.pem"
# end
 
 
end
</source>
 
== Test or Run ==
When you're done with the customizations to the Vagrantfile-extra.rb
 
<source lang="bash">
vagrant status
## status looks good?
vagrant up --provider=aws
</source>
 
 
{{References}}
[[Category:DevOps]]
[[Category:Wiki]]
4,558

edits

Navigation menu