云计算day25

负载均衡
nginx
lvs
haproxy
官网 https://www.haproxy.co
m/
自由及开放源代码软件
HAProxy是一个使用C语言编写的自由及开放源代码软件,其提供高可用
性、负载均衡,以及基于TCP和HTTP的应用程序代理。
HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保
持或七层处理。HAProxy运行在当前的硬件上,完全可以支持数以万计的并
发连接。并且它的运行模式使得它可以很简单安全地整合进用户当前的架构
中, 同时可以保护用户的web服务器不被暴露到网络上。
HAProxy实现了一种事件驱动 , 单一进程模型,此模型支持非常大的并发连
接数。多进程或多线程模型受内存限制 、系统调度器限制以及无处不在的
锁限制,很少能处理数千并发连接。事件驱动模型因为在有更好的资源和时
间管理的用户空间(User-Space) 实现所有这些任务,所以没有这些问题。此
模型的弊端是,在多核系统上,这些程序通常扩展性较差。这就是为什么他
们必须进行优化以 使每个CPU时间片(Cycle)做更多的工作。
包括 GitHub、Bitbucket[3]、Stack Overflow[4]、Reddit、Tumblr、
Twitter[5][6]和 Tuenti[7]在内的知名网站,及亚马逊网络服务系统都使用
了HAProxy。1.安装
2.配置
[root@haproxy ~]# yum -y install ntpdate.x86_64
[root@haproxy ~]# yum -y install ntp
[root@haproxy ~]# ntpdate cn.ntp.org.cn
13 Aug 19:39:27 ntpdate[1955]: adjust time server
120.197.116.202 offset 0.059032 sec
[root@haproxy ~]# systemctl start ntpd
[root@haproxy ~]# systemctl enable ntpd
[root@haproxy ~]# yum -y install haproxy18.x86_64
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
60 #-----------------------------------------------------

61 # main frontend which proxys to the backends
62 #-----------------------------------------------------

63 frontend main *:80
64 acl url_static path_beg -i /static
/images /javascript /stylesheets
65 acl url_static path_end -i .jpg .gif
.png .css .js
66
67 # use_backend static if url_static
68 default_backend web
......
77 #----------------------------------------------------
-----------------3.重启,设置开机启动
78 # round robin balancing between the various backends
79 #-----------------------------------------------------

80 backend web
81 balance roundrobin
82 server web01 10.1.1.200:80 check
83 server web02 10.1.1.201:80 check
84
[root@haproxy ~]# systemctl restart haproxy
[root@haproxy ~]# systemctl enable haproxy4.测试4.添加统计页面

定义web管理界面

listen statistics
bind *:9090 #定义监听端口
mode http #默认使用协议
stats enable #启用stats
stats uri /hadmin?stats #自定义统计页面的url
stats auth admin:admin #统计页面的账号密码
stats hide-version #隐藏在统计页面上的
haproxy版本信息
stats refresh 30s #统计页面自动刷新时间
stats admin if TRUE #如果认证通过就做管理
功能,可以管理后端服务器
stats realm hapadmin #统计页面密码框上提示
文件,默认为haproxy\statistics
1.503错误,503service unavaliable
2.请求服务间歇性报错,一会儿正常,一会儿不正常

  1. 两台服务有一台异常
  2. 网关没有清除
    3.9090无效,写错了
    4.haproxy无法正常启动,查看配置文件是否异常
    a
    内⽹主机 不可以被⽹络访问
    b
    外⽹主机 可以被外⽹通过ip或者域名访问
    使⽤b代理a主机,通过访问b主机管理a主机
    访问b主机的特定端⼝,管理a主机的22端⼝
    现在我们说b为服务端,提供代理服务
    a主机是客户端,被代理了
    服务端
    开启端⼝⽂件
    配置⽂件

打开控制台⾯板端⼝

[root@hcss-ecs-e083 ~]# firewall-cmd --zone=public
--add-port=7500/tcp --permanent

打开frp服务端⼝

[root@hcss-ecs-e083 ~]# firewall-cmd --zone=public
--add-port=7000/tcp --permanent

打开⼀组客户端⼝

[root@hcss-ecs-e083 ~]# firewall-cmd --zone=public
--add-port=6000-6100/tcp --permanent

加载防⽕墙更新

