Introduction
In this article I will show you how to set up a new WordPress blog on Amazon EC2 public cloud and then migrate it to HP Public Cloud using Juju Jitsu, from Canonical, the company behind Ubuntu.
Prerequisites
- Amazon EC2 Account
- HP Public Cloud Account
- Ubuntu Desktop or Server 12.04 or above with root or sudo access
Juju Environment Setup
First of all we need to install Juju and Jitsu from the PPA archive to make it available for use, so first of all add the PPA to the installation sources:
sudo apt-get -y install python-software-properties
sudo add-apt-repository ppa:juju/pkgs
Now update apt and install juju, charm-tools and juju-jitsu
sudo apt-get update sudo apt-get install juju charm-tools juju-jitsu
You will now need to set up your ~/.juju/environments.yaml file for Amazon EC2, see here: https://juju.ubuntu.com/get-started/amazon/
and then for HP cloud also, so see here:
https://juju.ubuntu.com/get-started/hp-cloud/
So you should end up with an environments.yaml file that will look something like this:
default: amazon environments: amazon: type: ec2 control-bucket: juju-b1bb8e0313d14bf1accb8a198a389eed admin-secret:[any-unique-string-shared-among-admins-u-like] access-key: [PUT YOUR ACCESS KEY HERE] secret-key: [PUT YOUR SECRET KEY HERE] default-series: precise juju-origin: ppa ssl-hostname-verification: true hpcloud: juju-origin: ppa control-bucket: juju-hpc-az1-cb admin-secret: [any-unique-string-shared-among-admins-u-like] default-image-id: [8419] region: az-1.region-a.geo-1 project-name: [your@hp-cloud.com-tenant-name] default-instance-type: standard.small auth-url: https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/ auth-mode: keypair type: openstack default-series: precise access-key: [PUT YOUR ACCESS KEY HERE] secret-key: [PUT YOUR SECRET KEY HERE]
Deploying WordPress to Amazon EC2
Now we need to bootstrap the Amazon EC2 environment.
juju bootstrap -e amazon
Check it finishes bootstrapping correctly after a few minutes using:
juju status -e amazon
Which should output something like this:
machines: 0: agent-state: running dns-name: ec2-50-17-169-153.compute-1.amazonaws.com instance-id: i-78d4781b instance-state: running services: {}
To give a good view of what is going on and to also allow modification from a web control panel we can deploy juju-gui to the bootstrap node, using juju-jitsu:
jitsu deploy-to 0 juju-gui -e amazon juju expose juju-gui -e amazon
This will take a few minutes to deploy.
Once complete you will see this from the output of “juju status -e amazon”, which should output something like:
machines: 0: agent-state: running dns-name: ec2-50-17-169-153.compute-1.amazonaws.com instance-id: i-78d4781b instance-state: running services: juju-gui: charm: cs:precise/juju-gui-3 exposed: true relations: {} units: juju-gui/0: agent-state: started machine: 0 open-ports: - 80/tcp - 443/tcp public-address: ec2-50-17-169-153.compute-1.amazonaws.com
Then use the “public-address” entry in your web browser to connect to juju-gui and see what is going on visually.
Juju-gui currently works well on Google Chrome or Chromium, it uses a Self-signed SSL certificate so you will be prompted to connect given a security warning which you can safely ignore and proceed.
Initially you should see the login page, with the username already filled in as “admin” and the password is the same as your password for the admin-secret in your ~/.juju/environments.yaml file.
Once logged in you should see a page that looks like this showing that only juju-gui is deployed to your environment, so far:
First we need to deploy a MySQL Database to store your blog’s data:
juju deploy mysql -e amazon
This will take a few minutes to deploy, so go ahead and also deploy a wordpress application server:
juju deploy wordpress -e amazon
While deployment continues you should see them appear in Juju-gui too
:Once deployment is complete you can check the name of the new servers with:
juju status -e amazon
Which should output something like this:
machines: 0: agent-state: running dns-name: ec2-50-17-169-153.compute-1.amazonaws.com instance-id: i-78d4781b instance-state: running 1: agent-state: running dns-name: ec2-23-22-68-159.compute-1.amazonaws.com instance-id: i-3a9bd554 instance-state: running 2: agent-state: running dns-name: ec2-54-234-249-131.compute-1.amazonaws.com instance-id: i-f9e56696 instance-state: running services: juju-gui: charm: cs:precise/juju-gui-3 exposed: true relations: {} units: juju-gui/0: agent-state: started machine: 0 open-ports: - 80/tcp - 443/tcp public-address: ec2-50-17-169-153.compute-1.amazonaws.com mysql: charm: cs:precise/mysql-16 relations: {} units: mysql/0: agent-state: started machine: 1 public-address: ec2-23-22-68-159.compute-1.amazonaws.com wordpress: charm: cs:precise/wordpress-11 exposed: false relations: loadbalancer: - wordpress units: wordpress/0: agent-state: started machine: 2 public-address: ec2-54-234-249-131.compute-1.amazonaws.com
Now we need to add a relationship between the wordpress application server and the MySQL database server. This will set up the SQL backend database for your blog and configure the usernames and passwords and database tables needed, all automatically.
juju add-relation wordpress mysql -e amazon
Finally, we need to expose the wordpress instance so you can connect to it using your web browser:
juju expose wordpress -e amazon
Now your Juju gui should look like this:
Setting up WordPress and adding your first post
Then connect to the wordpress server using your web browser, by using the public-address from the status output above, i.e. http://ec2-54-234-249-131.compute-1.amazonaws.com/
This will then show you the initial set up page for your wordpress blog, like this:
You will need to enter some configuration details such as a site name and password:
After you have saved the new details you will get a confirmation page:
So, click on Login to login to your new blog on Amazon EC2.
Now in order to make sure we are testing a live blog we need to enter some data. So, let’s post a blog entry.
First click on New Post on the top left menu:
Now, type in the details of your new blog post and click on Publish on the top right:
Now you have a new blog on Amazon EC2 with your first blog entry posted.
Migrating from Amazon EC2 to HP Cloud
So, now we have a live blog running on Amazon EC2 it is now time to migrate to HP Cloud.
We could just run the commands above but using the extension “-e hpcloud” to deploy the services to HP Cloud and then migrate the data.
But a more satisfying way is to use Juju-jitsu again to export the current layout from Amazon EC2 environment and then replicate that on HP Cloud.
So, we can use:
jitsu export -e amazon > wordpress-deployment.json
This will save a file in JSON format detailing the deployed services and their relationships.
First we need to bootstrap our HP Cloud environment:
juju bootstrap -e hpcloud
This will take a few minutes to deploy a new instance and install the Juju bootstrap node.
Once the bootstrap is complete you should be able to check the status by using:
juju status -e hpcloud
The output should be something like this:
machines: 0: agent-state: running dns-name: 15.185.102.93 instance-id: 1064649 instance-state: running services: {}
So, let us now deploy the replica of the environment on Amazon to HP:
jitsu import -e hpcloud wordpress-deployment.json
This will then deploy the replicated environment from Amazon EC2. You can check progress with:
juju status -e hpcloud
When completed your output should be as follows:
So we now have a replica of the environment from Amazon EC2 on HP Cloud, but we have no data, yet.
We also need to copy the SQL data from the existing Amazon EC2 MySQL database to the HP Cloud MySQL database to get all your live blog data across to the new environment.
Let’s login to the MySQL DB node on Amazon EC2:
juju ssh mysql/0 -e amazon
Now we are logged in we can get the root password for the Database:
sudo cat /var/lib/juju/mysql.passwd
This will output the root password for the MySQL DB so you can take a copy of the data with:
sudo mysqldump -p wordpress > wordpress.sql
When prompted copy and past the password that you recovered from the previous step.
Now exit the login using:
exit
Now copy the SQL backup file from Amazon EC2 to your local machine:
juju scp mysql/0:wordpress.sql ./ -e amazon
This will download the wordpress.sql file.
You will now need to know your new wordpress server IP address for HP Cloud.
You can find this from juju status:
juju status wordpress -e hpcloud
The output should look like this:
machines: 3: agent-state: running dns-name: 15.185.102.121 instance-id: 1064677 instance-state: running services: wordpress: charm: cs:precise/wordpress-11 exposed: false relations: db: - mysql loadbalancer: - wordpress units: wordpress/0: agent-state: started machine: 3 public-address: 15.185.102.121
In order to fix your WordPress server name you will have to replace your Amazon EC2 WordPress public-address with your HP Cloud WordPress server public-address.
So, you will need to do a find and replace in the wordpress.sql file as follows:
sed -e 's/ec2-54-234-249-131.compute-1.amazonaws.com/15.185.102.121/g' wordpress.sql > wordpress-hp.sql
Obviously you will need to customise the command to replace your server addresses from Amazon and HP Cloud in the command above.
NB:This step can be problematic and if you need more detailed information on changing the server name of a wordpress installation and moving servers see this more detailed instructions here:
http://codex.wordpress.org/Moving_WordPress
Now upload to your new HP Cloud MySQL server the database backup file, fixed with the new server public-address:
juju scp wordpress-hp.sql mysql/0: -e hpcloud
Now let’s import the data into your wordpress database on HP Cloud.
First we need to log in to the database server, as before:
juju ssh mysql/0 -e hpcloud
Now let’s get the root password for the Database:
sudo cat /var/lib/juju/mysql.passwd
Now we can import the data using:
sudo mysql -p wordpress < wordpress-hp.sql
And when you are prompted for the password enter the password you retrieved in the previous step, and then exit.
Finally you will still need to expose the wordpress instance on HP Cloud to the outside world using:
juju expose wordpress -e hpcloud
Now connect to your new wordpress blog migrated to HP Cloud from Amazon by connecting to the public-address of the wordpress node.
You can find the address from the output of juju status as follows:
juju status wordpress -e hpcloud
The output should look like this:
machines: 3: agent-state: running dns-name: 15.185.102.121 instance-id: 1064677 instance-state: running services: wordpress: charm: cs:precise/wordpress-11 exposed: true relations: db: - mysql loadbalancer: - wordpress units: wordpress/0: agent-state: started machine: 3 open-ports: - 80/tcp public-address: 15.185.102.121
Now connect to http://15.185.102.121/ and your blog is now hosted on HP Cloud.