Clash Party 桌面客户端打包指南:从源码到全平台安装包

1. 项目概览 clash-party(https://github.com/zdltech8989/clash-party)是一套 Electron + Vue3(或 React) 的跨平台桌面客户端,用来可视化管理 Clash(代理)规则、订阅等功能。 项目的目录结构大致如下(以官方仓库为准): clash-party/ ├─ public/ # 静态资源(图标、网页入口文件等) ├─ src/ # 前端代码(Vue/React + TypeScript) │ ├─ renderer/ # 渲染进程(UI) │ └─ main/ # 主进程(Electron 主入口) ├─ build/ # 打包脚本、electron-builder 配置 ├─ electron-builder.yml # electron‑builder 配置文件 ├─ package.json └─ ... # 其他 核心技术栈 Electron(负责创建跨平台的原生窗口、系统托盘、文件系统 API) Vite / Webpack(编译前端资源) electron‑builder(把 Electron 项目打包成 Windows .exe、macOS .dmg/.pkg、Linux .AppImage/.deb/.rpm 等可分发文件) 下面会一步步讲解 如何把源码编译并打包成可运行的桌面客户端,并分别说明在 Windows、macOS、Linux 三个平台上需要的工具与注意事项。 2. 打包前的准备工作 环境 必装软件 说明 通用 - Node.js ≥ 18(LTS) - npm(或 yarn、pnpm) - Git 项目本身的依赖管理与构建脚本都基于 Node。 Windows 本机打包 - Windows 10/11 - VS Build Tools(包含 windows-build-tools) - (可选) wine 用来在 Linux 上交叉编译 Windows Electron‑builder 会调用 nsis 生成安装程序,需要本机或交叉的 wine。 macOS 本机打包 - macOS 12+(推荐最新) - Xcode Command Line Tools (xcode-select --install) 生成 .dmg/.app 需要 codesign 与 productsign,如果要做 notarization(苹果公证),还需要 Apple Developer 账号并配置 APPLE_ID、APPLE_APP_SPECIFIC_PASSWORD 环境变量。 Linux 本机打包 - Ubuntu 22.04 / Debian 12 / Fedora 39 等(64‑bit) - fakeroot、dpkg、rpm、snapcraft(取决于要生成的包格式) Linux 打包相对直接,只要系统支持对应的打包工具。 交叉编译(可选) - wine(Linux → Windows) - electron-builder 内置的 electron-osx-zip(macOS 包必须在 macOS 环境下生成) Linux/macOS 可以用 wine 生成 Windows 安装包;但 macOS 包只能在 macOS 上生成(除非使用 CI/CD/macOS 虚拟机)。 Tip:如果你只想快速生成可执行文件而不在意安装器(.exe、.dmg),可以直接使用 electron-builder 的 --dir 选项生成 “解压即用”(portable) 的文件夹。 ...

2026年5月30日 · 5 分钟 · 天边的星星

在Centos7上使用YUM升级更新Git版本(Git 2.x )

网站在部署到服务器的这个过程,有时候会非常麻烦,以前SEO禅都是用FTP或者用rsync命令,现在因为Github私有仓库免费了,就直接使用Git来部署,修改后的源码只要Push到仓库里,再在服务器Pull下来,别说有多方便有多爽了,要是再使用Docker去部署服务器程序,那就是分分种搞定网站部署的事,以前要部署一个网站少说要个把小时,这篇文章主要是分享下在阿里云的ECS服务器如何更新Git到2.x版本。 更新方法 默认在Centos上使用YUM命令安装的Git版本是1.8x,在使用的时候会有些问题,有很多种更新办法,这里只分享最简单方便的一种,先运行如下命令看看Git的版本信息: `git --version git version 1.8.3.1 ` 如果这不是你想要的版本,那我们第一步要做的就是先移除Git,运行如下命令: `sudo yum remove git* ` 之后安装相关的RPM仓库,运行如下命令: `sudo yum -y install https://packages.endpoint.com/rhel/7/os/x86_64/endpoint-repo-1.7-1.x86_64.rpm ` 再重新安装一遍Git,运行如下命令: `sudo yum install git ` 当出现提示的时候,输入y,完成安装 再看看安装后的Git版本: `git --version `

2021年10月9日 · 1 分钟 · 天边的星星

ab命令使用

ab安装 ab 是什么? Apache Benchmark(简称ab) 是Apache安装包中自带的压力测试工具 ,简单易用。 使用起来非常的简单和方便。 安装ab 可以通过安装apche web服务器,apache web服务器默认带有ab命令 centOS7 下的安装yum -y install httpd-tools 使用 `#使用:-n 表示请求数,-c 表示并发数. ab -n 100 -c 10 http://www.baidu.com/s #返回内容: ​ Server Software: BWS/1.1 ##服务器软件和版本 Server Hostname: www.baidu.com ##请求的地址/域名 Server Port: 80 ##端口 Document Path: /s ##请求的路径 Document Length: 112435 bytes ##页面数据/返回的数据量 Concurrency Level: 10 ##并发数 Time taken for tests: 4.764 seconds ##共使用了多少时间 Complete requests: 100 ##请求数 Failed requests: 99 ##失败请求 百度为什么失败这么多,应该是百度做了防范 (Connect: 0, Receive: 0, Length: 99, Exceptions: 0) Total transferred: 11342771 bytes ##总共传输字节数,包含http的头信息等 HTML transferred: 11247622 bytes ##html字节数,实际的页面传递字节数 Requests per second: 20.99 [#/sec] (mean) ##每秒多少请求,这个是非常重要的参数数值,服务器的吞吐量 Time per request: 476.427 [ms] (mean) ##用户平均请求等待时间 Time per request: 47.643 [ms] (mean, across all concurrent requests) ##服务器平均处理时间,也就是服务器吞吐量的倒数 Transfer rate: 2325.00 [Kbytes/sec] received ##每秒获取的数据长度 ​ Connection Times (ms) min mean[+/-sd] median max Connect: 22 41 12.4 39 82 ##连接的最小时间,平均值,中值,最大值 Processing: 113 386 211.1 330 1246 ##处理时间 Waiting: 25 80 43.9 73 266 ##等待时间 Total: 152 427 210.1 373 1283 ##合计时间 ​ Percentage of the requests served within a certain time (ms) 50% 373 ## 50%的请求在373ms内返回 66% 400 ## 60%的请求在400ms内返回 75% 426 80% 465 90% 761 95% 930 98% 1192 99% 1283 100% 1283 (longest request) ` 参数介绍 `-n 即requests,用于指定压力测试总共的执行次数。 -c 即concurrency,用于指定的并发数。 -t 即timelimit,等待响应的最大时间(单位:秒)。 -b 即windowsize,TCP发送/接收的缓冲大小(单位:字节)。 -p 即postfile,发送POST请求时需要上传的文件,此外还必须设置-T参数。 -u 即putfile,发送PUT请求时需要上传的文件,此外还必须设置-T参数。 -T 即content-type,用于设置Content-Type请求头信息,例如:application/x-www-form-urlencoded,默认值为text/plain。 -v 即verbosity,指定打印帮助信息的冗余级别。 -w 以HTML表格形式打印结果。 -i 使用HEAD请求代替GET请求。 -x 插入字符串作为table标签的属性。 -y 插入字符串作为tr标签的属性。 -z 插入字符串作为td标签的属性。 -C 添加cookie信息,例如:"Apache=1234"(可以重复该参数选项以添加多个)。 -H 添加任意的请求头,例如:"Accept-Encoding: gzip",请求头将会添加在现有的多个请求头之后(可以重复该参数选项以添加多个)。 -A 添加一个基本的网络认证信息,用户名和密码之间用英文冒号隔开。 -P 添加一个基本的代理认证信息,用户名和密码之间用英文冒号隔开。 -X 指定使用的和端口号,例如:"126.10.10.3:88"。 -V 打印版本号并退出。 -k 使用HTTP的KeepAlive特性。 -d 不显示百分比。 -S 不显示预估和警告信息。 -g 输出结果信息到gnuplot格式的文件中。 -e 输出结果信息到CSV格式的文件中。 -r 指定接收到错误信息时不退出程序。 -h 显示用法信息,其实就是ab -help。 `

2021年6月22日 · 2 分钟 · 天边的星星

简单详细的Typora 流程图使用

1、横向流程图源码格式(mermaid) graph LR A[方形] -->B(圆角) B --> C{条件a} C -->|a=1| D[结果1] C -->|a=2| E[结果2] A-->F[横向流程图] G[横向流程图] 例如 graph LR A[方形] --> B(圆角) B --> C{条件a} C --> |a=1| D[结果1] C --> |a==2| E[结果2] A --> F[横向流程图] G[横向流程图] ### 2、竖向流程图源码格式(mermaid) > ``` `graph TD A[方形] --> B(圆角) B --> C{条件a} C --> |a=1| D[结果1] C --> |a=2| E[结果2] A --> F[竖向流程图]` 例如: `graph TD A[方形] --> B(圆角) B --> C{条件a} C --> |a=1| D[结果1] C --> |a=2| E[结果2] A --> F[竖向流程图] ` 3、标准流程图源码格式(flow) st=>start: 开始框:>https://www.baidu.com op=>operation: 处理框 cond=>condition: 判断框(是或否?) sub1=subroutine: 子流程 io=>inputoutput: 输入输出框 e=>end: 结束框 st->op->cond cond(yes)->io->e cond(no)->sub1(right)->op 例如: ...

2021年1月29日 · 3 分钟 · 天边的星星

Typora 流程图使用

Typora 流程图 ## Typora 流程图 1、横向流程图源码格式(mermaid) ``` x </div> <div class="CodeMirror-measure"> </div> <div style="position: relative; z-index: 1;"> </div> <div class="CodeMirror-code" role="presentation" style=""> <div class="CodeMirror-activeline" style="position: relative;"> <div class="CodeMirror-activeline-background CodeMirror-linebackground"> </div> <div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"> </div> ``` <span role="presentation" style="padding-right: 0.1px;">graph LR</span> </div> <div class="" style="position: relative;"> ``` A[方形] –>B(圆角) ...

2021年1月28日 · 5 分钟 · 天边的星星

按揭贷款的计算原理与java实现

题目描述: Mortgage Calculator – Calculate the monthly payments of a fixed term mortgage over given Nth terms at a given interest rate. Also figure out how long it will take the user to pay back the loan. 题目翻译: 按揭贷款计算器——在给定利率下,计算固定期限按揭贷款在第N期的月还款。同时计算用户需要多长时间来偿还贷款。 按揭贷款的相关概念(Mortgage) 什么是按揭贷款 抵押贷款是指提供私人资产作为债务担保进行借款,多发生于购买房地产时英航借出的抵押贷款。 抵押贷款的类型 抵押贷款的类型有多种,主要通过一下几个因素来定义抵押贷款的类型。 利率(interest) :分为固定利率和浮动利率 期限(Term) :按揭贷款通常拥有最大还款期限 还款数额与还款频率(Payment amount and frequency) :规定两次还款之间的时间间隔以及在每个周期内需要还款的数目 预付款(PrePayment):贷款方提前支付的预付款 还款方式 按揭贷款一般采用分期还款,在固定汇率的情况下,规定一个还款期限,然后每月按时还一定数额。 常见的两种还款方式:等额本息还款和等额本金还款 两种还款方案每月还款金额计算如下: 假定贷款的年利率为r,还款年限为Y年,贷款本金为P,每月还款金额为A 贷款的月利率R=r/12R=r/12, 还款期数为N=12YN=12Y 等额本息还款: 等额本息还款是指在还款时,每个月总的还款金额是相同的。每月所还本金和所还利息是变化的 假定第t个还款月还款后,剩余的总还款金额为 p(t)p(t).p(0)=Pp(1)=p(0)(1+R)−A=P(1+R)−Ap(2)=P(1)(1+R)−A=P(1+R)−A−A=P(1+R)2−(1+R)A−A…p(t)=P(1+R)t−A(1+R)t−1−A(1+R)t−2−…−A(1+R)−Ap(0)=Pp(1)=p(0)(1+R)−A=P(1+R)−Ap(2)=P(1)(1+R)−A=P(1+R)−A−A=P(1+R)2−(1+R)A−A…p(t)=P(1+R)t−A(1+R)t−1−A(1+R)t−2−…−A(1+R)−A我们可以得到每月还款后剩余还款金额p(t)p(t)的表达式:p(t)=P(1+R)t−A∑i=0t−1(1+R)i=P(1+R)t−A1−(1+R)t1−(1+R)=P(1+R)t−A(1+R)t−1Rp(t)=P(1+R)t−A∑i=0t−1(1+R)i=P(1+R)t−A1−(1+R)t1−(1+R)=P(1+R)t−A(1+R)t−1R我们给定的还款期数为N,也就是说p(N)=0p(N)=0,我们可以求出每月还款数额A。 由方程P(n)=P(1+R)N−A(1+R)N−1R=0P(n)=P(1+R)N−A(1+R)N−1R=0可以得到A=PR(1+R)N(1+R)N−1A=PR(1+R)N(1+R)N−1也就是说,如果采用等额本息的方式来还款,每月需要还款的数额为PR(1+R)N(1+R)N−1PR(1+R)N(1+R)N−1虽然每个月的还款数额相同,每月所还得利息和本金是变化的 第t+1个还款月需要还的利息i(t+1)i(t+1),为该月还款前的剩余还款金额p(t)p(t)乘以月利率Ri(t+1)=p(t)R=PR(1+R)t−A(1+R)t+A=(PR−A)(1+R)t+A=((PR−A)(1+R)t−1+A)(1+R)−A(1+R)+A=i(t)(1+R)−ARi(t+1)=p(t)R=PR(1+R)t−A(1+R)t+A=(PR−A)(1+R)t+A=((PR−A)(1+R)t−1+A)(1+R)−A(1+R)+A=i(t)(1+R)−AR因为(PR−A)<0(PR−A)<0,所以i(t)i(t)是关于t的减函数,也就是说每个月的还款金额中,利息所占的比重是降低的,而本金所占的比重是上升的 等额本金还款: 在等额本金还款方式中,每个月还款的本金是相同,但是每个月所还的利息不同,所以每个月的还款总金额是变化的。 每个月需要还得本金pr为总本金除以总的还款月数。pr=PNpr=PN每个月需要还得利息pi(t)pi(t) = (本金-已归还的本金之和)*每月利率pi(t)=(P−pr(t−1))R=−prAt+(A+P)R=−PRNt+(PN+P)Rpi(t)=(P−pr(t−1))R=−prAt+(A+P)R=−PRNt+(PN+P)R可以看到,每个月所还利息pi(t)pi(t)是关于t的减函数,说明每个月所还的利息是逐渐减少的。由于每个月所还的本金数额不变,所以每个月所还贷款总额是递减的。 ...

2021年1月18日 · 2 分钟 · 天边的星星

DNSMasq安装及使用

** <strong>域名系统**([英文](https://baike.baidu.com/item/英文):**D**omain **N**ame **S**ystem,[缩写](https://baike.baidu.com/item/缩写):**DNS**)是[互联网](https://baike.baidu.com/item/互联网)的一项服务。它作为将[域名](https://baike.baidu.com/item/域名)和[IP地址](https://baike.baidu.com/item/IP地址)相互[映射](https://baike.baidu.com/item/映射)的一个[分布式数据库](https://baike.baidu.com/item/分布式数据库),能够使人更方便地访问[互联网](https://baike.baidu.com/item/互联网)。DNS使用[TCP](https://baike.baidu.com/item/TCP)和[UDP](https://baike.baidu.com/item/UDP)[端口](https://baike.baidu.com/item/端口)53。当前,对于每一级域名长度的限制是63个字符,域名总长度则不能超过253个字符。 [域名系统_百度百科 (baidu.com)](https://baike.baidu.com/item/域名系统/2251573) DNSmasq [DNSmasq_百度百科 (baidu.com)](https://baike.baidu.com/item/DNSmasq/7811792) dnsmasq原理 dnsmasq提供DNS缓存和DHCP服务、Tftp服务功能。 作为域名解析服务器,dnsmasq可以通过缓存DNS请求来提供对访问过的网址的的连接速度; 作为DHCP服务器,dnsmasq可以用于为局域网电脑分配内网IP地址和提供路由; DNS和DHCP两个功能可以同时或分别单独实现,此处只做DNS的配置; 当接受到一个DNS请求时,Dnsmasq首先会查找/etc/hosts这个文件,然后查找/etc/resolv.conf中定义的外部DNS。所以说Dnsmasq是一个很不错的外部DNS中继。 ​ 配置dnsmasq为DNS缓存服务器,同时在/etc/hosts文件中加入本地内网解析,这样一来每当内网机器查询时就会优先查询hosts文件,这就等于将/etc/hosts共享给全内网机器使用,从而解决内网机器互相识别的问题。 使用场景 构建私有DNS。例如: 我们有这么一个使用场景,在公司内网开发及测试的时候,我们会把部署好的服务,部署好,然后发送服务对应的IP给开发或者测试人员,开发或者测试通过IP进行访问,但是当IP变的是,我们还要在通知一次,当我们在一台服务器上部署了很多的服务的时候,我们还要指定端口,随着服务的越来越多,发现我们维护IP也越来越多,需要记住的端口也越来越多,怎么办,有没有好的解决方法,可能有人说配置本机Host啊,让公司内外全员配置HOST,下次IP修改或者新增IP的的时候,大家在修改HOST文件,发现工作量还是没有少。有没有更好的方式呢?这时大家想到DNS,内外构建私有DNS,大家只要配置一次DNS,下次测试使用的时候,直接使用域名(域名没有在域名服务商没有注册也可以),感觉和线上使用没有区别。 安装与配置dnsmasq 安装 yum install dnsmasq -y systemctl start dnsmasq.service 启动 systemctl enable dnsmasq.service # 开机启动 netstat -lnp|grep dnsmasq 查看是否执行 如果没有netstat命令,需要安装 yum install net-tools vi /etc/resolv.dnsmasq 创建resolve.dnsmasq 文件 添加上游dns服务器地址 `nameserver 114.114.114.114 nameserver 8.8.8.8` 这个文件配置上游dns,要不可能有些有些内网打不开 vi /etc/dnsmasqhosts 创建dnsmasqhosts文件,这个是域名和服务ip的映射关系文件 `192.168.1.148 admin.5188888.com` vi /etc/dnsmasq.conf 编辑配置文件,把上面的两个文件配置到这个配置文件中 ...

2020年12月4日 · 2 分钟 · 天边的星星

配置查询Nginx中异常IP处理

很多时候会发现好多,异常流量,处理这些异常流量,通常是封禁IP `# deny_ip_o.sh 文件内容 #!/bin/bash max=500 #我们设定的最大值,当访问量大于这个值得时候,封锁 logdir=/opt/nginx/logs/access.log #nginx 访问日志文件路径 confdir=/opt/nginx/logs/nginx_deny.log #检测文件 test -e &lt;span class="katex math inline">{confdir} || touch&lt;/span>{confdir} port=443 drop_Ip="" #循环遍历日志文件取出访问量大于 500 的 ip for drop_Ip in &lt;span class="katex math inline">(tail -n500000&lt;/span>logdir | awk '{print &lt;span class="katex math inline">1}' | sort | uniq -c | sort -rn | awk '{if (&lt;/span>1>500) print &lt;span class="katex math inline">2}') do echo "&lt;/span>{drop_Ip}---&lt;span class="katex math inline">{drop_ip}" grep -q "&lt;/span>{drop_Ip}" &lt;span class="katex math inline">{confdir} && eg=1 || eg=0; if ((&lt;/span>{eg}==0 ));then iptables -I INPUT -p tcp --dport &lt;span class="katex math inline">{port} -s&lt;/span>{drop_Ip} -j DROP echo ">>>>> `date '+%Y-%m-%d %H%M%S'` - 发现攻击源地址 -> &lt;span class="katex math inline">{drop_Ip} " >> /opt/nginx/logs/nginx_deny.log #记录 log fi done #################################################################### #!/bin/bash #_日志位置 _log_Path="/data0/nginx/weblogs/" #_日志文件名称 _log_FileName="access_blog.kinggoo.com.log" #_要被屏蔽的ip访问端口,默认80 _port="80" _nginx_deny="/opt/webserver/nginx/conf/deny.conf" _nginx_bin="/opt/webserver/nginx/sbin/nginx" _logfilepath=&lt;/span>{_log_Path}&lt;span class="katex math inline">{_log_FileName} #初始化被禁ip变量 _drop_Ip="" #检测文件 test -e&lt;/span>{_nginx_deny} || touch &lt;span class="katex math inline">{_nginx_deny} for _drop_Ip in&lt;/span>( tail -n50000 "&lt;span class="katex math inline">{_logfilepath}" |awk '{print&lt;/span>1,&lt;span class="katex math inline">12}' |grep -i -v -E "google|yahoo|baidu|msnbot|FeedSky|sogou|WordPress" |awk '{print&lt;/span>1}'|sort|uniq -c|sort -rn |awk '{if(&lt;span class="katex math inline">1>1000)print ""&lt;/span>2""}' ); do grep -q "&lt;span class="katex math inline">{_drop_Ip}"&lt;/span>{_nginx_deny} && eg=1 || eg=0 ; if (( &lt;span class="katex math inline">{eg}==0 ));then echo "deny&lt;/span>{_drop_Ip};" >> &lt;span class="katex math inline">{_nginx_deny}&lt;/span>{_nginx_bin} -s reload iptables -I INPUT -p tcp -dport &lt;span class="katex math inline">{_port} -s&lt;/span>{_drop_Ip} -j DROP echo ">>>>> `date '+%Y-%m-%d %H%M%S'` - 发现攻击源地址 -> &lt;span class="katex math inline">{_drop_Ip} " >> /tmp/nginx_deny.log; echo "iptables -I INPUT -p tcp --dport&lt;/span>{_port} -s &lt;span class="katex math inline">{_drop_Ip} -j DROP" >> /tmp/nginx_deny.log fi done 使用 nginx 封锁 ... -封锁 IP #!/bin/bash max=500 #我们设定的最大值,当访问量大于这个值得时候,封锁 confdir=/usr/local/data/nginx/conf/blockip.conf #nginx 封锁配置文件路径 logdir=/usr/local/data/nginx/logs/access_huke88.log #nginx 访问日志文件路径 #检测文件 test -e&lt;/span>{confdir} || touch &lt;span class="katex math inline">{confdir} drop_ip="" #循环遍历日志文件取出访问量大于 500 的 ip for drop_ip in&lt;/span>(cat &lt;span class="katex math inline">logdir | awk '{print&lt;/span>1}' | sort | uniq -c | sort -rn | awk '{if (&lt;span class="katex math inline">1>500) print&lt;/span>2}') do grep -q "&lt;span class="katex math inline">{drop_Ip}"&lt;/span>{confdir} && eg=1 || eg=0; if (( &lt;span class="katex math inline">{eg}==0 ));then echo "deny&lt;/span>{drop_Ip};">>&lt;span class="katex math inline">confdir #把“ deny IP ;”语句写入封锁配置文件中 echo ">>>>> `date '+%Y-%m-%d %H%M%S'` - 发现攻击源地址 ->&lt;/span>{drop_Ip} " >> /usr/local/data/nginx/logs/nginx_deny.log #记录 log fi done service nginx reload -解锁 IP #!/bin/bash sed -i 's/^/#&/g' /usr/local/nginx/conf/blockip.conf #把 nginx 封锁配置文件中的内容注释掉 service nginx reload #重置 nginx 服务,这样就做到了解锁 IP 使用 iptables 封锁 ... -封锁 IP 脚本 #!/bin/bash max=500 #我们设定的最大值,当访问量大于这个值得时候,封锁 logdir=/usr/local/data/nginx/logs/access_huke88.log #nginx 访问日志文件路径 confdir=/usr/local/data/nginx/conf/blockip.conf #nginx 封锁配置文件路径 #检测文件 test -e &lt;span class="katex math inline">{confdir} || touch&lt;/span>{confdir} port=80 drop_ip="" #循环遍历日志文件取出访问量大于 500 的 ip for drop_ip in &lt;span class="katex math inline">(cat&lt;/span>logdir | awk '{print &lt;span class="katex math inline">1}' | sort | uniq -c | sort -rn | awk '{if (&lt;/span>1>500) print &lt;span class="katex math inline">2}') do grep -q "&lt;/span>{drop_Ip}" &lt;span class="katex math inline">{confdir} && eg=1 || eg=0; if ((&lt;/span>{eg}==0 ));then iptables -I INPUT -p tcp --dport &lt;span class="katex math inline">{port} -s&lt;/span>{drop_Ip} -j DROP echo ">>>>> `date '+%Y-%m-%d %H%M%S'` - 发现攻击源地址 -> &lt;span class="katex math inline">{drop_Ip} " >> /usr/local/data/nginx/logs/nginx_deny.log #记录 log fi done ... 加入计划任务每五分钟执行一次 chmod +x /home/scripts/deny_ip.sh #####nginx 封 ip###### */5 * * * * /bin/sh /home/scripts/deny_ip.sh >/dev/null 2>&1 ### 添加定时任务 */5 * * * * /bin/sh /opt/nginx/logs/deny_ip_o.sh >/dev/null 2>&1 tail -n 500000 access.log | awk '{print&lt;/span>1,&lt;span class="katex math inline">13,&lt;/span>8}'|awk '{print &lt;span class="katex math inline">1}'|sort|uniq -c |sort -rn | awk '{if(&lt;/span>1>100)print "deny "&lt;span class="katex math inline">1,&lt;/span>2";"}' tail -n 500000000 access.log | awk '{print &lt;span class="katex math inline">1,&lt;/span>13,&lt;span class="katex math inline">8}'|awk '{print&lt;/span>1}'|sort|uniq -c |sort -rn | awk '{if(&lt;span class="katex math inline">1>100)print "deny "&lt;/span>2";"}' > blockip.conf tail -n 500000 access.log | awk '{print &lt;span class="katex math inline">1,&lt;/span>13,&lt;span class="katex math inline">8}'|awk '{print&lt;/span>1}'|sort|uniq -c |sort -rn | awk '{if(&lt;span class="katex math inline">1>100)print "deny "&lt;/span>2";"}' >> blockip.conf #if (&lt;span class="katex math inline">http_referer ~* "top1top1.top") { # rewrite ^/ http://top.top1top1.top/CallHelper/client/main.jsp; #} if (&lt;/span>http_referer ~* "top1top1.top") { return 404; } if (&lt;span class="katex math inline">http_referer ~* "shandiandxshop.xyz"){ rewrite ^/ http://tt.shandiandxshop.xyz/CallHelper/client/index.jsp; } https:&#47;&#47;blog.csdn.net/qq_41018743/article/details/105491785 http://www.siwei.me/blog/posts/linux-nginx-ip-ip #################################################################### #!/bin/bash num=100 # 每秒某个ip的访问上限 list=`netstat -an |grep ^tcp.*:80|egrep -v 'LISTEN|127.0.0.1'|awk -F"&#91; ]+|&#91;:]" '{print&lt;/span>6}'|sort|uniq -c|sort -rn|awk '{if (&lt;span class="katex math inline">1>&lt;/span>num){print &lt;span class="katex math inline">2}}'` for i in&lt;/span>list do iptables -I INPUT -s &lt;span class="katex math inline">i --dport 80 -j DROP echo ">>>>> `date '+%Y-%m-%d %H%M%S'` - 发现攻击源地址 ->&lt;/span>{&lt;span class="katex math inline">i} " >> /opt/nginx/logs/nginx_deny80.log #记录 log done ##################################################################### #!/bin/bash num=100 list=`netstat -an |grep ^tcp.*:80|egrep -v 'LISTEN|127.0.0.1'|awk -F"&#91; ]+|&#91;:]" '{print&lt;/span>6}'|sort|uniq -c|sort -rn|awk '{if (&lt;span class="katex math inline">1>&lt;/span>num){print &lt;span class="katex math inline">2}}'` for i in&lt;/span>list do iptables -I INPUT -p tcp --dport 80 -s &lt;span class="katex math inline">{i} -j DROP echo ">>>>> `date '+%Y-%m-%d %H%M%S'` - 发现攻击源地址 ->&lt;/span>{i} " >> /opt/nginx/logs/nginx_deny80.log done ####################################################################### #!/bin/bash max=500 #我们设定的最大值,当访问量大于这个值得时候,封锁 logdir=/opt/nginx/logs/access.log #nginx 访问日志文件路径 confdir=/opt/nginx/logs/nginx_deny.log #检测文件 test -e &lt;span class="katex math inline">{confdir} || touch&lt;/span>{confdir} port=80 drop_ip="" #循环遍历日志文件取出访问量大于 500 的 ip for drop_ip in &lt;span class="katex math inline">(tail -n5000000&lt;/span>logdir | awk '{print &lt;span class="katex math inline">1}' | sort | uniq -c | sort -rn | awk '{if (&lt;/span>1>500) print &lt;span class="katex math inline">2}') do grep -q "&lt;/span>{drop_Ip}" &lt;span class="katex math inline">{confdir} && eg=1 || eg=0; if ((&lt;/span>{eg}==0 ));then iptables -I INPUT -p tcp --dport &lt;span class="katex math inline">{port} -s&lt;/span>{drop_Ip} -j DROP echo ">>>>> `date '+%Y-%m-%d %H%M%S'` - 发现攻击源地址 -> &lt;span class="katex math inline">{drop_Ip} " >> /opt/nginx/logs/nginx_deny.log #记录 log fi done #################################################################### #!/usr/bin/env bash echo "" echo " ========================================================= " echo " \ Nginx日志安全分析脚本 V1.0 / " echo " ========================================================= " echo " # 支持Nginx日志分析,攻击告警分析等 " echo " # author:al0ne " echo " # https://github.com/al0ne " echo -e "\n" #此脚本是参考nmgxy/klionsec修改而来,重新添加了一些特征,只用来临时救急,还是推荐到ELK或者Splunk中分析 #功能 ###统计Top 20 地址 ###SQL注入分析 ###SQL注入 FROM查询统计 ###扫描器/常用黑客工具 ###漏洞利用检测 ###敏感路径访问 ###文件包含攻击 ###HTTP Tunnel ###Webshell ###寻找响应长度的url Top 20 ###寻找罕见的脚本文件访问 ###寻找302跳转的脚本文件 #如果存在多个access文件或者有多个access.x.gz 建议先zcat access*.gz >> access.log文件中 #设置分析结果存储目录,结尾不能加/ outfile=/tmp/logs #如果目录以存在则清空,未存在则新建目录 if &#91; -d&lt;/span>outfile ]; then rm -rf &lt;span class="katex math inline">outfile/* else mkdir -p&lt;/span>outfile fi #设置nginx日志目录,结尾必须加/ access_dir=/var/log/nginx/ #设置文件名,如果文件名为access那么匹配的是access*文件 access_log=access #判断日志文件是否存在 num=&lt;span class="katex math inline">(ls&lt;/span>{access_dir}&lt;span class="katex math inline">{access_log}* | wc -l) >/dev/null 2>&1 if &#91;&lt;/span>num -eq 0 ]; then echo '日志文件不存在' exit 1 fi echo -e "\n" # 验证操作系统是debian系还是centos OS='None' if &#91; -e "/etc/os-release" ]; then source /etc/os-release case &lt;span class="katex math inline">{ID} in "debian" | "ubuntu" | "devuan") OS='Debian' ;; "centos" | "rhel fedora" | "rhel") OS='Centos' ;; *) ;; esac fi if &#91;&lt;/span>OS = 'None' ]; then if command -v apt-get >/dev/null 2>&1; then OS='Debian' elif command -v yum >/dev/null 2>&1; then OS='Centos' else echo -e "\n不支持这个系统\n" echo -e "已退出" exit 1 fi fi # 检测ag软件有没有安装 if ag -V >/dev/null 2>&1; then echo -e "\e&#91;00;32msilversearcher-ag已安装 \e&#91;00m" else if &#91; &lt;span class="katex math inline">OS = 'Centos' ]; then yum -y install the_silver_searcher >/dev/null 2>&1 else apt-get -y install silversearcher-ag >/dev/null 2>&1 fi fi #如果检测别的日志请手动替换偏移,例如awk的&lt;/span>7代表url,&lt;span class="katex math inline">9代表状态码,&lt;/span>10代表长度,本脚本是以nginx日志为基础 echo "分析结果日志:&lt;span class="katex math inline">{outfile}" echo "Nginx日志目录:&lt;/span>{access_dir}" echo "Nginx文件名:&lt;span class="katex math inline">{access_log}" echo -e "\n" echo -e "\e&#91;00;31m&#91;+]TOP 20 IP 地址\e&#91;00m" ag -a -o --nofilename '\d+\.\d+\.\d+\.\d+'&lt;/span>{access_dir}&lt;span class="katex math inline">{access_log}* | sort | uniq -c | sort -nr | head -n 20 | tee -a&lt;/span>{outfile}/top20.log echo -e "\n" echo -e "\e&#91;00;31m&#91;+]SQL注入攻击分析\e&#91;00m" #在SQL注入中排除掉了一些扫描css/js/png图片类等无用告警,并且重点筛选状态码200或者500的告警 ag -a "xp_cmdshell|%20xor|%20and|%20AND|%20or|%20OR|select%20|%20and%201=1|%20and%201=2|%20from|%27exec|information_schema.tables|load_file|benchmark|substring|table_name|table_schema|%20where%20|%20union%20|%20UNION%20|concat\(|concat_ws\(|%20group%20|0x5f|0x7e|0x7c|0x27|%20limit|\bcurrent_user\b|%20LIMIT|version%28|version\(|database%28|database\(|user%28|user\(|%20extractvalue|%updatexml|rand\(0\)\*2|%20group%20by%20x|%20NULL%2C|sqlmap" &lt;span class="katex math inline">{access_dir}&lt;/span>{access_log}* | ag -v '/\w+\.(?:js|css|html|jpg|jpeg|png|htm|swf)(?:\?| )' | awk '(&lt;span class="katex math inline">9==200)||(&lt;/span>9==500) {print &lt;span class="katex math inline">0}' >&lt;/span>{outfile}/sql.log awk '{print "SQL注入攻击" NR"次"}' &lt;span class="katex math inline">{outfile}/sql.log | tail -n1 echo "SQL注入 TOP 20 IP地址" ag -o '(?&lt;=:)\d+\.\d+\.\d+\.\d+'&lt;/span>{outfile}/sql.log | sort | uniq -c | sort -nr | head -n 20 | tee -a &lt;span class="katex math inline">{outfile}/sql_top20.log # 重点关注from查询,是否存在脱裤行为,排除扫描行为 echo "SQL注入 FROM 查询" cat&lt;/span>{outfile}/sql.log | ag '\bfrom\b' | ag -v 'information_schema' >&lt;span class="katex math inline">{outfile}/sql_from_query.log awk '{print "SQL注入FROM查询" NR"次"}'&lt;/span>{outfile}/sql_from_query.log | tail -n1 echo -e "\n" echo -e "\e&#91;00;31m&#91;+]扫描器scan & 黑客工具\e&#91;00m" ag -a "acunetix|by_wvs|nikto|netsparker|HP404|nsfocus|WebCruiser|owasp|nmap|nessus|HEAD /|AppScan|burpsuite|w3af|ZAP|openVAS|.+avij|.+angolin|360webscan|webscan|XSS@HERE|XSS%40HERE|NOSEC.JSky|wwwscan|wscan|antSword|WebVulnScan|WebInspect|ltx71|masscan|python-requests|Python-urllib|WinHttpRequest" &lt;span class="katex math inline">{access_dir}&lt;/span>{access_log}* | ag -v '/\w+\.(?:js|css|jpg|jpeg|png|swf)(?:\?| )' | awk '(&lt;span class="katex math inline">9==200)||(&lt;/span>9==500) {print &lt;span class="katex math inline">0}' >&lt;/span>{outfile}/scan.log awk '{print "共检测到扫描攻击" NR"次"}' &lt;span class="katex math inline">{outfile}/scan.log | tail -n1 echo "扫描工具流量 TOP 20" ag -o '(?&lt;=:)\d+\.\d+\.\d+\.\d+'&lt;/span>{outfile}/scan.log | sort | uniq -c | sort -nr | head -n 20 | tee -a &lt;span class="katex math inline">{outfile}/scan_top20.log echo -e "\n" echo -e "\e&#91;00;31m&#91;+]敏感路径访问\e&#91;00m" ag -a "/_cat/|/_config/|include=|phpinfo|info\.php|/web-console|JMXInvokerServlet|/manager/html|axis2-admin|axis2-web|phpMyAdmin|phpmyadmin|/admin-console|/jmx-console|/console/|\.tar.gz|\.tar|\.tar.xz|\.xz|\.zip|\.rar|\.mdb|\.inc|\.sql|/\.config\b|\.bak|/.svn/|/\.git/|\.hg|\.DS_Store|\.htaccess|nginx\.conf|\.bash_history|/CVS/|\.bak|wwwroot|备份|/Web.config|/web.config|/1.txt|/test.txt"&lt;/span>{access_dir}&lt;span class="katex math inline">{access_log}* | awk '(&lt;/span>9==200)||(&lt;span class="katex math inline">9==500) {print&lt;/span>0}' >&lt;span class="katex math inline">{outfile}/dir.log awk '{print "共检测到针对敏感文件扫描" NR"次"}'&lt;/span>{outfile}/dir.log | tail -n1 echo "敏感文件访问流量 TOP 20" ag -o '(?&lt;=:)\d+\.\d+\.\d+\.\d+' &lt;span class="katex math inline">{outfile}/dir.log | sort | uniq -c | sort -nr | head -n 20 | tee -a&lt;/span>{outfile}/dir_top20.log echo -e "\n" echo -e "\e&#91;00;31m&#91;+]漏洞利用检测\e&#91;00m" ag -a "%00|/win.ini|/my.ini|\.\./\.\./|/etc/shadow|%0D%0A|file:/|gopher:/|dict:/|WindowsPowerShell|/wls-wsat/|call_user_func_array|uddiexplorer|@DEFAULT_MEMBER_ACCESS|@java\.lang\.Runtime|OgnlContext|/bin/bash|cmd\.exe|wget\s|curl\s|s=/index/\think" &lt;span class="katex math inline">{access_dir}&lt;/span>{access_log}* | awk '(&lt;span class="katex math inline">9==200)||(&lt;/span>9==500) {print &lt;span class="katex math inline">0}' >&lt;/span>{outfile}/exploit.log awk '{print "漏洞利用探测" NR"次"}' &lt;span class="katex math inline">{outfile}/exploit.log | tail -n1 echo "漏洞利用检测 TOP 20" ag -o '(?&lt;=:)\d+\.\d+\.\d+\.\d+'&lt;/span>{outfile}/exploit.log | sort | uniq -c | sort -nr | head -n 20 | tee -a &lt;span class="katex math inline">{outfile}/exploit_top20.log echo -e "\n" echo -e "\e&#91;00;31m&#91;+]webshell\e&#91;00m" ag -a "=whoami|dbname=|exec=|cmd=|\br57\b|\bc99\b|\bc100\b|\bb374k\b|adminer.php|eval\(|assert\(|%eval|%execute|tunnel\.&#91;asp|php|jsp|aspx]{3,4}|makewebtaski|ma\.&#91;asp|php|jsp|aspx]{3,4}|\bup\.&#91;asp|php|jsp|aspx]{3,4}|cmd\.&#91;asp|php|jsp|aspx]{3,4}|201\d\.&#91;asp|php|jsp|aspx]{3,4}|xiaoma\.&#91;asp|php|jsp|aspx]{3,4}|shell\.&#91;asp|php|jsp|aspx]{3,4}|404\.&#91;asp|php|jsp|aspx]{3,4}|tom\.&#91;asp|php|jsp|aspx]{3,4}|k8cmd\.&#91;asp|php|jsp|aspx]{3,4}|ver&#91;0-9]{3,4}\.&#91;asp|php|jsp|aspx]{3,4}|\.aar|&#91;asp|php|jsp|aspx]{3,4}spy\.|o=vLogin|aioshell|admine|ghost\.&#91;asp|php|jsp|aspx]{3,4}|r00ts|90sec|t00ls|editor\.aspx|wso\.&#91;asp|aspx]{3,4}"&lt;/span>{access_dir}&lt;span class="katex math inline">{access_log}* | awk '(&lt;/span>9==200)||(&lt;span class="katex math inline">9==500) {print&lt;/span>0}' >&lt;span class="katex math inline">{outfile}/webshell.log awk '{print "共检测到webshell行为" NR "次"}'&lt;/span>{outfile}/webshell.log | tail -n1 echo "Webshell TOP 20" ag -o '(?&lt;=:)\d+\.\d+\.\d+\.\d+' &lt;span class="katex math inline">{outfile}/webshell.log | sort | uniq -c | sort -nr | head -n 20 | tee -a&lt;/span>{outfile}/webshell_top20.log echo -e "\n" echo -e "\e&#91;00;31m&#91;+]HTTP Tunnel\e&#91;00m" #Regeorg代理特征 ag -a "cmd=disconnect|cmd=read|cmd=forward|cmd=connect|127.0.0.1" &lt;span class="katex math inline">{access_dir}&lt;/span>{access_log}* | awk '(&lt;span class="katex math inline">9==200)||(&lt;/span>9==500) {print &lt;span class="katex math inline">0}' | tee -a&lt;/span>{outfile}/tunnel.log awk '{print "共检测到隧道行为" NR "次"}' &lt;span class="katex math inline">{outfile}/tunnel.log | tail -n1 echo -e "\n" echo -e "\e&#91;00;31m&#91;+]Top 20 url响应长度\e&#91;00m" # 查找url响应长度最长的url排序,目的是有没有下载服务器的一些打包文件 len=&lt;/span>(cat &lt;span class="katex math inline">{access_dir}&lt;/span>{access_log}* | awk '{print &lt;span class="katex math inline">10}' | sort -nr | head -n 20) echo&lt;/span>len | awk 'BEGIN{ RS=" " }{ print &lt;span class="katex math inline">0 }' | xargs -i{} ag -a --nocolor '\d+\s{}\s'&lt;/span>{access_dir}&lt;span class="katex math inline">{access_log}* | awk '{print&lt;/span>7,&lt;span class="katex math inline">10}' | sort | uniq | sort -k 2 -nr | tee -a&lt;/span>{outfile}/url_rsp_len.log echo -e "\n" echo -e "\e&#91;00;31m&#91;+]罕见的脚本文件访问\e&#91;00m" echo "访问量特别特别少的脚本文件极有可能是webshell" cat &lt;span class="katex math inline">{access_dir}&lt;/span>{access_log}* | awk '(&lt;span class="katex math inline">9==200)||(&lt;/span>9==500) {print &lt;span class="katex math inline">7}' | sort | uniq -c | sort -n | ag -v '\?' | ag '\.php|\.jsp|\.asp|\.aspx' | head -n 20 | tee -a&lt;/span>{outfile}/rare_url.log echo -e "\n" echo -e "\e&#91;00;31m&#91;+]302跳转\e&#91;00m" echo "此目的是寻找一些登录成功的脚本文件" cat &lt;span class="katex math inline">{access_dir}&lt;/span>{access_log}* | awk '(&lt;span class="katex math inline">9==302)||(&lt;/span>9==301) {print &lt;span class="katex math inline">7}' | sort | uniq -c | sort -n | ag -v '\?' | ag '\.php|\.jsp|\.asp|\.aspx' | head -n 20 | tee -a&lt;/span>{outfile}/302_goto.log echo -e "\n" ###################################################################### #!/bin/bash echo "##########################################################################" echo "# nginx日志分析小工具,author:william,https://github.com/xiucaiwu #" echo "# 本工具暂时不支持跨天日志分析,Nginx日志格式为默认格式 #" echo "# 请输入要分析的时段(为空则分析全部日志): #" echo "# 分析今天3点10分到5点的数据:03:10-05:00 "-"前后没有空格 #" echo "# 分析2018年8月20号3点到5点的数据:2018-08-20 03:00-05:00 #" echo "##########################################################################" # 默认存放切割后的Nginx日志目录 default_parse_ngx_dir_path='/opt/log/nginx' # 生成的切割后的Nginx日志路径 parse_ngx_path="" # 默认Nginx日志路径 #default_ngx_path="/usr/local/nginx/logs/host.access.145.`date "+%Y%m%d"`.log" default_ngx_path="/root/wwwlog/access.log" # 记录用户手动输入Nginx日志路径的字符串长度 ngx_path_len=0 # 记录用户手动输入切割后的Nginx日志目录字符串长度 ngx_dir_path_len=0 # 一个空数组 array=() # 一个字符串分割另一个字符串 function str_split(){ # 分割字符串 delimiter=&lt;span class="katex math inline">1 # 目标字符串 string=&lt;/span>2 # 注意后面有个空格 array=(&lt;span class="katex math inline">{string//&lt;/span>delimiter/ }) # return 只能返回int型数值 # return &lt;span class="katex math inline">arr } read -p "请输入nginx日志文件路径:" ngx_path ngx_path_len=`echo&lt;/span>ngx_path | wc -L` if &#91; `echo &lt;span class="katex math inline">ngx_path | wc -L` == 0 ];then ngx_path=&lt;/span>default_ngx_path fi if &#91; ! -f &lt;span class="katex math inline">ngx_path ];then echo "日志不存在" # exit fi read -p "请输入存放分析后的nginx日志文件夹路径,默认为/opt/log/nginx:" ngx_parse_dir_path if &#91; `echo&lt;/span>ngx_dir_path | wc -L` == 0 ];then ngx_parse_dir_path=&lt;span class="katex math inline">default_parse_ngx_dir_path fi if &#91; ! -d&lt;/span>ngx_parse_dir_path ];then echo &lt;span class="katex math inline">ngx_parse_dir_path "不存在" # exit fi read -p "请输入要分析的时段(24小时制):" ngx_time # 统计输入的字符串长度 len=`echo&lt;/span>ngx_time | wc -L` if &#91; &lt;span class="katex math inline">len == 0 ];then # 当前是几时几分 hour_minute=`date +%H:%I` filename=`date +%Y%m%d`".log" mydate=`date +%d/%b/%Y` parse_ngx_path=&lt;/span>ngx_parse_dir_path/&lt;span class="katex math inline">filename echo -e "\033&#91;32m 文件&lt;/span>{parse_ngx_path}正在生成... \033&#91;0m" awk -v mydate=&lt;span class="katex math inline">mydate -v arr=&lt;/span>hour_minute -F "&#91; /:]" '&lt;span class="katex math inline">1"/"&lt;/span>2"/"&lt;span class="katex math inline">3==mydate &&&lt;/span>4":"&lt;span class="katex math inline">5>="00:00" &&&lt;/span>4":"&lt;span class="katex math inline">5&lt;=arr'&lt;/span>ngx_path > &lt;span class="katex math inline">parse_ngx_path echo -e "\033&#91;32m 文件&lt;/span>{parse_ngx_path}生成成功!!! \033&#91;0m" elif &#91; &lt;span class="katex math inline">len == 11 ];then # 统计"-"出现的次数 if &#91; `echo&lt;/span>ngx_time | grep -o '-' | wc -l` == 1 ];then # 当前日期 current_date=`date "+%Y-%m-%d %H:%M"` # 当前日期对应的时间戳 current_timestamp=`date -d "&lt;span class="katex math inline">current_date" +%s` str_split "-"&lt;/span>ngx_time # 用户输入的日期 user_date="`date \"+%Y-%m-%d\"` &lt;span class="katex math inline">{array&#91;0]}" # 用户输入的日期对应的时间戳 user_timestamp=`date -d "&lt;/span>user_date" +%s` filename=`date +%Y%m%d`"&#91;&lt;span class="katex math inline">{array&#91;0]}-&lt;/span>{array&#91;1]}].log" mydate=`date +%d/%b/%Y` parse_ngx_path=&lt;span class="katex math inline">ngx_parse_dir_path/&lt;/span>filename if &#91; &lt;span class="katex math inline">user_timestamp ==&lt;/span>current_timestamp ];then echo -e "\033&#91;32m 文件&lt;span class="katex math inline">{parse_ngx_path}正在生成... \033&#91;0m" awk -v mydate=&lt;/span>mydate -v arr1=&lt;span class="katex math inline">{array&#91;0]} -v arr2=&lt;/span>{array&#91;1]} -F "&#91; /:]" '&lt;span class="katex math inline">1"/"&lt;/span>2"/"&lt;span class="katex math inline">3==mydate &&&lt;/span>4":"&lt;span class="katex math inline">5>=arr1 &&&lt;/span>4":"&lt;span class="katex math inline">5&lt;=arr2'&lt;/span>ngx_path > &lt;span class="katex math inline">parse_ngx_path echo -e "\033&#91;32m 文件&lt;/span>{parse_ngx_path}生成成功!!! \033&#91;0m" elif &#91; ! -f &lt;span class="katex math inline">parse_ngx_path ];then echo -e "\033&#91;32m 文件&lt;/span>{parse_ngx_path}正在生成... \033&#91;0m" awk -v mydate=&lt;span class="katex math inline">mydate -v arr1=&lt;/span>{array&#91;0]} -v arr2=&lt;span class="katex math inline">{array&#91;1]} -F "&#91; /:]" '&lt;/span>1"/"&lt;span class="katex math inline">2"/"&lt;/span>3==mydate && &lt;span class="katex math inline">4":"&lt;/span>5>=arr1 && &lt;span class="katex math inline">4":"&lt;/span>5&lt;=arr2' &lt;span class="katex math inline">ngx_path >&lt;/span>parse_ngx_path echo -e "\033&#91;32m 文件&lt;span class="katex math inline">{parse_ngx_path}生成成功!!! \033&#91;0m" fi else echo "格式输入不正确" exit fi elif &#91;&lt;/span>len == 22 ];then # 统计"-"出现的次数 if &#91; `echo &lt;span class="katex math inline">ngx_time | grep -o '-' | wc -l` == 3 ];then str_split " " "&lt;/span>ngx_time" # 自定义日期格式 mydate1=`date -d "&lt;span class="katex math inline">{array&#91;0]}" +%d/%b/%Y` # 日期转时间戳 timestamp=`date -d "&lt;/span>{array&#91;0]}" +%s` # 时间戳转日期 mydate2=`date -d @&lt;span class="katex math inline">timestamp "+%Y%m%d"` str_split "-"&lt;/span>{array&#91;1]} filename=&lt;span class="katex math inline">mydate2"&#91;&lt;/span>{array&#91;0]}-&lt;span class="katex math inline">{array&#91;1]}].log" parse_ngx_path=&lt;/span>ngx_parse_dir_path/&lt;span class="katex math inline">filename if &#91; ! -f&lt;/span>parse_ngx_path ];then echo -e "\033&#91;32m 文件&lt;span class="katex math inline">{parse_ngx_path}正在生成... \033&#91;0m" awk -v mydate=&lt;/span>mydate1 -v arr1=&lt;span class="katex math inline">{array&#91;0]} -v arr2=&lt;/span>{array&#91;1]} -F "&#91; /:]" '&lt;span class="katex math inline">1"/"&lt;/span>2"/"&lt;span class="katex math inline">3==mydate &&&lt;/span>4":"&lt;span class="katex math inline">5>=arr1 &&&lt;/span>4":"&lt;span class="katex math inline">5&lt;=arr2'&lt;/span>ngx_path > &lt;span class="katex math inline">parse_ngx_path echo -e "\033&#91;32m 文件&lt;/span>{parse_ngx_path}生成成功!!! \033&#91;0m" fi else echo "格式输入不正确" exit fi else echo "格式输入不正确" exit fi # 开始解析切割后的Nginx日志 if &#91; ! -f &lt;span class="katex math inline">parse_ngx_path ];then echo -e "\033&#91;31m 文件&lt;/span>{parse_ngx_path}不存在 \033&#91;0m" fi # 统计访问最多的ip echo -e "\033&#91;31m 访问TOP10的IP: \033&#91;0m" awk '{print &lt;span class="katex math inline">1}'&lt;/span>parse_ngx_path | sort | uniq -c | sort -n -k 1 -r | head -n 10 ip_array=`(awk '{print &lt;span class="katex math inline">1}'&lt;/span>parse_ngx_path | sort | uniq -c | sort -n -k 1 -r | head -n 10 | awk '{print &lt;span class="katex math inline">2}')` # 统计访问最多的url echo -e "\033&#91;31m 访问TOP10的URL: \033&#91;0m" awk '{print&lt;/span>7}' &lt;span class="katex math inline">parse_ngx_path | sort |uniq -c | sort -rn | head -n 10 # 统计ip对应的url for i in&lt;/span>{ip_array&#91;@]};do echo -e "\033&#91;31m IP(&lt;span class="katex math inline">{i})访问TOP10的URL: \033&#91;0m" cat access.log | grep&lt;/span>i |awk '{print $7}'| sort | uniq -c | sort -rn | head -10 | more done`

2020年11月27日 · 11 分钟 · 天边的星星

SaaS系统多租户数据隔离的实现

什么是SaaS SaaS平台是运营saas软件的平台。SaaS提供商为企业搭建信息化所需要的所有网络基础设施及软件、硬件运作平台,并负责所有前期的实施、后期的维护等一系列服务,企业无需购买软硬件、建设机房、招聘IT人员,即可通过互联网使用信息系统。SaaS 是一种软件布局模型,其应用专为网络交付而设计,便于用户通过互联网托管、部署及接入。也就是说,我只需要能连接上互联网,并且给saas平台交租金,我就能用saas平台给我提供的系统服务。 多租户技术或称多重租赁技术,是一种软件架构技术,是实现如何在多用户环境下共用相同的系统或程序组件,并且可确保各用户间数据的隔离性。多租户架构的重点就是同一套程序下多个租户数据的隔离 SaaS 数据隔离方案 目前saas多租户系统的数据隔离有三种解决方案,即为每个租户提供独立的数据库、独立的表空间、按字段区分租户,每种方案都有其各自的适用情况 独立数据库 即一个租户一个数据库,这种方案的用户数据隔离级别最高,安全性最好,但成本较高。 优点 为不同的租户提供独立的数据库,有助于简化数据模型的扩展设计,满足不同租户的独特需求,如果出现故障,恢复数据比较简单。 缺点 增多了数据库的数量,随之带来维护成本或购置成本的增加。这种方案与传统的一个客户、一套数据、一套部署类似。差别只在于软件统一部署在运营商那里。如果面对的是银行、医院等需要非常高数据隔离级别的租户、可以选择这种模式,提高租用的定价。如果定价较低,产品走低价路线,这种方案一般对运营商来说是无法承受的。 共享数据库,隔离数据架构(独立表空间) 这种方案实现,就是所有租户共享同一个应用,应用后端连接同一个数据库系统,所有租户共享这个数据库系统,每个租户在数据库系统中拥有一个独立的表空间 优点 为安全性要求较高的租户提供了一定程度的逻辑数据隔离,并不是完全隔离。每个数据库可支持更多的租户数量 缺点 如果出现故障,数据恢复比较困难,因为恢复数据库将牵涉到其他租户的数据;如果需要跨租户统计数据,存在一定困难。 共享数据库,共享数据架构(表空间-按租户id字段区分租户) 即租户共享同一个数据库,同一个表空间,但是表中增加TenantID多租户的数据字段。这是共享程度最高,隔离级别最低的模式。通过TenantID来标识每一条数据属于哪个租户,所有操作的时候都要注意添加上TenantID作为过滤条件。 优点 三种方案中,这个方案的维护和购置成本最低,允许每个数据库支持的租户数量最多。 缺点 隔离级别最低,安全性最低,需要在设计开发的时候加大对安全的开发量。数据备份和恢复最困难,需要逐表备份和还原。如果希望以最少的服务器为最多的租户提供服务,并且租户接受牺牲隔离级别换取降低成本,这种方案最合适。 衡量要素 衡量三种模式主要考虑的因素是隔离还是共享。 成本角度 隔离性越好,设计和实现的难度和成本越高。共享性越好,同一运营成本下支持的用户越多,运营成本越低。 安全角度 要考虑业务和客户的安全方面的要求。安全性要求越高,越要倾向于隔离。 租户数量角度 系统要支持多少租户?上百?上千还是上完?可能的租户越多,越倾向于共享。平均每个租户要存储数据需要的空间大小。存储的数据越多,越倾向于隔离。每个租户的同时访问系统的最终用户数量。需要支持的越多,越倾向于隔离。是否想针对每一个租户提供附加的服务,例如数据的备份和恢复等。这方面的需求越多,越倾向于隔离。 信息监管因素 要考虑政府,机关,企业,公司的安全和信息监管的一些政策和规定。 技术成本 共享性越好,对技术的要求越高。

2020年11月22日 · 1 分钟 · 天边的星星

Redis使用问题一

Reid 使用指南一 问题一 OOM command not allowed when used memory > ‘maxmemory’ 这里表示使用内存超过了设置的最大内存。 redis.conf中的maxmemory定义REdis可用最大物理内存,有多种书写方式,以下均为合法: maxmemory 1048576 maxmemory 1048576B maxmemory 1000KB maxmemory 100MB maxmemory 1GB maxmemory 1000K maxmemory 100M maxmemory 1G 没有带单位尾巴的为字节数,以B结尾的表示相应的大小。但需要注意KB和K、MB和M、GB和G是不同的,如1K表示1000字节,而1KB则为1024字节。如果maxmemory值为0,表示不做限制。 如果是32位系统,当maxmemory值为0时,redis启动时会记录WARN日志 Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with ’noeviction’ policy now. server.maxmemory = 3072LL_(1024_1024); /* 3 GB */ server.maxmemory_policy = MAXMEMORY_NO_EVICTION; 相关的源代码如下: /* Convert a string representing an amount of memory into the number of ...

2020年9月28日 · 2 分钟 · 天边的星星