.OpenNJet应用引擎实践——从 0-1 体验感受

目录

  • 一. 🦁 写在前面
  • 二. 🦁 安装使用
    • 2.1 安装环境
    • 2.2 配置yum源
    • 2.3 安装软件包
    • 2.4 编译代码
    • 2.5 启动
  • 三. 🦁 使用效果
    • 3.1 编辑配置文件
    • 3.2 编辑 HTML 代码
  • 四. 🦁 使用感受

权限管理

一. 🦁 写在前面

现在互联网体系越来越往云原生方向进发,云原生组件的地位也逐渐水涨船高,比如阿里研发的Higress 网关,无感聚合项目端口,统一分发到各个子服务,很好地替代了SpringCloud Gateway
今天狮子又来给大家介绍一款应用引擎层面的云原生神器——OpenNJet,它是面向互联网和云原生应用提供的运行时组态服务程序。具备环境感知、安全控制、加速优化等能力,一般呈现为Web服务、流媒体服务、代理(Proxy)、应用中间件、API网关、消息队列等产品形态。

应用引擎在云原生架构中,除了提供南北向通信网关的功能以外,因为提供了服务网格中东西向通信、透明流量劫持、熔断、遥测与故障注入等新功能特性,其地位和作用在云原生架构中变得愈发重要。

体验官网链接:https://njet.org.cn/

在这里插入图片描述

现在狮子来给读者详细介绍一下体验过程:

二. 🦁 安装使用

OpenNJet应用引擎是基于 C/C++ 语言编写,需要先编译再运行。

2.1 安装环境

我这里使用的是腾讯云服务器 Centos7.9,所以使用Centos的安装方法。

2.2 配置yum源

sudo yum --enablerepo=extras install -q -y epel-release centos-release-scl-rh https://repo.ius.io/ius-release-el7.rpm
sudo curl -o /etc/yum.repos.d/mercurial.repo https://www.mercurial-scm.org/release/centos7/mercurial.repo

配置完yum源,/etc/yum.repos.d 会生成相对于的 repo 文件。
在这里插入图片描述

2.3 安装软件包

sudo yum install -y devtoolset-8-make devtoolset-8-toolchain ca-certificates mercurial zlib-devel cmake3 ninja-build libunwind-devel pcre-devel openssl-devel libtool libtool-ltdl

安装成功结果:
在这里插入图片描述
创建符号连接:

sudo ln -s /opt/rh/devtoolset-8/root/usr/bin/gcc /usr/local/bin/gcc
sudo ln -s /opt/rh/devtoolset-8/root/usr/bin/c++ /usr/local/bin/c++
sudo ln -s /opt/rh/devtoolset-8/root/usr/bin/cc /usr/local/bin/cc
sudo ln -s /opt/rh/devtoolset-8/root/usr/bin/make /usr/local/bin/make

2.4 编译代码

第一步执行:

sh build_cc.sh conf

第二步执行:

make

在这里插入图片描述

tips:
文件太大了,编译时间会有点长,耐心等待哟!

第三步执行:

make install

在这里插入图片描述
这样就安装成功了!!

2.5 启动

 cd /usr/local/njet
 sbin/njet

tips:
有小伙伴可能看到官网教程使用的是直接
sudo systemctl start njet 启动,显示 njet not found的结果,这是因为通过源码编译安装的,可执行文件及相关的配置文件将安装到目录/usr/local/njet
只有通过使用 rpm 或 deb 二进制安装才能使用 systemctl 起停哟!

启动成功截图如下:

在这里插入图片描述

三. 🦁 使用效果

狮子通过官网的配置文件示例,将请求重定向到之前很火的一个动态爱心代码中。

3.1 编辑配置文件

  1. 进入配置文件:
cd /usr/local/njet/conf/njet.conf
vim /usr/local/njet/conf/njet.conf
  1. 编辑配置文件
worker_processes auto;

cluster_name njet;
node_name node1;

error_log logs/error.log error;

helper ctrl /usr/local/njet/modules/njt_helper_ctrl_module.so /usr/local/njet/conf/njet_ctrl.conf;
helper broker /usr/local/njet/modules/njt_helper_broker_module.so;

