服务器
2024-01-17
基础环境
- Debian 操作系统
- MariaDB 集群方案、数据同步、备份与恢复
- MongoDB 集群方案
- Redis 集群方案
- Redis Cluster
- Codis Cluster
- 如果考虑内存成本,又没有那么高的性能要求,可以改用基于磁盘的 Redis 兼容服务作为替代
- PocketMQ 集群方案
- HAProxy + Keepalived
Web 服务器
- Nginx
- 后端:Golang / Python / PHP / Java / Node.js
- CDN、云存储
其他
- 通用管理后台
- 分布式任务系统
- S3 存储
- 推送系统(邮件、短信等)
Redis 服务器
2022-01-09
Redis 官方其实还提供了以下拓展:
PS: 还有更多第三方拓展,参考 https://redis.io/modules。
关于授权协议
Redis 是 BSD 协议,Redis 拓展模块是 AGPL 协议。
2018 年 8 月,为了防止云服务厂商的利益侵害,Redis 拓展模块授权协议切换到 Apache v2.0 modified with Commons Clause (官方声明)。其中 Common Clause 就是限制提供商业的 Reids 服务。
2019 年 2 月,Redis 拓展模块授权协议再次切换,改成 Redis Source Available License (RSAL),(官方声明)。因为认为当前协议不够明确,容易让人产生误解,而且对 Redis 公司的权益保障不到位。
这个协议对普通用户(个人或企业)没有限制,只是限制了直接利用 Redis 服务赚钱的云厂商。我觉得这是开发者的合理诉求,没有什么值得质疑的。
模块的安装

如果只是要体验一下,不想编译,可以去 https://redis.com/redis-enterprise-software/download-center/modules/ 下载试用。
- 下载模块源代码,然后编译,生成动态链接库
xxx.so
- 修改 Redis 配置文件
loadmodule xxx.so
,然后重启 Redis 服务
PS: 也可以在启动时使用 --loadmodule
参数动态加载模块。
比如 ReJSON:
wget https://github.com/RedisJSON/RedisJSON/archive/refs/tags/v2.0.6.zip -O redisjson-v2.0.6.zip
unzip redisjson-v2.0.6.zip
cd RedisJSON-2.0.6/
# 安装需要用到官网没有提到的 libclang.so
# From: bindgen-0.59.2/src/lib.rs
sudo apt install libclang-dev
cargo build --release
cargo test --features test
# 需要先安装 Rust (请参考其他资料)
# 我了解到的其他模块大多数是 C 写的,RedisJSON 比较特殊,用 Rust 写的
redis-server --loadmodule target/release/librejson.so
相关文章:RedisJSON 体验
WebDev 安全 网站 服务器
2021-10-30
非常简单,就是告诉别个,如果网站出现安全问题应该向谁报告,用什么方式报告。
服务器 Redis
2021-07-15
先将命令写在 commands.txt 中,一行一个,不用分号结尾,然后:
echo commands.txt | redis-cli -h 127.0.0.1 -p 6379
服务器 操作系统 Linux CentOS Debian Ubuntu
2021-07-15
列一下常见的服务器操作系统。
supervisord 服务器
2021-07-13

线上服务日志中看到 Too many open files,于是检查了一番。
一、过程
确认:进程最大打开文件数
首先确认了系统没有限制最大打开文件数,但进程的最大打开文件数是限制的:
ulimit -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 30007
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 655350
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 327675
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
cat /proc/29749/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 10485760 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 30007 30007 processes
Max open files 1024 1024 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 30007 30007 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
解决方法
最后网上搜索之后,有人说 supervisor 有限制,我一检查果然是 supervisor 服务器的最大打开文件数问题:
[supervisord]
...
minfds = 65535
...
改成 655350,之后再看 proc 信息,就好了。
PS: 好像 reload
,reread
,restart
都没用,需要关闭 supervisor 重启服务才能生效。(有待进一步确认)
二、minfds
配置
官方解释:
The minimum number of file descriptors that must be available before supervisord will start successfully. A call to setrlimit will be made to attempt to raise the soft and hard limits of the supervisord process to satisfy minfds. The hard limit may only be raised if supervisord is run as root. supervisord uses file descriptors liberally, and will enter a failure mode when one cannot be obtained from the OS, so it’s useful to be able to specify a minimum value to ensure it doesn’t run out of them during execution. These limits will be inherited by the managed subprocesses. This option is particularly useful on Solaris, which has a low per-process fd limit by default.
Default: 1024
Required: No.
Introduced: 3.0
这个名字很有迷惑性,怎么看也想不到进程的最大打开文件数上面去,不过官方文档也能自洽:这是保证 supervisor 正常启动的一个最小值,相当于一个检查点。然后它会调用 setrlimit 设置子进程的最大打开文件数。
服务器 Redis
2020-08-26

