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` ```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` ```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 **1. Pada node backend webserver :** Server Block yang digunakan adalah sebagai berikut : ``` server { root /var/www/html/wp; index index.php index.html index.htm; server_name frontend.floss.my.id; server_tokens off; access_log /var/log/nginx/frontend_access.log; error_log /var/log/nginx/frontend_error.log; gzip on; gzip_vary on; gzip_min_length 10240; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/javascript text/x-javascript; gzip_disable "MSIE [1-6]\."; location / { try_files $uri $uri/ /index.php?$args; proxy_headers_hash_max_size 512; proxy_headers_hash_bucket_size 64; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; add_header Front-End-Https on; } location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 365d; } location ~* \.(pdf)$ { expires 30d; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } ```