当前位置: 首页 > 工具软件 > Stun-Lib > 使用案例 >

安装 stun/turn服务

秦永望
2023-12-01



1,关于stun和turn

STUN(Simple Traversal of UDP over NATs,NAT 的UDP简单穿越)是一种网络协议,它允许位于NAT(或多重NAT)后的客户端找出自己的公网地址,查出自己位于哪种类型的NAT之后以及NAT为某一 个本地端口所绑定的Internet端端口。这些信息被用来在两个同时处于NAT 路由器之后的主机之间建立UDP通信。该协议由RFC 3489定义。目前RFC 3489协议已被RFC 5389协议所取代,新的协议中,将STUN定义为一个协助穿越NAT的工具,并不独立提供穿越的解决方案。它还有升级版本RFC 7350,目前正在完善中。 
http://baike.baidu.com/view/884586.htm

TURN的全称为Traversal Using Relay NAT,即通过Relay方式穿越NAT,TURN应用模型通过分配TURNServer的地址和端口作为客户端对外的接受地址和端口,即私网用户发出的报文都要经过TURNServer进行Relay转发。 
http://baike.baidu.com/subview/351571/10359693.htm

2,安装

参考: 
http://www.hankcs.com/program/network/compile-rfc5766-turn-server-to-build-turn-server.html

代码下载: 
https://github.com/coturn/rfc5766-turn-server/releases 
下载最新的tar.gz包。rfc5766-turn-server-3.2.5.9.tar.gz

安装依赖环境

<code class="hljs vala has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">##ssl 需要yum安装</span>
yum install openssl openssl-libs libevent libevent-devel</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>

如果还是报错,就手动安装libevent。

<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">centos <span class="hljs-constant" style="box-sizing: border-box;">Libevent2</span> development libraries are <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">not</span> installed properly <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> required location</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

下载:http://libevent.org/ 官网,下载 
https://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz 
然后解压缩编译安装即可

编译turn-server

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">tar <span class="hljs-attribute" style="box-sizing: border-box;">-zxvf</span> rfc5766<span class="hljs-attribute" style="box-sizing: border-box;">-turn</span><span class="hljs-attribute" style="box-sizing: border-box;">-server</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.2</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.5</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.9</span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span>tar<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span>gz
cd rfc5766<span class="hljs-attribute" style="box-sizing: border-box;">-turn</span><span class="hljs-attribute" style="box-sizing: border-box;">-server</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.2</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.5</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.9</span>
<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">.</span>/configure 
make
make install</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li></ul>

configure成功:

<code class="hljs vbnet has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">more <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">is</span> /usr/bin/more
install <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">is</span> /usr/bin/install
pkill <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">is</span> /usr/bin/pkill
Use TMP dir /var/tmp
Compiler: cc
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">Do</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">not</span> use -lsocket
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">Do</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">not</span> use -lwldap32
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">Do</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">not</span> use -lwldap64
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">Do</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">not</span> use -lintl
Sockets code <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">is</span> fine: no sin_len field present
Ignore IP_RECVERR
Crypto SSL <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">lib</span> found.
SSL <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">lib</span> found.
Libevent2 development found.
Libevent2 runtime found.
Libevent2 openssl found.
Libevent2 pthreads found.

POSTGRESQL DEVELOPMENT LIBRARY (libpq.a) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">AND</span>/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OR</span> HEADER (libpq-fe.h)
        ARE <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">NOT</span> INSTALLED PROPERLY <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">ON</span> THIS SYSTEM.
        THAT<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">'S OK BUT THE TURN SERVER IS BUILDING WITHOUT POSTGRESQL DATABASE SUPPORT.</span>


MYSQL DEVELOPMENT LIBRARY (libmysqlclient) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">AND</span>/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OR</span> HEADER (mysql.h)
        ARE <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">NOT</span> INSTALLED PROPERLY <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">ON</span> THIS SYSTEM.
        THAT<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">'S OK BUT THE TURN SERVER IS BUILDING WITHOUT MYSQL DATABASE SUPPORT.</span>


HIREDIS DEVELOPMENT LIBRARY (libhiredis.*) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">AND</span>/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OR</span> HEADERS (hiredis/*.h)
        ARE <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">NOT</span> INSTALLED PROPERLY <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">ON</span> THIS SYSTEM.
        THAT<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">'S OK BUT THE TURN SERVER IS BUILDING WITHOUT REDIS SUPPORT.</span>

