cfanzp

个人Linux开发笔记

lua第三方开源库学习整理

lua第三方开源库学习整理 skynet框架:https://github.com/cloudwu/skynet lua的protobuf工具-pbc:https://github.com/cloudwu/pbc lua-cjson库:https://github.com/mpx/lua-cjson 一个lua写的websocket库https://github.com/flaribbit/love2d-lua-websocket lua-protobuf库https://github.com/starwing/lua-protobuf/blob/master/README.zh.md

lua中string.pack,string.unpack的用法

lua中string.pack,string.unpack的用法 lua string.pack的用法,查看lua5.4的官方帮助手册不难找到下面的解释: string.pack (fmt, v1, v2, ···) Returns a binary string containing the values v1, v2, etc. serialized in binary form (packed) according to the format string fmt (see §6.4.2). 最近一个新项目要将brotobuf协议包裹在http协议内进行传输,刚好用到了这个函数,在pb数据包封包后,协议按3部分拼接: 1 数据包长度(msgid + pb_data) + 协议ID + pb数据包体 封包过程如下: 1 2 3 local pb_data = pb_helper.pb_encode(msgname, msg) local buf = string.pack(">I4c" .. #pb_data, msgid, pb_data) local send_buf = string.pack(">s2", buf) 解包过程如下: 1 2 3 local buf = msg --des_decode(secret, msg) local len = string.

nginx配置https转发

nginx配置https转发 下载nginx http://nginx.org/en/download.html 1 wget http://nginx.org/download/nginx-1.20.2.tar.gz 安装nginx 参考: https://www.cnblogs.com/-wei/p/15219624.html 1 2 3 4 tar -xzvf nginx-1.20.2.tar.gz cd nginx-1.20.2 ./configure --prefix=/opt/nginx --with-http_ssl_module make && make install aliyun申请免费证书 这里以www.cfanzp.com为例子,具体申请流程这里就不赘述了。 申请成功后得到ngnix配置需要的证书和证书秘钥 1 2 3 4 #证书 5837690_www.cfanzp.com.pem #证书秘钥 5837690_www.cfanzp.com.key 将证书秘钥放到配置目录 1 2 3 4 #证书位置 etc/nginx/cert/5837690_www.cfanzp.com.pem #证书秘钥位置 /etc/nginx/cert/5837690_www.cfanzp.com.key nginx.conf demo: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 #user nobody; worker_processes 1; #error_log logs/error.

nginx web负载均衡配置

nginx web负载均衡配置 下载nginx http://nginx.org/en/download.html 1 wget http://nginx.org/download/nginx-1.20.2.tar.gz 安装nginx 参考: https://www.cnblogs.com/-wei/p/15219624.html 1 2 3 4 5 ./configure --prefix=/opt/nginx 或 ./configure --prefix=/opt/nginx --with-http_ssl_module make make install 报错 ./configure: error: the HTTP rewrite module requires the PCRE library 1 yum -y install pcre-devel ./configure: error: the HTTP gzip module requires the zlib library. 1 yum -y install zlib-devel ./configure: error: SSL modules require the OpenSSL library. 1 yum -y install openssl openssl-devel nginx限制请求数据包大小 1 client_max_body_size 1000m; 负载均衡配置 参考: https://www.

nginx基本用法与配置笔记

nginx配置笔记 基本概念 惊群现象:一个网路连接到来,多个睡眠的进程被同时叫醒,但只有一个进程能获得链接,这样会影响系统性能。 全局块 nginx服务器用户组 nginx进程pid 日志存放路径 配置文件引入 允许生成worker process数 event块 配置影响nginx服务器或与用户的网络连接。包括: 每个进程的最大连接数 选取那种事件驱动模型处理连接请求 是否允许同时接受多个网路连接 开启多个网络连接序列化等。 http块 可以嵌套多个server 配置代理,缓存,日志定义等绝大多数功能和第三方模块的配置。 文件引入 mime-type定义 日志定义 是否使用sendfile传输文件 连接超时时间 单连接请求数 server块 配置虚拟主机的相关参数,一个http中可以有多个server块 location 块 配置请求的路由,以及各种页面的请求情况 nginx文件结构 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 ... #全局块 events { #events块 ... } http #http块 { ... #http全局块 server #server块 { .

skynet中使用uuid库

skynet中使用uuid库 最近在使用之前一位同学写的uuid库时发现了uuid在不通的skynet虚拟机中可能会产生相同的值的现象,这里记录一下。产生的原因是,这2个虚拟机是在服务启动的时候创建的,间隔时间很短,随机种子估计是一样的。后面产生的随机序列都是一样的。 uuid库初始化种子 相同时间初始化种子,后续产生的随机数是相同的,随机种子初始化代码如下: 1 2 local uuid = require "uuid" uuid.seed() -- 初始化uuid种子 不同lua虚拟机中使用uuid可能生成相同的uuid,下面就是2个skynet服务在相同时间创建并初始化uuid种子的例子,不难看出,2个服务轮询接受请求,依次产生的uuid是相同的。 1 2 3 4 [:0000001a] [2022-07-29 11:36:36.561] [W] [login_web_agent1] service/login/platform/account_login.lua:111: req: 40a1bbf6-2e44-4b4a-cb9d-7a383472184b [:0000001b] [2022-07-29 11:36:44.059] [W] [login_web_agent2] service/login/platform/account_login.lua:111: req: 40a1bbf6-2e44-4b4a-cb9d-7a383472184b [:0000001a] [2022-07-29 11:36:55.069] [W] [login_web_agent1] service/login/platform/account_login.lua:111: req: bc96f82f-c94c-4398-c346-e956a92dcc11 [:0000001b] [2022-07-29 11:41:13.213] [W] [login_web_agent2] service/login/platform/account_login.lua:111: req: bc96f82f-c94c-4398-c346-e956a92dcc11 总结 这个uuid库的使用需要保证uuid的使用是在一个虚拟机内。如果想uuid不重复,又要保证唯一性,可以创建一个专有的skynet虚拟机来提供uuid的分配工作。