Repositori berisi langkah konfigurasi load balancing pada WordPress khususnya pada layer 7

root authored 8 days ago
README.md Update README.md 8 days ago
block.sh Update block.sh 13 days ago
haproxy.sh Create haproxy.sh 13 days ago
lsyncd.sh Update lsyncd.sh 12 days ago
wordpress.sh Update wordpress.sh 12 days ago
README.md

WordPress-Load-Balance-Layer-7

Repositori berisi langkah konfigurasi load balancing pada WordPress khususnya pada layer 7

Persiapan

  • 1 Node Load Balance
    • server-ha.floss.my.id
  • 2 Node Backend Webserver
    • backend1.floss.my.id
    • backend2.floss.my.id
  • 1 Node Database
    • server-db.floss.my.id

Pre-installation

1. Buat bash script untuk otomasi install paket epel

$ vi epel.sh

#!/bin/bash
for i in server-ha.floss.my.id \
backend1.floss.my.id \
backend2.floss.my.id \
server-db.floss.my.id
do
   ssh root@"$i" yum install epel-release htop yum-utils -y
done

Beri permission execute pada file epel.sh :

$ chmod +x epel.sh

Eksekusi file tersebut :

$ ./epel.sh

2. Buat bash script untuk otomasi install paket nginx dan php

$ vi ephp.sh

#!/bin/bash
for i in backend1.floss.my.id \
backend2.floss.my.id
do
   ssh root@"$i" yum install nginx -y;
   ssh root@"$i" "systemctl enable nginx && systemctl start nginx";
   ssh root@"$i" yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y;
   ssh root@"$i" yum-config-manager --enable remi-php72;
   ssh root@"$i" yum -y install php \
               php-intl \
               php-common \
               php-opcache \
               php-mcrypt \
               php-cli \
               php-gd \
               php-curl \
               php-mysqlnd  \
               php-dom \
               php-curl \
               php-zip \
               php-mbstring \
               php-xml \
               php-xmlreader \
               php-simplexml \
               php-bcmath \
               php-soap \
               php-amqplib \
               php-fpm;
    ssh root@"$i" "systemctl enable php-fpm && systemctl start php-fpm";
done

Beri permission execute pada file epel.sh :

$ chmod +x ephp.sh

Eksekusi file tersebut :

$ ./ephp.sh

3. Install HAProxy pada node load balance

$ yum install haproxy -y

Jalankan service HAProxy

$ systemctl start haproxy

Aktifkas service HAProxy

$ systemctl enable haproxy

4. Install MariaDB pada node database

Tambahkan repository MariaDB :

$ vi /etc/yum.repos.d/mariadb.repo

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Install MariaDB

$ yum install -y mariadb-server

Jalankan service HAProxy

$ systemctl start mariadb

Aktifkas service HAProxy

$ systemctl enable mariadb

Konfigurasi Node Database

1. Buat database dengan nama wp_db :*

$ mysql -u root -p

> create database wp_db;

2. Beri akses wp_db ke user wp_user

$ mysql -u root -p

> GRANT ALL PRIVILEGES on wp_db.* to 'wp_user'@'%' IDENTIFIED BY 'some-password';

> flush privileges;

Konfigurasi Node Webserver1

1. Konfigurasi Server Block :

Download server block yang akan digunakan :

$ curl "https://git.leon36.web.id/leon/WordPress-Load-Balance-Layer-7/raw/e302271458a7538a06dcfa8e74f9261ebdb1717c/block.sh" | sh

Verifikasi server block :

$ ls -lah /etc/nginx/conf.d/blocks.conf

$ cat /etc/nginx/conf.d/blocks.conf

2. Konfigurasi file php-fpm :

$ sed -i 's/apache/nginx/g' /etc/php-fpm.d/www.conf

Restart service php-fpm :

systemctl restart php-fpm

3. Download file source WordPress :

$ curl "https://git.leon36.web.id/leon/WordPress-Load-Balance-Layer-7/raw/25eca602f1bec41d9e4eb666727e846f113186a2/wordpress.sh" | sh

4. Atur koneksi database :

$ cd /var/www/html/wp;

$ cp wp-config-sample.php wp-config.php

$ vi wp-config.php

define( 'DB_NAME', 'wp_db' );
define( 'DB_USER', 'wp_user' );
define( 'DB_PASSWORD', 'some-password' );
define( 'DB_HOST', 'server-db.floss.my.id' );

5. Definisikan site_url dan home_url :

Definisikan site_url dan home_url menggunakan variabel berikut agar website tidak hanya listen ke 1 hostname saja :

$ vi wp-config.php

define( 'WP_HOME',    'http://' . $_SERVER['HTTP_HOST'] );
define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] );

6. Install & konfigurasi lsyncd agar root directory website antar node backend sync :

$ curl "https://git.leon36.web.id/leon/WordPress-Load-Balance-Layer-7/raw/13dc8447c4638ed38843219e0c1cd0a2ecd5a35a/lysyncd.conf" | sh

Catatan 1 : Pastikan status service lsyncd berjalan dengan baik.

Catatan 2 : Cek directory /var/www/html/wp pada node backend2.floss.my.id.

Catatan 3 : restart service nginx pada node backend2.floss.my.id.

Konfigurasi Node HAProxy :

1. Gunakan konfigurasi berikut ini :

$ curl "https://git.leon36.web.id/leon/WordPress-Load-Balance-Layer-7/raw/8fd115b7b30c865fffd1e92bc3f0ef4ab65b3341/haproxy.sh" | sh;

Catatan : Pastikan status service haproxy berjalan dengan baik.

Pengujian

1. Buka website http://frontend.floss.my.id

2. Lakukan instalasi seperti biasa

3. Pastikan response header pada node berubah :

Node.png

Node1.png

4. Instalkan theme custom pada halaman wp-admin.php dan pastikan website tidak error

Questions ?

If you have questions related to the topic in this repository, please feel free to contact me at :