node

node

Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境。
javascript/jQuery

javascript/jQuery

一种直译式脚本语言,是一种动态类型、弱类型、基于原型的语言,内置支持类型。
MongoDB

MongoDB

MongoDB 是一个基于分布式文件存储的数据库
openstack

openstack

OpenStack是一个由NASA(美国国家航空航天局)和Rackspace合作研发并发起的,以Apache许可证授权的自由软件和开放源代码项目。
VUE

VUE

一套构建用户界面的渐进式框架。与其他重量级框架不同的是,Vue 采用自底向上增量开发的设计。
bootstrap

bootstrap

Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile first projects on the web.
HTML

HTML

超文本标记语言,标准通用标记语言下的一个应用。
CSS/SASS/SCSS/Less

CSS/SASS/SCSS/Less

层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
PHP

PHP

PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,利于学习,使用广泛,主要适用于Web开发领域。PHP 独特的语法混合了C、Java、Perl以及PHP自创的语法。它可以比CGI或者Perl更快速地执行动态网页。用PHP做出的动态页面与其他的编程语言相比,PHP是将程序嵌入到HTML(标准通用标记语言下的一个应用)文档中去执行,执行效率比完全生成HTML标记的CGI要高许多;PHP还可以执
每天进步一点点

每天进步一点点

乌法把门的各累笑寂静
求职招聘

求职招聘

猎头招聘专用栏目
Python

Python

一种解释型、面向对象、动态数据类型的高级程序设计语言。

OpenResty安装

lopo1983 发表了文章 • 0 个评论 • 550 次浏览 • 2023-02-06 13:55 • 来自相关话题

1、获取预编译包
wget https://openresty.org/package/ ... .repo 2、移动编译包到etc目录
sudo mv openresty.repo /etc/yum.repos.d/ 如果需要更新资源包执行如下命令进行更新
sudo yum check-update3、安装软件包,默认安装在/usr/local/openresty目录下
sudo yum install -y openresty4、 启动nginx
#启动
/usr/local/openresty/nginx/sbin/nginx
#重启
/usr/local/openresty/nginx/sbin/nginx -s reload
#停止
/usr/local/openresty/nginx/sbin/nginx -s stop 查看全部
1、获取预编译包
wget https://openresty.org/package/ ... .repo
 2、移动编译包到etc目录
sudo mv openresty.repo /etc/yum.repos.d/
 如果需要更新资源包执行如下命令进行更新
sudo yum check-update
3、安装软件包,默认安装在/usr/local/openresty目录下
sudo yum install -y openresty
4、 启动nginx
#启动
/usr/local/openresty/nginx/sbin/nginx
#重启
/usr/local/openresty/nginx/sbin/nginx -s reload
#停止
/usr/local/openresty/nginx/sbin/nginx -s stop

RabbitMQ amqplib 死信和延时队列操作

lopo1983 发表了文章 • 0 个评论 • 743 次浏览 • 2022-06-02 01:00 • 来自相关话题

conn.js

const amqp = require('amqplib');
let connection = null;
module.exports = {
    connection,
    init: () => amqp.connect({
        protocol: 'amqp',
        hostname: '127.0.0.1',
        port: 5672,
        username: 'admin',
        password: '*********',
        frameMax: 0,
        heartbeat: 30,
        vhost: '/',
        client_provided_name: 'BFF'
    }).then(conn => {
        connection = conn;
        console.log('rabbitmq connect success');
        return connection;
    })
}
 
死信
 
pub

const rabbitmq = require('./conn/mqtt');
async function producerDLX(connnection) {
    const testExchange = 'testEx';
    const testQueue = 'testQu';
    const testExchangeDLX = 'testExDLX';
    const testRoutingKeyDLX = 'testRoutingKeyDLX';
    const ch = await connnection.createChannel();
    await ch.assertExchange(testExchange, 'direct', {
        durable: true
    });
    const {queue} = await ch.assertQueue(testQueue, {
        deadLetterExchange: testExchangeDLX,
        deadLetterRoutingKey: testRoutingKeyDLX,
    });
    await ch.bindQueue(queue, testExchange);
    const msg = {
        'ut':new Date() -0
    };
    // console.log(msg)
    await ch.sendToQueue(queue, Buffer.from(JSON.stringify(msg)), {
        expiration: 10000
    });
    ch.close();
}
rabbitmq.init().then(conn => {
        producerDLX(conn)
})
 
