1. 使用Statistics 模块中的以下两个命令来实现统计在线人数的功能
http {
server {
listen 8080;
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /path/to/stat.xsl/;
}
}
2. 但是ngx_rtmp_stat_module 不支持多进程。这个问题通过这个补丁per-worker-listener优化。
步骤:
1. 克隆per-worker-listener : https://github.com/arut/nginx-patches.git 到nginx 目录下面
2. 打补丁
root@ubuntu2004:/media/code/kaiyuan/openresty-1.19.9.1/bundle/nginx-1.19.9# patch -p1 < per-worker-listener
root@ubuntu2004:/media/code/kaiyuan/openresty-1.19.9.1/bundle/nginx-1.19.9# patch -p1 < nginx-patches/per-worker-listener
patching file src/core/ngx_connection.c
Hunk #2 succeeded at 414 (offset 102 lines).
Hunk #3 succeeded at 486 (offset 142 lines).
Hunk #4 succeeded at 657 with fuzz 1 (offset 190 lines).
patching file src/core/ngx_connection.h
Hunk #1 succeeded at 57 (offset 3 lines).
patching file src/http/ngx_http.c
Hunk #1 succeeded at 1769 with fuzz 1 (offset -48 lines).
patching file src/http/ngx_http_core_module.c
Hunk #1 succeeded at 3920 (offset -106 lines).
patching file src/http/ngx_http_core_module.h
Hunk #1 FAILED at 72.
1 out of 1 hunk FAILED -- saving rejects to file src/http/ngx_http_core_module.h.rej
patching file src/os/unix/ngx_process.c
patching file src/os/unix/ngx_process.h
Hunk #1 succeeded at 85 (offset 2 lines).
patching file src/os/unix/ngx_process_cycle.c
Hunk #1 succeeded at 764 with fuzz 2 (offset 27 lines).
Hunk #2 FAILED at 972.
1 out of 2 hunks FAILED -- saving rejects to file src/os/unix/ngx_process_cycle.c.rej
3 make &make install