Debugging NGINX

这篇文章来自nginx document https://docs.nginx.com/nginx/admin-guide/monitoring/debugging/ nginx的故障排除和大多数程序一样, 可以通过gdb调试二进制文件, 增加debug日志,或者分析coredump文件方式解决。 配置nginx nginx 商业版本从Release8开始已经提供nginx-debug版本,使用这个版本直接在配置文件中将日志设置成debug级别即可。 error_log /var/log/nginx/error.log debug; 如果是开源版本, 需要增加**--with-debug**标识重新编译, 步骤如下 $nginx -V 2>&1 | grep arguments $./congfigure --with-debug <other configure arguments> $sudo make $sudo make install 调试符号 和大多数调试都需要增加调试符号,他可以提供除了内存地址以外的其他信息, 将可执行文件中的内存地址和如变量名称, 函数,类,数据结构,源码行数这些代码中的信息关联起来。 编译通过增加**-g**可以包含调试符号。 $ ./configure --with-debug --with-cc-opt='-O0 -g' Debug日志 当二进制支持debug日志后,还需要在配置文件中配置日志路径。日志可以存放到内存中, 标准输出中,或者指定的文件中。默认配置可以看到通过error_log变量指定到文件中。 $ cat /etc/nginx/nginx.conf $ error_log /var/log/nginx/error.log debug; 内存方式 配置 error_log memory:32m debug; 调试 $sudo gdb -p <pid> 将调试脚本拷贝到gdb中,按回车日志就会输出到 debug_log.txt文件中 set $log = ngx_cycle->log while $log->writer != ngx_log_memory_writer set $log = $log->next end set $buf = (ngx_log_memory_buf_t *) $log->wdata dump binary memory debug_log.txt $buf->start $buf_end 按CTRL+D 退出gdb可以查看日志内容。 ...

2022-05-01 · 2 min · 264 words

mysql error 1364 Field doesn't have a default values

问题描述 前一阵在做一个系统迁移工作, mysql数据库版本进行了升级, 数据库mariadb版本原有版本 5.5.56,升级后版本10.3.9. $ mysql -V or $ mysql > select version(); 升级后原有功能报1364错误, 原因由于数据库中的SQL mode 默认定义调整。 可以通过以下命令进行看出 $mysql -u -e "select @@sql_mode" mysql 5.7版本以后默认打开了打开了STRICT_TRANS_TABLES。 可以通过配置文件修改,设置为"“则为取消 [mysqld] sql-mode = "STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" 或者使用sql, 多个模式间的用逗号分割不能有空格。 >SET session sql_mode = 'modes...'; 立即生效设置当前session sql_mode sql_mode mysql 文档关于STRICT_TRANS_TABLES描述。 Strict SQL Mode Strict mode controls how MySQL handles invalid or missing values in data-change statements such as INSERT or UPDATE. A value can be invalid for several reasons. For example, it might have the wrong data type for the column, or it might be out of range. A value is missing when a new row to be inserted does not contain a value for a non-NULL column that has no explicit DEFAULT clause in its definition. (For a NULL column, NULL is inserted if the value is missing.) Strict mode also affects DDL statements such as CREATE TABLE. 严格模式控制MySQL如何处理数据如插入或更新中的无效值。例如,它可能具有错误的列数据类型,或者可能超出范围。当要插入的新行不包含一个非NULL列的值时,其定义中没有明确的默认子句。(对于null列,如果丢失了值,则将插入空。)严格模式还会影响诸如创建表之类的DDL语句. ...

2022-04-30 · 2 min · 348 words

git 常用命令

查看分支 git branch -av 导出分支 git remote add origin ssh://git@ip:port/branch.git git checkout -b localbranch origin/remotebranch 稀疏导出 git init <project> cd <project> git config core.sparsecheckout true echo "path1/" >> .git/info/sparse-checkout echo "path2/" >> .git/info/sparse-checkout git pull origin remotebranch 恢复误删除文件 git status git reset HEAD git checkout . non-fast-forward git fetch origin master git merge origin FETCH_HEAD 本地rebase导致non-fast-forward git reflog 查看HEAD的移动历史 git reset --hard xxxx 提交 git push origin localbranchname 参考及引用 图片 from 墨玉

2022-04-05 · 1 min · 72 words

Message-Based Load Balancing

