creating a blog the nerd way – Part 2

part 1 is here

ok, now we have a clustered mysql (or better mariaDB) database running, next step is to setup the blog itself…

  • Web Server

to serve the blog, we have to install the webserver first – i decided to use the de-facto standard apache2. on ubunto it’s very easy to install

sudo apt-get install apache2 php php-mysql

done… of course you can now modify the configuration etc – but for my purpose the default is sufficient.

  • Storage for the blog

since i want to distribute all uploaded files and the blog binaries itself to both servers, i need either a shared volume(i.e. nfs from my nas) or a cluster file system… since i’m a nerd and nfs is too easy, I was seeking for a cluster solution – and found Gluster

the installation is again easier than i thought it might be…

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:gluster/glusterfs-3.8
sudo apt-get update
sudo apt-get install -y glusterfs-server glusterfs-client
sudo service glusterfs-server start

of course you have to do the installation on both servers… afterwards, you only have to create the volumes to be clustered. Therefore I have created the mountpoint /data on dedicated disks (one per server) – since there are thousands of tutorials describing how to add and partition a new disk I won’t repeat it here.

# on both servers
sudo mkdir -p /data/gluster/gvol0

# on one node only
sudo gluster peer probe <SERVER2>
sudo gluster pool list
sudo gluster volume create gvol0 replica 2 <SERVER1>:/data/gluster/gvol0 <SERVER2>:/data/gluster/gvol0
sudo gluster volume start gvol0
sudo gluster volume info gvol0

the last command should tell you that everything is fine. Now we just have to mount the gluster volume:

# on both nodes
sudo mkdir -p /var/www/blog
sudo mount -t glusterfs localhost:/gvol0 /var/www/blog

as you can see, we are mounting a device with file type glusterfs – this means the gluster client is connecting to the gluster server instead of directly accessing the local disk. In this way it’s guaranteed that we get the current data, event if it’s not distributed to all servers.
To make it permanent you can add the mount command to the /etc/fstab file, but be aware: the mountpoint /data must alreade be mounted and the glusterfs deamon must be running… so I recommend to configure it in the new systemctl config files where you can configure dependencies or define the upstart order in /etc/rc.local file.

  • install wordpress

first we have to add the directory known by apache

sudo chown www-data:www-data /var/www/blog
echo "<VirtualHost *:80>" > /etc/apache2/sites-available/blog.conf
echo "DocumentRoot /var/www/blog" >> /etc/apache2/sites-available/blog.conf
echo "ServerName <YOUR PUBLIC FQDN>" >> /etc/apache2/sites-available/blog.conf
echo "</VirtualHost>" >> /etc/apache2/sites-available/blog.conf
a2ensite blog
service apache2 reload
wget wordpress.org/latest.zip
unzip latest.zip -d /var/www/blog/
mv /var/www/blog/wordpress/* /var/www/blog/
rm -rf /var/www/blog/wordpress/

now you just have to open a browser on your client and navigate to the FQDN you just entered in your apache config… I assume that you already configured your firewall. If you don’t want to open the firewall yet, it’s also possible to modify your /etc/hosts (*nix) or %windir%/system32/drivers/etc/hosts (win) file and enter the FQDN and private ip adress of one of your servers. The rest of the setup process is easy and not worth describing it here.

  • automatic failover

nearly finished – the blog itself is running and the content is distributed on two independent servers… now we only have to establish some kind of failover or load balancing mechanism to make sure it’s always on. since the goal is always on and i do not expect thousends of users a day, I just searched for an IP based HA solution – and found UCARP
just install the packages and add a few lines to the network configuration – done

sudo apt-get install ucarp

and now just add some ucarp specific settings to the network configuration file /etc/network/interfaces

#######################
# ucarp configuration
#######################
ucarp-vid 1 # vid : The ID of the virtual server [1-255]
ucarp-vip 10.0.0.201 # vip : The virtual address
ucarp-password secret # password : A password used to encrypt Carp communications
ucarp-advskew 1 # advskew : Advertisement skew [1-255]
ucarp-advbase 1 # advbase : Interval in seconds that advertisements will occur
ucarp-master yes # master : determine if this server is the master. Must be "no" on 2nd server!

iface ens32:ucarp inet static
        address 10.0.0.201
        netmask 255.255.255.0

that’s it, now just restart the network and configure your firewall to forward to the virtual ip…

sudo service networking restart

done… ok, there are some other tasks you might do, i.e. secure the blog with an ssl certificate. Maybe I’m going to make another blog post describing how to do it 😉

If you have any questions or suggestions, just leave a note…
Benjamin

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply