当前位置:   article > 正文

Haproxy安装和配置负载_target 'linux26' was removed from haproxy 2.0 due

target 'linux26' was removed from haproxy 2.0 due to being irrelevant and of

一、实验环境

实验用途IP地址操作系统
haproxy192.168.31.61Centos7.9
node1192.168.31.62Centos7.9
node2192.168.31.63Centos7.9

需要关闭selinux,防火墙,并清空Iptables规则。

软件名称版本
haproxy2.5

二、实验原理

HAProxy 概述:
HAProxy 提供高可用性、负载均衡以及基于 TCP 和 HTTP 应用的代理,支持虚拟主机,它是免费、快速并且可靠的一种解决方案。根据官方数据,其最高极限支持 10G 的并发。
HAProxy 特别适用于那些负载特大的 web 站点, 这些站点通常又需要会话保持或七层处理。
HAProxy 运行在当前的硬件上,完全可以支持数以万计的并发连接。并且它的运行模式使得它可以很简单安全的整合进您当前的架构中, 同时可以保护你的 web 服务器不被暴露到网络上。
其支持从 4 层至 7 层的网络交换,即覆盖所有的 TCP 协议。就是说,Haproxy 甚至还支持 Mysql的均衡负载。

  • 相同点:在功能上,proxy 通过反向代理方式实现 WEB 均衡负载。和 Nginx,ApacheProxy, lighttpd,Cheroke 等一样。
  • 不同点:Haproxy 并不是 web 服务器。以上提到所有带反向代理均衡负载的产品,都清一色是 WEB 服务器。简单说,就是他们能处理解析页面的。而 Haproxy 仅仅是一款的用于均衡负载的应用代理。其自身并不能提供 web 服务。
    但其配置简单,拥有非常不错的服务器健康检查功能还有专门的系统状态监控页面,当其代理的后端服务器出现故障, HAProxy 会自动将该服务器摘除,故障恢复后再自动将该服务器加入。

www.haproxy.org #打不开
http://haproxy.com/ #收费
http://haproxy.1wt.eu/ 社区版地址, 打不开
https://github.com/haproxy/haproxy/releases/ 在 github 可以下载

实验拓扑图:
haproxy实验拓扑

三、安装haproxy

将GitHub下载的安装包上传到要安装haproxy服务器,并解压

[root@haproxy ~]# tar xvf haproxy-2.5-dev2.tar.gz
[root@master ~]# cd haproxy-2.5-dev2
  • 1
  • 2

编译之前首先安装编译需要的组件,这里使用yum进行安装

[root@haproxy ~]#yum -y install make gcc gcc-c++ openssl-devel
  • 1

根据服务器的内核版本进行编译,最新版本参数为 ‘linux-glibc’ ,如果使用之前的
TARGET=linux2628 ,则会报以下错误。

[root@master haproxy-2.5-dev2]# make TARGET=linux2628
make: Warning: File `Makefile' has modification time 237859 s in the future

Target 'linux2628' was removed from HAProxy 2.0 due to being irrelevant and
often wrong. Please use 'linux-glibc' instead or define your custom target
by checking available options using 'make help TARGET=<your-target>'.

make: *** [all] 错误 1

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

因此,编译2.0以上的haproxy版本的时候需要使用:

[root@master haproxy-2.5-dev2]# make TARGET=linux-glibc PREFIX=/usr/local/haproxy #指定操作系统内核类型和安装的路径。也可以直接修改Makefile配置文件中这两个变量的值。如下:
[root@master haproxy-2.5-dev2]# vim Makefile
146 PREFIX = /usr/local  #修改这个将制定haproxy安装路径
157 TARGET =  #指定内核类型
#编译完成之后进行安装,指定安装目录为:/usr/local/haproxy
[root@master haproxy-2.5-dev2]# make install PREFIX=/usr/local/haproxy 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

安装完成后查看安装目录,发现没有配置文件,因此新建一个配置文件:

[root@haproxy ~]# ls /usr/local/haproxy
doc  sbin  share
[root@haproxy ~]# mkdir /usr/local/haproxy/etc
#新建haproxy配置文件
[root@haproxy ~]# vim /usr/local/haproxy/etc/haprox.cfg
global
log 127.0.0.1 local0
maxconn 4096
chroot /usr/local/haproxy
uid 99
gid 99
daemon

defaults
log global
log 127.0.0.1 local3
mode http
option httplog
option httpclose
option dontlognull
option forwardfor
option redispatch
retries 2
maxconn 2000
balance roundrobin
stats uri /haproxy-stats
timeout connect 5000
timeout client 50000
timeout server 50000
mode http
option httpchk GET /index.html
frontend http
bind 0.0.0.0:80
default_backend http_back
backend http_back
server s1 192.168.31.62:80 weight 3 check
server s2 192.168.31.63:80 weight 3 check
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

保存并退出,之后启动haproxy

[root@haproxy ~]# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/etc/haproxy.cfg
  • 1

查看启动的进程

[root@haproxy ~]# ps -ef | grep haproxy
nobody    17644      1  0 00:00 ?        00:00:01 /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/etc/haproxy.cfg
  • 1
  • 2

登录haproxy网页进行查看,地址是安装haproxy服务器的地址+/haproxy-stats,这里是http://192.168.31.61/haproxy-stats
在这里插入图片描述

由上图可以看出当前转发的后端服务器s1/s2异常,因为我们还没有在后端服务器配置服务。

四、后端服务器配置

配置web服务器:

[root@node1 ~]# yum install httpd php -y
生成测试文件:
root@node1 ~]# echo 192.168.31.62 > /var/www/html/index.html
启动apache服务器:
[root@node1 ~]# systemctl start httpd
node2同理,这里不再进行展示
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

再次查看haproxy,发现2台后端服务器已经已经正常,变成绿色。
在这里插入图片描述

五、访问测试

[root@haproxy ~]# curl 192.168.31.61
192.168.31.62
[root@haproxy ~]# curl 192.168.31.61
192.168.31.63
  • 1
  • 2
  • 3
  • 4

可以查看到haproxy将访问请求平均分配到后端的服务器。

六、停止haproxy

1.使用kill -9 <haproxy的进程号>
[root@haproxy ~]# ps -ef | grep haproxy
nobody    17644      1  0 00:00 ?        00:00:01 /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/etc/haproxy.cfg
[root@haproxy ~]# kill -9 17644     
2.使用killall进行停止,首先安装命令工具
[root@haproxy ~]# yum install -y psmisc
[root@haproxy ~]# killall haproxy
#查看进程,进程已经停止了
[root@master ~]# ps -ef | grep haproxy
root      17873  17685  0 01:02 pts/2    00:00:00 grep --color=auto haproxy  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/303102
推荐阅读
相关标签
  

闽ICP备14008679号