• Turnserver cotrun 安装调试


    Install libevent

    Because the libevent version installed by apt is not satisfied by default.

    wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz
    tar zxvf libevent-2.1.12-stable.tar.gz
    cd libevent-2.1.12-stable
    ./configure
    mkdir build
    cd build
    cmake ..
    make && make install
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    如果出现:
    configure: error: openssl is a must but can not be found. You should add the directory containing ‘openssl.pc’ to the ‘PKG_CONFIG_PATH’ environment variable, or set ‘CFLAGS’ and ‘LDFLAGS’ directly for openssl, or use `–disable-openssl’ to disable support for openssl encryption

    则先安装:sudo apt-get install libssl-dev。

    如果已经安装还报错,则按上文提示处理

    Install coturn

    wget https://coturn.net/turnserver/v4.5.0.8/turnserver-4.5.0.8.tar.gz

    tar -zxvf turnserver-4.5.0.8.tar.gz
    cd turnserver-4.5.0.8/

    ./configure --prefix=/usr/local/turnserver # 指定安装的目录
    make && make install

    vim ~/.bashrc

    export turnserver_home=/usr/local/turnserver
    export PATH= P A T H : PATH: PATH:turnserver_home/bin
    source ~/.bashrc

    配置 turnserver
    创建配置文件

    touch /etc/turnserver.conf

    vim /etc/turnserver.conf

    # TURN server name and realm
    realm=mytest
    server-name=turnserver
    
    # Use fingerprint in TURN message
    fingerprint
    
    # IPs the TURN server listens to
    listening-ip=0.0.0.0
    
    # External IP-Address of the TURN server
    external-ip=IP_ADDRESS
    
    # Main listening port
    listening-port=3478
    
    # Further ports that are open for communication
    min-port=10000
    max-port=20000
    
    # Log file path
    log-file=/var/log/turnserver.log
    
    # Enable verbose logging
    verbose
    
    # Specify the user for the TURN authentification
    user=test:test123
    
    # Enable long-term credential mechanism
    Lt-cred-mech
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    通过配置文件启动 turnserver
    turnserver -v -r mytest -a -o -c /etc/turnserver.conf

    /usr/local/turnserver/bin/turnserver -v -r mytest -a -o -c /etc/turnserver.conf

    Test:

    Test URL:

    https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/

    If you test a STUN server, it works if you can gather a candidate with type “srflx”. If you test a TURN server, it works if you can gather a candidate with type “relay”.

    /usr/local/turnserver/bin/turnutils_uclient -u test -w test123 -y sg.mytest.hk

    一定要加上 -y 参数,client-to-client 才可以看到:

    leon@v-server:~/src/turnserver-4.5.0.8$ /usr/local/turnserver/bin/turnutils_uclient -u test -w test123 -y sg.mytest.hk
    0: Total connect time is 0
    1: start_mclient: msz=4, tot_send_msgs=0, tot_recv_msgs=0, tot_send_bytes ~ 0, tot_recv_bytes ~ 0
    2: start_mclient: msz=4, tot_send_msgs=3, tot_recv_msgs=3, tot_send_bytes ~ 300, tot_recv_bytes ~ 300
    3: start_mclient: msz=4, tot_send_msgs=10, tot_recv_msgs=10, tot_send_bytes ~ 1000, tot_recv_bytes ~ 1000
    4: start_mclient: msz=4, tot_send_msgs=15, tot_recv_msgs=15, tot_send_bytes ~ 1500, tot_recv_bytes ~ 1500
    5: start_mclient: msz=4, tot_send_msgs=15, tot_recv_msgs=15, tot_send_bytes ~ 1500, tot_recv_bytes ~ 1500
    5: start_mclient: tot_send_msgs=20, tot_recv_msgs=20
    5: start_mclient: tot_send_bytes ~ 2000, tot_recv_bytes ~ 2000
    5: Total transmit time is 5
    5: Total lost packets 0 (0.000000%), total send dropped 0 (0.000000%)
    5: Average round trip delay 0.000000 ms; min = 0 ms, max = 0 ms
    5: Average jitter 0.450000 ms; min = 0 ms, max = 4 ms

    DEBUG

    If got errors below, try it withou VPN:

    The server stun:sg.mytest.hk:3478 returned an error with code=701:
    STUN host lookup received error.
    The server turn:sg.mytest.hk:3478?transport=udp returned an error with code=701:
    TURN host lookup received error.

    USAGE:

    let iceServer = {
        iceServers: [      
          {
            url: "stun:xxx:3478"
          },
          {
            urls: "turn:xxxx:3478",
            username: "xxxx",
            credential: "123456",
          },
        ],
      };
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    Golang:

    var (
       defaultRTCConfiguration = webrtc.RTCConfiguration{
           IceServers: []webrtc.RTCIceServer{
               {
                   URLs: []string{
                       "turn:sg.mytest.hk:3478",
                   },
                   Username:       "test",
                   Credential:     "test123",
                   CredentialType: 1,
               },
           },
       }
    )
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    安装服务:

    sudo vi /etc/systemd/system/turnserver.service

    [Unit]
    Description=coturn
    Documentation=man:coturn(1) man:turnadmin(1) man:turnserver(1)
    After=syslog.target network.target

    [Service]
    Type=forking
    PIDFile=/var/run/turnserver.pid
    ExecStart=/usr/local/turnserver/bin/turnserver --daemon --pidfile /var/run/turnserver.pid -c /etc/turnserver.conf
    ExecStopPost=/usr/bin/rm -f /var/run/turnserver.pid
    Restart=on-abort

    LimitCORE=infinity
    LimitNOFILE=999999
    LimitNPROC=60000
    LimitRTPRIO=infinity
    LimitRTTIME=7000000
    CPUSchedulingPolicy=other

    sudo systemctl enable turnserver

    sudo systemctl start turnserver

    参考:

    https://yuanchieh.page/posts/2020-09-21_aws-coturn-server-%E6%9E%B6%E8%A8%AD%E6%95%99%E5%AD%B8/

    https://blog.csdn.net/kyl282889543/article/details/106816517#t13

  • 相关阅读:
    机器学习与模式识别(判断+简答题)
    用vite搭建一个vue3 + ts项目
    工业智能化转型升级难?华为云这三招,加速商业变现
    “集世界精华·展中国风采”2024北京智能科技展会(世亚智博会)
    使用React-Query解决接口请求
    C++:详细的说明智能指针的使用以及底层实现,以及删除器和包装器的使用
    FinClip 助力商家全副武装迎战
    2023年09月 Scratch(二级)真题解析#中国电子学会#全国青少年软件编程等级考试
    基于SSM的网络财务管理系统设计与实现
    BiMPM实战文本匹配【上】
  • 原文地址:https://blog.csdn.net/shelutai/article/details/126890896