前言
因为领导要求做linux的推拉流时服务器压力测试,于是在网上找了找。一顿操作下来,发现很多软件盗用一款名为srs-bench的开源软件。
该代码仓库有详细的使用说明,而且可以在issues中找到可能会遇到的问题的解决办法
需要下载该仓库的源码自行在linux上编译
测试环境:
- centos9和麒麟V10均已编译成功
1.将仓库克隆到本地,这里注意需要下载指定分支
git clone https://github.com/ossrs/srs-bench.git
2.进入文件夹
cd srs-bench/
构建
#先给configure文件可执行权限
chmod 777 configure
#构建
./configure
不出意外,出问题了
我们需要修改文件把这个错误忽略
将srs-bench/3rdparty/http-parser-2.1.zip文件里的Makefile里的CFLAGS += -Wall -Wextra -Werror改为CFLAGS += -Wall -Wextra。我市将压缩文件拷出来,解压修改完再压缩成zip,替换回去
再次构建,构建成功
./configure
3.编译
make
如果幸运的话,直接就编译成功了
objs/里面的程序就是我们需要的
#拉1路流
./sb_rtmp_load -c 1 -r rtmp://127.0.0.1/live/test
#拉100路流
./sb_rtmp_load -c 100 -r rtmp://127.0.0.1/live/test
#推1路流
./sb_rtmp_publish -i test.flv -c 1 -r rtmp://127.0.0.1/live/livestream
#推100路流
./sb_rtmp_publish -i test.flv -c 10 -r rtmp://127.0.0.1/live/livestream_{i}
好像必须flv格式的视频才能被推上去
我在编译过程遇到了下面的错误
g++ -o objs/sb_http_load objs/src/core/htl_core_log.o objs/src/core/htl_core_error.o objs/src/core/htl_core_uri.o objs/src/core/htl_core_aggregate_ret.o objs/src/os/htl_os_st.o objs/src/app/htl_app_hls_load.o objs/src/app/htl_app_http_load.o objs/src/app/htl_app_http_client.o objs/src/app/htl_app_rtmp_play.o objs/src/app/htl_app_m3u8_parser.o objs/src/app/htl_app_task_base.o objs/src/app/htl_app_rtmp_load.o objs/src/app/htl_app_rtmp_protocol.o objs/src/app/htl_app_rtmp_publish.o objs/src/app/htl_app_srs_hijack.o objs/st-1.9/obj/libst.a objs/http-parser-2.1/libhttp_parser.a -ldl
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
objs/src/core/htl_core_uri.o: In function `ProtocolUrl::Initialize(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
/home/suhui/work/git/srs-bench/src/core/htl_core_uri.cpp:59: undefined reference to `context'
/home/suhui/work/git/srs-bench/src/core/htl_core_uri.cpp:59: undefined reference to `context'
/home/suhui/work/git/srs-bench/src/core/htl_core_uri.cpp:59: undefined reference to `context'
/home/suhui/work/git/srs-bench/src/core/htl_core_uri.cpp:59: undefined reference to `context'
objs/src/core/htl_core_uri.o: In function `RtmpUrl::Initialize(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
/home/suhui/work/git/srs-bench/src/core/htl_core_uri.cpp:199: undefined reference to `context'
objs/src/core/htl_core_uri.o:/home/suhui/work/git/srs-bench/src/core/htl_core_uri.cpp:199: more undefined references to `context' follow
collect2: error: ld returned 1 exit status
objs/Makefile:79: recipe for target 'objs/sb_http_load' failed
make[1]: *** [objs/sb_http_load] Error 1
make[1]: Leaving directory '/home/suhui/work/git/srs-bench'
Makefile:31: recipe for target 'all' failed
make: *** [all] Error 2
我在代码仓库的issues中找到了答案
原因是configure生成Makefile不严谨,新版本lld检查问题。我们需要修改某个文件
修改srs-bench/objs/Makefile文件。
搜索# build objs/sb_http_load,将该行以下的所有内容用如下内容替换
# build objs/sb_http_load
sb_http_load: objs/sb_http_load
objs/sb_http_load: objs/src/main/htl_main_http_load.o objs/src/core/htl_core_log.o objs/src/core/htl_core_error.o objs/src/core/htl_core_uri.o objs/src/core/htl_core_aggregate_ret.o objs/src/os/htl_os_st.o objs/src/app/htl_app_hls_load.o objs/src/app/htl_app_http_load.o objs/src/app/htl_app_http_client.o objs/src/app/htl_app_rtmp_play.o objs/src/app/htl_app_m3u8_parser.o objs/src/app/htl_app_task_base.o objs/src/app/htl_app_rtmp_load.o objs/src/app/htl_app_rtmp_protocol.o objs/src/app/htl_app_rtmp_publish.o objs/src/app/htl_app_srs_hijack.o
$(LINK) -o objs/sb_http_load objs/src/main/htl_main_http_load.o objs/src/core/htl_core_log.o objs/src/core/htl_core_error.o objs/src/core/htl_core_uri.o objs/src/core/htl_core_aggregate_ret.o objs/src/os/htl_os_st.o objs/src/app/htl_app_hls_load.o objs/src/app/htl_app_http_load.o objs/src/app/htl_app_http_client.o objs/src/app/htl_app_rtmp_play.o objs/src/app/htl_app_m3u8_parser.o objs/src/app/htl_app_task_base.o objs/src/app/htl_app_rtmp_load.o objs/src/app/htl_app_rtmp_protocol.o objs/src/app/htl_app_rtmp_publish.o objs/src/app/htl_app_srs_hijack.o objs/st-1.9/obj/libst.a objs/http-parser-2.1/libhttp_parser.a -ldl
# build objs/sb_rtmp_load
sb_rtmp_load: objs/sb_rtmp_load
objs/sb_rtmp_load: objs/src/main/htl_main_rtmp_load.o objs/src/core/htl_core_log.o objs/src/core/htl_core_error.o objs/src/core/htl_core_uri.o objs/src/core/htl_core_aggregate_ret.o objs/src/os/htl_os_st.o objs/src/app/htl_app_hls_load.o objs/src/app/htl_app_http_load.o objs/src/app/htl_app_http_client.o objs/src/app/htl_app_rtmp_play.o objs/src/app/htl_app_m3u8_parser.o objs/src/app/htl_app_task_base.o objs/src/app/htl_app_rtmp_load.o objs/src/app/htl_app_rtmp_protocol.o objs/src/app/htl_app_rtmp_publish.o objs/src/app/htl_app_srs_hijack.o
$(LINK) -o objs/sb_rtmp_load objs/src/main/htl_main_rtmp_load.o objs/src/core/htl_core_log.o objs/src/core/htl_core_error.o objs/src/core/htl_core_uri.o objs/src/core/htl_core_aggregate_ret.o objs/src/os/htl_os_st.o objs/src/app/htl_app_hls_load.o objs/src/app/htl_app_http_load.o objs/src/app/htl_app_http_client.o objs/src/app/htl_app_rtmp_play.o objs/src/app/htl_app_m3u8_parser.o objs/src/app/htl_app_task_base.o objs/src/app/htl_app_rtmp_load.o objs/src/app/htl_app_rtmp_protocol.o objs/src/app/htl_app_rtmp_publish.o objs/src/app/htl_app_srs_hijack.o objs/st-1.9/obj/libst.a objs/http-parser-2.1/libhttp_parser.a -ldl
# build objs/sb_rtmp_load_fast
sb_rtmp_load_fast: objs/sb_rtmp_load_fast
objs/sb_rtmp_load_fast: objs/src/main/htl_main_rtmp_load_fast.o objs/src/core/htl_core_log.o objs/src/core/htl_core_error.o objs/src/core/htl_core_uri.o objs/src/core/htl_core_aggregate_ret.o objs/src/os/htl_os_st.o objs/src/app/htl_app_hls_load.o objs/src/app/htl_app_http_load.o objs/src/app/htl_app_http_client.o objs/src/app/htl_app_rtmp_play.o objs/src/app/htl_app_m3u8_parser.o objs/src/app/htl_app_task_base.o objs/src/app/htl_app_rtmp_load.o objs/src/app/htl_app_rtmp_protocol.o objs/src/app/htl_app_rtmp_publish.o objs/src/app/htl_app_srs_hijack.o
$(LINK) -o objs/sb_rtmp_load_fast objs/src/main/htl_main_rtmp_load_fast.o objs/src/core/htl_core_log.o objs/src/core/htl_core_error.o objs/src/core/htl_core_uri.o objs/src/core/htl_core_aggregate_ret.o objs/src/os/htl_os_st.o objs/src/app/htl_app_hls_load.o objs/src/app/htl_app_http_load.o objs/src/app/htl_app_http_client.o objs/src/app/htl_app_rtmp_play.o objs/src/app/htl_app_m3u8_parser.o objs/src/app/htl_app_task_base.o objs/src/app/htl_app_rtmp_load.o objs/src/app/htl_app_rtmp_protocol.o objs/src/app/htl_app_rtmp_publish.o objs/src/app/htl_app_srs_hijack.o objs/st-1.9/obj/libst.a objs/http-parser-2.1/libhttp_parser.a -ldl
# build objs/sb_rtmp_publish
sb_rtmp_publish: objs/sb_rtmp_publish
objs/sb_rtmp_publish: objs/src/main/htl_main_rtmp_publish.o objs/src/core/htl_core_log.o objs/src/core/htl_core_error.o objs/src/core/htl_core_uri.o objs/src/core/htl_core_aggregate_ret.o objs/src/os/htl_os_st.o objs/src/app/htl_app_hls_load.o objs/src/app/htl_app_http_load.o objs/src/app/htl_app_http_client.o objs/src/app/htl_app_rtmp_play.o objs/src/app/htl_app_m3u8_parser.o objs/src/app/htl_app_task_base.o objs/src/app/htl_app_rtmp_load.o objs/src/app/htl_app_rtmp_protocol.o objs/src/app/htl_app_rtmp_publish.o objs/src/app/htl_app_srs_hijack.o
$(LINK) -o objs/sb_rtmp_publish objs/src/main/htl_main_rtmp_publish.o objs/src/core/htl_core_log.o objs/src/core/htl_core_error.o objs/src/core/htl_core_uri.o objs/src/core/htl_core_aggregate_ret.o objs/src/os/htl_os_st.o objs/src/app/htl_app_hls_load.o objs/src/app/htl_app_http_load.o objs/src/app/htl_app_http_client.o objs/src/app/htl_app_rtmp_play.o objs/src/app/htl_app_m3u8_parser.o objs/src/app/htl_app_task_base.o objs/src/app/htl_app_rtmp_load.o objs/src/app/htl_app_rtmp_protocol.o objs/src/app/htl_app_rtmp_publish.o objs/src/app/htl_app_srs_hijack.o objs/st-1.9/obj/libst.a objs/http-parser-2.1/libhttp_parser.a -ldl
# build objs/sb_hls_load
sb_hls_load: objs/sb_hls_load
objs/sb_hls_load: objs/src/main/htl_main_hls_load.o objs/src/core/htl_core_log.o objs/src/core/htl_core_error.o objs/src/core/htl_core_uri.o objs/src/core/htl_core_aggregate_ret.o objs/src/os/htl_os_st.o objs/src/app/htl_app_hls_load.o objs/src/app/htl_app_http_load.o objs/src/app/htl_app_http_client.o objs/src/app/htl_app_rtmp_play.o objs/src/app/htl_app_m3u8_parser.o objs/src/app/htl_app_task_base.o objs/src/app/htl_app_rtmp_load.o objs/src/app/htl_app_rtmp_protocol.o objs/src/app/htl_app_rtmp_publish.o objs/src/app/htl_app_srs_hijack.o
$(LINK) -o objs/sb_hls_load objs/src/main/htl_main_hls_load.o objs/src/core/htl_core_log.o objs/src/core/htl_core_error.o objs/src/core/htl_core_uri.o objs/src/core/htl_core_aggregate_ret.o objs/src/os/htl_os_st.o objs/src/app/htl_app_hls_load.o objs/src/app/htl_app_http_load.o objs/src/app/htl_app_http_client.o objs/src/app/htl_app_rtmp_play.o objs/src/app/htl_app_m3u8_parser.o objs/src/app/htl_app_task_base.o objs/src/app/htl_app_rtmp_load.o objs/src/app/htl_app_rtmp_protocol.o objs/src/app/htl_app_rtmp_publish.o objs/src/app/htl_app_srs_hijack.o objs/st-1.9/obj/libst.a objs/http-parser-2.1/libhttp_parser.a -ldl
保存之后再次make即可成功
码字不易,如果这篇博客对你有帮助,麻烦点赞收藏,非常感谢!有不对的地方