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

Kong网关的负载均衡

安装java环境

查询 java安装包
196  yum list java*
安装java8197  yum install -y java-1.8.0-openjdk.x86_64
检验java8是否安装成功。198  java -version

2个tomcat准备

另外一个tomcat区别在于:配置文件。conf/server.xml

image.png

image.png

启动tomcat

[root@localhost bin]# ./startup.sh

测试tomcat

[root@localhost bin]# curl http://localhost:8081/test/index.html
tomcat-8081,81,81
[root@localhost bin]# curl http://localhost:8082/test/index.html
tomcat-8082,82,82
[root@localhost bin]#

nginx安装:

目录:/etc/yum.repos.d/241  vi nginx.repo文件内容:
[root@192 yum.repos.d]# cat nginx.repo 
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@192 yum.repos.d]#
239  cd /etc/yum.repos.d/240  ll安装nginx:242  yum install nginx243  nginx -v244  ps -ef | grep nginx245  cd /usr/sbin/246  ll247  ./nginx248  ps -ef | grep nginx
测试nginx249  curl http://localhost

nginx做负载均衡

修改/etc/nginx/nginx.conf

/test/index.html[root@192 nginx]# cat nginx.conf user  nginx;
worker_processes  auto;error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;events {worker_connections  1024;
}http {include       /etc/nginx/mime.types;default_type  application/octet-stream;log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  /var/log/nginx/access.log  main;sendfile        on;#tcp_nopush     on;keepalive_timeout  65;#gzip  on;include /etc/nginx/conf.d/*.conf;# diyupstream myServer {server localhost:8081;server localhost:8082;}server {listen 80;server_name myNginx.com;location /test/ {proxy_pass http://myServer;}}
}
[root@192 nginx]#

重新加载配置文件

启动nginx:/usr/sbin/nginx
[root@192 nginx]# /usr/sbin/nginx -s reload

域名:

myNginx.com

配置linux域名:

image.png

配置宿主机域名:

image.png

image.png

kong负载均衡

先看nginx

# diyupstream myServer {server localhost:8081;server localhost:8082;}server {listen 80;server_name myNginx.com;location /test/ {proxy_pass http://myServer;}}

kong:

upstream

查看:http://127.0.0.1:8001/upstreams。

image.png

添加:

[root@localhost etc]# curl -X POST http://localhost:8001/upstreams --data "name=myServer"{"client_certificate":null,"hash_on":"none","id":"933c3aab-85da-4dc1-a34f-2fae01b56b48","hash_on_header":null,"algorithm":"round-robin","hash_on_query_arg":null,"hash_on_uri_capture":null,"healthchecks":{"passive":{"type":"http","healthy":{"http_statuses":[200,201,202,203,204,205,206,207,208,226,300,301,302,303,304,305,306,307,308],"successes":0},"unhealthy":{"tcp_failures":0,"timeouts":0,"http_failures":0,"http_statuses":[429,500,503]}},"active":{"headers":null,"http_path":"/","https_sni":null,"https_verify_certificate":true,"concurrency":10,"unhealthy":{"tcp_failures":0,"timeouts":0,"http_failures":0,"http_statuses":[429,404,500,501,502,503,504,505],"interval":0},"timeout":1,"type":"http","healthy":{"successes":0,"http_statuses":[200,302],"interval":0}},"threshold":0},"hash_on_cookie":null,"hash_on_cookie_path":"/","hash_fallback":"none","hash_fallback_header":null,"hash_fallback_query_arg":null,"hash_fallback_uri_capture":null,"host_header":null,"tags":null,"created_at":1669830017,"name":"myServer","slots":10000}[root@localhost etc]#

再检查一下,做确认。

Target

查询:http://127.0.0.1:8001/upstreams/myServer/targets

image.png

添加:

[root@localhost etc]# curl -X POST http://localhost:8001/upstreams/myServer/targets --data "target=10.0.2.4:8081"{"upstream":{"id":"933c3aab-85da-4dc1-a34f-2fae01b56b48"},"tags":null,"id":"499d1373-45fc-44b5-b952-1e590f3be680","weight":100,"created_at":1669830273.544,"target":"10.0.2.4:8081"}[root@localhost etc]# curl -X POST http://localhost:8001/upstreams/myServer/targets --data "target=10.0.2.4:8082"
{"upstream":{"id":"933c3aab-85da-4dc1-a34f-2fae01b56b48"},"tags":null,"id":"093cc5cf-ac84-4bb9-b0c7-0289fec7da6a","weight":100,"created_at":1669830307.884,"target":"10.0.2.4:8082"}[root@localhost etc]#

添加完,查看一下。

Service

查看service:http://127.0.0.1:8001/services

image.png

添加:

[root@localhost etc]# curl -X POST http://localhost:8001/services --data "name=myService" --data "host=myServer"{"client_certificate":null,"tls_verify_depth":null,"id":"a5997d4d-c868-43fe-8a73-9db62c5410f8","created_at":1669830610,"updated_at":1669830610,"read_timeout":60000,"protocol":"http","host":"myServer","name":"myService","enabled":true,"retries":5,"port":80,"write_timeout":60000,"tags":null,"ca_certificates":null,"connect_timeout":60000,"tls_verify":null,"path":null}[root@localhost etc]#

查看:http://127.0.0.1:8001/services

Route

查看route:http://127.0.0.1:8001/services/myService/routes

添加:

[root@localhost etc]# curl -X POST http://localhost:8001/services/myService/routes --data "name=myRoute" --data "paths[]=/test"{"paths":["/test"],"methods":null,"sources":null,"destinations":null,"id":"231fc5ba-a1f1-4d6f-9fcb-eac4e897923d","created_at":1669830883,"updated_at":1669830883,"service":{"id":"a5997d4d-c868-43fe-8a73-9db62c5410f8"},"https_redirect_status_code":426,"regex_priority":0,"protocols":["http","https"],"path_handling":"v0","name":"myRoute","strip_path":true,"snis":null,"hosts":null,"tags":null,"headers":null,"request_buffering":true,"response_buffering":true,"preserve_host":false}[root@localhost etc]#

测试负载均衡:

[root@localhost etc]# curl http://localhost:8000/test/test/index.html
tomcat-8082,82,82
[root@localhost etc]# curl http://localhost:8000/test/test/index.html
tomcat-8081,81,81
[root@localhost etc]# curl http://localhost:8000/test/test/index.html
tomcat-8082,82,82
[root@localhost etc]# curl http://localhost:8000/test/test/index.html
tomcat-8081,81,81
[root@localhost etc]# curl http://localhost:8000/test/test/index.html
tomcat-8082,82,82
[root@localhost etc]# curl http://localhost:8000/test/test/index.html
tomcat-8081,81,81
[root@localhost etc]#

成功。

请求需要两个test的原因。

加了/。 相当于匹配到目标地址的 根路径。

# diyupstream myServer {server localhost:8081;server localhost:8082;}server {listen 80;server_name myNginx.com;location /test/ {proxy_pass http://myServer/;}}

总结:

upstream: 对应一组 target节点,实现负载均衡。(还可以指定权重)

target: 对应的具体的服务url。controller。

route: 负责将请求,匹配,映射到 upstream。

service: 将服务节点,指定到一个upstream(具体的服务)。

upstream

----target

service

----route


操作方面:

添加 POST, 修改:PATCH, 删除:DELETE, 查:GET

service:url

创建:175  curl -X POST http://localhost:8001/services --data name=myTomcat --data url=http://10.0.2.4:8081/test/index.html
查看176  curl -X GET http://localhost:8001/services
删除177  curl -X DELETE http://localhost:8001/services/myTomcat
查看178  curl -X GET http://localhost:8001/services更新:180  curl -X PATCH http://localhost:8001/services/myTomcat --data url=http://10.0.2.4:8082/test/index.html181  curl -X POST http://localhost:8001/services/myTomcat/routes --data name=8082Route --data 'paths[]=/tomcat82'

相关文章:

Kong网关的负载均衡

安装java环境 查询 java安装包 196 yum list java* 安装java8197 yum install -y java-1.8.0-openjdk.x86_64 检验java8是否安装成功。198 java -version2个tomcat准备 另外一个tomcat区别在于:配置文件。conf/server.xml 启动tomcat [rootlocalhost bin]# ./…...

这是一个逗号

还不太能是句号,随想录这两个月算是给我一个学算法的开头,感慨还是挺多的,但是语文功底很差,就接着写流水账吧。 高考前想报计算机,但是那年是先报志愿后考试,家里人劝我选择更稳一点的985,又说…...

oracle tree

select * from "Test"; INSERT INTO "Test" ("id", "name", "pid") VALUES (01, 中国, 00); INSERT INTO "Test" ("id", "name", "pid") VALUES (01.01, 福建, 01); INSERT INTO…...

react-beautiful-dnd 横纵排序demo

简单导入就可以看到效果 1. 安装依赖 npm i react-beautiful-dnd 2. 纵向排序 import React, { useState } from react; import { DragDropContext, Droppable, Draggable } from react-beautiful-dnd;// 纵向排序 const reorder (list, startIndex, endIndex) > {con…...

web练习

[CISCN 2022 初赛]ezpop ThinkPHP V6.0.12LTS 反序列化漏洞 漏洞分析 ThinkPHP6.0.12LTS反序列漏洞分析 - FreeBuf网络安全行业门户 解题过程 ThinkPHP V6.0.12LTS反序列化的链子可以找到,找到反序列化的入口就行 反序列化的入口在index.php/index/test 链子 …...

