在 Ubuntu 上为 WebRTC 安装 TURN 服务器



如何在 ubuntu 12.04 上安装 TURN 服务器?你能分享教程吗?我阅读了本教程:为WebRTC应用程序实现我们自己的STUN/TURN服务器。但我不明白的是如何在我的 ubuntu 12.04 上安装自己的 TURN 服务器?

我正在使用当前使用以下代码来创建RTCPeerConnection

const pc_config = {"iceServers": [{"url": "stun:stun.l.google.com:19302"},
  {"url":"turn:my_username@<turn_server_ip_address>", "credential":"my_password"}]};
const pc_new = new webkitRTCPeerConnection(pc_config);

我想填充上述代码的参数以使用不同的网络。

当我想安装轮次服务器时,我得到

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package resiprocate-turn-server

我用了apt-get install resiprocate-turn-server.我也用了这个 https://www.webrtc-experiment.com/docs/TURN-server-installation-guide.html 教程。

很容易安装在Linux机器中,而不是在其他操作系统中尝试。

简单方法:

sudo apt-get install coturn

如果你说不,我想要最新的尖端技术,你可以从他们的下载页面下载源代码,自己安装,例如:

sudo -i     # ignore if you already in admin mode
apt-get update && apt-get install libssl-dev libevent-dev libhiredis-dev make -y    # install the dependencies
wget -O turn.tar.gz http://turnserver.open-sys.org/downloads/v4.5.0.3/turnserver-4.5.0.3.tar.gz     # Download the source tar
tar -zxvf turn.tar.gz     # unzip
cd turnserver-*
./configure
make && make install 

运行 TURN 服务器的示例命令:

sudo turnserver -a -o -v -n  --no-dtls --no-tls -u test:test -r "someRealm"

命令说明:

  • -a - 使用长期凭据机制
  • -o - 以守护程序身份运行服务器进程
  • -v - "中等"详细模式。
  • -n - 无配置文件
  • --
  • no-dtls - 不启动 DTLS 侦听器
  • --
  • no-tls - 不启动 TLS 侦听器
  • -u - 要使用的用户凭据
  • -r - 要使用的默认领域,需要 TURN REST API

查看此 Wiki 以获取更多详细信息和配置。

现在你可以在WebRTC应用程序中使用TURN服务器作为:

var peerConnectionConfig = {
  iceServers: [{
    urls: YOUR_IP:3478,
    username: 'test',
    password: 'test'
  }]
}

在 ubuntu 服务器机器上,设置、配置和运行打包版本的 coturn。对于基本设置,请执行

# set up
sudo apt-get install --assume-yes coturn
# configure & run
USERNAME="some-username"
PASSWORD="some-password"
PORT=3478
# -n: use only commandline parameters, no config file
sudo turnserver 
    -n 
    --verbose 
    --lt-cred-mech 
    --user $USERNAME:$PASSWORD 
    --realm "someRealm" 
    --no-dtls 
    --no-tls 
    --listening-port $PORT

添加--daemon以使其在后台运行。有关turnserver选项的列表,请参阅 https://github.com/coturn/coturn/wiki/turnserver,如果您想将一个与-c CONFIGFILE一起使用,而不是像我上面那样使用 -n 并在命令行上传递所有选项,请查看它们的示例配置文件。

要在 Google Chrome 中检查它是否有效,而在安全来源的任何页面(例如 stackoverflow.com(上,请在开发者控制台中运行以下命令:

function checkTURNServer(turnConfig, timeout){ 
  return new Promise(function(resolve, reject){
    setTimeout(function(){
        if(promiseResolved) return;
        resolve(false);
        promiseResolved = true;
    }, timeout || 5000);
    var promiseResolved = false
      , myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection   //compatibility for firefox and chrome
      , pc = new myPeerConnection({iceServers:[turnConfig]})
      , noop = function(){};
    pc.createDataChannel("");    //create a bogus data channel
    pc.createOffer(function(sdp){
      if(sdp.sdp.indexOf('typ relay') > -1){ // sometimes sdp contains the ice candidates...
        promiseResolved = true;
        resolve(true);
      }
      pc.setLocalDescription(sdp, noop, noop);
    }, noop);    // create offer and set local description
    pc.onicecandidate = function(ice){  //listen for candidate events
      if(promiseResolved || !ice || !ice.candidate || !ice.candidate.candidate || !(ice.candidate.candidate.indexOf('typ relay')>-1))  return;
      promiseResolved = true;
      resolve(true);
    };
  });   
}
const USERNAME="some-username"
const PASSWORD="some-password"
const PORT=3478
const IP="10.11.0.115" // you will have to change this
console.log('TURN server reachable on TCP?', await checkTURNServer( {
    url: `turn:${IP}:${PORT}?transport=tcp`,
    username: USERNAME,
    credential: PASSWORD,
}))
console.log('TURN server reachable on UDP?', await checkTURNServer( {
    url: `turn:${IP}:${PORT}?transport=udp`,
    username: USERNAME,
    credential: PASSWORD,
}))

你应该得到

TURN server reachable on TCP? true
TURN server reachable on UDP? true
我认为

该指南有些过时了。

看看这个谷歌开源TURN服务器。
真的很容易安装,工作得很好。
https://code.google.com/p/rfc5766-turn-server/

此链接将提供有关安装和配置 TURN 服务器的所有详细信息。

https://www.webrtc-experiment.com/docs/TURN-server-installation-guide.html

这家伙有非常好的WebRTC演示存储库。

转 服务器安装

根据您的服务器更改软件包

wget http://turnserver.open-sys.org/downloads/v3.2.4.4/turnserver-3.2.4.4-debian-wheezy-ubuntu-mint-x86-64bits.tar.gz
tar -zxvf turnserver-3.2.4.4-debian-wheezy-ubuntu-mint-x86-64bits.tar.gz
wget http://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar -zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable/
./configure
make && make install
dpkg -i rfc5766-turn-server_3.2.4.4-1_amd64.deb
cd /etc/
vi turnserver.conf

添加以下内容以打开服务器.conf

listening-device=eth0
listening-ip=YOUR_IP_HERE
listening-port=3478
userdb=turnuserdb.conf
relay-device=eth0
realm=YOUR_REALM_IP_HERE
lt-cred-mech
log-file=/var/log/turnserver.log

turnuserdb.conf上添加用户名和密码

 vi turnuserdb.conf

采用以下格式

testuser:pass0wrd

要启动轮次服务器:

sh /data/start_turn_server.sh

要添加新的轮次用户:

sh /data/ addTurnUser.sh

要查看轮次服务器是否正在运行:

ps aux | grep –I turn

上面的命令应该列出一些进程作为turnserver,如果TURN服务器运行正常。

最新更新