当前位置: 首页 > news >正文

自定义HAProxy 错误界面

对指定的报错进行重定向,进行优雅的显示错误页面
使用errorfileerrorloc指令的两种方法,可以实现自定义各种错误页面
#haproxy默认使用的错误错误页面
[root@haproxy ~]# rpm -ql haproxy24z-2.4.27-1.el7.zenetys.x86_64 | grep -E http$
/usr/share/haproxy/400.http
/usr/share/haproxy/403.http
/usr/share/haproxy/408.http
/usr/share/haproxy/500.http
/usr/share/haproxy/502.http
/usr/share/haproxy/503.http
/usr/share/haproxy/504.http
基于自定义的错误页面文件
#自定义错误页
errorfile <code> <file>
<code> #HTTP status code.支持200, 400, 403, 405, 408, 425, 429, 500, 502,503,504
<file> #包含完整HTTP响应头的错误页文件的绝对路径。 建议后缀".http",以和一般的html文件相区分
#示例:
errorfile 503 /haproxy/errorpages/503page.http

[root@haproxy ~]# cat /haproxy/errorpages/503page.http
HTTP/1.0 503 Service Unavailable
Cache-Control: no-cache
Connection: close
Content-Type: text/html;charset=UTF-8<html><body><h1>什么动物生气最安静</h1>
大猩猩!!
</body></html>[root@haproxy ~]#

测试:

 基于http重定向错误页面
#错误页面重定向
errorloc <code> <url>
#相当于errorloc302 <code> <url>,利用302重定向至指URL
#示例:
errorloc 503 https://www.baidu.com

 #浏览器访问192.168.217.100 自动跳转到百度

HAProxy 四层负载

针对除HTTP以外的TCP协议应用服务访问的应用场景

MySQL
Redis
Memcache
RabbitMQ

四层负载示例

注意:如果使用frontendbackend,一定在 frontend backend 段中都指定mode tcp

listen mysql-port
bind 10.0.0.7:6379
mode tcp
balance leastconn
server server1 192.168.217.10:3306 check
server server2 192.168.217.20:3306 check backup

例:对MYSQL服务实现四层负载

#---------------------------------------------------------------------
listen webservermode        httpbind        *:80balance     roundrobinserver web1 192.168.217.10:80 check inter 3s fall 5 rise 3server web2 192.168.217.20:80 check inter 3s fall 5 rise 3
listen mysql_protmode        tcpbind        *:3306balance     roundrobinserver mysql1 192.168.217.10:3306 check inter 3s fall 5 rise 3server mysql2 192.168.217.20:3306 check##---------------------------------------------------------------------

在RS1和RS2上安装mariadb服务

[root@RS1 ~]# yum install mariadb-server -y
[root@RS2 ~]# yum install mariadb-server -y[root@RS1 ~]# vim /etc/my.cnf.d/mariadb-server.cnf[root@RS2 ~]# vim /etc/my.cnf.d/mariadb-server.cnf

然后启动mariadb服务

授权所有功能

rs1 ~]# mysql -e "grant all on *.* to lee@'%' identified by 'lee';"
rs2 ~]# mysql -e "grant all on *.* to lee@'%' identified by 'lee';"

在client上测试

 

证书生成

openssl req  -newkey rsa:2048 -nodes  -sha256 -keyout /etc/haproxy/certs/timinglee.org.key -x509 -days 365 -out /etc/haproxy/certs/timinglee.org.crt
[root@haproxy ~]# cd /etc/haproxy/certs/、
[root@haproxy certs]# cat timinglee.org.key timinglee.org.crt >timinglee.pem

使用浏览器访问就可以看到生成的证书

http://www.lryc.cn/news/596454.html

相关文章:

  • 开发板系统烧写
  • 【数学建模|Matlab】Matlab「基础知识」和「基础操作」
  • Vue3 面试题及详细答案120道(31-45 )
  • Arraylist与LinkedList区别
  • MATLAB软件使用频繁,企业如何做到“少买多用”?
  • 论文略读:Towards Safer Large Language Models through Machine Unlearning
  • Go 的第一类对象与闭包
  • (二)Python基础入门-基础语法核心
  • 【Python】常见模块及其用法
  • 解决栅格数据裁剪矢量数据问题两种方法,ArcGIS解决与PYTHON解决
  • Leetcode力扣解题记录--第41题(原地哈希)
  • 力扣-300.最长递增子序列
  • LeetCode 633.平方数之和
  • Uni-App:跨平台开发的终极解决方案
  • uniapp app打包流程
  • 《Uniapp-Vue 3-TS 实战开发》自定义预约时间段组件
  • Java (Spring AI) 实现MCP server实现数据库的智能问答
  • MS523NA非接触式读卡器 IC
  • 【金融机器学习】第四章:风险-收益权衡——Bryan Kelly, 修大成(中文翻译)
  • 【方案】网页由微应用拼图,微前端
  • Node.js:RESPful API、多进程
  • 【STM32】CRC 校验函数
  • linux初识网络及UDP简单程序
  • 二、计算机网络技术——第3章:数据链路层
  • 基于卷积神经网络与小波变换的医学图像超分辨率算法复现
  • DeepSPV:一种从2D超声图像中估算3D脾脏体积的深度学习流程|文献速递-医学影像算法文献分享
  • zmaiFy来说软字幕和硬字幕有什么优缺点?
  • qtbase5-dev库使用介绍
  • 生成式人工智能对网络安全的影响
  • OpenCV快速入门之CV宝典