# NetHalt - NSIS installer script
# Copyright (C) 2008 Daniel Collins <solemnwarning@solemnwarning.net>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of the author nor the names of its contributors may
# be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
!include MUI2.nsh
!include LogicLib.nsh
!include nsDialogs.nsh
Name "NetHalt"
OutFile "nhclient.exe"
InstallDir $PROGRAMFILES\NetHalt
InstallDirRegKey HKLM "SOFTWARE\NetHalt" "InstallDir"
!define MUI_ABORTWARNING
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "COPYING"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Function .onInit
nsisos::osversion
${If} $0 < 5
MessageBox MB_OK "Windows 2000 (NT 5.0) or greater is required"
Abort
${EndIf}
FunctionEnd
# Do local install
#
Section "NetHalt"
SetShellVarContext all
SetOutPath $INSTDIR
# Stop all running nhtray.exe processes
#
StrCpy $0 "nhtray.exe"
KillProc::KillProcesses
# Check if the NetHalt service is installed
#
SimpleSC::ExistsService "nhclient"
Pop $0
# Stop+Remove the NetHalt service if it's installed
#
${If} $0 == 0
DetailPrint "Stopping NetHalt Client service..."
SimpleSC::StopService "nhclient"
DetailPrint "Removing NetHalt Client service..."
SimpleSC::RemoveService "nhclient"
${EndIf}
WriteRegStr HKLM "SOFTWARE\NetHalt" "InstallDir" $INSTDIR
cinst::reg_write "dword" "SOFTWARE\NetHalt" "use_server" "0"
cinst::reg_write "string" "SOFTWARE\NetHalt" "server_name" ""
cinst::reg_write "dword" "SOFTWARE\NetHalt" "server_port" "0"
cinst::reg_write "dword" "SOFTWARE\NetHalt" "server_refresh" "1800"
cinst::reg_write "dword" "SOFTWARE\NetHalt" "warning" "300"
cinst::reg_write "dword" "SOFTWARE\NetHalt" "abort" "0"
cinst::reg_write "dword" "SOFTWARE\NetHalt" "delay" "0"
cinst::reg_write "string" "SOFTWARE\NetHalt" "sdtimes" ""
WriteUninstaller "$INSTDIR\uninstall.exe"
File "src\nhclient.exe"
File "src\evlog.dll"
File "src\nhtray.exe"
File "src\nhconfig.exe"
# Add the event log source (evlog.dll) to the registry
#
WriteRegStr HKLM "SYSTEM\CurrentControlSet\Services\Eventlog\Application\NetHalt Client" "EventMessageFile" "$INSTDIR\evlog.dll"
WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\Eventlog\Application\NetHalt Client" "TypesSupported" 0x00000007
# Add the uninstaller to Add/Remove programs
#
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt" "DisplayName" "NetHalt"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt" "UninstallString" "$INSTDIR\uninstall.exe"
WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt" "NoModify" 1
WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt" "NoRepair" 1
# Install and start the NetHalt service
# TODO: Check for errors
#
DetailPrint "Installing NetHalt Client service..."
SimpleSC::InstallService "nhclient" "NetHalt Client" "16" "2" "$INSTDIR\nhclient.exe" "" "" ""
DetailPrint "Starting NetHalt Client service..."
SimpleSC::StartService "nhclient"
# Add nhtray.exe to the registry to run at login
#
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "NetHalt" "$INSTDIR\nhtray.exe"
# Launch nhtray.exe
#
Exec '"$INSTDIR\nhtray.exe"'
# Create shortcuts
#
CreateDirectory "$SMPROGRAMS\NetHalt"
CreateShortCut "$SMPROGRAMS\NetHalt\Tray Icon.lnk" "$INSTDIR\nhtray.exe"
CreateShortCut "$SMPROGRAMS\NetHalt\Configuration.lnk" "$INSTDIR\nhconfig.exe"
CreateShortCut "$SMPROGRAMS\NetHalt\Uninstall.lnk" "$INSTDIR\uninstall.exe"
SectionEnd
Function un.onInit
SetShellVarContext all
ReadRegStr $INSTDIR HKLM "SOFTWARE\NetHalt" "InstallDir"
MessageBox MB_YESNO "This will uninstall NetHalt, continue?" IDYES NoAbort
Abort
NoAbort:
FunctionEnd
Section "Uninstall"
# Stop and remove the NetHalt service
#
DetailPrint "Stopping NetHalt Client service..."
SimpleSC::StopService "nhclient"
DetailPrint "Removing NetHalt Client service..."
SimpleSC::RemoveService "nhclient"
# Stop all running nhtray.exe processes
#
StrCpy $0 "nhtray.exe"
KillProc::KillProcesses
# Delete shortcuts
#
Delete "$SMPROGRAMS\NetHalt\Tray Icon.lnk"
Delete "$SMPROGRAMS\NetHalt\Configuration.lnk"
Delete "$SMPROGRAMS\NetHalt\Un-Install.lnk"
Delete "$SMPROGRAMS\NetHalt"
DeleteRegValue HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "NetHalt"
DeleteRegKey HKLM "SYSTEM\CurrentControlSet\Services\Eventlog\Application\NetHalt Client"
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt"
Delete "$INSTDIR\nhclient.exe"
Delete "$INSTDIR\evlog.dll"
Delete "$INSTDIR\nhtray.exe"
Delete "$INSTDIR\uninstall.exe"
RMDir $INSTDIR
SectionEnd
分类目录归档:Tools
NSIS实现安装前先停止并卸载旧版
以下脚本会先找到正在运行的程序和服务,停止并删除服务,然后杀掉正在运行的程序进程
;检查服务是否存在
SimpleSC::ExistsService "${SVCHOST_EXE_NAME}"
Pop $0
;停止并删除服务
${If} $0 == 0
DetailPrint "停止正在运行的打印服务"
SimpleSC::StopService "${SVCHOST_EXE_NAME}" 1 30
DetailPrint "删除已安装的打印服务"
SimpleSC::RemoveService "${SVCHOST_EXE_NAME}"
${EndIf}
;检查主程序是否运行,如果正在运行则进行终止
nsProcess::_FindProcess "${ANALYST_EXE_NAME}"
Pop $R0
${If} $R0 = 0
DetailPrint "停止正在运行的主程序"
nsProcess::_KillProcess "${ANALYST_EXE_NAME}"
Pop $R0
${EndIf}
;检查升级程序是否运行,如果正在运行则进行终止
nsProcess::_FindProcess "${UPDATE_EXE_NAME}"
Pop $R0
${If} $R0 = 0
DetailPrint "停止正在运行的升级程序"
nsProcess::_KillProcess "${UPDATE_EXE_NAME}"
Pop $R0
${EndIf}
JSON、BSON及Protocol Buffer比较
他们核心区别在于,bson在json基础上增加了数据日期、文档类型,并支持二进制传输;而protocol buffer则对传输数据和结构定义进行了分离。一般来说与浏览器通信通常使用json,如果需要跨语言通信,且考虑效率,则可以采用protocol buffer。
JSON
特点:
文本存储和传输,结构与数据一体,肉眼可识别
优点:
- 通用性好,各种语言都支持;
- 可用于存储
缺点:
- 采用文本传输,占用体积大,传输性能差
- 序列化,反序列化性能较差
- 不支持二进制,日期等数据类型
Bson
特点:
采用二进制传输,结构与数据一体
优点:
- 在json基础上增加二进制和日期等格式;
- 传输性能较好
- 序列化,反序列化性能较好
缺点:
- 多语言支持一般
- 传输数据与结构定义仍然在一体
Protocol Buffer
特点:
结构定义与传输数据分离,只传输二进制数据
优点:
- 用protoc工具可以根据proto文件生成各种语言对应代码
- 字段被编号,新添加的字段不影响老结构,解决了向后兼容问题。
- 二进制无结构消息,效率高,性能高。
缺点:
- 二进制格式,可读性差(抓包dump后的数据很难看懂)
- 默认不具备动态特性
NSIS递归添加和删除子目录及文件
NSIS打包比较配置文件手动编辑起来非常麻烦,使用HM NIS EDIT
向导的话就容易多了。
添加目录以及子目录文件
File /r "bin\Release\*.*"
删除目录以及子目录
RMDir /r "$INSTDIR"
参考
WSL不支持systemctl与service命令解决办法(ubuntu/arch/manjaro等)
ubuntu-wsl2-systemd-script(适用ubuntu)
sudo apt install git
git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
bash ubuntu-wsl2-systemd-script.sh
genie(适用arch/manjaro/centos等)
yay dotnet
yay -S genie-systemd
ubuntu使用国内源
sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
sudo apt update -y
启用适用于 Linux 的 Windows 子系统
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
更新到 WSL 2
要求
- 对于 x64 系统: 版本 1903 或更高版本,采用 内部版本 18362 或更高版本。
- 对于 ARM64 系统: 版本 2004 或更高版本,采用 内部版本 19041 或更高版本。
- 低于 18362 的版本不支持 WSL 2。 使用 Windows Update 助手更新 Windows 版本。
若要检查 Windows 版本及内部版本号,选择 Windows 徽标键 + R,然后键入“winver”,选择“确定”。 (或者在 Windows 命令提示符下输入 ver 命令)。 更新到“设置”菜单中的最新 Windows 版本。
启用虚拟机功能
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
下载 Linux 内核更新包
将 WSL 2 设置为默认版本
wsl --set-default-version 2
安装所选的 Linux 分发
打开 Microsoft Store,并选择你偏好的 Linux 分发版。
安装 Windows 终端 (可选)
https://docs.microsoft.com/zh-cn/windows/terminal/get-started
参考
php redis连接数过多解决办法(Yii,predis,phpredis等)
Yii redis 持久配置
'redis' => [
'class' => 'yii\redis\Connection',
'hostname' => '127.0.0.1',
'retries' => 3,
'port' => 6379,
'password' => '',
'socketClientFlags' => STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT,
],
predis redis 持久配置
$client = new \Predis\Client([
'scheme' => 'tcp',
'host' => $redis->hostname,
'port' => $redis->port,
'password' => $redis->password,
'persistent'=>true,
]);
phpredis redis 持久配置
$redis->pconnect('127.0.0.1', 6379);
nginx/python/mysql/fpm/go连接数解决办法
使用MSYS2+mingw+QT作为C++开发环境
下载msys2
在清华大学大学镜像站点https://mirrors.tuna.tsinghua.edu.cn/msys2/distrib/
下载最新版32(i686)/64(x86_64)位系统msys2
下载后安装
pacman 的配置
msys2采用pacman管理软件包,修改pacman的软件源提高下载速度
编辑 /etc/pacman.d/mirrorlist.mingw32 ,在文件开头添加:
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686
编辑 /etc/pacman.d/mirrorlist.mingw64 ,在文件开头添加:
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64
编辑 /etc/pacman.d/mirrorlist.ucrt64 ,在文件开头添加:
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/ucrt64
编辑 /etc/pacman.d/mirrorlist.clang64 ,在文件开头添加:
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/clang64
编辑 /etc/pacman.d/mirrorlist.msys ,在文件开头添加:
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch
然后执行 pacman -Sy 刷新软件包数据即可。
pacman -Sy
安装开发环境
安装基本开发环境和常用工具
pacman -S base-devel git wget p7zip perl ruby python
安装 32位 MinGW-w64
pacman -S mingw-w64-i686-toolchain
安装 64位 MinGW-w64
pacman -S mingw-w64-x86_64-toolchain
安装Qt5和Qt Creator
pacman -S mingw64/mingw-w64-x86_64-qt5 mingw64/mingw-w64-x86_64-qt-creator
参考
GlitchTip – 开源的Sentry API兼容的错误跟踪系统
GlitchTip is an open source, Sentry API compatible error tracking platform. It is a partial fork/partial reimplementation of Sentry’s open source codebase before it went proprietary. Its goals are to be a modern, easy-to-develop error tracking platform that respects your freedom to use it any way you wish. Some differences include:
A modern development environment with Python 3 and Django 3.1.
Simplicity over features. We use Postgres to store error data. Our code base is a fraction of the size of Sentry and looks like a typical Django app. We leverage existing open source Django ecosystem apps whenever possible.
Respects your privacy. No massive JS bundles. No invasive tracking. No third party spying. Even our marketing site runs Matomo and respects Do Not Track. GlitchTip will never report home. We will never know if you run it yourself.
Commitment to open source. We use open source tools like GitLab whenever possible. With our MIT license, you can use it for anything you’d like and even sell it. We believe in competition and hope you make GlitchTip even better.
Project status: Stable. Open an issue and say hello if you’d like to help. We are able to process basic error requests from the open source Sentry client tools. More features are on the way.
参考
PHP AMQP 使用指南
为什么要使用消息队列?
提速
使用了消息队列,生产者一方,把消息往队列里一扔,就可以立马返回,响应用户了。无需等待处理结果。
处理结果可以让用户稍后自己来取,如医院取化验单。也可以让生产者订阅(如:留下手机号码或让生产者实现listener接口、加入监听队列),有结果了通知。获得约定将结果放在某处,无需通知。
解耦
考虑电商系统下订单,发送数据给生产系统的情况。电商系统和生产系统之间的网络有可能掉线,生产系统可能会因维护等原因暂停服务。如果不使用消息队列,电商系统数据发布出去,顾客无法下单,影响业务开展。两个系统间不应该如此紧密耦合。应该通过消息队列解耦。同时让系统更健壮、稳定。
消除峰值
消息存在队列中,等待高峰期过后再处理
广播
多个客户端可以订阅同一个TOPIC,或者多个worker轮询并发执行任务
CentOS 安装 RabbitMQ
安装并启动rabbitmq
yum install rabbitmq-server
systemctl start rabbitmq-server
systemctl status rabbitmq-server
systemctl enable rabbitmq-server
rabbitmq-plugins enable rabbitmq_management
启动管理后台插件
rabbitmq-plugins enable rabbitmq_management
添加管理账户
rabbitmqctl add_user admin password
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
开启端口
amqp端口是 5672 , 管理后台是 15672
RabbitMQ management API
https://rawcdn.githack.com/rabbitmq/rabbitmq-management/v3.8.9/priv/www/api/index.html
可以通过API管理RabbitMQ服务器
PHP的amqp扩展
php-amqplib 纯PHP库
https://github.com/php-amqplib/php-amqplib
composer 安装
composer require php-amqplib/php-amqplib
perl c扩展
https://pecl.php.net/package/amqp
linux 编译安装
pecl install amqp
centos yum remi库安装
yum install php74-php-pecl-amqp
windows dll 安装
https://pecl.php.net/package/amqp
下载后php_amqp.dll放到ext目录,rabbitmq.4.dll放在php目录,修改php.ini添加extension=php_amqp.dll
使用AMQP
https://www.rabbitmq.com/tutorials/tutorial-one-php.html