Home > Kiến thức hữu ích > Load Balancing với Lsyncd

Load Balancing với Lsyncd

Mô hình không có Load Balancing:

Mô hình Load Balancing với Lsyncd:

Bài viết này sẽ chỉ hướng dẫn đồng bộ hoá giữa 2 web server bằng Lsyncd.

Vào Z.com –> Cloud VPS –> Network –> Load Balancing.

Balancing Method: Lease Connection.

Thêm 2 port 80 và 443.

Nghĩa là: Máy chủ nào sử dụng ít tài nguyên hơn sẽ chuyển hướng sang máy chủ đó để cân bằng tài nguyên.

SV1:
cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
TYPE="Ethernet"
BOOTPROTO="static"
IPADDR0="10.10.0.1"
NETMASK0="255.255.255.0"
ONBOOT="yes"
reboot
ip a
ssh-keygen
ssh-copy-id root@10.10.0.2
ssh root@10.10.0.2
clear
nmcli c modify eth0 ipv4.addresses "163.44.195.25"
nmcli c down eth0; nmcli c up eth0
clear
yum install lsyncd -y
nano /etc/lsyncd.conf (Thêm lsync.txt - thay đoạn IP)
systemctl start lsyncd
systemctl status lsyncd
systemctl enable lsyncd
clear
cd /home
touch test.txt
clear
yum update -y
yum install docker -y
systemctl enable docker
systemctl start docker
docker pull nginx
docker pull wordpress:php8.0-fpm
docker network create web
docker run -d --name wordpress --network web -v /home/code:/var/www/html wordpress:php8.0-fpm
docker run -d --name nginx --network web -v /home/code:/var/www/html -v /home/config:/etc/nginx/conf.d -p 80:80 -p 443:443 nginx
docker ps
docker start nginx
cd /home/config
nano default.conf
#add file default.conf
docker restart nginx
# truy cập ip kiểm tra.
nano longvippro.xyz.conf
#add file port80.conf
docker restart nginx

SV2:
ssh-keygen
ssh-copy-id root@10.10.0.1
ssh root@10.10.0.1
clear
nmcli c modify eth0 ipv4.addresses "163.44.195.25"
nmcli c down eth0; nmcli c up eth0
clear
yum install lsyncd -y
nano /etc/lsyncd.conf (Thêm lsync.txt)
systemctl start lsyncd
systemctl status lsyncd
systemctl enable lsyncd
rm -f test.txt
clear
yum update -y
yum install docker -y
systemctl enable docker
systemctl start docker
docker pull nginx
docker pull wordpress:php8.0-fpm
docker network create web
docker run -d --name wordpress --network web -v /home/code:/var/www/html wordpress:php8.0-fpm
docker run -d --name nginx --network web -v /home/code:/var/www/html -v /home/config:/etc/nginx/conf.d -p 80:80 -p 443:443 nginx
docker ps
docker start nginx
docker logs -f nginx

SV3:
yum update -y
yum install docker -y
systemctl enable docker
systemctl start docker
docker pull mariadb
docker run -d --name db -p 3306:3306 -e MYSQL_ROOT_PASSWORD=Tenten@123 -e MYSQL_USER=wp -e MYSQL_DATABASE=wp -e MYSQL_PASSWORD=Tenten@123 mariadb
localhost : 10.10.0.3:3306