Kong网关的负载均衡

news2024/9/20 17:30:37

安装java环境

查询 java安装包
196  yum list java*
安装java8
  197  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 nginx
  243  nginx -v
  244  ps -ef | grep nginx
  245  cd /usr/sbin/
  246  ll
  247  ./nginx
  248  ps -ef | grep nginx
测试nginx
  249  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;


# diy
    upstream 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

# diy
    upstream 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的原因。

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

# diy
    upstream 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.html
  181  curl -X POST http://localhost:8001/services/myTomcat/routes --data name=8082Route --data 'paths[]=/tomcat82'

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1715400.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

如何在.htaccess文件创建一个自定义404页面

本周有一个客户,购买Hostease的虚拟主机,询问我们的在线客服,如何在.htaccess文件创建一个自定义404页面?我们为用户提供相关教程,用户很快解决了遇到的问题。在此,我们分享这个操作教程,希望可…

手摸手教你uniapp原生插件开发

行有余力,心无恐惧 这篇技术文章写了得有两三个礼拜,虽然最近各种事情,工作上的生活上的,但是感觉还是有很多时间被浪费.还记得几年前曾经有一段时间7点多起床运动,然后工作学习,看书提升认知.现在我都要佩服那会儿的自己.如果想回到那种状态,我觉得需要有三个重要的条件. 其…

错误记录:从把项目从Tomcat8.5.37转到Tomcat10.1.7

错误信息:在本地Servlet项目里没有报错,但是浏览器跳转该servlet时报错 型 异常报告 消息 实例化Servlet类[com.wangdao.lx.MyServlet1]异常 描述 服务器遇到一个意外的情况,阻止它完成请求。 例外情况 jakarta.servlet.ServletExceptio…

剪映网页版

https://www.capcut.cn/web 免费,免安装,跨平台,视频云合成,简直太好用了!

在Windows 10中,如何利用命令提示符删除应用程序

如果你使用的是Windows 10,并且需要释放一些磁盘空间,你可以直接从命令提示符卸载不再使用的应用程序。以下是操作方法。 首先,你必须以管理员身份运行命令提示符才能卸载程序。在“Windows搜索”框中,键入“cmd”或“命令提示符…

比较kube-proxy模式:iptables还是IPVS?

kube-proxy是任何 Kubernetes 部署中的关键组件。它的作用是将流向服务(通过集群 IP 和节点端口)的流量负载均衡到正确的后端pod。kube-proxy可以运行在三种模式之一,每种模式都使用不同的数据平面技术来实现:userspace、iptables…

非线性优化:高斯-牛顿法的原理与实现

非线性优化:高斯-牛顿法的原理与实现 引言 在实际应用中,很多问题都是非线性的。非线性优化问题广泛应用于机器学习、数据拟合、工程设计等领域。高斯-牛顿法是一种常用于解决非线性最小二乘问题的迭代算法。本文将详细介绍高斯-牛顿法的原理、推导过程…

LORA微调,让大模型更平易近人

技术背景 最近和大模型一起爆火的,还有大模型的微调方法。 这类方法只用很少的数据,就能让大模型在原本表现没那么好的下游任务中“脱颖而出”,成为这个任务的专家。 而其中最火的大模型微调方法,又要属LoRA。 增加数据量和模…

力扣:104. 二叉树的最大深度

104. 二叉树的最大深度 给定一个二叉树 root ,返回其最大深度。 二叉树的 最大深度 是指从根节点到最远叶子节点的最长路径上的节点数。 示例 1: 输入:root [3,9,20,null,null,15,7] 输出:3示例 2: 输入&#xff1a…

【STL】C++ stack(栈) 基本使用