PREFIX=/usr/local OSLIBS= -L/usr/local/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">lib</span>/ -L/usr/local/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">lib</span>/ -L/usr/local/lib64/ -L/usr/local/lib64/ -lrt -pthread -lcrypto -lssl -levent_core -levent_openssl -levent_pthreads  -Wl,-rpath,/usr/local/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">lib</span>/ -Wl,-rpath,/usr/local/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">lib</span>/ -Wl,-rpath,/usr/local/lib64/ -Wl,-rpath,/usr/local/lib64/ -Wl,-rpath,/usr/lib64/mysql -Wl,-rpath,/usr/local/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">lib</span> DBLIBS= OSCFLAGS=-g  -Wall -Wno-deprecated-declarations -Wextra -Wformat-security -Wnested-externs -Wstrict-prototypes  -Wmissing-prototypes -Wpointer-arith -Wcast-qual -I/usr/local/include -I/usr/local/include/ -I/usr/local/include  -DTURN_HAS_DAEMON    -DINSTALL_PREFIX=/usr/local DBCFLAGS=</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li></ul>

只是说没有数据库支持的库,暂时不需要。

安装之后说明:

<code class="hljs sql has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">1) If you system supports automatic <span class="hljs-operator" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">start</span>-up system daemon services, 
the, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">to</span> enable the turnserver <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">as</span> an automatically started system 
service, you have <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">to</span>:

        a) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">Create</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">and</span> edit /etc/turnserver.conf <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">or</span> 
        /usr/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">local</span>/etc/turnserver.conf . 
        Use /usr/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">local</span>/etc/turnserver.conf.<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">as</span> an example.

        b) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">For</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">user</span> accounts settings, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">using</span> the turnserver 
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">with</span> authentication: <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">create</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">and</span> edit /etc/turnuserdb.conf 
        file, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">or</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">set</span> up PostgreSQL <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">or</span> MySQL <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">or</span> Redis <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">database</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">user</span> accounts.
        Use /usr/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">local</span>/etc/turnuserdb.conf.<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">as</span> example <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> flat file DB,
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">or</span> use /usr/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">local</span>/share/turnserver/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">schema</span>.<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">sql</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">as</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">SQL</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">database</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">schema</span>,
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">or</span> use /usr/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">local</span>/share/turnserver/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">schema</span>.userdb.redis <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">as</span> Redis
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">database</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">schema</span> description <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">and</span>/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">or</span> /usr/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">local</span>/share/turnserver/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">schema</span>.stats.redis
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">as</span> Redis status & statistics <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">database</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">schema</span> description.

        c) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">add</span> whatever <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">is</span> necessary <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">to</span> enable <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">start</span>-up daemon <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> the /usr/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">local</span>/bin/turnserver.

<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">If</span> you <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">do</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">not</span> want the turnserver <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">to</span> be a system service, 
   <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">then</span> you can <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">start</span>/stop it <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"manually"</span>, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">using</span> the <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"turnserver"</span> 
   executable <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">with</span> appropriate options (see the documentation).

<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">To</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">create</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">database</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">schema</span>, use <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">schema</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> file /usr/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">local</span>/share/turnserver/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">schema</span>.<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">sql</span>.

<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">For</span> additional information, run:

   $ man turnserver
   $ man turnadmin
   $ man turnutils</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li></ul>

在根目录创建一个user.db文件 
使用turnserver启动:

<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">turnserver --userdb /root/turnuser<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.db</span> 
里面是webrtc用户名密码:
<span class="hljs-label" style="box-sizing: border-box;">webrtc:</span>secret</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>

3,页面调用

https://github.com/EricssonResearch/openwebrtc-examples/tree/master/web 
安装node参考之前文章: 
http://blog.csdn.net/freewebsys/article/details/46649667#t1

修改main.js

<code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// must use 'url' here since Firefox doesn't understand 'urls'</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">var</span> configuration = {
  <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"iceServers"</span>: [
  {
    <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"url"</span>: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"stun:mmt-stun.verkstad.net"</span>
  },
  {
    <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"url"</span>: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"turn:mmt-turn.verkstad.net"</span>,
    <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"username"</span>: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"webrtc"</span>,
    <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"credential"</span>: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"secret"</span>
  }
  ]
};</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li></ul>

将stun服务器和turn服务器替换。

4,总结

本文的原文连接是: http://blog.csdn.net/freewebsys/article/details/47109183 未经博主允许不得转载。

stun和trun是webrtc打通的关键服务器,但是资源有限没有在公网测试。


 类似资料: