当前位置: 首页 > 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:写完再整理 文章目录 系列文章目录前言相同思想的采样概率评估快速避障算法前言 认知有限,望大家多多包涵,有什么问题也希望能够与大家多交流,共同成长! 本文先对基于似然场的快速…...

Flutter 中的 IndexedStack 小部件:全面指南

Flutter 中的 IndexedStack 小部件&#xff1a;全面指南 Flutter 是一个功能强大的 UI 框架&#xff0c;它提供了多种方式来构建动态和响应式的用户界面。IndexedStack 是 Flutter 中的一个有趣的小部件&#xff0c;它允许开发者根据索引值来显示一组子元素中的一个。这使得 I…...

基于51单片机的交通灯设计

一.硬件方案 本设计能模拟基本的交通控制系统&#xff0c;用红绿黄灯表示禁行&#xff0c;通行和等待的信号发生&#xff0c;还能进行倒计时显示。按键可以控制禁行、深夜模式、复位、东西通行、南北通行、时间加、时间减、切换等功能。共四个二位阴极数码管&#xff0c;东南西…...

ECMAScript 详解

ECMAScript 详解 ECMAScript&#xff08;ES&#xff09;是JavaScript的标准化脚本语言&#xff0c;由ECMA国际通过ECMA-262标准进行规范。ECMAScript定义了语法、类型、对象模型和内置对象等基本特性&#xff0c;是JavaScript、JScript和ActionScript等语言的核心部分。 以下…...

使用Java Swing制作一个飞翔的小鸟游戏

文章目录 一、需求分析二、技术介绍2.1相关技术2.2开发环境 三、功能实现1、开始2、运动3、死亡 四、部分代码实现获取源码 文章最下方获取源码&#xff01;&#xff01;&#xff01; 文章最下方获取源码&#xff01;&#xff01;&#xff01; 文章最下方获取源码&#xff01;&…...

leetcode 684.冗余连接

思路&#xff1a;并查集 这里的图比较像一种特殊的数据结构&#xff0c;其实也是图论的一种东西&#xff0c;就是基环树&#xff0c;但是这里并不是有向图&#xff0c;而是无向图&#xff0c;所以并不能用那种剪枝操作然后找基环。 看到连通量&#xff0c;我们应该能想到两种…...

RestTemplet 自定义消息转换器总结

在RestTemplet 请求中&#xff0c;请求发送一个 HTTP 请求时&#xff0c;RestTemplet 会根据请求中的内容类型&#xff08;Content-Type&#xff09;选择合适的 HttpMessageConverter 来处理请求体的数据。同样地&#xff0c;当服务器返回一个 HTTP 响应时&#xff0c;RestTemp…...

贝叶斯算法:机器学习中的“黄金法则”与性能提升之道

&#x1f440;传送门&#x1f440; &#x1f50d;机器学习概述&#x1f340;贝叶斯算法原理&#x1f680;贝叶斯算法的应用✨文本分类✨医疗系统 &#x1f496;贝叶斯算法优化✨贝叶斯算法优化的主要步骤✨贝叶斯算法优化的优点✨贝叶斯算法优化的局限性 &#x1f697;贝叶斯算…...

element-ui 实现输入框下拉树组件(2024-05-23)

用element-ui的 el-input&#xff0c;el-tree&#xff0c;el-popover组件组合封装 import url("//unpkg.com/element-ui2.15.14/lib/theme-chalk/index.css"); <script src"//unpkg.com/vue2/dist/vue.js"></script> <script src"//…...

Nginx 相关使用

一、 Nginx 相关使用。 相关命令 启动 nginx start nginx立即停止 nginx nginx -s stop平缓停止 nginx&#xff08;已有请求不会意外停止&#xff09; nginx -s quit重新加载配置文件 nginx -s reload二、Nginx conf 配置文件详解 参考文章皮卡丘的猫 server 配置项 server 可…...

基于Python实现 HR 分析(逻辑回归和基于树的机器学习)【500010104】

介绍 数据集说明 此数据集包含与员工有关的综合属性集合&#xff0c;从人口统计细节到与工作相关的因素。该分析的主要目的是预测员工流动率并辨别导致员工流失的潜在因素。 在这个数据集中&#xff0c;有14,999行&#xff0c;10列&#xff0c;以及这些变量&#xff1a;满意度…...