Introduction In this lab, we will develop and deploy a scalable and reliable WordPress site on LEMP stack. Different from LAMP stack, LEMP uses ngi
Introduction
In this lab, we will develop and deploy a scalable and reliable WordPress site on LEMP stack. Different from LAMP stack, LEMP uses nginx [engine x], instead of Apache as web server. Compared with Apache, nginx can handle much more concurrent hits. I found an article on the Internet, demonstrating the performance difference ‘Web server performance comparison‘.
Please refer to nginx official site https://nginx.org/en/ for further details.
Design Rationale
A design proposed for production environment is as below. Firewall is not illustrated in the digram, but required in production environment.
Design Key Points:
- A pair of load balancers in active/passive HA cluster, sharing single virtual IP (VIP). DNS name will be associated to the VIP.
- The separation of web, application and backend layers in different subnets, allows flexibility to enforce security.
- Web cluster, PHP cluster, database cluster and file server cluster are created to achieve high availability and horizontal scalability
- PHP servers, file serves and database servers are external to web serves, which helps scalability. File server cluster will store WordPress files and mounted to web nodes and PHP nodes.
Lab Description
Lab Scope
Due to the limit of my time and computing resource (= ‘money’), the boxes highlighted in RED in the above diagram are in the current lab scope. If time allows, I will deploy LVS load balancers as well. If you are interested in pfSense as load balancer, please refer to my posts Use pfSense to Load Balance Web Servers (1) and Use pfSense to Load Balance Web Servers (2).
Lab Servers and Software
I used DigitalOcean for cloud servers. It is cheaper than AWS. The cheapest instance is only US$5/month.
DigitalOcean $5 deal provides: 1 CPU, 512MB RAM, 20GB SSD, and 1000GB transfer. All servers used in this lab are $5 servers.
If you decide to use DigitalOcean, please use my referral link http://www.digitalocean.com/?refcode=81650e396096. You will get US$10 in credit immediately; and I may get some referral benefits as well, so win-win.
The downside is DigitalOcean provides less features. It allows private IP… but the private IP is automatically generated based on the selected datacentre (DC). For example, all my servers are in New York 3 DC, and their private IPs are all in the same subnet. It means I cannot manipulate IP allocation and routing as I did in AWS. In addition, it provides little ready-to-use security mechanism, though we can use Linux native firewall and install additional security services.
It is good and bad: good for quick DevOp testing, no hustle with network; bad for production environment or if you particular like network…myself for example 🙂
Web Service Layer | Application/Service | Platform |
---|---|---|
Load Balancer Layer | Linux Virtual Server(LVS) | Not deployed yet |
Web Server Layer | Nginx | Ubuntu16.04.1×64 |
Application Layer | php-fpm php-mysql | Ubuntu16.04.1×64 |
Backend Layer-Database | MySQL | Ubuntu14.04.5×64 |
Backend Layer-File System | Gluster | Ubuntu16.04.1×64 |
Deployment Steps
Step 1 – MySQL Database
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#update and install mysql server on DB01. A GUI window will appear to assign mysql root password <span style="color:#0000ff;">sudo apt-get update sudo apt-get -y install mysql-server</span> #create 'wordpress1' database. '-u' followed by username.'-p' means password, it will require password in a separate line. <span style="color:#0000ff;">sudo mysqladmin -u root -p create wordpress1</span> #change root password if required. <span style="color:#0000ff;">sudo mysqladmin -u root -p password</span> #enter mysql shell and enter password in separate line. <span style="color:#0000ff;">sudo mysql -u root -p</span> #create a user (CREATE USER 'wpuser1'), who can access from any host (@'%'), and with a password ('password'). Remember to add ';' at the end of each command under mysql shell to complete a command. <span style="color:#0000ff;">CREATE USER 'wpuser1'@'%' IDENTIFIED BY 'password';</span> #grant user 'wpuser1' full permission in particular to 'wordpress1'database, but not global database. <span style="color:#0000ff;">GRANT ALL PRIVILEGES ON wordpress1.* TO 'wpuser1'@'%';</span> #verify the existence of 'wordpress1' database and 'wpuser1' <span style="color:#0000ff;">show databases; select User from mysql.user;</span> #Update database permissions and exit mysql shell <span style="color:#0000ff;">flush privilege; exit</span> #Edit mysql config file to update the bind address from 127.0.0.1(loopback) to the actual private address. #Refer 'Note' section for details. <span style="color:#0000ff;">sudo nano /etc/mysql/my.cnf</span> #restart mysql service <span style="color:#0000ff;">sudo service mysql restart </span> |
Note – MySQL Bind Address:
If the bind address in ‘my.cnf’ remains loopback, the database will not allow remote database access. When accessing the website, the following will show:
We will need to edit ‘/etc/mysql/my.cnf‘ as following, where ‘10.132.88.196’ is the DB server’s private IP.
Then we execute ‘service mysql restart‘ to restart mysql service. The following screenshot shows the DB server was listening on localhost port 3306 before restarting mysql service; and listening on DB01’s IP after restarting the service.
I also checked firewall status to make no traffic is accidentally blocked.
COMMENTS
[…] Deploy Scalable and Reliable WordPress Site on LEMP(1) introduced the LEMP design, lab setup and MySQL configuration. This post will further introduce how to deploy Gluster distributed file system and Nginx web server. PHP will be initially enabled on the Nginx web server to prove WordPress site is working. The next post will introduce hosting PHP on a separate server. […]
[…] Boot another $5 ubuntu server from DigitalOcean, details available in Deploy Scalable and Reliable WordPress Site on LEMP(1). […]