Kong网关的负载均衡

安装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'

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

深度学习——卷积神经网络

卷积神经网络 1.导入需要的包2.数据导入与数据观察3.卷积层4.汇聚层最大汇聚 平均汇聚全局平均汇聚 5.搭建卷积神经网络进行手写数字识别导入并对数据进行预处理搭建卷积神经网络 6.利用函数式API与子类API搭建复杂神经网络残差层 1.导入需要的包 numpy as np: NumPy是一个用于…

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

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

Java中的ORM框架——myBatis

一、什么是ORM ORM 的全称是 Object Relational Mapping。Object代表应用程序中的对象,Relational表示的是关系型数据库,Mapping即是映射。结合起来就是在程序中的对象和关系型数据库之间建立映射关系,这样就可以用面向对象的方式&#xff0c…

写代码之前一定要提前想好思路

就和写数学题目一样,在做题目之前要先把思路确立下来。可能是我早年做数学的时候老是着急做题目没怎么分析过题目,把这个习惯不自觉地代入了代码的写入当中。习惯的养成使得我即使明白了自己的问题也依然会不断的犯错,看来只有刻意地提醒自己…

去除字符串中的空格和特殊字符

自学python如何成为大佬(目录):https://blog.csdn.net/weixin_67859959/article/details/139049996?spm1001.2014.3001.5501 用户在输入数据时,可能会无意中输入多余的空格,或在一些情况下,字符串前后不允许出现空格和特殊字符,…

[双指针] --- 快乐数 盛最多水的容器

Welcome to 9ilks Code World (๑•́ ₃ •̀๑) 个人主页: 9ilk (๑•́ ₃ •̀๑) 文章专栏: 算法Journey 本篇博客我们分享一下双指针算法中的快慢指针以及对撞双指针,下面我们开始今天的学习吧~ 🏠 快乐数 📒 题…

windows系统电脑外插键盘驱动出现感叹号或者显示未知设备,键盘无法输入的解决办法

笔记本外插的键盘不能用,鼠标可以使用。 查找故障,结果打开设备管理器看到键盘那项里是一个的黄色惊叹号显示未知设备![图片]如下图所示 其实解决办法很简单,不要相信网上的一些博主说删除什么注册表,我开始跟着他们操…

蓝桥杯-AB路线(详细原创)

问题描述: 有一个由 N M 个方格组成的迷宫,每个方格写有一个字母 A 或者 B。小蓝站在迷宫左上角的方格,目标是走到右下角的方格。他每一步可以移动到上下左右相邻的方格去。 由于特殊的原因,小蓝的路线必须先走 K 个 A 格子、再…

Slurm集群使用基础

Introduction 我们在做生物信息分析时,对于大规模的上游数据的处理,一般需要在大型服务器或集群上进行。我最早接触并使用的是一个基于SLURM调度系统的集群,在此记录一下基础使用方法。 高性能计算集群(High-Performance Comput…

vs工程添加自定义宏

一、简介 用户可以添加自定义宏变量方便工程路径名称的修改和配置 例:$(SolutionDir) 为解决方案路径,$(PojectDir) 为工程所在路径 测试环境:vs2017,qt5.14.0 二、配置 1、打开属性窗口:视图-》其他窗口-》属性管…

使用Webcam实现摄像头的开启和关闭,并保存和复制图片

实现思路 0,将webcam的jar文件传入项目中 1,显示摄像头的地方:创建一个画板,在画板上添加开启和关闭按钮 2,设置开启和关闭功能:创建一个类实现动作监听器,进而实现监听动作按钮 3&#xff…

豪赌?远见?浙江东方的量子冒险

今年4月16日,量子通信概念异动,浙江东方(600120)拉升涨停。 量子和浙江东方,要把这两个词联系起来似乎并不太容易。 浙江东方,即浙江东方金融控股集团股份有限公司,系浙江省国资委下属浙江省国…

华发股份:加强业务协同 新政下项目热销

“5.17”楼市政策出台后,各地密集落地执行。5月27—28日,上海、广州、深圳三个一线城市跟进落地“517”新政。上海发布《关于优化本市房地产市场平稳健康发展政策措施的通知》,共计9条调整政策,涵盖外地户籍、人才、单身、婚否、企…

SpringBootWeb 篇-深入了解会话技术与会话跟踪三种技术(Cookie 会话跟踪、Session 会话跟踪与 JWT 令牌会话跟踪)

🔥博客主页: 【小扳_-CSDN博客】 ❤感谢大家点赞👍收藏⭐评论✍ 文章目录 1.0 会话技术 2.0 会话跟踪 2.1 会话跟踪 - Cookie 2.1.1 客户端获取 Cookie 的流程 2.1.2 Cookie 会话跟踪的特点 2.2 会话跟踪 - Session 2.2.1 客户端获取 SESSION…

【Linux 网络编程】网络的基础知识详解!

文章目录 1. 计算机网络背景2. 认识 "协议" 1. 计算机网络背景 网络互联: 多台计算机连接在一起, 完成数据共享; 🍎局域网(LAN----Local Area Network): 计算机数量更多了, 通过交换机和路由器连接。 🍎 广域网WAN: 将…

猫狗分类识别模型建立②模型建立

一、导入依赖库 pip install opencv-python pip install numpy pip install tensorflow pip install keras 二、模型建立 pip install opencv-python pip install numpy pip install tensorflow pip install kerasimport os import xml.etree.ElementTree as ETimpor…

Python Selenium 详解:实现高效的UI自动化测试

落日余辉,深情不及久伴。大家好,在当今软件开发的世界中,自动化测试已经成为保障软件质量和快速迭代的重要环节。而在自动化测试的领域中,UI自动化测试是不可或缺的一部分,它可以帮助测试团队快速验证用户界面的正确性…

【RAG论文】文档树:如何提升长上下文、非连续文档、跨文档主题时的检索效果

RAPTOR Recursive Abstractive Processing for Tree-Organized RetrievalICLR 2024 Stanfordhttps://arxiv.org/pdf/2401.18059 RAPTOR(Recursive Abstractive Processing for Tree-Organized Retrieval)是一种创建新的检索增强型语言模型,它…

使用NuScenes数据集生成ROS Bag文件:深度学习与机器人操作的桥梁

在自动驾驶、机器人导航及环境感知的研究中,高质量的数据集是推动算法发展的关键。NuScenes数据集作为一项开源的多模态自动驾驶数据集,提供了丰富的雷达、激光雷达(LiDAR)、摄像头等多种传感器数据,是进行多传感器融合…

【PostgreSQL17新特性之-事务级别超时参数transaction_timeout】

PostgreSQL数据库里有多个和会话相关的参数,PostgreSQL17-beta1版本新增了一个transaction_timeout参数,来限制事务的持续时间。 当前的一些和会话相关的超时参数如下 -----------------------------------------------------------------------------…