Switch language
zh
Switch theme
Light
  • mysql 220k 数据行时, count() 很慢, 要2s多

    问 deepseek “mysql innodb 20万行, 使用 select count(*) from tablea; 耗时2s, 正常吗” 答: mysql innodb 的查询行数是全表扫描, 而 myisam 是直接存储了数量, 可通过加大 innodb_buffer_pool_size 的值来加速, innodb_buffer_pool_size 一般默认为 128M, 现在 改为 4G, 速度变成了 0.2s 查询当前 mysql 的 innodb_buffer_pool_size 值 sql: SHOW VARIABLES LIKE 'innodb_buffer_pool_size'; my.ini(windows) 或 my.cnf(linux) 的 [mysqld] 下 修改 my.ini(my.cnf) 配置文件修改(重启后生效) [mysqld] innodb_buffer_pool_size = 4G 临时修改(重启后失效) SET GLOBAL innodb_buffer_pool_size = 4294967296; # 4G 如果是在 docker compose 中改了配置文件, 需要重新 build image # 在 docker-compose.
  • docker compose 部署 nextjs & mysql

    # dock 文件夹为根文件夹 # 其下包涵 mysql 和 next 文件夹, 及 docker-compose.yml 和 .env 文件 # dock/.env ########################################################### ###################### General Setup ###################### ########################################################### ### Paths ################################################# # Choose storage path on your machine. For all storage systems DATA_PATH_HOST=~/.dock/data ### Drivers ################################################ # All volumes driver VOLUMES_DRIVER=local # All Networks driver NETWORKS_DRIVER=bridge ### Docker compose files ################################## # Select which docker-compose files to include. If using docker-sync append `:docker-compose.sync.yml` at the end COMPOSE_FILE=docker-compose.
  • gofrp (内网穿透) 的安装和使用

    文档地址 使用 gogrp 通过自定义域名访问内网的 Web 服务 1. 安装 分别在 client 和 server 下载便携版的可执行文件, 如 client 是 windows 系统, 则下载后的文件为 frpc.exe, frpc.toml, frps.exe, frps.toml, LICENSE, client 端只需要 frpc.exe 及 frpc.toml 即可 如 server 是 linux 系统, 则下载后的文件只需要 frps 及 frps.toml 2. 配置 # frps.toml 配置 bindPort = 7000 vhostHTTPPort = 8600 # 要设置 vhostHTTPPORT, 最后通过服务端的 ip:vhost端口 进行访问 # frpc.toml 配置 serverAddr = "xx.xx.xx.xx" serverPort = 7000 [[proxies]] name = "test-web" type = "http" localIP = "127.
  • linux 安装、配置 fail2ban 避免服务器恶意登录

    详见 github: fail2ban 安装 fail2ban, 以 ubuntu 为例 apt update && apt upgrade apt install fail2ban systemctl start fail2ban systemctl enable fail2ban 配置 fail2ban fail2ban 分为 server 和 client 在 /etc/fail2ban/jail.d 中增加一个自定义 conf, 如 my-jail.conf (从 defaults-debian.conf 复制得到), 添加如下 sshd 配置 # my-jail.conf [DEFAULT] banaction = nftables banaction_allports = nftables[type=allports] backend = systemd [sshd] enabled = true port = 2222 filter = sshd maxretry = 3 bantime = 2592000 # 2592000second = 30day, -1 为永久封禁 重启 fail2ban sudo systemctl restart fail2ban #重启 sudo fail2ban-client status #查看状态 sudo fail2ban-client status sshd #查看sshd的详细状态 查看已禁用的ip fail2ban-client get sshd banned fail2ban-client status sshd # 查看登录尝试记录 lastb # 显示显示失败的登录尝试 last # 与 lastb 类似,但显示的是所有登录尝试,包括成功的登录
  • goaccess export nginx access log to report

    使用 goaccess 将 nginx access.log 生成可视化 report.html goaccess github地址 nginx access.log 过滤 # 过滤不统计的日志(如图片、js、css、恶意访问的 login、404 等) cat access.log | grep -vE '(\.css|\.js|\.jpg|\.png|\.gif|\.ico|\.jfif|\.woff|\.woff2|\.eot|\.ttf|\.svg|\.map|bot|Bot|favicon|404|curl|Java|scaninfo|phpMyAdmin|\.env|admin|login|python|http\-client|wp\-|post|POST|\.php|api|ajax|ads\.txt|humans\.txt|well\-known|security\.txt|CONNECT|Head)' > new.log # 只统计 GET 请求 cat new.log | grep 'GET' > new2.log # 只统计 GET 首页的请求 cat new2.log | grep 'GET /' > new3.log goaccess 操作步骤 linux 环境(编译/包管理器)安装 goaccess, 编译安装注意要 --enable-utf8 --enable-geoip=mmdb /etc/goaccess/goaccess.conf 配置 ## 2.1 打开 nginx time-format, date-format, log-format # Apache/NGINX's log formats below. time-format %H:%M:%S # Apache/NGINX's log formats below.
  • Centos磁盘查看

    记一次服务器负载过高导致web访问变慢 阿里云监控 在阿里云监控平台发现内存占用 75%以上, cpu在 50%左右, 检查系统负载 uptime, 分别显示一段时间的平均系统负载, 1分钟, 5分钟, 15分钟 检查内存 free -h 检查 cpu 服务器查看 top 都卡, 后查看 pm2, 发现一个实例就占用了 1G+内存, pm2 reload 1 实现重启, 内存占用到 200M ps: ssh界面 如果宽度不够长, pm2 ls 只会显示部分列, 要查看更多(如 uptime 等), 需拉长或全屏终端. 检查磁盘 df -h 查看总占用 cd / && du -ah –max-depth=1 | sort -rh 查看根目录下文件夹占用 进去某个文件夹, du -ah –max-depth=1 | sort -rh 查看文件夹占用 nginx access.log 过大, echo -n '' > access.log 清空文件
  • Fix Failed to Verify Certificate X509

    修复 “Failed to Verify Certificate X509” 问题 问题出现背景 linux 环境下在 go 中用一个函数获取 https 证书有效期, 在查询一个由 freessl cname 申请的证书后, 发现报错 Errortls: failed to verify certificate: x509: certificate signed by unknown authority 而在 windows 环境又正常, 遂在 linux 中使用 curl https://xxx.com 得到 curl: (60) Peer's Certificate issuer is not recognized. More details here: http://curl.haxx.se/docs/sslcerts.html package pkg import ( "crypto/tls" "errors" "time" ) func WillExpireIn7Days(hostname string) (bool, time.Time, error) { conn, err := tls.Dial("tcp", hostname+":443", nil) if err !
  • Upgrade Nodejs by Yum on Centos

    centos7.9 yum 升级 nodejs(14->16) 步骤 首先确定当前 nodejs 是由 yum 安装的 $ yum list installed | grep nodejs # nodejs.x86_64 2:12.22.12-1nodesource @nodesource 删除当前 nodejs 版本 (https://github.com/nodesource/distributions) yum remove nodejs rm -r /etc/yum.repos.d/nodesource*.repo yum clean all 添加 nodejs16 源 $ curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash - 安装 nodejs $ sudo yum install -y nodejs $ node -v $ npm -v
  • Nginx__config Proxy_pass

    参考简书: nginx 之 proxy_pass 详解 nginx conf 之 proxy_pass 使用背景 vue3 项目调用后台接口时, 不希望将后端接口地址(host地址) 暴露给普通用户, 并且直接解决浏览器跨域问题, 会使用 nginx 对接口地址作代码, 表面上访问前端 vue 项目的接口地址, 实际上会通过代码转发到真正的后端服务地址 vue3+vite 开发环境在 vite.config.js 配置代理 // vite.config.js export defaut defineConfig({ ... server: { proxy: { '/api': { target: 'http://backend.test/api', changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, '') } } } ... }) nginx conf 生产环境 按要代理的地址最后是否带 ‘/’,及是否有 子目录分为 2 种情况, 每种情况按是否有子目录又可再细分为 2 种情况 有 ‘/’ 表示绝对路径, 不带 location; 没有表示相对路径, 要带上 location 后的路径
  • Apache_bench_in_go__hey

    使用 hey 代替 ab 对网站应用做性能测试 (服务器配置) https://github.com/rakyll/hey hey is a tiny program that sends some load to a web application. 二八定律: 80% 的请求(访问)集中在 20% 的时间内 假设一个网站每日 pv (page visit) 300w, 也就是 300w*80% <=> 3600*24*20%, 240w pv 在 17280s 内, 240*10000/17280 = 138 QPS (query per second) 如果单台机器支持的 QPS 在 50, 那么需要 3 台这样的机器才能满足需求 ## hey 执行结果示例 $ hey http://localhost:8080/api/tmp Summary: Total: 0.1239 secs Slowest: 0.0961 secs Fastest: 0.0006 secs Average: 0.
🍀