模型蒸馏笔记

文章目录 一、什么是模型蒸馏二、如何蒸馏三、常见问题3.1 四、参考文献 一、什么是模型蒸馏 Hinton在NIPS2014提出了知识蒸馏(Knowledge Distillation)的概念,旨在把一个大模型或者多个模型ensemble学到的知识迁移到另一个轻量级单模型上&a…...

HAL库使用FreeRTOS实时操作系统时配置时基源(TimeBase Source)

需要另外的定时器,用systic的时候生成项目会有警告 https://blog.51cto.com/u_16213579/10967728...

如何让你的网站能通过域名访问

背景 当我们租一台云服务器,并在上面运行了一个Web服务,我们可以使用云服务器的公网IP地址进行访问,如下: 本文主要记录如何 实现让自己的网站可以通过域名访问。 买域名 可以登录腾讯云等主流公有云平台的,购买域名…...

Spring Boot + Spring Security + JWT 从零开始

Spring Boot + Spring Security + JWT 从零开始 这篇笔记中,我们将学习如何从头开始设置一个带有Spring Security的Spring Boot应用程序,它连接到一个LDAP身份验证的Spring Security身份验证提供程序,这将是即将出现的,这个连接和工作都是开箱即用的。 实际上,设置这个非…...

【busybox记录】【shell指令】rmdir

目录 内容来源: 【GUN】【rmdir】指令介绍 【busybox】【rmdir】指令介绍 【linux】【rmdir】指令介绍 使用示例: 删除空目录 - 默认 删除dirname下的所有空目录,包括因删除其他目录而变为空的目录 常用组合指令: 指令不…...

[LitCTF 2023]yafu (中级) (素数分解)

题目: from Crypto.Util.number import * from secret import flagm bytes_to_long(flag) n 1 for i in range(15):n *getPrime(32) e 65537 c pow(m,e,n) print(fn {n}) print(fc {c})n 152412082177688498871800101395902107678314310182046454156816957…...

MySQL alter 语句

ALTER TABLE user ADD COLUMN cdkey varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT CD-Key, ADD COLUMN erp_userid varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT ERP用户ID, ADD UNIQUE INDEX un…...

列表推导式(解析式)python

Python中的列表推导式(list comprehension)是一种简洁且强大的语法,用于创建新的列表。它允许你通过对现有列表中的元素进行操作或筛选来快速生成新列表。以下是列表推导式的基本语法和一些示例: 基本语法: new_list…...

YOLO-10更快、更强

YOLO-10简介 主要贡献: 无NMS的一致双分配 YOLOv10提出了一种通过双标签分配而不用非极大值抑制NMS的策略。这种方法结合了一对多和一对一分配策略的优势,提高了效率并保持了性能。 高效的网络设计 轻量化分类头:在不显著影响性能的情况下&a…...

新火种AI|寻求合作伙伴,展开豪赌,推出神秘AI项目...苹果能否突破AI困境?

作者:小岩 编辑:彩云 2024年,伴随着AI技术的多次爆火,不仅各大科技巨头纷纷进入AI赛道展开角力,诸多智能手机厂商也纷纷加紧布局相关技术,推出众多AI手机。作为手机领域的龙头老大,苹果自然是…...

MFC工控项目实例一主菜单制作

1、本项目用在WIN10下安装的vc6.0兼容版实现。创建项目名为SEAL_PRESSURE的MFC对话框。在项目res文件下添加相关256色ico格式图片。 2、项目名称:密封压力试验机 主菜单名称: 系统参数 SYS_DATA 系统测试 SYS_TEST 选择型号 TYP_CHOICE 开始试验 TES_STA…...

代码随想录-Day22

235. 二叉搜索树的最近公共祖先 方法一&#xff1a;两次遍历 class Solution {public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {List<TreeNode> path_p getPath(root, p);List<TreeNode> path_q getPath(root, q);TreeNode anc…...

uniapp项目 使用vue-plugin-hiprint静默打印功能

插件地址&#xff1a;https://toscode.mulanos.cn/gyy155/vue-plugin-hiprint h5项目使用插件的静默打印功能 1.下载vue-plugin-hiprint和jquery npm install vue-plugin-hiprint npm install jquery --save2.在mian.js引入插件和jqerry //引入vue-plugin-hiprint import { h…...

视频汇聚EasyCVR视频监控平台GA/T 1400协议特点及应用领域解析

GA/T 1400协议&#xff0c;也被称为视图库标准&#xff0c;全称为《公安视频图像信息应用系统》。这一标准在公安系统中具有举足轻重的地位&#xff0c;它详细规定了公安视频图像信息应用系统的设计原则、系统结构、视频图像信息对象、统一标识编码、系统功能、系统性能、接口协…...