sub

const rabbitmq = require('./conn/mqtt');
async function consumerDLX(connnection) {
    const testExchangeDLX = 'testExDLX';
    const testRoutingKeyDLX = 'testRoutingKeyDLX';
    const testQueueDLX = 'testQueueDLX';
    const ch = await connnection.createChannel();
    await ch.assertExchange(testExchangeDLX, 'direct', {
        durable: true
    });
    const {
        queue
    } = await ch.assertQueue(testQueueDLX, {
        exclusive: false,
    });
    await ch.bindQueue(queue, testExchangeDLX, testRoutingKeyDLX);
    await ch.consume(queue, msg => {
        const CONTENT = msg.content.toString();
        console.log(new Date() - 0- JSON.parse(CONTENT).ut)
        // console.log('consumer msg:');
    }, {
        noAck: true
    });
}
rabbitmq.init().then(connection => consumerDLX(connection));
 
延时队列
需要在rabbitmq中安装对应的延时插件
pub

const rabbitmq = require('./conn/mqtt');
async function producerDLX(connnection) {
    const EXCHANGE = 'zdnf-xdm'
    const ch = await connnection.createChannel();
    await ch.assertExchange(EXCHANGE, 'x-delayed-message', {
        durable: true,
        'x-delayed-type': 'topic'
    });
    const {
        queue
    } = await ch.assertQueue('xdpub-test');
    await ch.bindQueue(queue, EXCHANGE);
    const msg = {
        'ut': new Date() - 0
    };
    // console.log(msg)
    await ch.publish(EXCHANGE,'rtk-xdpub-test', Buffer.from(JSON.stringify(msg)), {
        headers: {
            'x-delay': 10000, // 一定要设置,否则无效
        }
    });
    ch.close();
}
rabbitmq.init().then(conn => {
    // setInterval(() => {
        producerDLX(conn)
    // }, 3000);
})
 
 
sub
 

const rabbitmq = require('./conn/mqtt');
async function consumerDLX(connnection) {
    const EXCHANGE = 'zdnf-xdm'
    const ch = await connnection.createChannel();
    await ch.assertExchange(EXCHANGE, 'x-delayed-message', {
        durable: true,
        'x-delayed-type': 'topic'
    });
    ch.prefetch(1);
    const {
        queue
    } = await ch.assertQueue('xdpub-test');
     await ch.bindQueue(queue, EXCHANGE, 'rtk-xdpub-test');
    await ch.consume(queue, msg => {
        const CONTENT = msg.content.toString();
        console.log(new Date() - 0 - JSON.parse(CONTENT).ut)
        // console.log('consumer msg:');
    }, {
        noAck: true
    });
}
rabbitmq.init().then(connection => consumerDLX(connection));
  查看全部
conn.js

const amqp = require('amqplib');
let connection = null;
module.exports = {
    connection,
    init: () => amqp.connect({
        protocol: 'amqp',
        hostname: '127.0.0.1',
        port: 5672,
        username: 'admin',
        password: '*********',
        frameMax: 0,
        heartbeat: 30,
        vhost: '/',
        client_provided_name: 'BFF'
    }).then(conn => {
        connection = conn;
        console.log('rabbitmq connect success');
        return connection;
    })
}
 
死信
 
pub

const rabbitmq = require('./conn/mqtt');
async function producerDLX(connnection) {
    const testExchange = 'testEx';
    const testQueue = 'testQu';
    const testExchangeDLX = 'testExDLX';
    const testRoutingKeyDLX = 'testRoutingKeyDLX';
    const ch = await connnection.createChannel();
    await ch.assertExchange(testExchange, 'direct', {
        durable: true
    });
    const {queue} = await ch.assertQueue(testQueue, {
        deadLetterExchange: testExchangeDLX,
        deadLetterRoutingKey: testRoutingKeyDLX,
    });
    await ch.bindQueue(queue, testExchange);
    const msg = {
        'ut':new Date() -0
    };
    // console.log(msg)
    await ch.sendToQueue(queue, Buffer.from(JSON.stringify(msg)), {
        expiration: 10000
    });
    ch.close();
}
rabbitmq.init().then(conn => {
        producerDLX(conn)
})
 
