srs.txt
1ubuntu 18.04 安装 srs 2 31. 上传srs_40.7z和h2ws.7z到linux服务器,然后远程ssh连接 4(假设登陆用户名是bob,linux服务器ip是192.168.0.50) 5$ scp *.7z bob@192.168.0.50:~ 6$ ssh bob@192.168.0.50 7 82. 安装编译依赖 9$ sudo apt install gcc make python p7zip-full -y 10 113. 解压 12$ 7z x srs_40.7z; 7z x h2ws.7z 13 144. 编译srs 15$ cd srs-master/trunk/ 16$ sudo rm -rf ./objs 17$ CFLAGS='-w' ./configure 18$ CFLAGS='-w' make 19 205. 查看srs端口配置文件 21$ cat ./conf/http.flv.live.conf 22 23listen 1935; 24max_connections 1000; 25daemon off; 26srs_log_tank console; 27http_server { 28 enabled on; 29 listen 8888; 30 dir ./objs/nginx/html; 31} 32vhost __defaultVhost__ { 33 http_remux { 34 enabled on; 35 mount [vhost]/[app]/[stream].flv; 36 hstrs on; 37 } 38} 39 406. 运行srs$ chmod +x ~/srs-master/trunk/objs/srs 41$ screen -S srs ~/srs-master/trunk/objs/srs -c conf/http.flv.live.conf 42Ctrl+A,D 43 447. 运行h2ws$ chmod +x ~/h2ws/bin/linux_amd64/h2ws 45$ screen -S h2ws ~/h2ws/bin/linux_amd64/h2ws -i http://localhost:8888 -o 9999 46Ctrl-A,D 47 488. 查看运行情况 49$ screen -ls 50There are screens on: 51 44930.h2ws (06/28/2018 03:12:44 AM) (Detached) 52 44887.srs (06/28/2018 03:08:44 AM) (Detached) 532 Sockets in /run/screen/S-bob. 54 55关于screen其他操作 56返回srs可以输入:screen -r srs 57杀掉h2ws可以输入:screen -XS h2ws quit 58或者通过-r返回后按Ctrl+C,或者按Ctrl+A,K然后输入y 59 609. 防火墙配置 61$ sudo ufw enable 62$ sudo ufw allow 22 63sudo ufw allow 1935 64sudo ufw allow 8888 65sudo ufw allow 9999 66$ sudo ufw status numbered 67删除:sudo ufw delete 编号 68 6910. 测试 70(假设linux服务器ip是192.168.0.50,rtsp地址的用户名密码是admin:admin) 71(1)浏览器访问: 72http://192.168.0.50:8888 73(2)ffmpeg推流,ffplay播放: 74264: 75C:\> ffmpeg -i rtsp://admin:admin@192.168.205.155:554/Streaming/Channels/102 -c copy -f flv rtmp://192.168.0.50/live/264.flv 76C:\> ffplay rtmp://192.168.0.50/live/264.flv 77265: 78C:\> ffmpeg -i rtsp://admin:admin@192.168.205.155:554/Streaming/Channels/202 -c copy -f flv rtmp://192.168.0.50/live/265.flv 79C:\> ffplay rtmp://192.168.0.50/live/265.flv 80(3)nodeplayer测试 81先用ffmpeg推265的流。 82用httpserver启动nodeplayer的页面,打开浏览器导航到nodeplayer的index.html, 83播放地址输入:ws://192.168.0.50:9999/live/265.flv 84 85 86------------------------- 87测试通过后,下面部分将srs和h2ws配置为自启动服务 88 891. 复制srs.service和h2ws.service到linux服务器,然后登陆 90$ scp *.service bob@192.168.0.50:~ 91$ ssh bob@192.168.0.50 92 932. 替换两个service文件中bob为自己的登录用户名,sed方式如下 94(如果是使用root用户,请用vi编辑器手动修改这两个文件) 95假设替换为用户jude: 96$ sed -i 's/bob/jude/g' *.service 97 983. 配置服务 99$ sudo mv *.service /etc/systemd/system/ 100$ sudo systemctl enable srs h2ws 101 1024. 启动服务 103$ sudo systemctl start srs h2ws 104 1055. 查看服务状态 106$ sudo systemctl status srs h2ws 107如果看见两个绿色的active (running),表示启动成功。 108如果失败,请修改对应的/etc/systemd/system/xxxxxx.service,然后 109调用systemctl daemon-reload,再调用启动服务命令。 110 1116. 服务日志 112(1)查看srs日志 113$ journalctl -u srs 114(2)查看srs从今天开始的日志 115$ journalctl -u srs --since today 116可以指定时间,如:--since "2015-01-10" --until "2015-01-11 03:00" 117(3)跟随日志显示-f 118$ journalctl -u srs --since today -f 119(4)只显示错误日志 120$ journalctl -u srs --since today -p err 121可选: 1220: emerg 1231: alert 1242: crit 1253: err 1264: warning 1275: notice 1286: info 1297: debug
srs.service
1[Unit] 2Description=SRS 3After=syslog.target 4After=network.target 5 6[Service] 7Type=simple 8User=bob 9Group=bob 10WorkingDirectory=/home/bob/srs-master/trunk 11ExecStart=/home/bob/srs-master/trunk/objs/srs -c conf/http.flv.live.conf 12Restart=always 13Environment=USER=bob 14 15[Install] 16WantedBy=multi-user.target
h2ws.service
1[Unit] 2Description=H2WS 3After=syslog.target 4After=network.target 5 6[Service] 7Type=simple 8User=bob 9Group=bob 10WorkingDirectory=/home/bob/h2ws/bin/linux_amd64 11ExecStart=/home/bob/h2ws/bin/linux_amd64/h2ws -i http://localhost:8888 -o 9999 12Restart=always 13Environment=USER=bob 14 15[Install] 16WantedBy=multi-user.target