Skip to content

A comprehensive guide on how to implement a Wordpress website with LVM Storage Management.

Notifications You must be signed in to change notification settings

ekedonald/Implementing-Wordpress-Website-with-LVM-Storage-Management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 

Repository files navigation

Implementing a WordPress Website with LVM Storage Management

Understanding Three-Tier Architecture

A Three-Tier Architecture is a client-server architecture model that separates an application into three interconnected but distinct layers, each responsible for specific aspects of the application's functionality.

3-Tier Architecture

Generally, web or mobile solutions are implemented based on a Three-Tier Architecture to improve scalability and flexibility. The three distinct layers are:

  1. Presentation Layer (PL): This is the user interface such as the client server or browser on your laptop.

  2. Business Layer (BL): This is the backend program that implements business logic (i.e. Application or Web Server).

  3. Data Access or Management Layer (DAL): This is the layer for computer data storage and data access (i.e. Database Server or File System Server such as FTP Server or NFS Server).

What is Logical Volume Manager (LVM)?

LVM stands for Logical Volume Manager, a technology used in Linux and other Unix-like operating systems to manage storage devices and create flexible, resizable storage configurations. LVM provides a layer of abstraction between the physical storage devices (such as hard drives, SSDs, or partitions) and the file systems or logical volumes used by the operating system.

Key components of LVM include:

  1. Physical Volumes (PVs): These are the physical storage devices or partitions (i.e. hard drives or SSDs) that are added to the LVM system.

  2. Volume Groups (VGs): Volume Groups are created by combining one or more Physical Volumes. VGs serve as a pool of storage that can be allocated to various Logical Volumes.

  3. Logical Volumes (LVs): Logical Volumes are similar to traditional partitions and are created within a Volume Group. They are what you format with a file system and use to store data. Logical Volumes can be resized and moved dynamically, which is a significant advantage of LVM.

How To Implement a WordPress Website with LVM Storage Management

The following steps are taken to implement a WordPress Website with LVM Storage Management:

Step 1: Provision a Web Server EC2 Instance

Use the following parameters when configuring the EC2 Instance:

  1. Name of Instance: Web Server
  2. AMI: Red Hat Enterprise Linux 9 (HVM), SSD Volume Type
  3. New Key Pair Name: web11
  4. Key Pair Type: RSA
  5. Private Key File Format: .pem
  6. New Security Group: WordPress
  7. Inbound Rules: Allow Traffic From Anywhere On Port 80 and Port 22.

web server instance summary Instance Summary for Web Server

  • On the Instances tab, you will see the Availability Zone (i.e. us-east-1d). This will be used when creating Elastic Block Volumes for the Web Server Instance.

web server availability zone

Step 2: Create and Attach 3 Elastic Block Store Volumes to the Web Server EC2 Instance

  • On the EC2 dashboard, click on Volumes on the Elastic Block Store tab.

ebs volumes

  • Click on the Create volume button.

create volume

  • Give the EBS Volume the following parameters and click on the create volume button:
  1. Size (GiB): 10
  2. Availability Zone: us-east-1d (Note that the Availability Zone you select must match the Availability zone of the Web Server Instance)

ebs parameters

  • Repeat the steps above to create two more EBS Volumes.

available ebs volumes You will see the 3 EBS Volumes you created have an Available Volume state

  • Click on one of the Volumes then click on the Actions button, you will see a drop-down and click on the Attach volume option.

attach volume

  • Select the Web Server Instance and click on the Attach volume button.

select web server instance

  • Repeat these steps for the other 2 volumes and you will see that the volumes have been attached to the Web Server Instance as shown below:

volumes attached to web server

Step 3: Implement LVM Storage Management on the Web Server

  • Open terminal on your computer.

  • Go to the Downloads directory (i.e. .pem key pair is stored here) using the command shown below:

cd Downloads
  • Run the following command to give read permissions to the .pem key pair file.
chmod 400 <private-key-pair-name>.pem

chmod web11

  • SSH into the Web Server Instance using the command shown below:
ssh -i <private-key-name>.pem ec2-user@<Public-IP-address>

ssh web server

  • Use the lsblk command to inspect the block devices attached to the server.

lsblk Notice the names of the newly created devices.

  • Use the df -h command to see all mounts and free space on your server.

df -h

  • Use gdisk utility to create a single partition on /dev/xvdf disk.

gdisk dev/xvdf Note that all devices in Linux reside in the /dev directory.