sub

const rabbitmq = require('./conn/mqtt');
async function consumerDLX(connnection) {
    const testExchangeDLX = 'testExDLX';
    const testRoutingKeyDLX = 'testRoutingKeyDLX';
    const testQueueDLX = 'testQueueDLX';
    const ch = await connnection.createChannel();
    await ch.assertExchange(testExchangeDLX, 'direct', {
        durable: true
    });
    const {
        queue
    } = await ch.assertQueue(testQueueDLX, {
        exclusive: false,
    });
    await ch.bindQueue(queue, testExchangeDLX, testRoutingKeyDLX);
    await ch.consume(queue, msg => {
        const CONTENT = msg.content.toString();
        console.log(new Date() - 0- JSON.parse(CONTENT).ut)
        // console.log('consumer msg:');
    }, {
        noAck: true
    });
}
rabbitmq.init().then(connection => consumerDLX(connection));
 
延时队列

需要在rabbitmq中安装对应的延时插件


pub

const rabbitmq = require('./conn/mqtt');
async function producerDLX(connnection) {
    const EXCHANGE = 'zdnf-xdm'
    const ch = await connnection.createChannel();
    await ch.assertExchange(EXCHANGE, 'x-delayed-message', {
        durable: true,
        'x-delayed-type': 'topic'
    });
    const {
        queue
    } = await ch.assertQueue('xdpub-test');
    await ch.bindQueue(queue, EXCHANGE);
    const msg = {
        'ut': new Date() - 0
    };
    // console.log(msg)
    await ch.publish(EXCHANGE,'rtk-xdpub-test', Buffer.from(JSON.stringify(msg)), {
        headers: {
            'x-delay': 10000, // 一定要设置,否则无效
        }
    });
    ch.close();
}
rabbitmq.init().then(conn => {
    // setInterval(() => {
        producerDLX(conn)
    // }, 3000);
})
 
 
sub
 

const rabbitmq = require('./conn/mqtt');
async function consumerDLX(connnection) {
    const EXCHANGE = 'zdnf-xdm'
    const ch = await connnection.createChannel();
    await ch.assertExchange(EXCHANGE, 'x-delayed-message', {
        durable: true,
        'x-delayed-type': 'topic'
    });
    ch.prefetch(1);
    const {
        queue
    } = await ch.assertQueue('xdpub-test');
     await ch.bindQueue(queue, EXCHANGE, 'rtk-xdpub-test');
    await ch.consume(queue, msg => {
        const CONTENT = msg.content.toString();
        console.log(new Date() - 0 - JSON.parse(CONTENT).ut)
        // console.log('consumer msg:');
    }, {
        noAck: true
    });
}
rabbitmq.init().then(connection => consumerDLX(connection));
 

eggjs egg-ioredis 中使用lua 脚本 (redis lua 脚本的扫盲帖 )

lopo1983 发表了文章 • 0 个评论 • 1031 次浏览 • 2022-03-28 23:47 • 来自相关话题

基础语法解析调用Lua脚本的语法:
$ redis-cli --eval path/to/redis.lua numberkeys KEYS[1] KEYS[2] , ARGV[1] ARGV[2] ...