load_module /usr/local/njet/modules/njt_http_split_clients_2_module.so;
load_module /usr/local/njet/modules/njt_agent_dynlog_module.so;
load_module /usr/local/njet/modules/njt_http_dyn_bwlist_module.so;
load_module /usr/local/njet/modules/njt_dyn_ssl_module.so;
load_module /usr/local/njet/modules/njt_http_vtsc_module.so;
load_module /usr/local/njet/modules/njt_http_location_module.so;
#load_module /usr/local/njet/modules/njt_http_lua_module.so;
#load_module /usr/local/njet/modules/njt_http_modsecurity_module.so;
#load_module /usr/local/njet/modules/njt_http_dyn_modsecurity_module.so;


events {
    worker_connections  1024;
}


http {
    include mime.types;
    access_log off;
    vhost_traffic_status_zone;
    #lua_package_path "$prefix/lualib/lib/?.lua;/usr/local/njet/modules/?.lua;;";
    #lua_package_cpath "$prefix/lualib/clib/?.so;;";
    server {
        #modsecurity on;
        #modsecurity_rules_file /usr/local/njet/conf/modsec/main.conf;

        listen       8080;
        location / {
           root /opt/html;
           index index.html
        }
    }

}

这里我们定义一个 server ,该 server 监听8080端口,将该请求的根目录设置为 /opt/html 下的index.html,当外部访问 192.168.0.99:8080 时,则会直接访问到 /opt/html/index.html 网页。

3.2 编辑 HTML 代码

我们来编辑 /opt/html/index.html 代码,将爱心桃代码放进去:
在这里插入图片描述

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>canvas爱心</title>

<style>
html, body {
  height: 100%;
  padding: 0;
  margin: 0;
  background: #000;
}
canvas {
  position: absolute;
  width: 100%;
  height: 100%;
}</style>
</head>
<body>

<canvas id="pinkboard"></canvas>

<script>
/*
 * Settings
 */
var settings = {
  particles: {
    length:   500, // maximum amount of particles
    duration:   2, // particle duration in sec
    velocity: 100, // particle velocity in pixels/sec 
    effect: -0.75, // play with this for a nice effect
    size:      30, // particle size in pixels
  },
};

/*
 * RequestAnimationFrame polyfill by Erik M?ller
 */
(function(){var b=0;var c=["ms","moz","webkit","o"];for(var a=0;a<c.length&&!window.requestAnimationFrame;++a){window.requestAnimationFrame=window[c[a]+"RequestAnimationFrame"];window.cancelAnimationFrame=window[c[a]+"CancelAnimationFrame"]||window[c[a]+"CancelRequestAnimationFrame"]}if(!window.requestAnimationFrame){window.requestAnimationFrame=function(h,e){var d=new Date().getTime();var f=Math.max(0,16-(d-b));var g=window.setTimeout(function(){h(d+f)},f);b=d+f;return g}}if(!window.cancelAnimationFrame){window.cancelAnimationFrame=function(d){clearTimeout(d)}}}());

/*
 * Point class
 */
var Point = (function() {
  function Point(x, y) {
    this.x = (typeof x !== 'undefined') ? x : 0;
    this.y = (typeof y !== 'undefined') ? y : 0;
  }
  Point.prototype.clone = function() {
    return new Point(this.x, this.y);
  };
  Point.prototype.length = function(length) {
    if (typeof length == 'undefined')
      return Math.sqrt(this.x * this.x + this.y * this.y);
    this.normalize();
    this.x *= length;
    this.y *= length;
    return this;
  };
  Point.prototype.normalize = function() {
    var length = this.length();
    this.x /= length;
    this.y /= length;
    return this;
  };
  return Point;
})();

/*
 * Particle class
 */

var Particle = (function() {
  function Particle() {
    this.position = new Point();
    this.velocity = new Point();
    this.acceleration = new Point();
    this.age = 0;
  }
  Particle.prototype.initialize = function(x, y, dx, dy) {
    this.position.x = x; 
    this.position.y = y;
    this.velocity.x = dx;
    this.velocity.y = dy;
    this.acceleration.x = dx * settings.particles.effect;
    this.acceleration.y = dy * settings.particles.effect;
    this.age = 0;
  };
  Particle.prototype.update = function(deltaTime) {
    this.position.x += this.velocity.x * deltaTime;
    this.position.y += this.velocity.y * deltaTime;
    this.velocity.x += this.acceleration.x * deltaTime;
    this.velocity.y += this.acceleration.y * deltaTime;
    this.age += deltaTime;
  };
  Particle.prototype.draw = function(context, image) {
    function ease(t) {
      return (--t) * t * t + 1;
    }
    var size = image.width * ease(this.age / settings.particles.duration);
    context.globalAlpha = 1 - this.age / settings.particles.duration;
    context.drawImage(image, this.position.x - size / 2, this.position.y - size / 2, size, size);
  };
  return Particle;
})();