sudo gdisk /dev/xvdf
  • Type n to create a new partition and fill in the data shown below into the parameters:
  1. Partition number (1-128, default 1): 1
  2. First sector (34-20971486, default = 2048) or {+-}size{KMGTP}: 2048
  3. Last sector (2048-20971486, default = 20971486) or {+-}size{KMGTP}: 20971486
  4. Current type is 8300 (Linux filesystem) Hex code or GUID (l to show codes, Enter = 8300): 8300

n partition

  • Type pto print the partition table of the /dev/xvdf device.

p partition

  • Type w to write the table to disk and type y to exit.

w y partiton

  • Repeat the gdisk utility partitioning steps for /dev/xvdg and /dev/xvdh disks.

  • Use the lsblk command to view the newly configured partition on each of the 3 disks.

lsblk

  • Install lvm2 package using the command shown below:
sudo yum install lvm2 -y

install lvm2

  • Run the following command to check for available partitons:
sudo lvmdiskscan

lvmdiskscan

  • Use pvcreate utility to mark each of the 3 disks as physical volumes (PVs) to be used by LVM.
sudo pvcreate /dev/xvdf1
sudo pvcreate /dev/xvdg1
sudo pvcreate /dev/xvdh1

pvcreate

  • Verify that your physical volumes (PVs) have been created successfully by running sudo pvs

pvs

  • Use vgcreate utility to add 3 physical volumes (PVs) to a volume group (VG). Name the volume group webdata-vg.
sudo vgcreate webdata-vg /dev/xvdf1 /dev/xvdg1 /dev/xvdh1

vgcreate

  • Verify that your volume group (VG) has been created successfully by running sudo vgs

vgs

  • Use lvcreate utility to create 2 logical volumes: apps-lv (use half of the PV size) and logs-lv (use the remaining space of the PV size). Note that apps-lv will be used to store data for the website while logs-lv will be used to store data for logs.
sudo lvcreate -n apps-lv -L 14G webdata-vg
sudo lvcreate -n logs-lv -L 14G webdata-vg

lvcreate

  • Verify that your logical volume (LV) has been created successfully by running sudo lvs

lvs

  • Verify the entire setup running the following commands:
sudo vgdisplay -v #view complete setup - VG, PV, and LV

vgdisplay

sudo lsblk

lsblk

  • Use mkfs.ext4 to format the logical volumes (LV) with ext4 file system.
sudo mkfs -t ext4 /dev/webdata-vg/apps-lv

mkfs ext4 apps-lv

sudo mkfs -t ext4 /dev/webdata-vg/logs-lv

mkfs ext4 logs-lv

  • Create /var/www/html directory to store website files.
sudo mkdir -p /var/www/html

mkdir /var/www/html

  • Create /home/recovery/logs to store backup of log data.
sudo mkdir -p /home/recovery/logs

mkdir /home/recovery/logs

  • Mount /var/www/html on apps-lv logical volume.
sudo mount /dev/webdata-vg/apps-lv /var/www/html/

mount apps-lv /var/www/html

  • Use rsync utility to backup all the files in the log directory /var/log into /home/recovery/logs (This is required before mounting the file system).
sudo rsync -av /var/log/. /home/recovery/logs/

rsync var/log home/recovery

  • Mount /var/log on logs-lv logical volume. (Note that all the existing data on /var/log will be deleted).
sudo mount /dev/webdata-vg/logs-lv /var/log

mount logs-lv var/log

  • Restore log files back into /var/log directory.
sudo rsync -av /home/recovery/logs/ /var/log

rsync home/recovery /var/log

  • Update /etc/fstab file so that the mount configuration will persist after restarting the server. The UUID of the device will be used to update the /etc/fstab file. Run the command shown below to get the UUID of the apps-lv and logs-lv logical volumes:
sudo blkid

blkid

  • Update /etc/fstab in this format using your own UUID and remember to remove the leading and ending quotes.
sudo vi /etc/fstab

/etc/fstab

  • Test the configuration using the command shown below:
sudo mount -a

mount -a

  • Reload the daemon using the command shown below:
sudo systemctl daemon-reload

systemctl daemon-reload

  • Verify your setup by running df -h

df -h

Step 4: Install WordPress on the Web Server

  • Update the list of packages in the package manager.
sudo yum -y update

yum update

  • Install wget, apache and its dependencies.
sudo yum -y install wget httpd php php-mysqlnd php-fpm php-json

install wget httpd php

  • Enable and start apache
