HAProxy——监控管理HAProxy服务器的负载均衡、 添加日志、动静分离、页面重定向、读写分离

一、HAProxy(单核)是什么?

HAProxy是一款提供高可用性、负载均衡以及基于 TCP(第四层) 和 HTTP(第七层) 应用的代理软件, 支持虚拟主机,它是免费、快速并且可靠的一种解决方案。HAProxy 特别适用于那些负载特大的 web 站点, 这些站点通常又需要会话保持或七层处理。HAProxy 运行在当前的硬件上,完全可以支持数以万计的并发连接。并且它的运行模式使得它可以很简单安全的整合进您当前的架构中, 同时可以保护你的 web 服务器不被暴露到网络上。

二、监控管理haproxy服务器的负载均衡

实验环境

主机名 IP 服务
虚拟机server1 172.25.7.1 haproxy,httpd,代理服务器
虚拟机server2 172.25.7.2 httpd,php,后端服务器
虚拟机server3 172.25.7.3 httpd,php,后端服务器
物理机 172.25.7.250 测试端

搭建一个基本的haproxy服务器

1、在 server1 上面搭建HAProxy服务器,安装haproxy服务 yum install haproxy -y
在这里插入图片描述
查看该服务的版本
在这里插入图片描述
2、更改配置文件:vim /etc/haproxy/haproxy.cfg

 listen admin *:8080
       stats enable
       stats uri /status  		# 监控页面地址
       stats auth admin:westos  # 管理帐号和密码
       stats refresh 5s  		#刷新频率


listen  ranran *:80      		#监听的实例名称,地址和端口 
        balance roundrobin      #负载均衡算法
        server web1 172.25.7.2:80 check
        server web2 172.25.7.3:80 check

在这里插入图片描述

3、在server1上开启haproxy服务

在这里插入图片描述
在这里插入图片描述
4、在 server2和server3 上,安装httpd服务且配置web资源。

 1)yum install httpd -y
 2)vim /var/www/html--》server2/server3
 3)systemctl start httpd  

在这里插入图片描述

在这里插入图片描述

5、在物理机测试:curl 172.25.7.1,实现了负载均衡

一个典型的Haproxy_exporter的监控metric例子 包含指标 haproxy_backend_bytes_in_total haproxy_backend_bytes_out_total haproxy_backend_client_aborts_total haproxy_backend_compressor_bytes_bypassed_total haproxy_backend_compressor_bytes_in_total haproxy_backend_compressor_bytes_out_total haproxy_backend_connection_errors_total haproxy_backend_current_queue haproxy_backend_current_server haproxy_backend_current_session_rate haproxy_backend_current_sessions haproxy_backend_http_connect_time_average_seconds haproxy_backend_http_queue_time_average_seconds haproxy_backend_http_response_time_average_seconds haproxy_backend_http_responses_compressed_total haproxy_backend_http_responses_total haproxy_backend_http_total_time_average_seconds haproxy_backend_response_errors_total haproxy_backend_retry_warnings_total haproxy_backend_server_aborts_total haproxy_backend_server_selected_total haproxy_backend_sessions_total haproxy_backend_up haproxy_backend_weight haproxy_exporter_build_info haproxy_exporter_csv_parse_failures haproxy_exporter_total_scrapes haproxy_frontend_bytes_in_total haproxy_frontend_bytes_out_total haproxy_frontend_compressor_bytes_bypassed_total haproxy_frontend_compressor_bytes_in_total haproxy_frontend_compressor_bytes_out_total haproxy_frontend_connections_total haproxy_frontend_current_session_rate haproxy_frontend_current_sessions haproxy_frontend_http_requests_total haproxy_frontend_http_responses_compressed_total haproxy_frontend_http_responses_total haproxy_frontend_limit_session_rate haproxy_frontend_limit_sessions haproxy_frontend_max_session_rate haproxy_frontend_max_sessions haproxy_frontend_request_errors_total haproxy_frontend_requests_denied_total haproxy_frontend_sessions_total haproxy_server_bytes_in_total haproxy_server_bytes_out_total haproxy_server_check_duration_seconds haproxy_server_check_failures_total haproxy_server_client_aborts_total haproxy_server_connection_errors_total haproxy_server_current_queue haproxy_server_current_session_rate haproxy_server_current_sessions haproxy_server_downtime_seconds_total haproxy_server_http_responses_total haproxy_server_max_queue haproxy_server_max_session_rate haproxy_server_max_sessions haproxy_server_redispatch_warnings_total haproxy_server_response_errors_total haproxy_server_retry_warnings_total haproxy_server_server_aborts_total haproxy_server_server_selected_total haproxy_server_sessions_total haproxy_server_up haproxy_server_weight haproxy_up process_cpu_seconds_total process_max_fds process_open_fds process_resident_memory_bytes process_start_time_seconds process_virtual_memory_bytes promhttp_metric_handler_requests_in_flight promhttp_metric_handler_requests_total
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值