/*
 * ParticlePool class
 */
var ParticlePool = (function() {
  var particles,
      firstActive = 0,
      firstFree   = 0,
      duration    = settings.particles.duration;
  
  function ParticlePool(length) {
    // create and populate particle pool
    particles = new Array(length);
    for (var i = 0; i < particles.length; i++)
      particles[i] = new Particle();
  }
  ParticlePool.prototype.add = function(x, y, dx, dy) {
    particles[firstFree].initialize(x, y, dx, dy);
    
    // handle circular queue
    firstFree++;
    if (firstFree   == particles.length) firstFree   = 0;
    if (firstActive == firstFree       ) firstActive++;
    if (firstActive == particles.length) firstActive = 0;
  };
  ParticlePool.prototype.update = function(deltaTime) {
    var i;
    
    // update active particles
    if (firstActive < firstFree) {
      for (i = firstActive; i < firstFree; i++)
        particles[i].update(deltaTime);
    }
    if (firstFree < firstActive) {
      for (i = firstActive; i < particles.length; i++)
        particles[i].update(deltaTime);
      for (i = 0; i < firstFree; i++)
        particles[i].update(deltaTime);
    }
    
    // remove inactive particles
    while (particles[firstActive].age >= duration && firstActive != firstFree) {
      firstActive++;
      if (firstActive == particles.length) firstActive = 0;
    }
    
    
  };
  ParticlePool.prototype.draw = function(context, image) {
    // draw active particles
    if (firstActive < firstFree) {
      for (i = firstActive; i < firstFree; i++)
        particles[i].draw(context, image);
    }
    if (firstFree < firstActive) {
      for (i = firstActive; i < particles.length; i++)
        particles[i].draw(context, image);
      for (i = 0; i < firstFree; i++)
        particles[i].draw(context, image);
    }
  };
  return ParticlePool;
})();

/*
 * Putting it all together
 */
(function(canvas) {
  var context = canvas.getContext('2d'),
      particles = new ParticlePool(settings.particles.length),
      particleRate = settings.particles.length / settings.particles.duration, // particles/sec
      time;
  
  // get point on heart with -PI <= t <= PI
  function pointOnHeart(t) {
    return new Point(
      160 * Math.pow(Math.sin(t), 3),
      130 * Math.cos(t) - 50 * Math.cos(2 * t) - 20 * Math.cos(3 * t) - 10 * Math.cos(4 * t) + 25
    );
  }
  
  // creating the particle image using a dummy canvas
  var image = (function() {
    var canvas  = document.createElement('canvas'),
        context = canvas.getContext('2d');
    canvas.width  = settings.particles.size;
    canvas.height = settings.particles.size;
    // helper function to create the path
    function to(t) {
      var point = pointOnHeart(t);
      point.x = settings.particles.size / 2 + point.x * settings.particles.size / 350;
      point.y = settings.particles.size / 2 - point.y * settings.particles.size / 350;
      return point;
    }
    // create the path
    context.beginPath();
    var t = -Math.PI;
    var point = to(t);
    context.moveTo(point.x, point.y);
    while (t < Math.PI) {
      t += 0.01; // baby steps!
      point = to(t);
      context.lineTo(point.x, point.y);
    }
    context.closePath();
    // create the fill
    context.fillStyle = '#ea80b0';
    context.fill();
    // create the image
    var image = new Image();
    image.src = canvas.toDataURL();
    return image;
  })();
  
  // render that thing!
  function render() {
    // next animation frame
    requestAnimationFrame(render);
    
    // update time
    var newTime   = new Date().getTime() / 1000,
        deltaTime = newTime - (time || newTime);
    time = newTime;
    
    // clear canvas
    context.clearRect(0, 0, canvas.width, canvas.height);
    
    // create new particles
    var amount = particleRate * deltaTime;
    for (var i = 0; i < amount; i++) {
      var pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random());
      var dir = pos.clone().length(settings.particles.velocity);
      particles.add(canvas.width / 2 + pos.x, canvas.height / 2 - pos.y, dir.x, -dir.y);
    }
    
    // update and draw particles
    particles.update(deltaTime);
    particles.draw(context, image);
  }
  
  // handle (re-)sizing of the canvas
  function onResize() {
    canvas.width  = canvas.clientWidth;
    canvas.height = canvas.clientHeight;
  }
  window.onresize = onResize;
  
  // delay rendering bootstrap
  setTimeout(function() {
    onResize();
    render();
  }, 10);
})(document.getElementById('pinkboard'));</script>

