Distributed Wordpress with CoreOS
CoreOS can seem daunting at first. This tutorial is built to encourage you in your journey and to demonstrate the power of this minimalistic operating system.
You’ll see why later.
You’ll need a new one every time you rebuild a cluster.
Copy the entire URL provided in the body of the response somewhere safe.
etcd2 is a complete reimplementation based on research and learning about Raft. While backwards compatibility exists, we’d be silly not to go for the latest and greatest.
Update coreos-vagrant/user-data by changing the following.
Set the reboot strategy on CoreOS update:
Disable etcd properties in favour of etcd2:
Add your discovery token from 1D (warning: you need to do this each time):
Stop etcd.service from starting in favour of etcd2:
In the coreos-vagrant directory run:
Within a few minutes, you’ll have 3 CoreOS machines, ready to go all based on the beta channel.
Unzip to an appropriate location, add the binary to your path (.bashrc / .bash_profile / .zshrc)
- Restart your terminal
Add the correct vagrant .ssh identify
Fortunately there is a specific known_hosts file to clean up. Do this after every cluster rebuild.
You should see your 3 CoreOS machines listed.
SSH onto one of your CoreOS hosts.
exit when done.
Download some sample unit files:
Submit the hello unit and watch the containers say hello.
Once you’re done greeting yourself, stop the unit and destroy it.
Hello worlds suck. Let’s deploy something that’s interesting with scale!
Let’s fire up lots of Wordpress instances. We won’t go into detail in this tutorial, but this is what we’ll build (minus the top Load Balancer - but expect it’s easy).
NOTE: The wp instances will talk through to a single database server. While databases on CoreOS and containers is entirely possible, and done, I prefer to exclude the database from this setup. Set yourself up with a VM, install mariadb (/mysql) and follow the wordpress database installation instructions.
Edit wordpress@.service …
… and change line 12 to incorporate your database and S3 creds:
Edit wordpress-admin.service …
… and change line 12 to this (only difference is this: -e WORDPRESS_ADMIN_ENABLED=true):
Either follow clusterable-wordpress/README.md for instructions on how to run, or if you’re like me and like to cheat:
The cluster deploys the following:
- A discovery sidekick unit that watches for wordpress units that start and get destroyed. This particular unit is unique in that it can detect the type of wordpress container firing up, and configures the vulcand locations and paths as required.
- vulcand, a “programmatic load balancer backed by etcd” that listens for etcd entries and reconfigures itself instantly as config changes.
- wpadmin (the wordpress control panel) as a separate container. After much trial and error vulcand doesn’t support sticky session persistence and wp-admin isn’t written to deal with sessions moving all over the place.
- customised wordpress containers, using the w3 total cache plugin, with wp-admin disabled by a custom .htaccess denying access.
The vulcan@.service, wordpress@.service and wordpress.service units all depend on docker images, which take a while to download the first time. As your cluster fires up watch the status of all units until all are up and running:
Since you’re firing these containers up at the same time, your containers may take some time to start and be in
Ctrl+c at any time.
Add an entry to your hostfile:
Add the following line:
Note, you must call the host
wordpress.local because this is the value configured in our sample wordpress database.
And finally… click on this magic link:
Refresh the page over and over again and watch the container id change.
Oh, don’t forget to shut everything down! Repeat until everything is destroyed:
If you don’t want this coreos cluster anymore, just blow it away (in fact you don’t really have to manually clean up each unit, as above … just destroy your CoreOS cluster)!
You’ve deployed a scalable Wordpress site.
Grab yourself some french toast, paw paw juice and toffee apple and chill out in celebration.
If you need some help with CoreOS, ping me on twitter. I think this OS brings great promise and I’m keen to understand how you’ll use it.