[root@hcss-ecs-e083 ~]# firewall-cmd --reload
[root@hcss-ecs-e083 ~]# ls -l
frp_0.33.0_linux_amd64/frps*
-rwxrwxr-x 1 yuanyu yuanyu 12976128 Apr 27 2020
frp_0.33.0_linux_amd64/frps
-rw-rw-r-- 1 yuanyu yuanyu 4639 Apr 27 2020
frp_0.33.0_linux_amd64/frps_full.ini
-rw-rw-r-- 1 yuanyu yuanyu 114 Jul 18 21:41
frp_0.33.0_linux_amd64/frps.ini配置⽂件
[root@hcss-ecs-e083 ~]# vim
~/frp_0.33.0_linux_amd64/frps.ini


服务名称

[common]

服务端⼝

bind_port = 7000

控制台⾯板账号

dashboard_user=xxxxxx

控制台密码

dashboard_pwd=xxxxxxx

控制台端⼝

dashboard_port=7500

代理标识

token=xxxxxxxx客户端
⽂件
配置⽂件
[root@hcss-ecs-e083 ~]# ls -l
frp_0.33.0_linux_amd64/frpc*
-rwxrwxr-x 1 yuanyu yuanyu 10629120 Apr 27 2020
frp_0.33.0_linux_amd64/frpc
-rw-rw-r-- 1 yuanyu yuanyu 7575 Apr 27 2020
frp_0.33.0_linux_amd64/frpc_full.ini
-rw-rw-r-- 1 yuanyu yuanyu 126 Apr 27 2020
frp_0.33.0_linux_amd64/frpc.ini

服务器名称

[common]

服务器ip

server_addr = x.x.x.x# 服务器端⼝
server_port = 7000

代理标识

token=xxxxxxx

被代理的主机名称,不允许和其他重复

[被代理主机名称xxx]

代理服务类型

type = tcp

本地ip

local_ip = 127.0.0.1

本地被代理的端⼝

local_port = 22

选择代理后的端⼝

remote_port = ⾃选端⼝xxxxxxx60000
1.修改配置文件
42 defaults
43 mode tcp
44 log global
45 option httplog
46 option dontlognull
......
63 frontend main *:3306
64 acl url_static path_beg -i /static
/images /javascript /stylesheets
65 acl url_static path_end -i .jpg .gif
.png .css .js
66
67 # use_backend static if url_static
68 default_backend mysql
....
85 backend mysql
86 balance roundrobin
87 server master 10.1.1.11:3306 check
88 server slave 10.1.1.12:3310 check
2.测试
[root@client bin]# ./mysql -h10.1.1.30 -P3306 -uzhangmin -
pzhangmin
mysql: [Warning] Using a password on the command line
interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.33 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation
and/or its
affiliates. Other names may be trademarks of their
respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the
current input statement.
mysql> show variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 10 |
+---------------+-------+
1 row in set (0.00 sec)
mysql> exit
Bye
[root@client bin]# ./mysql -h10.1.1.30 -P3306 -uzhangmin -
pzhangmin
mysql: [Warning] Using a password on the command line
interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 8.0.33 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation
and/or its
affiliates. Other names may be trademarks of their
respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the
current input statement.
mysql> show variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 11 |
+---------------+-------+
1 row in set (0.01 sec)mysql> exit
Bye
[root@client bin]# cd bin/

相关推荐
Anna_Tong1 天前
腾讯云安全加速:应对网络攻击与访问延迟的现实挑战
安全·云计算·腾讯云·企业安全·ddos·云安全·数据保护
渲染101专业云渲染1 天前
渲染101对Blender的支持与硬件配置详解
3d·云计算·blender·maya·houdini
严文文-Chris1 天前
【奥卡姆剃刀原理-如何理解云计算和边缘计算 关键字摘取】
人工智能·云计算·边缘计算
HaoHao_0102 天前
腾讯云 轻量云对象存储
云计算·腾讯云·存储·轻量云·套餐
容器魔方2 天前
「挚文集团」正式加入 Karmada 用户组!携手社区共建多集群生态
云原生·容器·云计算
小狗很可爱2 天前
云计算相关
云计算
虚魍2 天前
高版本k8s文件无法识别镜像
linux·运维·容器·kubernetes·云计算
春生黎至10053 天前
云计算及其他计算
云计算
渲染101专业云渲染3 天前
渲染 101 平台 3ds Max 建筑动画渲染全攻略:费用与时间
3d·云计算·3dsmax·blender·maya·houdini
技术程序猿华锋3 天前
Claude 3.7 Sonnet 泄露,Anthropic 最先进 AI 模型即将在 AWS Bedrock 上首次亮相
人工智能·云计算·claude·aws