</body>
</html>

保存后,重启 njet,访问 192.168.0.99:8080,效果如下:
在这里插入图片描述

四. 🦁 使用感受

在使用上,OpenNjet 很好地继承了 Nginx 服务器,配置文件使用很相似,对于熟悉 Nginx 的开发者来说,学习成本并不会太高,并且 OpenNJet 具备环境感知、安全控制、加速优化等能力,并且可以通过动态加载机制实现不同的产品形态,如API网关、消息代理、入口/出口控制器、边车、负载均衡和WAF等,为企业更好地打造一款稳定、可靠、高效的应用。


在这里插入图片描述

欢迎加入狮子的社区:『Lion-编程进阶之路』,日常收录优质好文

更多文章可持续关注上方🦁的博客,2024 咱们顶峰相见!

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

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

相关文章

小丑的身份证和复印件 (BFS + Floyd)

本题链接&#xff1a;登录—专业IT笔试面试备考平台_牛客网 题目&#xff1a; 样例&#xff1a; 输入 2 10 (JOKERjoke #####asdr) 输出 12 思路&#xff1a; 根据题意&#xff0c;要求最短时间&#xff0c;实际上也可以理解为最短距离。 所以应该联想到有关最短距离的算法&…

css z-Index 详解--子元素盖在父元素的兄弟元素上

前置知识 1、z-index 只有在定位元素上才会生效&#xff08;即非static定位的元素上&#xff09; 2、同级元素&#xff0c;无论是z-index 相同还是没设置。后面的元素层级比前面 3、元素上有 transform 属性 z-index 会失效 dom结构如下 // dom部分 <div><div id&quo…

latex algorithm2e 库学习总结

