srs.txt
ubuntu 18.04 安装 srs
1. 上传srs_40.7z和h2ws.7z到linux服务器,然后远程ssh连接
(假设登陆用户名是bob,linux服务器ip是192.168.0.50)
$ scp *.7z bob@192.168.0.50:~
$ ssh bob@192.168.0.50
2. 安装编译依赖
$ sudo apt install gcc make python p7zip-full -y
3. 解压
$ 7z x srs_40.7z; 7z x h2ws.7z
4. 编译srs
$ cd srs-master/trunk/
$ sudo rm -rf ./objs
$ CFLAGS='-w' ./configure
$ CFLAGS='-w' make
5. 查看srs端口配置文件
$ cat ./conf/http.flv.live.conf
listen 1935;
max_connections 1000;
daemon off;
srs_log_tank console;
http_server {
enabled on;
listen 8888;
dir ./objs/nginx/html;
}
vhost __defaultVhost__ {
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
hstrs on;
}
}
6. 运行srs$ chmod +x ~/srs-master/trunk/objs/srs
$ screen -S srs ~/srs-master/trunk/objs/srs -c conf/http.flv.live.conf
Ctrl+A,D
7. 运行h2ws$ chmod +x ~/h2ws/bin/linux_amd64/h2ws
$ screen -S h2ws ~/h2ws/bin/linux_amd64/h2ws -i http://localhost:8888 -o 9999
Ctrl-A,D
8. 查看运行情况
$ screen -ls
There are screens on:
44930.h2ws (06/28/2018 03:12:44 AM) (Detached)
44887.srs (06/28/2018 03:08:44 AM) (Detached)
2 Sockets in /run/screen/S-bob.
关于screen其他操作
返回srs可以输入:screen -r srs
杀掉h2ws可以输入:screen -XS h2ws quit
或者通过-r返回后按Ctrl+C,或者按Ctrl+A,K然后输入y
9. 防火墙配置
$ sudo ufw enable
$ sudo ufw allow 22
sudo ufw allow 1935
sudo ufw allow 8888
sudo ufw allow 9999
$ sudo ufw status numbered
删除:sudo ufw delete 编号
10. 测试
(假设linux服务器ip是192.168.0.50,rtsp地址的用户名密码是admin:admin)
(1)浏览器访问:
http://192.168.0.50:8888
(2)ffmpeg推流,ffplay播放:
264:
C:\> 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
C:\> ffplay rtmp://192.168.0.50/live/264.flv
265:
C:\> 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
C:\> ffplay rtmp://192.168.0.50/live/265.flv
(3)nodeplayer测试
先用ffmpeg推265的流。
用httpserver启动nodeplayer的页面,打开浏览器导航到nodeplayer的index.html,
播放地址输入:ws://192.168.0.50:9999/live/265.flv
-------------------------
测试通过后,下面部分将srs和h2ws配置为自启动服务
1. 复制srs.service和h2ws.service到linux服务器,然后登陆
$ scp *.service bob@192.168.0.50:~
$ ssh bob@192.168.0.50
2. 替换两个service文件中bob为自己的登录用户名,sed方式如下
(如果是使用root用户,请用vi编辑器手动修改这两个文件)
假设替换为用户jude:
$ sed -i 's/bob/jude/g' *.service
3. 配置服务
$ sudo mv *.service /etc/systemd/system/
$ sudo systemctl enable srs h2ws
4. 启动服务
$ sudo systemctl start srs h2ws
5. 查看服务状态
$ sudo systemctl status srs h2ws
如果看见两个绿色的active (running),表示启动成功。
如果失败,请修改对应的/etc/systemd/system/xxxxxx.service,然后
调用systemctl daemon-reload,再调用启动服务命令。
6. 服务日志
(1)查看srs日志
$ journalctl -u srs
(2)查看srs从今天开始的日志
$ journalctl -u srs --since today
可以指定时间,如:--since "2015-01-10" --until "2015-01-11 03:00"
(3)跟随日志显示-f
$ journalctl -u srs --since today -f
(4)只显示错误日志
$ journalctl -u srs --since today -p err
可选:
0: emerg
1: alert
2: crit
3: err
4: warning
5: notice
6: info
7: debug
srs.service
[Unit]
Description=SRS
After=syslog.target
After=network.target
[Service]
Type=simple
User=bob
Group=bob
WorkingDirectory=/home/bob/srs-master/trunk
ExecStart=/home/bob/srs-master/trunk/objs/srs -c conf/http.flv.live.conf
Restart=always
Environment=USER=bob
[Install]
WantedBy=multi-user.target
h2ws.service
[Unit]
Description=H2WS
After=syslog.target
After=network.target
[Service]
Type=simple
User=bob
Group=bob
WorkingDirectory=/home/bob/h2ws/bin/linux_amd64
ExecStart=/home/bob/h2ws/bin/linux_amd64/h2ws -i http://localhost:8888 -o 9999
Restart=always
Environment=USER=bob
[Install]
WantedBy=multi-user.target