美文网首页
Android WebRTC 01 --- 服务器环境搭建

Android WebRTC 01 --- 服务器环境搭建

作者: 沪漂意哥哥 | 来源:发表于2022-02-27 16:42 被阅读0次

    一. 安装基础工具

    yum update
    yum install git
    yum install  make
    yum install gcc-c++
    

    二. 搭建Node环境

    mkdir webrtc
    cd webrtc
    wget https://nodejs.org/dist/v10.16.0/node-v10.16.0-linux-x64.tar.xz
    # 解压
    tar -xvf node-v10.16.0-linux-x64.tar.xz
    # 改名
    mv node-v10.16.0-linux-x64 nodejs
    # 进入目录
    cd nodejs/
    
    # 确认一下nodejs下bin目录是否有node 和npm文件,如果有就可以执行软连接
    sudo ln -s /root/webrtc/nodejs/bin/npm /usr/local/bin/
    sudo ln -s /root/webrtc/nodejs/bin/npm /usr/bin/
    sudo ln -s /root/webrtc/nodejs/bin/node /usr/local/bin/
    sudo ln -s /root/webrtc/nodejs/bin/node /usr/bin/
    
    #查看是否安装
    node -v 
    npm -v 
    

    三. 安装turn服务器依赖库

    yum install openssl openssl-libs libevent2 libevent-devel
    yum install openssl-devel
    yum install sqlite
    yum install sqlite-devel
    yum install postgresql-devel
    yum install postgresql-server
    yum install mysql-devel
    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    sudo yum install mysql-server
    yum install hiredis
    yum install hiredis-devel
    

    四. 安装turn服务器

    git clone  https://gitee.com/dation/coturn.git
    cd coturn 
    ./configure 
    make 
    sudo make install
    
    #创建软连接
    sudo ln -s /root/webrtc/coturn/bin/turnserver /usr/bin/
    sudo ln -s /root/webrtc/coturn/bin/turnadmin /usr/bin/
    
    #查看是否安装成功
    which turnserver
    
    #生成用户名和密码
    turnadmin -k -u liuyi -r north.gov -p 123456
    0xa3e61b64afbb67660216f745222d1605
    

    安全访问秘钥 0xa3e61b64afbb67660216f745222d1605

    接下来配置turnserver 的配置文件/usr/local/etc/turnserver.config

    创建内容

    verbose
    fingerprint
    lt-cred-mech
    realm=test
    user=liuyi:0xa3e61b64afbb67660216f745222d1605
    user=liuyi:123456
    stale-nonce
    no-loopback-peers
    no-multicast-peers
    mobility
    no-cli
    

    五. 安装Webrtc服务端

    #安装webrtc服务器和浏览器端
    git clone https://gitee.com/luisliuyi/webrtc-node-js.git
    cd webrtc-node-js
    npm install
    

    六. 安装nginx服务器

    wget http://nginx.org/download/nginx-1.12.0.tar.gz
    tar xvf nginx-1.12.0.tar.gz
    cd nginx-1.12.0
    ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
    make 
    sudo make install 
    

    七. 更改nginx 配置文件

    vim /usr/local/nginx/conf/nginx.conf

    user root;
    worker_processes auto;
    pid /run/nginx.pid;
    include /etc/nginx/modules-enabled/*.conf;
    
    events {
        worker_connections 768;
            multi_accept on;
        }
    
    http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 300;
        types_hash_max_size 2048;
        default_type application/octet-stream;
    
    
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;
    
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
    
        gzip on;
    
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
    
            upstream web {
            server localhost:3000;      
            }
        
        upstream websocket {
            server localhost:3000;   
            }
    
        server { 
            listen       443; 
            server_name  localhost;
            ssl          on;
    
            ssl_certificate     /cert/cert.crt;#配置证书
            ssl_certificate_key  /cert/cert.pem;#配置密钥
                ssl_session_cache    shared:SSL:1m;
            ssl_session_timeout  50m;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2 SSLv2 SSLv3;
            ssl_ciphers  HIGH:!aNULL:!MD5;
            ssl_prefer_server_ciphers  on;
            
            location /wss {
            proxy_pass http://websocket/; # 代理到上面的地址去
            proxy_read_timeout 300s;
            proxy_set_header Host $host;
            proxy_set_header X-Real_IP $remote_addr;
            proxy_set_header X-Forwarded-for $remote_addr;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'Upgrade';  
             }
            location / {
            proxy_pass         http://web/;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
             }
        }
    }
    

    八. 生成nginx中的https证书

    #创建目录
    mkdir /cert
    cd /cert
    #key的生成
    openssl genrsa -des3 -out server.key 2048
    
    #生成没有密码的key
    openssl rsa -in server.key -out server.key
    
    #生成CA的crt
    openssl req -new -x509 -key server.key -out ca.crt -days 3650
    
    #csr的生成方法
    openssl req -new -key server.key -out server.csr
    
    #crt生成方法
    openssl x509 -req -days 3650 -in server.csr -CA ca.crt -CAkey server.key -CAcreateserial -out server.crt
    
    #证书合并
    cat server.key server.crt > server.pem
    

    九. 启动服务

    #启动turnserver服务
    turnserver
    
    #启动nginx服务
    nginx -s reload
    
    #启动webrtc 服务
    cd /root/webrtc/WebrtcNodeJS
    node server
    

    十. 验证

    #访问
    
    https://serverIp#roomName
    
    如:
    外网:https://192.168.103.23/#123
    内网:http:192.168.103.23:3000#123
    

    相关文章

      网友评论

          本文标题:Android WebRTC 01 --- 服务器环境搭建

          本文链接:https://www.haomeiwen.com/subject/emphrrtx.html