--eval,告诉redis-cli读取并运行后面的lua脚本
path/to/redis.lua,是lua脚本的位置,也可以直接为脚本字符串。是一个Lua 5.1 script。
numberkeys ,指定后续参数有几个key。
KEYS[1] KEYS[2],是要操作的键,可以指定多个,在lua脚本中通过KEYS[1], KEYS[2]获取
ARGV[1] ARGV[2],参数,在lua脚本中通过ARGV[1], ARGV[2]获取。实例脚本 批量查询hash的值 hget 和切换db 以eggjs为例/**
* @summary 竞拍列表
* @description 1.type 【1】检测用户是否已报名 【2】用户报名的拍卖列表
* @router GET /api/v1/user/auction/auction/list
* @request query string page 第几页
* @request query string limit 每页几个
* @request query string type 类型
* @request query string status 状态
* @apikey Authorization
* @response 200 ACRES
*/
async index() {
const {
ctx,
ctx:{
uid,
query:{
page=1,
limit=12,
type,
status
}
}
}= this;
const RDS = await ctx.app.redis.get('auctionRoom')
try {
// 查询符合条件的hash key
const [[],LIST] = await RDS.sscan(`ar:u:${uid}`,(page-1)*limit,'count',limit);

// 注册脚本
// 1 声明输出的类型 rst {} {}对应key 为数组的下标记
// 2 格式化输入的参数KEYS 对应lua的numberkeys 为1
// 3 lua中切换db 也可以做多个参数 如KEYS2 这里我是固定的 所以只传一个 KEYS
// 4,5,6 执行redis的hget脚本 .. v 为lua中的链接符号
// 7 返回值
await RDS.defineCommand("hmgetall", {
lua: `local rst={};
local id=cjson.decode(KEYS[1]);
redis.call('select',13);
for i,v in pairs(id)
do rst[i]=redis.call('hget', 'ar:' .. v,'meta_info')
end;
return rst;`,
})
// 使用脚本并格式化 输出
ctx.body = (await RDS.hmgetall(1,JSON.stringify(LIST.map(e=>`${e}`)))).reduce((a,b)=>{
a['list'].push(JSON.parse(b));
return a
},{list:,page:{limit,page}})
} catch (err) {
console.log(err)
return ctx.body = {
code: 211,
message: ctx.app.config.env === 'local' ? `${(err.message)}`:'服务器忙,请稍后重试!',
data: err.errors
}
}
}[/i]
 
  查看全部
基础语法解析
调用Lua脚本的语法:
$ redis-cli --eval path/to/redis.lua numberkeys KEYS[1] KEYS[2] , ARGV[1] ARGV[2] ...

--eval,告诉redis-cli读取并运行后面的lua脚本
path/to/redis.lua,是lua脚本的位置,也可以直接为脚本字符串。是一个Lua 5.1 script。
numberkeys ,指定后续参数有几个key。
KEYS[1] KEYS[2],是要操作的键,可以指定多个,在lua脚本中通过KEYS[1], KEYS[2]获取
ARGV[1] ARGV[2],参数,在lua脚本中通过ARGV[1], ARGV[2]获取。
实例脚本 批量查询hash的值 hget 和切换db 以eggjs为例
/**
* @summary 竞拍列表
* @description 1.type 【1】检测用户是否已报名 【2】用户报名的拍卖列表
* @router GET /api/v1/user/auction/auction/list
* @request query string page 第几页
* @request query string limit 每页几个
* @request query string type 类型
* @request query string status 状态
* @apikey Authorization
* @response 200 ACRES
*/
async index() {
const {
ctx,
ctx:{
uid,
query:{
page=1,
limit=12,
type,
status
}
}
}= this;
const RDS = await ctx.app.redis.get('auctionRoom')
try {
// 查询符合条件的hash key
const [[],LIST] = await RDS.sscan(`ar:u:${uid}`,(page-1)*limit,'count',limit);

// 注册脚本
// 1 声明输出的类型 rst {} {}对应key 为数组的下标记
// 2 格式化输入的参数KEYS 对应lua的numberkeys 为1
// 3 lua中切换db 也可以做多个参数 如KEYS2 这里我是固定的 所以只传一个 KEYS
// 4,5,6 执行redis的hget脚本 .. v 为lua中的链接符号
// 7 返回值
await RDS.defineCommand("hmgetall", {
lua: `local rst={};
local id=cjson.decode(KEYS[1]);
redis.call('select',13);
for i,v in pairs(id)
do rst[i]=redis.call('hget', 'ar:' .. v,'meta_info')
end;
return rst;`,
})
// 使用脚本并格式化 输出
ctx.body = (await RDS.hmgetall(1,JSON.stringify(LIST.map(e=>`${e}`)))).reduce((a,b)=>{
a['list'].push(JSON.parse(b));
return a
},{list:,page:{limit,page}})
} catch (err) {
console.log(err)
return ctx.body = {
code: 211,
message: ctx.app.config.env === 'local' ? `${(err.message)}`:'服务器忙,请稍后重试!',
data: err.errors
}
}
}[/i]

 
 