最近工作中涉及到一些负载均衡一些知识这里今天这篇文章是F5的 Message-Based Load Balancing。 这是2009年发布的一篇文章,后续F5已经建议从MBLB迁移到MRP功能模块。 原文链接: https://www.f5.com/services/resources/white-papers/message-based-load-balancing Migrating MBLB Functionality to MRPF Functionality https://techdocs.f5.com/kb/en-us/products/big-ip_ltm/manuals/product/bigip-mblb-to-mrf-migration-12-0-0/2.html 在高可用可扩展性应用场景中,经常能看到负载均衡身影,有硬件设备也有软件实现,由于Web应用广泛应用负载平衡也变得更加适用于HTTP这些协议。 与HTTP不同也会有一些异步的协议:Diameter,RADIUS and SIP,由于大多数负载的设计针对同步消息传输环境,这使得原有的负载难以分发这些协议。 文中主要提到SIP协议的复杂性,SIP是一种基于文本的协议,它的语法和消息非常类似于HTTP协议,不同之处在于SIP不仅可以用TCP,也可以用UDP封装, 对移动业务支持比较好。 如果举一个更好理解的例子, 由于在金融机构工作,一些系统使用长连接异步的通讯方式,比如银联CUPS系统卡接口, 使用的是异步长链接模式,如何做到在前端接入和后端系统均为长连接情况下做到,报文级别的负载? 挑战 Asynchronous Messaging 异步消息 下面是同步场景,客户端发送一个请求同步等待一个响应。 下面是异步场景,客户端发送n个请求,服务端返回n个响应。 这种场景下没有明显的客户端服务端之分,可以看到右边的服务也可能主动发起请求到左边的服务。 Long-Lived Sessions 长连接 在传统负载中,每次会话或连接基础上完成。在同一会话中收到的所有请求都是相同服务器的负载平衡。当通信完成时,会话终止。 长连接场景中导致流量无法均匀分配到指定服务上。 Message-Oriented Communication 消息处理 传统负载均衡维护请求和服务器端连接之间的1:1关系, 针对这种异步长连接场景,就需要做到1:n。也就是需要将请求均匀发送到后端的服务上。这时候就需要区分服务边界,需要多报文进行标识处理。 这里文档中提到AVP, 对AVP的理解,就是报文的标识,也就是需要从报文中找到唯一能标识他的信息。 解决方案 也就是MBLB (Message-Based Load Balancing)。 MBLB使Big-IP LTM能够以交钥匙方式实现特定协议支持,同时仍通过iRules实现客户和环境特定的自定义。 可以看到他提取A报文中的AVP代码根据负载策略送到上面服务器, 提起B报文的AVP送到下面服务器。 总结 F5 TMOS架构提供了F5能够快速实现基于消息的协议, 保持通过iRules翻遍实现了各位异步并进行双向通信的协议适配。 参考及引用 文中图片来自原文 封面图片from 陳丁光

2022-04-01 · 1 min · 59 words

Tournament winner

问题 循环赛每个队对战所有其他对手, 胜利者记3分, 失败者记1分. 两个数组做为输入, competitions,存放主场队和客场队, results存放结果, 1表示主队获胜, 0表示客队获胜。返回分数最高的队伍。 解答 使用一个hash表,key为队伍名称, 值为累计分数。时间复杂度O(n) 循环赛的数量, 空间复杂度O(k), 参赛队数量。对应hash表需要的容量。 def tournamentWinner(competitions, results): currentBestTeam = "" scores = {currentBestTeam: 0} for idx, competition in enumerate(competitions): result = results[idx] homeTeam, awayTeam = competition winningTeam = homeTeam if result == 1 else awayTeam updateScores(winningTeam, 3 , scores) if scores[winningTeam] > scores[currentBestTeam]: currentBestTeam = winningTeam return currentBestTeam def updateScores(team, points, scores): if team not in scores: scores[team] = 0 scores[team] += points ...

2022-03-30 · 1 min · 78 words

vim putty gruvbox

putty 使用的是putty进行访问,可以使用gruvbox 提供的配色访问进行调整。 可以使用下面链接进去: https://github.com/morhetz/gruvbox-contrib/tree/master/putty 其他工具 如果使用是其他工具也可以找到对应的工具 https://github.com/morhetz/gruvbox-contrib 操作系统自带Vim 如果使用的操作系统自带Vim工具,可以下载下面工具编辑~/.vimrc $ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim $ cat ~/.vimrc 。。。 call plug#begin() Plug 'morhetz/gruvbox' call plug#end() 。。。 $ vi打开后 :PlugInstall grubbox提供的一些安装方法 https://github.com/morhetz/gruvbox/wiki/Installation 参考及引用 https://opensource.com/article/20/2/how-install-vim-plugins 图片from 江金倫 彰化縣-竹塘鄉-竹塘木棉道

