设为首页 加入收藏

TOP

keepalived实现haporxy负载均衡机高可用(一)
2023-07-23 13:35:16 】 浏览:80
Tags:keepalived 实现 haporxy 衡机高

keepalived实现haporxy负载均衡机高可用

环境说明

系统信息 主机名 IP 服务
centos8 master 192.168.111.141 haproxy
keepalived
centos8 backup 192.168.111.142 haproxy
keepalived
centos8 RS1 192.168.111.143 httpd
centos8 RS2 192.168.111.144 nginx

1.首先部署好web界面

RS1配置

//修改名字
[root@localhost ~]# hostnamectl set-hostname RS1
[root@localhost ~]# bash
[root@RS1 ~]# 

//关闭防火墙和selinux
[root@RS1 ~]# setenforce 0
[root@RS1 ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@RS1 ~]# systemctl disable --now firewalld
[root@RS1 ~]# reboot

//配置yum源
[root@RS1 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@RS1 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

//安装httpd服务,主页内容为web1
[root@RS1 ~]# dnf -y install httpd
[root@RS1 ~]# echo "web1" > /var/www/html/index.html
[root@RS1 ~]# systemctl enable --now httpd.service 
[root@RS1 ~]# ss -anlt
State   Recv-Q  Send-Q   Local Address:Port   Peer Address:Port  Process  
LISTEN  0       128            0.0.0.0:22          0.0.0.0:*                        
LISTEN  0       128                  *:80                *:*              
LISTEN  0       128               [::]:22             [::]:*                     
[root@RS1 ~]# curl 192.168.111.143
web1

RS2配置

//修改名字
[root@RS1 ~]# hostnamectl set-hostname RS2
[root@RS1 ~]# bash
[root@RS2 ~]# 

//关闭防火墙和selinux
[root@RS2 ~]# setenforce 0
[root@RS2 ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@RS2 ~]# systemctl disable --now firewalld
[root@RS2 ~]# reboot

//配置yum源
[root@RS2 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@RS2 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
 
 //安装nginx服务,主页内容为web2
[root@RS2 ~]# dnf -y install nginx
[root@RS2 ~]# echo "web2" > /usr/share/nginx/html/index.html 
[root@RS2 ~]# systemctl enable --now nginx.service 
[root@RS2 ~]# ss -anlt
State   Recv-Q  Send-Q   Local Address:Port   Peer Address:Port  Process  
LISTEN  0       128            0.0.0.0:80          0.0.0.0:*              
LISTEN  0       128            0.0.0.0:22          0.0.0.0:*              
LISTEN  0       128               [::]:80             [::]:*              
LISTEN  0       128               [::]:22             [::]:* 
[root@RS2 ~]# curl 192.168.111.144
web2

2.在部署haproxy负载均衡

master端

//修改名字
[root@localhost ~]# hostnamectl set-hostname master
[root@localhost ~]# bash
[root@master ~]# 

//关闭防火墙和selinux
[root@master ~]# setenforce 0
[root@master ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@master ~]# systemctl disable --now firewalld
[root@master ~]# reboot

//配置yum源
[root@master ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@master ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

//创建用户
[root@master ~]# useradd -rMs /sbin/nologin haproxy

//安装依赖包
[root@master ~]# dnf -y install make gcc pcre-devel bzip2-devel openssl-devel systemd-devel wget vim

//下载haproxy压缩包
[root@master ~]# wget https://src.fedoraproject.org/repo/pkgs/haproxy/haproxy-2.6.0.tar.gz/sha512/7bb70bfb5606bbdac61d712bc510c5e8d5a5126ed8827d699b14a2f4562b3bd57f8f21344d955041cee0812c661350cca8082078afe2
首页 上一页 1 2 3 4 5 6 下一页 尾页 1/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Installation Nginx-1.22.0 on Ce.. 下一篇Installation FastDFS-6.08 on Ce..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目