案例1 \documentclass{article}\usepackage{xeCJK} \usepackage[]{algorithm2e} %\usepackage{ctex} % 中文包\begin{document}\renewcommand{\algorithmcfname}{算法} % 把标题设置为“算法” \begin{algorithm…

html table thead打印时带重复表头不生效

今天做一个打印功能时要求每页都带相同的表头&#xff0c;使用的方式是table的thead标签来实现&#xff0c;结果发现thead里边的内容放多了之后只有第一页才会有表头。最后发现问题是 thead的内容不能超过table的25%。

实例分割——Mask R-CNN、YOLOV8、RTMDET、DeepLab四种实例分割算法比对

1.概述 1.1 语义分割与实例分割 实例分割和语义分割都是计算机视觉领域中图像分割的任务&#xff0c;它们在目标和方法上有一些区别&#xff1a; 语义分割&#xff1a; 语义分割的目标是对图像中的每个像素打上类别标签&#xff0c;即识别出图像中每个像素属于哪个预定义的…

云动态摘要 2024-05-09

给您带来云厂商的最新动态&#xff0c;最新产品资讯和最新优惠更新。 最新优惠与活动 [免费试用]即刻畅享自研SaaS产品 腾讯云 2024-04-25 涵盖办公协同、营销拓客、上云安全保障、数据分析处理等多场景 云服务器ECS试用产品续用 阿里云 2024-04-14 云服务器ECS试用产品续用…

YOLOv5,YOLOv7改进之结合​SOCA

1.SOCA moudle结构图 2,YOLOv5,YOLOv7改进之结合​SOCA 1.配置common.py文件 #SOCA moudle 单幅图像超分辨率 class Covpool(Function):@staticmethoddef forward(ctx, input):x = inputbatchSize = x.data.shape[0]dim = x.data.shape[1]h = x.data.shape[2]w = x.data.sha…

PLC学习笔记

PLC学习笔记 前言一、一些基操知识二、GX works2编程2.1 位逻辑1.2 中间寄存器1.3 PLC的扫描方式 总结 前言 我这个人真的是太渴望知识了~ 一、一些基操知识 一般X表示输入&#xff0c;Y表示输出。一般八个为一组X0~X7M表示中间寄存器&#xff0c;M0~M7时间T、计数C 二、GX …

短信群发公司

伴随着移动互联网和智能手机的普及&#xff0c;短信群发成为了企业与个人之间高效沟通的一种重要方式。短信群发公司应运而生&#xff0c;致力于为用户提供专业、安全、高效的群发服务。 服务内容 短信群发公司提供多样化的服务内容&#xff0c;满足不同用户的需求。短信群发公…

javaWeb快速部署到tomcat阿里云服务器

目录 准备 关闭防火墙 配置阿里云安全组 点击控制台 点击导航栏按钮 点击云服务器ECS 点击安全组 点击管理规则 点击手动添加 设置完成 配置web服务 使用yum安装heepd服务 启动httpd服务 查看信息 部署java通过Maven打包好的war包项目 Maven打包项目 上传项目 …

深度学习笔记001

目录 一、批量规范化 二、残差网络ResNet 三、稠密连接网络&#xff08;DenseNet&#xff09; 四、循环神经网络 五、信息论 六、梯度截断 本篇blog仅仅是本人在学习《动手学深度学习 Pytorch版》一书中做的一些笔记&#xff0c;感兴趣的读者可以去官网http://zh.gluon.a…

Abp框架,EF 生成迁移文件时,自动添加表和字段注释内容

在使用 abp 框架&#xff0c;或者ef 的时候都会遇到一个问题&#xff0c;就是建实体后要将实体描述生成到数据库中&#xff0c;就需要手动去添加 [Comment("注释内容")] 注解&#xff0c;这样相当于手动写两次注释&#xff08;即使你是 Ctrl C&#xff09;&#x…

若依集成mybatis-plus 超详细教程(亲测可用)

文章目录 简介步骤第一步第二步第三步第四步第五步第六步 使用QueryWrapperservice层impl 实现接口类层Mapper层 简介 话不多说 直接跟着下面的教程操作&#xff0c;如果有报错私信我&#xff0c;或者通过博文下面的微信名片加我微信&#xff0c;免费解答哦&#xff01; 步骤 …

解决方案:‘Series‘ object has no attribute ‘xxxx‘

文章目录 一、现象二、解决方案 一、现象 ...... model.fit(X_train, y_train) y_pred model.predict(X_test) recall recall_score(y_test, y_pred) precision precision_score(y_test. y_pred) ......执行语句到**“precision precision_score(y_test. y_pred)”**这里发…

StarRocks 跨集群数据迁移,SDM 帮你一键搞定!

作者&#xff1a;严祥光&#xff0c;StarRocks Active Contributor&#xff0c;StarRocks 存算分离核心研发&#xff0c;在社区中主要负责数据导入、跨集群同步、数据迁移和容灾等工作。 有时候&#xff0c;你可能会为以下需求而苦恼&#xff0c;苦苦搜索更好的解决方案&#x…

记录创建项目java version 没有8的问题

问题&#xff1a; 解决方案 java版本选择21&#xff08;21可以兼容jdk8&#xff09; SpringBoot选择3.2.5 进入项目后手动在pom.xml中修改版本

基于stm32的spi从机实验HAL库编程

目录 基于stm32的spi从机实验HAL库编程前言业务场景硬件设计接线配置swd接口配置spi配置DMA配置中断配置系统时钟配置工程生成代码写点从机代码上机现象后记本文使用的测试工程 基于stm32的spi从机实验HAL库编程 前言 在微控制器的世界中&#xff0c;串行外设接口(SPI)是一种…

java面向对象实现文字格斗游戏细节完善版

为了完善上一篇的文字格斗游戏的细节&#xff0c;所以加了些代码&#xff0c;使得交互更加的具体有趣! 效果 大家可以多运行几次代码&#xff0c;得到不同的战况&#xff01;&#xff01; 代码实现 1.bean类 import java.util.Random;public class TextGame {private Strin…

ardupilot的固定翼飞行模式

飞行模式 APM所有的飞行模式都在对应的机型的文件夹下的mode.h里面有定义,针对于不同的模型,功能函数在基类中Mode中都是以纯虚函数实现了, 然后在继承的子类中重新实现它,以实现多态。 takeoff模式 参见网址在 ArduPlane 4.0 及更高版本中,自动起飞本身也是一种模式(…

文件操作

前言&#xff1a; 文件内容属性 要向访问文件就要打开文件——>用进程来打开——>要把文件先加载到内存中——> 一个进程可以打开多个文件&#xff0c;OS中也有可能多个进程打开了多个文件 文件以多&#xff0c;就需要进行管理&#xff0c;——先描述再组织 没有被打开…
最新文章