基于似然场的快速避障算法

系列文章目录 提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加 TODO:写完再整理 文章目录 系列文章目录前言相同思想的采样概率评估快速避障算法前言 认知有限,望大家多多包涵,有什么问题也希望能够与大家多交流,共同成长! 本文先对基于似然场的快速…...

应用升级/灾备测试时使用guarantee 闪回点迅速回退

1.场景 应用要升级,当升级失败时,数据库回退到升级前. 要测试系统,测试完成后,数据库要回退到测试前。 相对于RMAN恢复需要很长时间&#xff0c; 数据库闪回只需要几分钟。 2.技术实现 数据库设置 2个db_recovery参数 创建guarantee闪回点&#xff0c;不需要开启数据库闪回。…...

日语学习-日语知识点小记-构建基础-JLPT-N4阶段(33):にする

日语学习-日语知识点小记-构建基础-JLPT-N4阶段(33):にする 1、前言(1)情况说明(2)工程师的信仰2、知识点(1) にする1,接续:名词+にする2,接续:疑问词+にする3,(A)は(B)にする。(2)復習:(1)复习句子(2)ために & ように(3)そう(4)にする3、…...

CMake基础:构建流程详解

目录 1.CMake构建过程的基本流程 2.CMake构建的具体步骤 2.1.创建构建目录 2.2.使用 CMake 生成构建文件 2.3.编译和构建 2.4.清理构建文件 2.5.重新配置和构建 3.跨平台构建示例 4.工具链与交叉编译 5.CMake构建后的项目结构解析 5.1.CMake构建后的目录结构 5.2.构…...

大数据零基础学习day1之环境准备和大数据初步理解

学习大数据会使用到多台Linux服务器。 一、环境准备 1、VMware 基于VMware构建Linux虚拟机 是大数据从业者或者IT从业者的必备技能之一也是成本低廉的方案 所以VMware虚拟机方案是必须要学习的。 &#xff08;1&#xff09;设置网关 打开VMware虚拟机&#xff0c;点击编辑…...

【JavaWeb】Docker项目部署

引言 之前学习了Linux操作系统的常见命令&#xff0c;在Linux上安装软件&#xff0c;以及如何在Linux上部署一个单体项目&#xff0c;大多数同学都会有相同的感受&#xff0c;那就是麻烦。 核心体现在三点&#xff1a; 命令太多了&#xff0c;记不住 软件安装包名字复杂&…...

稳定币的深度剖析与展望

一、引言 在当今数字化浪潮席卷全球的时代&#xff0c;加密货币作为一种新兴的金融现象&#xff0c;正以前所未有的速度改变着我们对传统货币和金融体系的认知。然而&#xff0c;加密货币市场的高度波动性却成为了其广泛应用和普及的一大障碍。在这样的背景下&#xff0c;稳定…...

云原生玩法三问:构建自定义开发环境

云原生玩法三问&#xff1a;构建自定义开发环境 引言 临时运维一个古董项目&#xff0c;无文档&#xff0c;无环境&#xff0c;无交接人&#xff0c;俗称三无。 运行设备的环境老&#xff0c;本地环境版本高&#xff0c;ssh不过去。正好最近对 腾讯出品的云原生 cnb 感兴趣&…...

浪潮交换机配置track检测实现高速公路收费网络主备切换NQA

浪潮交换机track配置 项目背景高速网络拓扑网络情况分析通信线路收费网络路由 收费汇聚交换机相应配置收费汇聚track配置 项目背景 在实施省内一条高速公路时遇到的需求&#xff0c;本次涉及的主要是收费汇聚交换机的配置&#xff0c;浪潮网络设备在高速项目很少&#xff0c;通…...

招商蛇口 | 执笔CID,启幕低密生活新境

作为中国城市生长的力量&#xff0c;招商蛇口以“美好生活承载者”为使命&#xff0c;深耕全球111座城市&#xff0c;以央企担当匠造时代理想人居。从深圳湾的开拓基因到西安高新CID的战略落子&#xff0c;招商蛇口始终与城市发展同频共振&#xff0c;以建筑诠释对土地与生活的…...

LCTF液晶可调谐滤波器在多光谱相机捕捉无人机目标检测中的作用

中达瑞和自2005年成立以来&#xff0c;一直在光谱成像领域深度钻研和发展&#xff0c;始终致力于研发高性能、高可靠性的光谱成像相机&#xff0c;为科研院校提供更优的产品和服务。在《低空背景下无人机目标的光谱特征研究及目标检测应用》这篇论文中提到中达瑞和 LCTF 作为多…...