2022-03-21 · 1 min · 38 words

ISO8583协议

背景介绍 在银行卡支付领域,经常提到“8583”, 他是金融机构中银行卡交易使用的一种内部协议。使用场景主要是终端如POS, ATM等金融终端到银行收单系统, 以及银行卡系统间。协议出现时期, 网络主要还是PSTN网络,电话拨号方式接入方式。考虑到带宽限制以及交易实时性要求,所以结构设计很紧凑,报文长度是1K左右,一般不会大于2K, 涉及数字的域还会采用BCD编码,从而减少报文长度。当然后续由于芯片卡应用,报文长度也有所增加。 银行卡的一些事 国际上最早的通用信用卡产生于20世纪50年代,1949年9月一天,纽约金融金融家麦克纳马拉与其好友布卢明代尔,在一家高档餐馆就餐,结账时发现现金不够,只好请其妻子来付款。这件事情给了麦克纳马拉重要启示,他和布卢明代尔一起策划了餐馆赊账网络, 发行一种可以记账的卡片,这就是大莱卡的开端。 受大莱卡的启发, 美国市场上出现了各种旅游娱乐卡, 美国运通公司凭借其遍布全球的旅行俱乐部及旅行者服务,后来居上最终成为旅游娱乐卡的领先者。 1951年,富兰克林银行在纽约长岛开始发行其首张信用卡,银行的主要收入来源是向零售商收取的5-7%的商户扣率, 持卡人无须支付任何直接费用。 1958年,美洲银行发行一种蓝、白、金三色组成,并带有飞鸽图案的银行卡,1976年,美洲银行卡公司更名为维萨(VISA)。 1966年, 一批银行家汇聚在美国的水牛城,召开了具有历史意义的第一次会议。并联合建立“同业银行卡协会”, 1979年银行卡协会更名为万事达卡国际组织,商标“MasterCard”。 1961年,日本信用卡株式会社(JCB)发行行用卡, 1981年开展国际业务。 2002年3月26日, 由国内80多家金融机构共同发起涉及的股份金融机构—中国银联成立。 注册资金16.5亿元人民币,总部设立在上海。 第一张人民币信用卡 1985年,中国银行珠海分行发行中国第一张人民币信用卡。 ISO 8583报文中包含信息 ISO8583报文格式 ISO 8583银行卡交换报文规范,目前的三个版本: IS08583:1987 IS08583:1993 IS08583:2003 3 个版本之间没有大的区别,主要字段长度和数据元素的变化 ISO 8583 做为通用标准被采用,同时存在一些保留字段可用于存放自定义字段。 ISO8583报文格式 各个域包含卡片信息,商户信息,交易信息 每个域都有自己的含义和语法 各个字段格式包括:数字、字母数字、固定或者可变长 ISO8583报文样例 一笔银行卡消费为例:MTI 0100 + 第三域的 000000 初步判断为一笔银行卡授权交易,一般是信用卡消费,当让根据这两个域的有多种组合,可以代表多种交易。 01 00 30 20 05 00 20 C0 10 1C 00 00 00 00 00 00 00 99 80 00 00 01 00 21 00 03 37 62 14 02 10 00 07 41 50 78 d1 56 07 12 20 10 00 00 00 00 31 32 33 34 35 36 37 38 30 34 33 20 20 20 20 20 20 20 20 20 20 20 20 c5 8e b2 00 18 03 1e 9a 00 06 30 30 30 30 30 31 00 06 30 30 30 30 30 30 00 06 30 30 30 30 30 31 01 00 报文类型标识符 格式:n4 内容:0100 位图:根据位图按照每个域指定的格式进行解析即可 ...

2022-03-19 · 2 min · 265 words

centos8 yum 相关国内镜像仓库弃用(deprecated)

今天centos8使用yum安装软件时报错。 - Curl error (28): Timeout was reached for http://mirrors.aliyuncs.com/centos/8/BaseOS/x86_64/os/repodata/repomd.xml [Connection timed out after 30001 milliseconds] - Status code: 404 for https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/repodata/repomd.xml (IP: 42.81.213.224) 查看一下:https://mirrors.aliyun.com/centos/8/readme This directory (and version of CentOS) is deprecated. 由于只是安装tcpdump,目前临时解决方案调整了一下安装源。 # echo "8-stream" > /etc/yum/vars/releasever # yum clean all # yum makecache 如果未使用国内镜像也可以手工更新到 vault.centos.org 镜像地址 # cd /etc/yum.repos.d/ # sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* # sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* # yum update -y 镜像地址更新成功后可以升级到centos stream。 # dnf install centos-release-stream -y --allowerasing # dnf distro-sync -y 更详细可以参考引用链接 ...

