HAProxy+Keepalived
程序员文章站
2024-03-21 09:29:16
...
环境准备
服务器系统 | Centos6.8 |
---|---|
内存 | 1G |
CPU | 2核 |
IP地址 | 10.0.0.20 |
服务1 | Keepalived |
服务2 | HAProxy |
服务器系统 | Centos6.8 |
---|---|
内存 | 1G |
CPU | 2核 |
IP地址 | 10.0.0.21 |
服务1 | Keepalived |
服务2 | HAProxy |
服务器系统 | Centos6.8 |
---|---|
内存 | 1G |
CPU | 2核 |
IP地址 | 10.0.0.22 |
服务1 | Nginx |
服务器系统 | Centos6.8 |
---|---|
内存 | 1G |
CPU | 2核 |
IP地址 | 10.0.0.23 |
服务1 | Nginx |
内存 1G
CPU 2核
IP地址 10.0.0.20
服务1 Nginx
服务2 Keepalived
yum -y install haproxy keepalived
cd /etc/haproxy/
cp haproxy.cfg haproxy.cfg.bak
# 在22、23两台主机上安装nginx依赖库和环境
yum -y install gcc gcc-c++ zlib-devel pcre-devel
在20主机上操作
# 编辑keepalived服务配置文件
vim /etc/keepalived/keepalived.conf
# 启动keepalived服务
service keepalived start
# 将20主机上修改好的配置文件远程拷贝至21主机上
scp /etc/keepalived/keepalived.conf 10.0.0.21:/etc/keepalived/keepalived.conf
开始在21主机上操作
vim /etc/keepalived/keepalived.conf
service keepalived start
测试
keepalived高可用服务实现故障漂移,模拟Master20主机故障
切换到20主机上操作
# 终止keepalived服务
service keepalived stop
ip addr
再来21主机上Keepalived-Backup这边查看虚拟IP已经漂移过来了
ip addr
模拟20主机服务恢复,根据优先级自动抢占虚拟IP
# 重启keepalived服务
service keepalived restart
在20主机上操作
# 编辑haproxy服务的配置文件
vim /etc/haproxy/haproxy.cfg
# 启动haproxy服务
service haproxy start
# 将20主机上修改好的配置文件远程拷贝至21主机上
scp /etc/haproxy/haproxy.cfg 10.0.0.21:/etc/haproxy/
在21主机上操作
vim /etc/haproxy/haproxy.cfg
# 重启keepalived服务
service keepalived restart
在22主机上操作
获取nginx源码包上传至服务器
tar zxf nginx-1.12.0.tar.gz
cd nginx-1.12.0
./configure && make && make install
# 进入nginx网站根目录
cd /usr/local/nginx/html/
vim index.html
把这些内容全部删除
自己随便写点内容进去,然后保存退出
/usr/local/nginx/sbin/nginx
scp nginx-1.12.0.tar.gz 10.0.0.23:/root/
在23主机上执行同样的操作安装nginx
tar zxf nginx-1.12.0.tar.gz
cd nginx-1.12.0
./configure && make && make install
vim /usr/local/nginx/html/index.html
同样跟上面一样的操作,但是内容不能重复,因为要测试负载均衡
/usr/local/nginx/sbin/nginx
测试负载均衡的页面
推荐阅读
-
HAProxy+Keepalived
-
HAProxy+Keepalived实现Web服务器负载均衡 博客分类: 网站架构
-
HAProxy+Keepalived实现Web服务器负载均衡 博客分类: 网站架构
-
haproxy+keepalived实现高可用负载均衡(实例配置)
-
haproxy+keepalived实现高可用负载均衡(理论篇)
-
Haproxy+Keepalived高可用环境部署梳理(主主和主从模式)
-
Haproxy+Keepalived高可用双机单活
-
rabbitmq集群cluster+HA(haproxy+keepalived)热备
-
rabbitmq集群cluster+HA(haproxy+keepalived)热备
-
haproxy+keepalived实现高可用负载均衡(实例配置)