centos nginx 启动

lopo1983 发表了文章 • 0 个评论 • 864 次浏览 • 2021-07-30 15:56 • 来自相关话题

nginx -c /etc/nginx/nginx.conf
 

nginx -c /etc/nginx/nginx.conf
 

linux 根据端口查进程id

lopo1983 发表了文章 • 0 个评论 • 1576 次浏览 • 2020-07-19 22:04 • 来自相关话题

netstat -tpln | grep [port]
kill [port]下面是windows的netstat -ano |findstr [port]
taskkill /f /t /im "进程id或者进程名称" 查看全部
netstat -tpln | grep [port]
kill [port]
下面是windows的
netstat -ano |findstr [port]
taskkill /f /t /im "进程id或者进程名称"

centos7.x 防火墙常用操作

lopo1983 发表了文章 • 0 个评论 • 1625 次浏览 • 2020-03-20 10:43 • 来自相关话题

1、开放端口firewall-cmd --zone=public --add-port=5672/tcp --permanent   # 开放5672端口firewall-cmd --zone=public --remove-port=5672/tcp --permanent  #关闭5672端口firewall-cmd --reload   # 配置立即生效

 

2、查看防火墙所有开放的端口firewall-cmd --zone=public --list-ports

 

3.、关闭防火墙

如果要开放的端口太多,嫌麻烦,可以关闭防火墙,安全性自行评估systemctl stop firewalld.service

 

4、查看防火墙状态 firewall-cmd --state

 

5、查看监听的端口netstat -lnpt
PS:centos7默认没有 netstat 命令,需要安装 net-tools 工具,yum install -y net-tools

 

 

6、检查端口被哪个进程占用netstat -lnpt |grep 5672

 

7、查看进程的详细信息

ps 6832

 

8、中止进程

kill -9 6832 查看全部
1、开放端口
firewall-cmd --zone=public --add-port=5672/tcp --permanent
   # 开放5672端口
firewall-cmd --zone=public --remove-port=5672/tcp --permanent 
 #关闭5672端口
firewall-cmd --reload
   # 配置立即生效

 

2、查看防火墙所有开放的端口
firewall-cmd --zone=public --list-ports


 

3.、关闭防火墙

如果要开放的端口太多,嫌麻烦,可以关闭防火墙,安全性自行评估
systemctl stop firewalld.service


 

4、查看防火墙状态
 firewall-cmd --state


 

5、查看监听的端口
netstat -lnpt

PS:centos7默认没有 netstat 命令,需要安装 net-tools 工具,yum install -y net-tools

 

 

6、检查端口被哪个进程占用
netstat -lnpt |grep 5672


 

7、查看进程的详细信息

ps 6832

 

8、中止进程

kill -9 6832

AMQP

lopo1983 发表了文章 • 0 个评论 • 1500 次浏览 • 2020-03-15 23:12 • 来自相关话题

什么是AMQP





从 AMQP 协议可以看出,Queue、Exchange 和 Binding 构成了 AMQP 协议的核心
Producer:消息生产者,即投递消息的程序Broker:消息队列服务器实体。
Exchange:消息交换机,它指定消息按什么规则,路由到哪个队列。Binding:绑定,它的作用就是把 Exchange 和 Queue 按照路由规则绑定起来。Queue:消息队列载体,每个消息都会被投入到一个或多个队列。
Consumer:消息消费者,即接受消息的程序。 查看全部
什么是AMQP

p.jpeg

从 AMQP 协议可以看出,Queue、Exchange 和 Binding 构成了 AMQP 协议的核心
  • Producer:消息生产者,即投递消息的程序
  • Broker:消息队列服务器实体。

  1. Exchange:消息交换机,它指定消息按什么规则,路由到哪个队列。
  2. Binding:绑定,它的作用就是把 Exchange 和 Queue 按照路由规则绑定起来。
  3. Queue:消息队列载体,每个消息都会被投入到一个或多个队列。

  • Consumer:消息消费者,即接受消息的程序。