Python 服务器
2017-01-31
子命令
help
help <action>
add <name> […]
remove <name> […]
update
update all
update <gname> […]
clear <name>
clear <name> <name>
clear all
fg <process>
pid
pid <name>
pid all
reload
reread
restart <name>
不会重新加载配置文件
- 如果配置有更新,应该 reread 一下
- 如果有 section 增删,还应该 update 一下
restart <gname>:*
restart <name> <name>
restart all
signal
start <name>
start <gname>:*
start <name> <name>
start all
status
status <name>
status <name> <name>
stop <name>
stop <gname>:*
stop <name> <name>
stop all
tail [-f] <name> [stdout|stderr]
(default stdout)
Nginx WebDev 服务器
2016-04-10
Nginx 商用版 1.5.7 (2013 年) 开始支持 sticky 指令。
文档: https://nginx.org/en/docs/http/ngx_http_upstream_module.html#sticky
Syntax: sticky cookie name [expires=time] [domain=domain] [httponly] [samesite=strict|lax|none] [secure] [path=path];
sticky route $variable ...;
sticky learn create=$variable lookup=$variable zone=name:size [timeout=time] [header] [sync];
Default: —
Context: upstream
开源版有 nginx-sticky-module。
C 语言写的,BSD 协议。
代码看起来并不复杂,如果需要用到的时候,可以进行一个粗略的 Review。
编译
# 下载 nginx 源码 (2016-04-26)
wget http://nginx.org/download/nginx-1.10.0.tar.gz http://nginx.org/download/nginx-1.10.0.tar.gz.asc
gpg --verify nginx-1.10.0.tar.gz.asc
# 下载 nginx-sticky-module (2015-08-06)
wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/1.2.6.zip
unzip 1.2.6.zip
cd nginx-goodies-nginx-sticky-module-ng-c78b7dd79d0d/
unzip nginx-1.10.0.zip
cd nginx-1.10.0/
# 其他参数按需添加
./configure --add-module=../nginx-goodies-nginx-sticky-module-ng-c78b7dd79d0d/
make && make install
# Configuration summary
# + using system PCRE library
# + OpenSSL library is not used
# + md5: using system crypto library
# + sha1: using system crypto library
# + using system zlib library
# nginx path prefix: "/usr/local/nginx"
# nginx binary file: "/usr/local/nginx/sbin/nginx"
# nginx modules path: "/usr/local/nginx/modules"
# nginx configuration prefix: "/usr/local/nginx/conf"
# nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
# nginx pid file: "/usr/local/nginx/logs/nginx.pid"
# nginx error log file: "/usr/local/nginx/logs/error.log"
# nginx http access log file: "/usr/local/nginx/logs/access.log"
# nginx http client request body temporary files: "client_body_temp"
# nginx http proxy temporary files: "proxy_temp"
# nginx http fastcgi temporary files: "fastcgi_temp"
# nginx http uwsgi temporary files: "uwsgi_temp"
# nginx http scgi temporary files: "scgi_temp"
用法
upstream {
sticky;
server 127.0.0.1:9000;
server 127.0.0.1:9001;
server 127.0.0.1:9002;
}
sticky [name=route] [domain=.foo.bar] [path=/] [expires=1h]
[hash=index|md5|sha1] [no_fallback] [secure] [httponly];