janus流媒体服务器搭建
准备ubuntu20 虚拟机注意:切换root用户 sudo su,否则以下很多命令要加sudo;linux新版本推荐apt(低版本apt-get还能用)一 安装工具apt install gitaptinstall makeaptinstall nginxapt install pythonapt install net-tools二 安装janus依赖库apt install libmicro
准备ubuntu20 虚拟机
注意:切换root用户 sudo su,否则以下很多命令要加sudo;
linux新版本推荐apt(低版本apt-get还能用)
一 安装工具
apt install git
apt install make
apt install nginx
apt install python
apt install net-tools
二 安装janus依赖库
apt install libmicrohttpd-dev
apt install libjansson-dev
apt install libssl-dev
apt install libsofia-sip-ua-dev
apt install libglib2.0-dev
apt install libopus-dev
apt install libogg-dev
apt install libcurl4-openssl-dev
apt install liblua5.3-dev
apt install libconfig-dev
apt install pkg-config
apt install gengetopt
apt install libtool
apt install automake
apt install libwebsockets-dev
apt install librabbitmq-dev
apt install libnanomsg-dev
apt install libnice-dev
apt install gtk-doc-tools
apt install doxygen
apt install graphviz
注意:apt源上的libsrtp(数据加密)没有将ssl编译进去,所以需要源码编辑,将ssl功能编译进去。下载,解压,生成makefile,编译,安装步骤如下。
wget https://github.com/cisco/libsrtp/archive/v2.2.0.tar.gz
tar xfv v2.2.0.tar.gz
cd libsrtp-2.2.0
./configure --prefix=/usr --enable-openssl
make shared_library && sudo make install
三 安装janus-gateway
git clone https://github.com/meetecho/janus-gateway.git
cd janus-gateway
sh autogen.sh
./configure --prefix=/usr/local/janus
ll Makefile(确认makefile生成成功没)
make -j 4
sudo make install
make configs
四 安装在coturn
coturn依赖项先安装
apt install libevent-dev
apt install libpq-dev
apt install mysql-client
apt install libmysqlclient-dev
apt install libhiredis-dev
git clone https://github.com/coturn/coturn
cd coturn
./configure
make
sudo make install
which turnserver(查看安装情况)
(sudo cp /us从默认的配置文件中复制生成Coturn的配置文件)
turnserver.conf
r/local/etc/turnserver.conf.default /usr/local/etc/turnserver.conf
使用openssl生成证书
sudo openssl req -x509 -newkey rsa:2048 -keyout /etc/turn_server_pkey.pem -out /etc/turn_server_cert.pem -days 99999 -nodes
五 janus配置
基于安全隐私问题,Webkit内核的浏览器共享视频、语音、经纬度坐标等必须通过https形式访问。为了体验Janus,就必须启用https服务,配置包括janus的https开启和Nginx服务器的https开启。
1 申请ssl证书
2 vim /usr/local/janus/etc/janus/janus.jcfg
certificates配置项如下:
certificates: {
cert_pem = "/etc/ssl/cert/domain.cert.pem"
cert_key = "/etc/ssl/cert/domain.key.pem"
}
3 nat配置项如下:(其中的用户名及密码为turnserver.conf中配置的用户名及密码)
nat: {
stun_server = "domain.com"
stun_port = 3478
nice_debug = true
#full_trickle = true
#ice_lite = true
ice_tcp = true
...
turn_server = "domain.com"
turn_port = 3478
turn_type = "udp"
turn_user = "user"
turn_pwd = "passwd"
4 传输的配置开启https打开,否则无法使用WebRTC
vim /usr/local/janus/etc/janus/janus.tranport.http.jcfg
general: {
...
https = true # Whether to enable HTTPS (default=false)
...
}
admin: {
...
admin_https = true # Whether to enable HTTPS (default=false)
...
}
certificates: {
cert_pem = "/etc/nginx/cert/domain.club.pem"
cert_key = "/etc/nginx/cert/domain.club.key"
...
}
六 nginx配置
Nginx开启https服务必须要有证书和密钥,获取到证书和密钥后,我们在/etc/nginx目录下创建一个cert目录,将文件拷贝进去,供我们后续使用。
这里自建nginx证书
openssl req -x509 -newkey rsa:2048 -keyout /etc/nginx/cert/nginx.key -out /etc/nginx/cert/nginx.crt -days 99999 -nodes
建立新的nginx配置文件 vim /etc/nginx/conf.d/domain.janus.conf
并添加如下内容
server {
listen 0.0.0.0:443 ssl;
listen [::]:443 ssl;
# tls configuration that is not covered in this guide
# we recommend the use of https://certbot.eff.org/
server_name doman.com;
# set the root
root /opt/janus/janus-gateway/html;
index index.html;
location ~ ^/([a-zA-Z0-9=\?]+)$ {
rewrite ^/(.*)$ / break;
}
location / {
ssi on;
}
ssl_certificate /etc/letsencrypt/live/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/privkey.pem; # managed by Certbot
}
启动nginx
nginx -t &nginx -s reload
启动janus
cd /usr/local/janus/bin
sudo ./janus
打开控制台,查询本机ip地址192.168.2.158
浏览器访问web服务器的地址,https://192.168.2.158:443/(切记https不能省略,否则浏览器默认使用http协议访问,就会导致400 band request访问错误)
打开demo->Echo Test->start,若浏览器打开了摄像头即说明janus搭建成功。
更多推荐
所有评论(0)