目录 一 stack常见构造 1 空容器构造函数(默认构造函数) 2. 使用指定容器构造 3 拷贝构造函数 二 其他操作 1 empty 2 size 3 top 4 push && pop 5 emplace 6 swap 三 总结 一 stack常见构造 1 空容器构造函数(默认构造…

Vue 前端加框 给div加红色框框 js实现

实现方式&#xff1a;用getElementsByClassName、createElement、appendChild实现在原有div上添加一个新的div&#xff0c;从而达到框选效果 <template><div><el-button click"addIten">添加</el-button><el-button click"deleteIt…

ARM-V9 RME(Realm Management Extension)系统架构之系统能力的内存隔离和保护

安全之安全(security)博客目录导读 目录 一、内存隔离和保护 1、颗粒PAS过滤Granular PAS filtering 2、Cache的一致性维护 2.1 物理别名点 Point of Physical Aliasing (PoPA) 2.2 加密点 3、内存(DRAM)保护 3.1 内存加密和完整性 3.2 DRAM scrubbing 本博客探讨 RME…

PHP:IntelliJ IDEA 配置 PHP 开发环境及导入PHP项目

在创建PHP项目之前我们需要安装PHP插件&#xff0c;安装步骤如下&#xff1a;Windows&#xff1a;IntelliJ IDEA Ultimate 安装 PHP 插件-CSDN博客 1、导入已有PHP项目&#xff0c;导入之后选择&#xff0c;File > Setting 选择对应 CLL Interpreter&#xff0c;如果没有操…

基于GO 写的一款 GUI 工具,M3u8视频下载播放器-飞鸟视频助手

M3u8视频下载播放器-飞鸟视频助手 M3u8视频飞鸟视频助手使用m3u8下载m3u8 本地播放 软件下载地址m3u8嗅探 M3u8视频 M3u8视频格式是为网络视频播放设计&#xff0c;视频网站多数采用 m3u8格式。如腾讯&#xff0c;爱奇艺等网站。 m3u8和 mp4的区别&#xff1a; 一个 mp4是一个…

软件游戏缺失d3dcompiler_47.dll如何解决,简单有效的五种解决方法分享

在现代游戏中&#xff0c;我们经常会遇到一些错误提示&#xff0c;其中之一就是“缺少d3dcompiler47.dll文件”。这个问题通常会导致游戏无法正常运行或出现崩溃的情况。为了解决这个问题&#xff0c;我总结出了以下五种解决方法。希望这些方法能够帮助到遇到相同问题的玩家。 …

LangChain入门开发教程(一):Model I/O

官方文档&#xff1a;https://python.langchain.com/docs/get_started/introduction/ LangChain是一个能够利用大语言模型&#xff08;LLM&#xff0c;Large Language Model&#xff09;能力进行快速应用开发的框架&#xff1a; 高度抽象的组件&#xff0c;可以像搭积木一样&a…

AI大模型日报#0529:杨红霞创业入局“端侧模型”、Ilya左膀右臂被Claude团队挖走

导读&#xff1a;AI大模型日报&#xff0c;爬虫LLM自动生成&#xff0c;一文览尽每日AI大模型要点资讯&#xff01;目前采用“文心一言”&#xff08;ERNIE 4.0&#xff09;、“零一万物”&#xff08;Yi-34B&#xff09;生成了今日要点以及每条资讯的摘要。欢迎阅读&#xff0…

原神抽卡点名程序教程(直接下载用)

今天我要给大家分享一个在抖音上特别火的视频——原神抽卡点名程序教程。 &#xff08;要源码的私信扣31&#xff09; 废话不多说&#xff0c;直接上效果图 &#xff1a; 步骤1&#xff1a; 步骤2&#xff1a;&#xff08;写名单&#xff0c;前面加数字代表星级&#xff0c;用…

【OrangePi AIpro】开箱初体验以及OAK深度相机测试

1. 简介 Orangepi AIPRO 是一款采用昇腾AI技术路线&#xff0c;集成4核64位处理器AI处理器的单板计算机&#xff0c;集成图形处理器&#xff0c;支持8TOPS AI算力&#xff0c;拥有8GB/16GB LPDDR4X&#xff0c;可以外接eMMC模块&#xff0c;支持双4K高清输出。 Orange Pi AIpr…

网上打印资料A4纸一般多少钱一张

我们知道&#xff0c;在打印需求上A4纸&#xff08;210mmx297mm&#xff09;是较为常见的打印用纸&#xff0c;同时因为纸张的不同在价格上也存在一定的差异。当然&#xff0c;因在网上打印平台打印资料&#xff0c;能够降低一定的租金个人工成本。 因此&#xff0c;在网上打印…