CentOS下搭建Janus服务
2020-03-07 本文已影响0人
星星编程
一、安装Janus服务
yum install -y epel-release && \
yum update -y && \
yum install -y deltarpm && \
yum install -y openssh-server sudo which file curl zip unzip wget && \
yum install -y libmicrohttpd-devel jansson-devel libnice-devel glib22-devel opus-devel libogg-devel pkgconfig gengetopt libtool autoconf automake make gcc gcc-c++ git cmake libconfig-devel openssl-devel
wget https://github.com/cisco/libsrtp/archive/v2.0.0.tar.gz
tar xfv v2.0.0.tar.gz
cd libsrtp-2.0.0
./configure --prefix=/usr --enable-openssl
make shared_library && sudo make install
#为sip网关插件安装sofi -sip
wget https://sourceforge.net/projects/sofia-sip/files/sofia-sip/1.12.11/sofia-sip-1.12.11.tar.gz
tar zxf sofia-sip-1.12.11.tar.gz && cd sofia-sip-1.12.11 && ./configure --prefix=/usr CFLAGS=-fno-aggressive-loop-optimizations && make && make install
#安装usrsctp来支持数据通道
git clone https://github.com/sctplab/usrsctp && cd usrsctp && \
./bootstrap && \
./configure --prefix=/usr && make && make install
#安装 libwebsocket
git clone https://github.com/warmcat/libwebsockets && \
mkdir libwebsockets/build && cd libwebsockets/build && \
cmake -DMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_C_FLAGS="-fpic" .. && \
make && make install
#安装Janus
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig
git clone https://github.com/meetecho/janus-gateway.git && \
cd janus-gateway &&\
sh autogen.sh && \
./configure --prefix=/opt/janus --disable-rabbitmq --disable-docs &&\
make && make install && make configs
二、扩展项(可忽略)
1.若要使用libsrtp1.5.4,需要在configure janus 时加上 --disable-libsrtp2
2.如果需要支持mqtt可以安装paho.mqtt.c后重新configure janus编译安装
git clone https://github.com/eclipse/paho.mqtt.c.git
cd paho.mqtt.c
make && sudo make install
三、运行
nohup /opt/janus/bin/janus >> /var/log/janus.log 2>&1 &
#可以通过如下命令查看janus已经起来
netstat -anp | grep janus
// error while loading shared libraries: libsrtp2.so.1: cannot open shared object file: No such file or directory
解决方法:http://git.xiph.org/?p=users/giles/libusrsctp.git;a=summary
https://salsa.debian.org/pkg-voip-team/libsrtp2
1、首先打开/etc/ld.so.conf文件
2、加入动态库文件所在的目录:执行vi /etc/ld.so.conf,在"include ld.so.conf.d/*.conf"下方增加"/usr/local/lib"。
3、保存后,在命令行终端执行:/sbin/ldconfig -v;其作用是将文件/etc/ld.so.conf列出的路径下的库文件缓存到/etc/ld.so.cache以供使用,因此当安装完一些库文件,或者修改/etc/ld.so.conf增加了库的新搜索路径,需要运行一下ldconfig,使所有的库文件都被缓存到文件/etc/ld.so.cache中,如果没做,可能会找不到刚安装的库。
四、运行官方demo
$ cd /usr/local/
$ wget http://nginx.org/download/nginx-1.8.0.tar.gz
$ tar -zxvf nginx-1.8.0.tar.gz
$ cd nginx-1.8.0
$ ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module
(注: --with-http_ssl_module:这个不加后面在nginx.conf配置ssl:on后,启动会报nginx: [emerg] unknown directive "ssl" in /opt/nginx/conf/nginx.conf 异常)
$ make && make install
开机自启动
即在rc.local增加启动代码就可以了。
vi /etc/rc.local
增加一行 /usr/local/nginx/sbin/nginx
设置执行权限:
chmod 755 rc.local
配置后无法启动,查看了下是rc-local.service未启动
systemctl enable rc-local.service
systemctl start rc-local.service
systemctl status rc-local.service
Nginx配置文件常见结构的从外到内依次是「http」「server」「location」等等,缺省的继承关系是从外到内,也就是说内层块会自动获取外层块的值作为缺省值。
vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
listen 8443 ssl;
server_name localhost;
location / {
root /opt/janus/share/janus/demos;
index index.html index.htm;
}
location 8089/janus{
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.0.238:8088/janus;
}
location /admin{
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.0.238:7088/admin;
}
location ~ /.*\.(bmp|gif|jpg|png|css|js|cur|flv|ico|swf|doc|pdf|html)$ {
root /opt/janus/share/janus/demos;
expires 1d;
}
ssl_certificate /etc/nginx/ssl/nginx.pem;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
}