负载均衡框架
节点: web -7 web -8,lb-5,lb-6
四个节点都安装好nginx以及php
将all-rpm.tgz传输到root目录下执行即可(需要先行配置yum用来安装createrepo)
#!/bin/bash
mv all-rpm.tgz /etc/yum.repos.d/
groupadd www
useradd -m -g www -s /sbin/nologin www
cd /etc/yum.repos.d/
tar -zxvf all-rpm.tgz
yum install -y createrepo
createrepo /etc/yum.repos.d/local_yum_rpm
cat > /etc/yum.repos.d/local.repo << EOF
[local]
name=local
baseurl=file:///etc/yum.repos.d/local_yum_rpm
gpgcheck=0
enabled=1
EOF
yum install -y php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb php71w-json php71w-pecl-apcu php71w-pecl-apcu-devel
#set user and group
sed -i '/^user/c user = www' /etc/php-fpm.d/www.conf
sed -i '/^group/c group = www' /etc/php-fpm.d/www.conf
systemctl restart php-fpm
yum install mariadb-server mariadb -y
systemctl start mariadb
设置web节点测试页面
[root@web-7 ~]#cat /var/www/html/index.html
<html>
<head>
<title>Web Server</title>
</head>
<body>
<h1>Welcome to the Web Server</h1>
<p>Server IP: <?php echo $_SERVER['SERVER_ADDR']; ?></p>
</body>
</html>
web-8同上
设置负载均衡节点 lb-5,lb-6
添加配置文件
[root@lb-5 /etc/keepalived]#cat /etc/nginx/conf.d/upsteam.conf
upstream web_servers {
server web-7;
server web-8;
}
server {
listen 80;
location / {
proxy_pass http://web_servers;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
lb-6同上
负载均衡节点设置keepalived
yum install -y keepalived
修改配置文件,将原配置文件添加后缀保存
mv keepalived.conf keepalived.conf.bak
[root@lb-5 /etc/keepalived]#cat keepalived.conf
global_defs {
router_id lb-5
}
vrrp_instance VIP_1 {
state MASTER
interface eth0
virtual_router_id 50
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.100.100
}
}
[root@lb-6 /etc/keepalived]#cat keepalived.conf
global_defs {
router_id lb-6
}
vrrp_instance VIP_1 {
state BACKUP
interface eth0
virtual_router_id 50
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.100.100/24
}
}
标签:web,负载,lb,conf,Keepalived,keepalived,etc,yum,均衡 From: https://blog.csdn.net/weixin_59300057/article/details/142462734出现错误,试验lb-5的keepalive 停止后虚拟ip转到lb-6,但是lb-5重新启动后,虚拟ip没有回到lb-5
原因:将两个节点keepalived.conf 中的priority设置成了一样,都设置了150.