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

news2024/9/23 7:28:48

目录

  • 一. 🦁 写在前面
  • 二. 🦁 安装使用
    • 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.coloradmin.cn/o/1645384.html

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

相关文章

C语言—控制语句

控制语句就是用来实现对流程的选择、循环、转向和返回等控制行为。 分支语句 if语句 基本结构 if(表达式) { 语句块1&#xff1b; } else { 语句块2&#xff1b; } 执行顺序&#xff1a; 如果表达式判断成立&#xff08;即表达式为真&#xff09;&#xff0c;则执行语句块…

fork后如何同步最新的代码

1.查看自己的库并添加远程源库 #查看所有远程库的url git remote -v; #添加源项目url&#xff08;upstream是自己定义的一个名字&#xff0c;可以删 git remote remove upstream&#xff09; git remote add upstream 这里替换为源项目url; #查看所有远程库的url&…

【信息安全管理与评估】某年“信息安全管理与评估”第二阶段:Windows应急响应例题

文章目录 1、提交攻击者的IP地址&#xff1b;2、识别攻击者使用的操作系统&#xff1b;3、找出攻击者资产收集所使用的平台&#xff1b;4、提交攻击者目录扫描所使用的工具名称&#xff1b;5、提交攻击者首次攻击成功的时间&#xff0c;格式&#xff1a;DD /MM/YY:HH:MM:SS&…

高效、精准:皮秒激光切割机在陶瓷基板加工中的应用

皮秒激光切割机&#xff08;激光划片机&#xff09;在陶瓷基板切割领域具有显著的优势和潜力&#xff0c;主要体现在以下几个方面&#xff1a; 1. 高精度&#xff1a;皮秒激光切割机能够实现极高的切割精度&#xff0c;对于陶瓷基板这种需要精细加工的材料尤为重要。它能够在不…

生产管理驾驶舱模板分享,制造业都来抄作业!

今天要讲的是一张从组织、生产车间、物料、仓库、时间等不同维度&#xff0c;展示产能、产量、投入成本、产能达成率等关键信息&#xff0c;让企业运营决策者全面了解生产产能情况、产量情况、投入成本情况、产能达成率情况的BI生产管理驾驶舱模板。这是奥威BI标准方案为设有生…

【Web漏洞指南】XSS漏洞详细指南

【Web漏洞指南】XSS漏洞详细指南 概述XSS的三种类型执行任意 JS 代码的方式在原始HTML中注入绕过手法在 HTML标记内注入绕过手法在JavaScript代码中注入绕过手法其他绕过手法XSS常见有效载荷检索Cookies窃取页面内容键盘记录器查找内部IP地址端口扫描器自动填充密码捕获窃取 Po…

小猫咪邮件在线发送系统源码v1.1,支持添加附件

内容目录 一、详细介绍二、效果展示1.部分代码2.效果图展示 三、学习资料下载 一、详细介绍 小猫咪邮件在线发送系统源码v1.1&#xff0c;支持添加附件 一款免登录发送邮件&#xff0c;支持发送附件&#xff0c;后台可添加邮箱,前台可选择发送邮箱 网站数据采取本地保存&…

Jmeter性能测试(三)

token鉴权处理 1、添加json提取器 2、写jsonpath表达式在响应Body中提取鉴权token token&#xff1a;变量名&#xff0c;可以直接引用 $…token&#xff1a;token数据在响应中的字段名称&#xff0c;根据自己情况写就行 3、将提取出来的token添加到请求头中 重点&#xff…

2024年电化学、可再生能源与绿色发展国际会议(ICERGD2024)

2024年电化学、可再生能源与绿色发展国际会议(ICERGD2024) 会议简介 2024国际电化学、可再生能源与绿色发展大会&#xff08;ICERGD2024&#xff09;将在青岛隆重举行。本次会议聚焦电化学、可再生能源和绿色发展领域的最新研究成果和技术趋势&#xff0c;旨在促进相关领域…

OZON卖家必看!2024年OZON运营必备工具大全

OZON运营过程中会用到许多工具网站&#xff0c;都是OZON跨境人运营必备的。为了帮助新卖家在运营OZON时更高效&#xff0c;下面汇总了一份我们在日常运营中频繁使用的工具网站列表。这样大家可以一次性找到所需的所有网址&#xff0c;无需在多个网站间来回切换&#xff0c;节省…

机器学习——3.梯度计算与梯度下降

基本概念 梯度的本意是一个向量&#xff08;矢量&#xff09;&#xff0c;表示某一函数在该点处的方向导数沿着该方向取得最大值&#xff0c;即函数在该点处沿着该方向&#xff08;此梯度的方向&#xff09;变化最快&#xff0c;变化率最大&#xff08;为该梯度的模&#xff0…

sqlalchemy 分表实现方案

1.需求及场景概述 现有系统中因历史数据量过大,产生了将历史数据进行按月存储的要求,系统和数据库交互使用的是sqlalchemy,假设系统的原来的历史记录表(record)如下: 为了将历史数据按月分表存储,我们需要以此表为基础按月创建对应的月表来进行分表存储,同时又要使用or…

怎么ai自动答题?方法揭晓!

怎么ai自动答题&#xff1f;在数字化和信息化的浪潮中&#xff0c;人工智能&#xff08;AI&#xff09;技术日新月异&#xff0c;逐渐渗透到我们生活的方方面面。其中&#xff0c;AI自动答题软件作为辅助学习的工具&#xff0c;受到了越来越多学生和考生的青睐。它们不仅能够帮…

Remix框架实现 SSR

SSR SSR是一种网页渲染方式&#xff0c;它与传统的客户端渲染&#xff08;CSR&#xff09;相对&#xff0c;在日常的项目中我们更多是使用 CSR 的方式进行前端分离开发&#xff0c;渲染会在浏览器端进行。然而在SSR中&#xff0c;当用户请求一个网页时&#xff0c;服务器将生成…

MLP实现fashion_mnist数据集分类(1)-模型构建、训练、保存与加载(tensorflow)

1、查看tensorflow版本 import tensorflow as tfprint(Tensorflow Version:{}.format(tf.__version__)) print(tf.config.list_physical_devices())2、fashion_mnist数据集下载与展示 (train_image,train_label),(test_image,test_label) tf.keras.datasets.fashion_mnist.l…

Jetson orin 刷机

因为现在的系统各种库已经都乱了&#xff0c;也怪自己太心急了&#xff0c;把cmake给删了&#xff0c;导致很多编译库都出现了问题。记住这个教训&#xff01; 找到合适的教程 首先是PC系统&#xff0c;看来好几个教程都说用ubuntu&#xff0c;也有的说Windows也可以&#xf…

SGX Memory Organization

文章目录 前言一、Processor Reserved Memory (PRM)二、Enclave Page Cache (EPC)三、Enclave Page Cache Map (EPCM)参考资料 前言 本节内容主要介绍了SGX Memory Organization&#xff0c;来自参考资料里的综述文章&#xff0c;可供初学者了解SGX内存组织对应的知识。 一、…

【C++练级之路】【Lv.20】位图和布隆过滤器(揭开大数据背后的神秘面纱)

快乐的流畅&#xff1a;个人主页 个人专栏&#xff1a;《算法神殿》《数据结构世界》《进击的C》 远方有一堆篝火&#xff0c;在为久候之人燃烧&#xff01; 文章目录 引言一、位图1.1 位图的概念1.2 位图的优势1.3 位图的模拟实现1.3.1 成员变量与默认成员函数1.3.2 test1.3.3…

LoRa无线通讯入门

本文图片来自于深入浅出讲解LoRa通信技术&#xff0c;LoRa技术介绍&#xff0c;LoRa开发与应用&#xff0c;物联网学习必备知识点&#xff01;_哔哩哔哩_bilibili LoRa无线通讯 LoRa&#xff08;Long Range&#xff09;是一种低功耗广域网&#xff08;LPWAN&#xff09;技术&a…

5.06号模拟前端面试8问

5.06号模拟前端面试8问 1.promise如何实现then处理 在JavaScript中&#xff0c;Promise 是一个代表异步操作最终完成或失败的对象。它有三种状态&#xff1a;pending&#xff08;等待&#xff09;&#xff0c;fulfilled&#xff08;完成&#xff09;&#xff0c;rejected&…