2022-02-03 · 1 min · 91 words

centos8 过滤 syslog信息

服务器(centos8)在用户登录的时候会出现一些登录日志。 example.com systemd[1]: Started /run/user/0 mount wrapper. example.com systemd[1]: Created slice User Slice of UID 0. example.com systemd[1]: Starting User Manager for UID 0... example.com systemd[1]: Started Session 51 of user root. example.com systemd[20871]: Starting D-Bus User Message Bus Socket. example.com systemd[20871]: Reached target Timers. example.com systemd[20871]: Reached target Paths. example.com systemd[20871]: Listening on D-Bus User Message Bus Socket. example.com systemd[20871]: Reached target Sockets. example.com systemd[20871]: Reached target Basic System. example.com systemd[20871]: Reached target Default. example.com systemd[20871]: Startup finished in 51ms. example.com systemd[1]: Started User Manager for UID 0. example.com systemd[1]: session-51.scope: Succeeded. example.com systemd[1]: Stopping User Manager for UID 0... example.com systemd[20871]: Stopped target Default. example.com systemd[20871]: Stopped target Basic System. example.com systemd[20871]: Stopped target Sockets. example.com systemd[20871]: Stopped target Paths. example.com systemd[20871]: dbus.socket: Succeeded. example.com systemd[20871]: Closed D-Bus User Message Bus Socket. example.com systemd[20871]: Reached target Shutdown. example.com systemd[20871]: Starting Exit the Session... example.com systemd[20871]: Stopped target Timers. example.com systemd[1]: user@0.service: Killing process 20967 (systemctl) with signal SIGKILL. example.com systemd[1]: user@0.service: Succeeded. example.com systemd[1]: Stopped User Manager for UID 0. example.com systemd[1]: Stopping /run/user/0 mount wrapper... example.com systemd[1]: Removed slice User Slice of UID 0. example.com systemd[1]: run-user-0.mount: Succeeded. example.com systemd[1]: user-runtime-dir@0.service: Succeeded. example.com systemd[1]: Stopped /run/user/0 mount wrapper. 通过下面命令生成rsyslog的过滤规则; echo 'if $programname == "systemd" and ($msg contains "Started /run/$msg" or $msg contains "Starting Session" or $msg contains "Started Session" or $msg contains "Created slice User" or $msg contains "Starting User Manager" or $msg contains "Starting User" or $msg contains "Starting D-Bus" or $msg contains "Reached target" or $msg contains "Listening on D-Bus" or $msg contains "Startup finished" or $msg contains "session-" or $msg contains "Stopping User Manager" or $msg contains "Stopped target" or $msg contain "dbus.socket" or $msg contains "Stopped target " or $msg contains "Removed session" or $msg contains "Removed slice User Slice of" or $msg contains "Stopped /run/user" or $msg contains "Stopped User Manager" or $msg contains "Stopping User Slice of" ) then stop' >/etc/rsyslog.d/ignore-systemd-session-slice.conf 根据实际情况, 新增相关过滤规则即可 ...

2022-01-02 · 2 min · 341 words

C++ pointers 和reference

Pointer 和 references 主要区别 reference:总代表一个对象, 没有null reference;pointer则没有限制,可以为null poiner可以被重新赋值; reference不可以被重新赋值。 应用场景 如果在不同时间指向不同对象则使用pointer, 如果一旦代表该对象就不能改变选择reference. 相关代码: 使用reference更富效率, 如下面的例子,不需要测试rd的值,他代表某一个double void printDouble(const double &rd) { cout << rd; } 而如果用pointers,那么就得测试下他是否为null。 void printDouble(const double *pd) { if (pd) { cout << *pd; } } 其他: 当然也有例外, 比如leveldb中就可以看到一下issue,DB::Get API should use reference instead of pointer #140 可以看到在下面一段描述,这里主要讨论关于函数参数使用引用还是指针。 Original issue 134 created by jvb127 on 2013-01-03T06:36:56.000Z: The current DB::Get API is defined as: virtual Status Get(const ReadOptions& options, const Slice& key, std::string* value) = 0; However, 'value' is not an optional parameter - it should point to a valid std::string. This is not checked by the implementation It could be considered to use a reference rather than a pointer: virtual Status Get(const ReadOptions& options, const Slice& key, std::string& value) = 0; 可以看到在google早些年的开发指南中,使用指针定义参数列表的参数和引用,通过const区分输入,输出参数。 ...

2021-10-25 · 2 min · 267 words