sudo systemctl enable httpd

enable httpd

sudo systemctl start httpd

start apache

  • Install PHP and its dependencies.
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo yum install yum-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo yum module list php
sudo yum module reset php
sudo yum module enable php:remi-7.4
sudo yum install php php-opcache php-gd php-curl php-mysqlnd
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
sudo setsebool -P httpd_execmem 1

install php dependencies

  • Restart apache.
sudo systemctl restart httpd

restart apache

  • Download WordPress and copy WordPress to /var/www/html
mkdir wordpress
cd   wordpress
sudo wget http://wordpress.org/latest.tar.gz
sudo tar xzvf latest.tar.gz
sudo rm -rf latest.tar.gz
sudo cp wordpress/wp-config-sample.php wordpress/wp-config.php
sudo cp -R wordpress /var/www/html/

download wordpress

  • Configure SELinux policies.
 sudo chown -R apache:apache /var/www/html/wordpress
 sudo chcon -t httpd_sys_rw_content_t /var/www/html/wordpress -R
 sudo setsebool -P httpd_can_network_connect=1

selinux policies

Step 5: Provision a Database Server EC2 Instance

Use the following parameters when configuring the EC2 Instance:

  1. Name of Instance: Database Server
  2. AMI: Red Hat Enterprise Linux 9 (HVM), SSD Volume Type
  3. Key Pair Name: web11
  4. New Security Group: WordPress
  5. Inbound Rules: Allow Traffic From Anywhere On Port 22 and Traffic from the Private IPv4 address of the Web Server on Port 3306 (i.e. MySQL).

instance summary for database server Instance Summary for Database Server

Step 6: Create and Attach 3 Elastic Block Store Volumes to the Database Server EC2 Instance

  • Repeat Step 3 but attach the Volumes to the Database Server and ensure the volumes are attached to the Availability Zone (i.e. us-east-1c) of the Database Server.

ebs volumes attached to database server The EBS Volumes have been attached to the Database Server

Step 7: Install MySQL on the Database Server

  • Open another terminal on your computer.

  • Go to the Downloads directory (i.e. .pem key pair is stored here) using the command shown below:

cd Downloads
  • SSH into the Database Server Instance using the command shown below:
ssh -i <private-key-name>.pem ec2-user@<Public-IP-address>

ssh database

  • Update the list of packages in the package manager.
sudo yum update -y

yum update

  • Install MySQL server.
sudo yum install mysql-server -y

install mysql-server

  • Verify that the service is up and running.
sudo systemctl status mysqld

status mysqld

  • Enable the MySQL service.
sudo systemctl enable mysqld

enable mysqld

  • Restart the MySQL service.
sudo systemctl restart mysqld

restart mysqld

Step 8: Configure the Database Server to work with WordPress

  • Log into the MySQL console application.
sudo mysql

sudo mysql

  • Create a database called wordpress.
CREATE DATABASE wordpress;

create database

  • Create a new user.
CREATE USER 'myuser'@'<web_server_private_ip_address>' IDENTIFIED BY 'mypass';

create user

  • Grant all privileges on the wordpress database to the user you created.
GRANT ALL ON wordpress.* TO 'myuser'@'<web_server_private_ip_address>';

grant all privileges

  • Run the following command to apply and make changes effective.
FLUSH PRIVILEGES;

flush privileges

  • Display all the databases.
SHOW DATABASES;

show databases

  • Exit the MySQL console.

exit mysql

Step 9: Configure WordPress to connect to the remote Database Server

  • Connect to the Web Server Instance.

  • Install MySQL client.

sudo yum install mysql -y

install mysql client

  • Test that you can connect from your Web Server to your Database Server by using mysql-client
sudo mysql -u admin -p -h <Database_Server_Private_IP_address>

mysql -u admin -p -h database private ip

  • Verify if you can successfully execute SHOW DATABAES; command to see a list of existing databases.

show databases

  • Run the following command to configure WordPress to establish connection with the Database Server.
sudo vi /var/www/html/wordpress/wp-config.php

vi wp-config.php The highlighted parameters are the ones that need to be configured

  • Input the credentials of the user you created when configuring the Database Server then save and exit the file.

update wp-config.php

  • Try to access the URL shown below from your browser:
http://<Web_Server_Public_IP_Address>/wordpress/

url1

url2

url3

url4

url5

About

A comprehensive guide on how to implement a Wordpress website with LVM Storage Management.

Topics

Resources

Stars

Watchers

Forks