centos 安装最新版 redis

lopo1983 发表了文章 • 0 个评论 • 1510 次浏览 • 2020-03-14 23:53 • 来自相关话题

安装源yum install -y http://rpms.famillecollet.com/ ... 7.rpm安装
yum --enablerepo=remi install redis设置开机启动启动
systemctl enable redis.service修改配置  
vim /etc/redis.conf
# 设置可外网访问 DEV 模式用 上线慎用
bind 0.0.0.0
# 设置访问密码
requirepass ***********
:wq

/bin/systemctl restart redis.service
记住默认只有16个 chanceDb 查看全部
安装源
yum install -y http://rpms.famillecollet.com/ ... 7.rpm
安装
yum --enablerepo=remi install redis
设置开机启动启动
systemctl enable redis.service
修改配置  
vim /etc/redis.conf
# 设置可外网访问 DEV 模式用 上线慎用
bind 0.0.0.0
# 设置访问密码
requirepass ***********
:wq

/bin/systemctl restart redis.service

记住默认只有16个 chanceDb


妈妈再也不用担心我烧CPU 和内存了 Puppeteer 并发

lopo1983 发表了文章 • 0 个评论 • 3321 次浏览 • 2020-03-11 22:29 • 来自相关话题

const MAX_WSE = 4; //启动几个浏览器
let WSE_LIST = ; //存储browserWSEndpoint列表
init();
app.get('/', function (req, res) {
let tmp = Math.floor(Math.random()* MAX_WSE);
(async () => {
let browserWSEndpoint = WSE_LIST[tmp];
const browser = await puppeteer.connect({browserWSEndpoint});
const page = await browser.newPage();
await page.goto('file://code/screen/index.html');
await page.setViewport({
width: 600,
height: 400
});
await page.screenshot({path: 'example.png'});
await page.close();
res.send('Hello World!');
})();
});

function init(){
(async () => {
for(var i=0;i<MAX_WSE;i++){
const browser = await puppeteer.launch({headless:true,
args: [
'--disable-gpu',
'--disable-dev-shm-usage',
'--disable-setuid-sandbox',
'--no-first-run',
'--no-sandbox',
'--no-zygote',
'--single-process'
]});
browserWSEndpoint = await browser.wsEndpoint();
WSE_LIST[i] = browserWSEndpoint;
}
console.log(WSE_LIST);
})();
}[/i]啰嗦几句
开启几个浏览器 随机在浏览器上打开tab 关闭headless 看更明显  使用express 是为了更方便看到结果 查看全部
const MAX_WSE = 4;  //启动几个浏览器 
let WSE_LIST = ; //存储browserWSEndpoint列表
init();
app.get('/', function (req, res) {
let tmp = Math.floor(Math.random()* MAX_WSE);
(async () => {
let browserWSEndpoint = WSE_LIST[tmp];
const browser = await puppeteer.connect({browserWSEndpoint});
const page = await browser.newPage();
await page.goto('file://code/screen/index.html');
await page.setViewport({
width: 600,
height: 400
});
await page.screenshot({path: 'example.png'});
await page.close();
res.send('Hello World!');
})();
});

function init(){
(async () => {
for(var i=0;i<MAX_WSE;i++){
const browser = await puppeteer.launch({headless:true,
args: [
'--disable-gpu',
'--disable-dev-shm-usage',
'--disable-setuid-sandbox',
'--no-first-run',
'--no-sandbox',
'--no-zygote',
'--single-process'
]});
browserWSEndpoint = await browser.wsEndpoint();
WSE_LIST[i] = browserWSEndpoint;
}
console.log(WSE_LIST);
})();
}[/i]
啰嗦几句
开启几个浏览器 随机在浏览器上打开tab 关闭headless 看更明显  使用express 是为了更方便看到结果

vm 退出保存文件(新建)

lopo1983 发表了文章 • 0 个评论 • 1259 次浏览 • 2020-03-06 13:31 • 来自相关话题

:filename:file
:wq
:filename:file 
:wq