Here are the Steps For Building Scalable WordPress on HP Cloud With GlusterFS and Nginx. With OpenStack Nova We Can Just Do it From Desktop. Previously, we wrote about GlusterFS. You possibly love to read Distributed Replicated Block Device. These are the theoretical part. This scalable WordPress instance will have MariaDB (a MySQL fork) database server, GlusterFS distributed filesystem, Nginx or Nginx Plus web servers. We can use Nginx as load balancer too But we can use the load balancer of HP Cloud as good alternative. In the fronted, Akamai DNS (via HP Cloud) will highly cache most commonly visited webpages plus decrease the chance of DDoS. There are different type of scaling – vertical and horizontal are the commonest types.
Scalable WordPress on HP Cloud With GlusterFS & Nginx
If you are new to HP Cloud and / or OpenStack, you can read how to install WordPress on HP Cloud. With OpenStack Python Client Commands, frankly we can build the instances from command line from Desktop, without opening the Web GUI on browser. If you are not easy with the Python clients, then use the Web GUI. We are starting after setting the Router, Ingress and Egress policy rightly. Instances are running Ubuntu 14.04 LTS.
Steps For Creating Scalable WordPress on HP Cloud With GlusterFS & Nginx
We can make the MariaDB to replicate on two server instances as well. This is called MySQL Cluster Replication and you will get reference on official MySQL website. InnoDB Storage Engine is commonly used by both Rackspace and us. We use MySQL tuner of Major Hayden to optimize the configuration and setup. What we are doing is known as “MySQL Master-Master Replication”. This is kind of an example blueprint :
---
1 2 3 4 | apt update -y && apt upgrade dpkg-reconfigure locales # en_GB, UTF-8 apt-get install mariadb-server mariadb-client |
Edit /etc/my.cnf
file :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | bind-address = 0.0.0.0 server-id = <any number> log-bin = /var/log/mysql/var/bin.log log-slave-updates log-bin-index = /var/log/mysql/log-bin.index log-error = /var/log/mysql/error.log relay-log = /var/log/mysql/relay.log relay-log-info-file = /var/log/mysql/relay-log.info relay-log-index = /var/log/mysql/relay-log.index auto_increment_increment = 10 auto_increment_offset = 1 master-host = <subnet mask> master-user = <username> master-password = <password> replicate-do-db = <database name to be replicated> |
You will do the same on another server. You need to run this format of comand on each server :
1 2 3 4 | # mysql -u root -h localhost -p grant replication slave on *.* to slave@'<subnet mask>' identified by '<password>'; flush privileges; exit; |
We can add both of these database IP on WordPress using HyperDB Plugin from WordPress later. There is software named “Tungsten Replicator” in case you want to do more than the above. Restart the service on both servers, create a database for WordPress :
1 2 3 | CREATE DATABASE wordpress; mysql -uroot -p<mysql_password> -e "CREATE USER 'wordpress_user'@'%' IDENTIFIED BY '<mysql_password>'"; mysql -uroot -p<mysql_password> -e "GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'%'"; |
Check the replication and troubleshoot it if needed.
For creation of web server, we can use multiple web servers – 4 or more. We need to configure them in this way. First /etc/hosts
should be rightly configured, like we need this entry for proper setup from DNS –
1 2 | 15.16.17.18server.example.comgluster1 # 15.16.17.19server1.example.comgluster2 |
1 2 3 4 5 6 7 8 9 10 11 12 | apt update -y && apt upgrade apt-get install -y python-software-properties add-apt-repository -y ppa:gluster/glusterfs-3.5 apt update -y && apt-get install -y glusterfs-server # check the command rightly gluster peer probe gluster1 gluster peer status # check the mounting mkdir -p /mnt/gluster # create another server named gluster2 gluster volume create datapoint replica 2 transport tcp gluster1:/mnt/gluster gluster2:/mnt/gluster force gluster volume start datapoint |
Then we will proceed to install Nginx-PHP5 FPM :
1 2 3 4 5 6 7 8 | apt-get update apt-get -y install nginx glusterfs-client php5-fpm php5-mysql # CGI path fix # sed -i s/\;cgi\.fix_pathinfo\=1/cgi\.fix_pathinfo\=0/g /etc/php5/fpm/php.ini mkdir -p /mnt/gluster # example mount -t glusterfs gluter_node_subnet_mask_ip:/file_store mnt/gluster; echo "gluter_node_subnet_mask_ip:/file_store mnt/gluster glusterfs defaults,_netdev 0 0" >> /etc/fstab |
We will install WordPress on mnt/gluster/www
, right? You can change the path name.
1 | mkdir mnt/gluster/www |
Settings of nginx default
will go like this :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /gluster/www; index index.php index.html index.htm; server_name localhost; location / { try_files $uri $uri/ =404; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } |
We are using unix socket for PHP5-fpm. TCP will be slower but easy to configure. We need a clean server running Nginx in front because we can add these on /etc/nginx/sites-available/default
:
1 2 3 4 5 | upstream backend { ip_hash; server node_1_subnet_ip server node_2_subnet_ip } |
This one’s IP will go to DNS. If you are new, it will take a bit time to getting a fully working setup within half an hour. One server, two server configuration can be guided easily. For multiple servers, it becomes a bit difficult to guide step by step. Making the concept clear is most important point. We can create HA cluster with Heartbeat Pacemaker.
Tagged With nginx in front of gluster