INSTALL 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. I. TURN Server as a standard OS package
  2. At the present time, several operation systems have this project pre-packaged:
  3. 1) New Linuxes in Debian family have package "coturn":
  4. http://packages.qa.debian.org/r/coturn.html
  5. which can be installed the usual way: apt install coturn
  6. If instead you are using the Debian package from the project download site,
  7. then follow these instructions:
  8. Unpack the archive:
  9. $ tar xvfz turnserver-<...>.tar.gz
  10. Read the INSTALl file:
  11. $ cat INSTALL
  12. Install the *.deb file:
  13. $ sudo apt-get update
  14. $ sudo apt-get install gdebi-core
  15. $ sudo gdebi coturn*.deb
  16. (to install the bare package without any dependencies, type:
  17. $ sudo dpkg -i coturn_*_*.deb)
  18. After the install, read the documentation in /usr/share/doc/coturn directory.
  19. All binaries will be installed in /usr/bin/ directory.
  20. The turn*.conf config files are in /etc directory.
  21. The service start-up control scripts will be in /etc/init.d/coturn and
  22. in /etc/defaults/coturn files.
  23. 2) ArchLinux has this TURN server package:
  24. https://aur.archlinux.org/packages/coturn/
  25. 3) FreeBSD and OpenSUSE have the predecessor of this project packaged
  26. (rfc5766-turn-server).
  27. II. DOWNLOAD
  28. You have to download the archive file turnserver-*.tar.gz and unpack it:
  29. $ tar xfz turnserver-*.tgz
  30. it will create the directory 'turnserver-*' with all sources, build files,
  31. examples and documentation.
  32. III. BUILD
  33. If you are sure that you system is ready for the build (see the section
  34. "Extra libraries and Utilities" below) then you can build the system.
  35. First, you have to run the configure script:
  36. $ cd turnserver-*
  37. $ ./configure
  38. It will create a Makefile customized for your system.
  39. By default, the generated Makefile will install everything to:
  40. - /usr on Solaris.
  41. - /usr/pkg on NetBSD.
  42. - /usr/local everywhere else.
  43. The binaries will be copied to the bin subdirectory of the installation
  44. destination, config files copied to etc subdirectory. The default SQLite database
  45. will be created in var/db/turndb. There will be
  46. also documents, examples and some other files, in separate directories.
  47. You can change the root configured destination directory by
  48. setting PREFIX variable in the
  49. configure command line. For example:
  50. $ PREFIX=/opt ./configure
  51. Or:
  52. $ ./configure --prefix=/opt
  53. You can change the auxiliary configured destination sub-directories by
  54. setting BINDIR, CONFDIR, MANPREFIX, EXAMPLESDIR, DOCSDIR, LIBDIR, SCHEMADIR,
  55. LOCALSTATEDIR, TURNDBDIR and TURNINCLUDEDIR variables in the
  56. configure command line. For example:
  57. $ PREFIX=/opt BINDIR=/opt/bin64 CONFDIR=/opt/conf ./configure
  58. Or:
  59. $ ./configure --prefix=/opt --bindir=/opt/bin64 --confdir=/opt/conf
  60. You also can change the compilation and link options by
  61. setting common build variables in the
  62. configure command line. For example:
  63. $ CC=clang CFLAGS=-D_CAURIB LDFLAGS=-lshanka ./configure --prefix=/opt/shy
  64. See below a separate INSTALL section for more details.
  65. The script "configure" is a proprietary script. It will create a Makefile
  66. that you can use to build the project:
  67. $ make
  68. The make command without options will do the following:
  69. - compile the code.
  70. - create bin/ sub-directory and put the TURN server, TURN admin and
  71. "utility" programs there.
  72. - create lib/ sub-directory and put the client library there.
  73. - create include/turn/ sub-directory and put include files there.
  74. - create sqlite/turndb default empty database that will be copied to
  75. var/db/ during the installation.
  76. The TURN programs can be either called directly, or a shell scripts can be used.
  77. The script examples are located in examples/scripts directory. These scripts
  78. are just examples: you can run them successfully for the tests, but
  79. you will have to change the script parameters for your real environment.
  80. The command:
  81. $ sudo make install
  82. will install everything into the system file structure (see below).
  83. (NOTE: On NetBSD, use "su root -c").
  84. The command:
  85. $ sudo make deinstall
  86. will remove all installed TURN Server files from your system.
  87. The command:
  88. $ make clean
  89. will clean all results of the build and configuration actions.
  90. Do not run "make clean" before "make deinstall". The "clean" command will
  91. remove the Makefile and you will not be able to "deinstall" then. If that
  92. has happened, then run ./configure and make again, then deinstall and then
  93. clean.
  94. NOTE: On most modern systems, the build will produce dynamically linked
  95. executables. If you want statically linked executables, you have to modify,
  96. accordingly, the Makefile.in template file.
  97. IV. OPENSSL
  98. If you are using the OpenSSL that is coming with your system, and you are
  99. OK with it, then you do not have to read this chapter. If your system has
  100. an outdated OpenSSL version, or if you need some very fresh OpenSSL features
  101. that are not present in the current usual stable version, then you may have
  102. to compile (and run) your TURN server with a different OpenSSL version.
  103. For example, if you need ALPN feature, or DTLS1.2, and your system comes with
  104. OpenSSL 1.0.1, you will not be able to use those features unless you install
  105. OpenSSL 1.0.2 and compile and run the TURN server with the newer version.
  106. The problem is, it is usually not safe to replace the system's OpenSSL with
  107. a different version. Some systems are "bound" to its "native" OpenSSL
  108. installations, and their behavior may become unpredictable with the newer
  109. versions.
  110. So you want to preserve your system's OpenSSL but you want to compile and to
  111. run the TURN server with newer OpenSSL version. There are different ways to
  112. do that. We are suggesting the following:
  113. 1) Download the OpenSSL version from openssl.org.
  114. 2) Let's assume that we want to install the "custom" OpenSSL into /opt.
  115. Configure and build OpenSSL as:
  116. $ ./config --prefix=/opt
  117. $ make
  118. $ make install
  119. Those commands will install OpenSSL into /opt, with static libraries (no
  120. dynamic libraries).
  121. 3) Build the TURN server:
  122. $ ./configure --prefix=/opt
  123. $ make
  124. Those commands will build the TURN server binaries, statically linked
  125. against the newer OpenSSL.
  126. 4) Then you can run the TURN server without setting the dynamic
  127. libraries paths - because it has been linked statically against the newer
  128. OpenSSL libraries.
  129. One potential problem is that libevent2 is using the OpenSSL, too. So, ideally,
  130. to be 100% safe of all potential discrepancies in the runtime, we'd suggesting
  131. rebuilding libevent2 with the newer OpenSSL, too.
  132. V. INSTALL
  133. This step is optional. You can run the turnserver from the original build
  134. directory, successfully, without installing the TURN server into your system.
  135. You have to install the turnserver only if you want to integrate the
  136. turnserver in your system.
  137. Run the command:
  138. $ make install
  139. It will install turnserver in /usr/local/ directory (or to whatever directory
  140. was set in the PREFIX variable). You will have to copy
  141. /usr/local/etc/turnserver.conf.default to /usr/local/etc/turnserver.conf file
  142. and adjust your runtime configuration.
  143. This command will also:
  144. - copy the content of examples subdirectory into
  145. PREFIX/share/examples/turnserver/ directory;
  146. - copy the generated default empty SQLite database from sqlite/turndb
  147. to /usr/local/var/db or to /var/db/turndb;
  148. - copy the content of include/turn subdirectory into
  149. PREFIX/include/turn/ directory;
  150. - copy the database schema file turndb/schema.sql into
  151. PREFIX/share/turnserver/
  152. directory;
  153. - copy all docs into PREFIX/share/doc/turnserver/ directory.
  154. The installation destination of "make install" can be changed by
  155. using DESTDIR variable, for example:
  156. $ ./configure --prefix=/usr
  157. $ make
  158. $ make DESTDIR=/opt install
  159. In this example, the root installation directory will be /opt/usr.
  160. The "configure" script by default generates a Makefile with "rpath" option
  161. set for the dynamic libraries linking (if your system and your compiler
  162. allow that option). If that is not desirable (like in some OS packaging
  163. procedures), then run the "configure" script with --disable-rpath option.
  164. If you are not using the rpath linking option, then after the installation,
  165. you may have to adjust the system-wide shared library search path with
  166. "ldconfig -n <libdirname>" (Linux), "ldconfig -m <libdirname>" (BSD) or
  167. "crle -u -l <libdirname>" (Solaris). Your system must be able to find the
  168. libevent2, openssl and (optionally) SQLite and/or PostgreSQL and/or MySQL
  169. (MariaDB) and/or MongoDB and/or Redis shared libraries, either with the
  170. help of the system-wide library search configuration or by using
  171. LD_LIBRARY_PATH. "make install" will make a non-guaranteed effort to add
  172. automatically PREFIX/lib and /usr/local/lib to the libraries search path,
  173. but if you have some libraries in different non-default directories then
  174. you will have to add them manually to the search path, or you will have
  175. to adjust LD_LIBRARY_PATH.
  176. VI. PLATFORMS
  177. The TURN Server is using generic *NIX system APIs and is supposed to be
  178. usable on wide range of *NIX systems.
  179. The following platforms are supported
  180. (both i386 and x86_64 variants when applicable):
  181. - Linux,
  182. - BSD family (Mac OS X, FreeBSD, NetBSD, OpenBSD),
  183. - Solaris 11,
  184. - Cygwin
  185. It must work on other *NIXes, as well. The configure script and/or
  186. Makefile may need adjustments for other *NIXes not mentioned above.
  187. The code of the client messaging library can be compiled and used on
  188. Windows, too, but it is not supported for now.
  189. VI. COMPILERS
  190. The TURN Server is written in C programming language, for portability
  191. and for the performance reasons.
  192. The tested C compilers are:
  193. - gcc 3.4.4 thru 4.8.x
  194. - clang 3.0 or better
  195. - Solaris Studio 12 C compiler
  196. It may be compiled with other compilers, too.
  197. The code is compatible with C++ compiler, and a C++ compiler
  198. (like g++) can be used for the compilation, too:
  199. $ CC=g++ ./configure
  200. $ make
  201. VIII. WHICH EXTRA LIBRARIES AND UTILITIES YOU NEED
  202. In addition to common *NIX OS services and libraries, to compile this code,
  203. OpenSSL (version 1.0.0a or better recommended) and libevent2 (version 2.0.5
  204. or better) are required, SQLite C development library and header is optional,
  205. the PostgreSQL C client development setup is optional,
  206. the MySQL (MariaDB) C client development setup is optional,
  207. the MongoDB C Driver and the Hiredis development files for Redis database
  208. access are all optional. For development build, the development headers and
  209. the libraries to link with, are to be installed. For the runtime, only the
  210. runtime setup is required. If the build is modified for
  211. static linking, then even runtime installation is not needed.
  212. OpenSSL, SQLite, libevent2, PostgreSQL, MySQL (or MariaDB) and Hiredis
  213. libraries can be downloaded from their web sites:
  214. - http://www.openssl.org (required);
  215. - http://www.libevent.org (required);
  216. - http://www.sqlite.org (optional);
  217. - http://www.postgresql.org (optional);
  218. - http://www.mysql.org (or http://mariadb.org) (optional);
  219. - https://github.com/mongodb/mongo-c-driver (optional);
  220. - http://redis.io (optional).
  221. The installations are pretty straightforward - the usual
  222. "./configure" and "make install" commands. Install them into their default
  223. locations - the configure script and the Makefile are assuming that they are
  224. installed in their default locations. If not, then you will have to modify
  225. those.
  226. Most modern popular systems (FreeBSD, Linux Ubuntu/Debian/Mint, Amazon Linux, Fedora)
  227. have a simpler way of the third party tools installation:
  228. *) FreeBSD (the FRESH ports database is assumed to be installed, with
  229. the turnserver port included):
  230. $ cd /usr/ports/net/turnserver
  231. $ sudo make install clear
  232. That's it - that command will install the TURN server with all necesary
  233. thrid-party tools.
  234. If you system have no fresh ports repository:
  235. $ cd /usr/ports/security/openssl/
  236. $ sudo make install clean
  237. $ cd /usr/ports/databases/sqlite3/
  238. $ sudo make install clean
  239. $ cd /usr/ports/devel/libevent2/
  240. $ sudo make install clean
  241. $ cd /usr/ports/databases/postgresql84-client/ (or any other version)
  242. $ sudo make install clean
  243. $ cd /usr/ports/databases/mysql51-client/ (or any other version)
  244. $ sudo make install clean
  245. $ cd /usr/ports/databases/hiredis/
  246. $ sudo make install clean
  247. **) Linux Ubuntu, Debian, Mint:
  248. $ sudo apt-get install libssl-dev
  249. $ sudo apt-get install libsqlite3 (or sqlite3)
  250. $ sudo apt-get install libsqlite3-dev (or sqlite3-dev)
  251. $ sudo apt-get install libevent-dev
  252. $ sudo apt-get install libpq-dev
  253. $ sudo apt-get install mysql-client
  254. $ sudo apt-get install libmysqlclient-dev
  255. $ sudo apt-get install libhiredis-dev
  256. or you can use Synaptic or other software center.
  257. ***) Fedora:
  258. $ sudo yum install openssl-devel
  259. $ sudo yum install sqlite
  260. $ sudo yum install sqlite-devel
  261. $ sudo yum install libevent
  262. $ sudo yum install libevent-devel
  263. $ sudo yum install postgresql-devel
  264. $ sudo yum install postgresql-server
  265. $ sudo yum install mysql-devel
  266. $ sudo yum install mysql-server
  267. $ sudo yum install hiredis
  268. $ sudo yum install hiredis-devel
  269. ****) Amazon Linux is similar to Fedora, but:
  270. - you have to install gcc first:
  271. $ sudo yum install gcc
  272. - mongo-c-driver packages are not available "automatically".
  273. MongoDB support will not be compiled, unless you install it "manually"
  274. before the TURN server compilation. Refer to
  275. https://github.com/mongodb/mongo-c-driver for installation instructions
  276. of the driver.
  277. - hiredis packages are not available, so do not issue the
  278. hiredis installation commands. Redis support will not be
  279. compiled, unless you install it "manually" before the TURN
  280. server compilation. For Amazon EC2 AMIs, we install the
  281. redis manually in the system. But the TURN server can be
  282. perfectly installed without redis support - if you do not
  283. need it.
  284. *****) Older Debian family Linuxes are using some packages
  285. with different names.
  286. ******) On some CentOS / RedHat 6.x systems you have to install
  287. libevent2 "manually", and optionally you have to download and
  288. install Hiredis, but everything else can be found in the software
  289. repository. Also, if you would like to make an RPM for CentOS,
  290. check the directory rpm/ with the instructions.
  291. NOTE: If your tools are installed in non-standard locations, you will
  292. have to adjust CFLAGS and LDFLAGS environment variables for TURN
  293. server ./configure script. For example, to configure the TURN server
  294. with Solaris 11 PostgreSQL 32-bits setup, you may use a command
  295. like this:
  296. $ CFLAGS="${CFLAGS} -I/usr/postgres/9.2-pgdg/include/" LDFLAGS="${LDFLAGS} -L/usr/postgres/9.2-pgdg/lib/" ./configure
  297. Dynamic library paths:
  298. You may also have to adjust the turn server start script, add all the dynamic runtime
  299. library paths to LD_LIBRARY_PATH. Or you may find that it would be more convenient to adjust the
  300. system-wide shared library search path by using commands:
  301. on Linux:
  302. $ ldconfig -n <libdirname>
  303. or on BSD:
  304. $ ldconfig -m <libdirname>
  305. or on Solaris:
  306. $ crle -u -l <libdirname>
  307. On Mac OS X, you have three different choices for dynamic libraries handling:
  308. 1) Use DYLD_LIBRARY_PATH environment variable in runtime; OR
  309. 2) Before the compilation, check the dynamic libraries and adjust their identification names,
  310. if necessary, to the absolute library path or to @rpath/<library-file-name>.
  311. For example, the MySQL dynamic library may need that adjustment. You will have to use
  312. "adjust_name_tool" with -id option for that; OR
  313. 3) After the compilation, you can use the same tool, "adjust_name_tool",
  314. with option -change, to adjust the library paths values in the binary,
  315. where necessary. All library paths must be absolute paths or @rpath/... .
  316. See also the next section.
  317. NOTE: See "SQLite setup" and "PostgreSQL setup" and "MySQL setup" and
  318. "MongoDB setup" and "Redis setup" sections below for more database setup
  319. information.
  320. NOTE: If you do not install SQLite or PostgreSQL or MySQL or MongoDB or Redis,
  321. then you will be limited to the command-line options for user database.
  322. It will work great for development setup, but for real runtime systems you
  323. will need SQLite or PostgreSQL or MySQL or MongoDB or Redis.
  324. NOTE: To run PostgreSQL or MySQL or MongoDB or Redis server on the same system,
  325. you will also have to install a corresponding PostgreSQL or MySQL or
  326. MongoDB or Redis server package. The DB C development packages only provide
  327. development libraries, and client libraries only provide client
  328. access utilities and runtime libraries. The server packages may
  329. include everything - client, C development and server runtime.
  330. NOTE: OpenSSL to be installed before libevent2. When libevent2 is building,
  331. it is checking whether OpenSSL has been already installed, and which version
  332. of OpenSSL. If the OpenSSL is missed, or too old, then libevent_openssl
  333. library is not being created during the build, and you will not be able to
  334. compile the TURN Server with TLS support.
  335. NOTE: An older libevent version, version 1.x.x, is often included in some *NIX
  336. distributions. That version has its deficiencies and is inferior to the newer
  337. libevent2, especially in the performance department. This is why we are
  338. not providing backward compatibility with the older libevent 1.x version.
  339. If you have a system with older libevent, then you have to install the new
  340. libevent2 from their web site. It was tested with older *NIXes
  341. (like FreeBSD 6.x) and it works just fine.
  342. NOTE: SQLite must be of version 3.x.
  343. NOTE: For extra security features (like DTLS)
  344. support, OpenSSL version 1.0.0a or newer is recommended. Older versions do
  345. not support DTLS, reliably, in some cases. For example, the Debian 'Squeeze'
  346. Linux supplies 0.9.8 version of OpenSSL, that does not work correctly with
  347. DTLS over IPv6. If your system already has an older version of OpenSSL
  348. installed (usually in directory /usr) then you may want to install your
  349. newer OpenSSL "over" the old one (because it will most probably will not allow
  350. removal of the old one). When installing the newer OpenSSL, run the OpenSSL's
  351. configure command like this:
  352. $ ./config --prefix=/usr
  353. that will set the installation prefix to /usr (without "--prefix=/usr"
  354. by default it would be installed to /usr/local). This is necessary if you
  355. want to overwrite your existing older OpenSSL installation.
  356. IX. BUILDING WITH NON-DEFAULT PREFIX DIRECTORY
  357. Say, you have an older system with old openssl and old libevent
  358. library and you do not want to change that, but you still want
  359. to build the turnserver.
  360. Do the following steps:
  361. 1) Download new openssl from openssl.org.
  362. 2) Configure and build new openssl and install it into /opt:
  363. $ ./config --prefix=/opt
  364. $ make
  365. $ make install
  366. 3) Download the latest libevent2 from libevent.org, configure and install
  367. it into /opt:
  368. $ ./configure --prefix=/opt
  369. $ make
  370. $ make install
  371. 4) Change directory to coturn and build it:
  372. $ ./configure --prefix=/opt
  373. $ make
  374. After that, you can either use it locally, or install it into /opt.
  375. But remember that to run it, you have to adjust your LD_LIBRARY_PATH,
  376. like that:
  377. $ LD_LIBRARY_PATH=/opt/lib ./bin/turnserver
  378. An alternative would be adjusting the system-wide shared library search path
  379. by using
  380. $ ldconfig -n <libdirname> (Linux)
  381. $ ldconfig -m <libdirname> (BSD)
  382. $ crle -u -l <libdirname> (Solaris)
  383. X. TEST SCRIPTS
  384. First of all, you can use the test vectors from RFC 5769 to double-check that the
  385. STUN/TURN message encoding algorithms work properly. Run the utility:
  386. $ cd examples
  387. $ ./scripts/rfc5769.sh
  388. It will perform several protocol checks and print the results on the output.
  389. If anything has compiled wrongly (TURN Server, or OpenSSL libraries)
  390. then you will see some errors.
  391. Now, you can perform the TURN functionality test (bare minimum TURN example).
  392. If everything compiled properly, then the following programs must run
  393. together successfully, simulating TURN network routing in local loopback
  394. networking environment:
  395. Open two shell screens or consoles:
  396. In shell number 1, run TURN server application:
  397. $ cd examples
  398. $ ./scripts/basic/relay.sh
  399. In shell number 2, run test client application:
  400. $ cd examples
  401. $ ./scripts/basic/udp_c2c_client.sh
  402. If the client application produces output and in approximately 22 seconds
  403. prints the jitter, loss and round-trip-delay statistics, then everything is
  404. fine.
  405. There is another more complex test:
  406. In shell number 1, run TURN server application:
  407. $ cd examples
  408. $ ./scripts/basic/relay.sh
  409. In shell number 2, run "peer" application:
  410. $ cd examples
  411. $ ./scripts/peer.sh
  412. In shell number 3, run test client application:
  413. $ cd examples
  414. $ ./scripts/basic/udp_client.sh (or ./scripts/basic/tcp_client.sh)
  415. There is a similar set of examples/scripts/longtermsecure/* scripts for
  416. TURN environment with long-term authentication mechanism. This set of
  417. scripts is more complex, and checking the scripts options is useful for
  418. understanding how the TURN Server works:
  419. In shell number 1, run secure TURN server application:
  420. $ cd examples
  421. $ ./scripts/longtermsecure/secure_relay.sh
  422. In shell number 2, run "peer" application:
  423. $ cd examples
  424. $ ./scripts/peer.sh
  425. In shell number 3, run secure test client application:
  426. $ cd examples
  427. $ ./scripts/longtermsecure/secure_udp_client.sh
  428. (or ./scripts/longtermsecure/secure_tcp_client.sh)
  429. (or ./scripts/longtermsecure/secure_tls_client.sh)
  430. (or ./scripts/longtermsecure/secure_dtls_client.sh)
  431. (or ./scripts/longtermsecure/secure_sctp_client.sh)
  432. (or ./scripts/longtermsecure/secure_udp_c2c.sh for "peerless"
  433. client-to-client communications)
  434. The provided scripts are set for the local loopback communications,
  435. as an example and as a test environment. Real networking IPs must be
  436. used in real work environments.
  437. Try wireshark to check the communications between client, turnserver
  438. and the peer.
  439. Check the README.* files and the comments in the scripts relay.sh and
  440. secure_relay.sh as a guidance how to run the TURN server.
  441. XI. OS X compilation notes
  442. OS X usually has an older version of openssl supplied, with some Apple
  443. additions. The the "native" openssl will work, within its limitations,
  444. but the best option is to install a good fresh openssl development
  445. library, from http://www.openssl.org. You will have
  446. to handle the dynamic linking of the generated binaries, or use the
  447. static linking (see the section OPENSSL).
  448. XII. MS Windows and Cygwin support
  449. Currently, this project cannot be compiled under MS Windows.
  450. As the project is using fairly straightforward *NIX API, it is supported
  451. under Cygwin environment in MS Windows.
  452. One note for Cygwin users: we recommended libevent2 installation from the cygwin
  453. "ports" site: http://sourceware.org/cygwinports/ . You will have to install
  454. libevent2 runtime and libevent-devel packages. "Manual" libevent2 compilation
  455. and installation in Cygwin is not recommended and does not garantee a good
  456. outcome.
  457. XIII. CLIENT API LIBRARY.
  458. The compilation process will create lib/ sub-directory with libturnclient.a
  459. library. The header files for this library are located in include/turn/client/
  460. sub-directory. The C++ wrapper for the messaging functionality is located in
  461. TurnMsgLib.h header. An example of C++ code can be found in stunclient.c file.
  462. This file is compiled as a C++ program if C++ compiler is used, and as a C
  463. program if C compiler is used.
  464. XIV. DOCS
  465. After installation, the man page turnserver(1) must be available. The man page
  466. is located in man/man1 subdirectory. If you want to see the man page without
  467. installation, run the command:
  468. $ man -M man turnserver
  469. HTML-formatted client library functions reference is located in docs/html
  470. subdirectory of the original archive tree. After the installation, it will
  471. be placed in PREFIX/share/doc/turnserver/html.
  472. XV. SQLite setup
  473. The site http://www.sqlite.org site has excellent extensive documentation.
  474. The default SQLite database location for the TURN Server is
  475. /usr/local/var/db/turndb or /var/db/turndb (depending on the platform).
  476. The database schema for the TURN server is very minimalistic and is located
  477. in project's turndb/schema.sql file, or in the system's
  478. PREFIX/share/turnserver/schema.sql file after the turnserver installation:
  479. If you would like to created a new fresh SQLite TURN database:
  480. $ sqlite3 <your-db-file-name> < turndb/schema.sql
  481. The schema description:
  482. # Table for long-term credentials mechanism authorization:
  483. #
  484. CREATE TABLE turnusers_lt (
  485. realm varchar(127) default '',
  486. name varchar(512),
  487. hmackey char(128),
  488. PRIMARY KEY (realm,name)
  489. );
  490. The field hmackey contains HEX string representation of the key.
  491. We do not store the user open passwords for long-term credentials, for
  492. security reasons. Storing only the HMAC key has its own implications -
  493. if you change the realm, you will have to update the HMAC keys of all
  494. users, because the realm is used for the HMAC key generation.
  495. The key must be up to 32 characters (HEX representation of 16 bytes) for SHA1:
  496. # Table holding shared secrets for secret-based authorization
  497. # (REST API). Shared secret can be stored either in unsecure open
  498. # plain form, or in encrypted form (see turnadmin docs).
  499. # It can only be used together with the long-term
  500. # mechanism:
  501. #
  502. CREATE TABLE turn_secret (
  503. realm varchar(127) default '',
  504. value varchar(127),
  505. primary key (realm,value)
  506. );
  507. # Table holding "white" allowed peer IP ranges.
  508. #
  509. CREATE TABLE allowed_peer_ip (
  510. realm varchar(127) default '',
  511. ip_range varchar(256),
  512. primary key (realm,ip_range)
  513. );
  514. # Table holding "black" denied peer IP ranges.
  515. #
  516. CREATE TABLE denied_peer_ip (
  517. realm varchar(127) default '',
  518. ip_range varchar(256),
  519. primary key (realm,ip_range)
  520. );
  521. # Table to match origin to realm.
  522. # Multiple origins may have the same realm.
  523. # If no realm is found or the origin is absent
  524. # then the default realm is used.
  525. #
  526. CREATE TABLE turn_origin_to_realm (
  527. origin varchar(127),
  528. realm varchar(127),
  529. primary key (origin,realm)
  530. );
  531. # Realm options.
  532. # Valid options are 'max-bps',
  533. # 'total-quota' and 'user-quota'.
  534. # Values for them are integers (in text form).
  535. #
  536. CREATE TABLE turn_realm_option (
  537. realm varchar(127) default '',
  538. opt varchar(32),
  539. value varchar(128),
  540. primary key (realm,opt)
  541. );
  542. # oAuth key storage table.
  543. #
  544. CREATE TABLE oauth_key (
  545. kid varchar(128),
  546. ikm_key varchar(256),
  547. timestamp bigint default 0,
  548. lifetime integer default 0,
  549. as_rs_alg varchar(64) default '',
  550. realm varchar(127) default '',
  551. primary key (kid)
  552. );
  553. The oauth_key table fields meanings are:
  554. kid: the kid of the key;
  555. ikm_key - base64-encoded key ("input keying material");
  556. timestamp - (optional) the timestamp (in seconds) when the key
  557. lifetime starts;
  558. lifetime - (optional) the key lifetime in seconds; the default value
  559. is 0 - unlimited lifetime.
  560. as_rs_alg - oAuth token encryption algorithm; the valid values are
  561. "A256GCM", "A128GCM" (see
  562. http://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40#section-5.1).
  563. The default value is "A256GCM";
  564. realm - (optional) can be used to set the user realm (if the field is not empty).
  565. # Https access admin users.
  566. # Leave this table empty if you do not want
  567. # remote https access to the admin functions.
  568. # Web user password can be stored either in unsecure open
  569. # plain form, or in encrypted form (see turnadmin docs).
  570. #
  571. CREATE TABLE admin_user (
  572. name varchar(32),
  573. realm varchar(127),
  574. password varchar(127),
  575. primary key (name)
  576. );
  577. You can use turnadmin program to manage the database - you can either use
  578. turnadmin to add/modify/delete users, or you can use turnadmin to produce
  579. the hmac keys and modify the database with your favorite tools.
  580. When starting the turnserver, the --db parameter will be, for example:
  581. turnserver ... --db="/var/db/turndb"
  582. You will have to use the program turnadmin to fill the
  583. database, or you can do that manually with psql.
  584. Fill in users, for example:
  585. Shared secret for the TURN REST API (realm north.gov):
  586. $ bin/turnadmin -s logen -r north.gov -b "/var/db/turndb"
  587. Long-term credentials mechanism:
  588. $ bin/turnadmin -a -b "/var/db/turndb" -u gorst -r north.gov -p hero
  589. $ bin/turnadmin -a -b "/var/db/turndb" -u ninefingers -r north.gov -p youhavetoberealistic
  590. Admin users:
  591. $ bin/turnadmin -A -b "/var/db/turndb" -u gorst -p hero
  592. $ bin/turnadmin -A -b "/var/db/turndb" -u ninefingers -p youhavetoberealistic -r north.gov
  593. XVI. PostgreSQL setup
  594. The site http://www.postgresql.org site has excellent extensive documentation.
  595. For a quick-start guide, you can take a look into this page:
  596. http://www.freebsddiary.org/postgresql.php. That page is written for
  597. FreeBSD users, but it has lots of generic information applicable to other
  598. *NIXes, too.
  599. For the psql-userdb TURN server parameter, you can either set a PostgreSQL
  600. connection string, or a PostgreSQL URI, see the link:
  601. For 8.4 PostgreSQL version:
  602. http://www.postgresql.org/docs/8.4/static/libpq-connect.html
  603. For newer 9.x versions:
  604. http://www.postgresql.org/docs/9.2/static/libpq-connect.html#LIBPQ-CONNSTRING.
  605. In the PostgreSQL connection string or URI, you can set the host, the
  606. access port, the database name, the user, and the user password
  607. (if the access is secured). Numerous other parameters can be set,
  608. see the links above. The TURN server will blindly use that connection
  609. string without any modifications. You are responsible for the right
  610. connection string format.
  611. Below are the steps to setup the PostgreSQL database server from scratch:
  612. 1) Install PostgreSQL server. After the installation, do not forget to
  613. initialize the postgres root database directory:
  614. $ sudo bash
  615. $ su -l pgsql
  616. $ initdb -D /usr/local/pgsql/data
  617. 2) Find and edit Postgres' pg_hba.conf file to set the access options
  618. (see docs). On different systems, it may be located in different places.
  619. Set the lines for local access as "trust" for now (you can change it later),
  620. for TCP/IP access set the value as "md5".
  621. To set TCP/IP access from any host, use "0.0.0.0/0" for IPv4, and "::/0"
  622. for IPv6.
  623. 3) Edit postgresql.conf file to allow TCP/IP access - uncomment and edit
  624. the "listen_addresses" option (see docs). On different systems, this file
  625. may be located in different places.
  626. 4) Restart your system or restart the postgresql server, for example:
  627. $ sudo /etc/init.d/postgresql stop
  628. $ sudo /etc/init.d/postgresql start
  629. The scripts may also be in /usr/local/etc/init.d, or in /etc/rc.d/, or
  630. in /usr/local/etc/rc.d/ .
  631. 5) Check /etc/passwd file to find out which user account is used for the
  632. PostgreSQL admin access on your system (it may be "pgsql", or "postgres",
  633. or "postgresql"). Let's assume that this is "postgres" account.
  634. 6) Create a database for the TURN purposes, with name, say, "turn":
  635. $ createdb -U postgres coturn
  636. 7) Create a user for the TURN with name, say, "turn":
  637. $ psql -U postgres coturn
  638. turn=# create user turn with password 'turn';
  639. turn=#
  640. Ctrl-D
  641. 8) Create the TURN users database schema.
  642. The database schema for the TURN server is very minimalistic and is located
  643. in project's turndb/schema.sql file, or in the system's
  644. PREFIX/share/turnserver/schema.sql file after the turnserver installation:
  645. $ cat turndb/schema.sql | psql -U turn -d coturn
  646. NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "turnusers_lt_pkey" for table "turnusers_lt"
  647. CREATE TABLE
  648. CREATE TABLE
  649. See the SQLite section for the detailed database schema explanation.
  650. To fill the database with test data:
  651. cat turndb/testsqldbsetup.sql | psql -U turn -d coturn
  652. You can use turnadmin program to manage the database - you can either use
  653. turnadmin to add/modify/delete users, or you can use turnadmin to produce
  654. the hmac keys and modify the database with your favorite tools.
  655. More examples of database schema creation:
  656. psql -h <host> -U <db-user> -d <database-name> < turndb/schema.sql
  657. (old style for 8.4)
  658. psql postgresql://username:password@/databasename < turndb/schema.sql
  659. (newer style for 9.x, UNIX domain local sockets)
  660. Or:
  661. psql postgresql://username:password@hostname:port/databasename < turndb/schema.sql
  662. (newer style for 9.x, TCP/IP access)
  663. Below, the string "postgresql://turn:turn@/turn" is the connection URI.
  664. Of course, the administrators can play with the connection string as they want.
  665. When starting the turnserver, the psql-userdb parameter will be, for example:
  666. turnserver ... --psql-userdb="host=localhost dbname=coturn user=turn password=turn connect_timeout=30"
  667. Or, for 9.x PostgreSQL versions:
  668. turnserver ... --psql-userdb=postgresql://username:password@/databasename ...
  669. 9) You are ready to use the TURN database. The database name is "turn",
  670. the user name is "turn", the user password is "turn". Of course, you can
  671. choose your own names. Now, you will have to use the program turnadmin to fill the
  672. database, or you can do that manually with psql.
  673. Fill in users, for example:
  674. Shared secret for the TURN REST API (realm north.gov):
  675. $ bin/turnadmin -s logen -r north.gov -e "host=localhost dbname=coturn user=turn password=turn"
  676. Long-term credentials mechanism:
  677. $ bin/turnadmin -a -e "host=localhost dbname=coturn user=turn password=turn" -u gorst -r north.gov -p hero
  678. $ bin/turnadmin -a -e "host=localhost dbname=coturn user=turn password=turn" -u ninefingers -r north.gov -p youhavetoberealistic
  679. Admin users:
  680. $ bin/turnadmin -A -e "host=localhost dbname=coturn user=turn password=turn" -u gorst -p hero
  681. $ bin/turnadmin -A -e "host=localhost dbname=coturn user=turn password=turn" -u ninefingers -p youhavetoberealistic -r north.gov
  682. XVII. MySQL (MariaDB) setup
  683. The MySQL setup is similar to PostgreSQL (the same idea), and is well documented
  684. on their site http://www.mysql.org. The TURN Server database schema is the
  685. same as for PostgreSQL and you can find it in turndb/schema.sql file, or
  686. in the system's PREFIX/share/turnserver/schema.sql file after the turnserver
  687. installation.
  688. The general setup is similar to PostgreSQL setup procedure:
  689. 1) Check that the mysql server access is OK. Immediately after the MySQL server
  690. installation, it must be accessible, at the very minimum, at the localhost with
  691. the root account.
  692. 2) Login into mysql console from root account:
  693. $ sudo bash
  694. # mysql mysql
  695. (or mysql -p mysql if mysql account password set)
  696. 3) Add 'turn' user with 'turn' password (for example):
  697. > create user 'turn'@'localhost' identified by 'turn';
  698. 4) Create database 'coturn' (for example) and grant privileges to user 'turn':
  699. > create database coturn character set latin1;
  700. > grant all on coturn.* to 'turn'@'localhost';
  701. > flush privileges;
  702. Ctrl-D
  703. 5) Create database schema:
  704. $ mysql -p -u turn coturn < turndb/schema.sql
  705. Enter password: turn
  706. $
  707. Fill in test database data, if this is a test database
  708. (not a production database):
  709. $ mysql -p -u turn coturn < turndb/testsqldbsetup.sql
  710. 6) Fill in users, for example:
  711. Shared secret for the TURN REST API (realm north.gov):
  712. $ bin/turnadmin -s logen -r north.gov -M "host=localhost dbname=coturn user=turn password=turn"
  713. Long-term credentials mechanism:
  714. $ bin/turnadmin -a -M "host=localhost dbname=coturn user=turn password=turn" -u gorst -r north.gov -p hero
  715. $ bin/turnadmin -a -M "host=localhost dbname=coturn user=turn password=turn" -u ninefingers -r north.gov -p youhavetoberealistic
  716. Admin users:
  717. $ bin/turnadmin -A -M "host=localhost dbname=coturn user=turn password=turn" -u gorst -p hero
  718. $ bin/turnadmin -A -M "host=localhost dbname=coturn user=turn password=turn" -u ninefingers -p youhavetoberealistic -r north.gov
  719. 7) Now we can use mysql in the turnserver.
  720. If the TURN server was compiled with MySQL support, then we can use the
  721. TURN server database parameter --mysql-userdb. The value of this parameter
  722. is a connection string for the MySQL database. As "native" MySQL does not
  723. have such a feature as "connection string", the TURN server parses the
  724. connection string and converts it into MySQL database connection parameter.
  725. The format of the MySQL connection string is:
  726. "host=<host> dbname=<database-name> user=<database-user> password=<database-user-password> port=<port> connect_timeout=<seconds> read_timeout=<seconds>"
  727. (all parameters are optional)
  728. So, an example of the MySQL database parameter in the TURN server command
  729. line would be:
  730. --mysql-userdb="host=localhost dbname=coturn user=turn password=turn connect_timeout=30 read_timeout=30"
  731. Or in the turnserver.conf file:
  732. mysql-userdb="host=localhost dbname=coturn user=turn password=turn connect_timeout=30 read_timeout=30"
  733. If you have to use a secure MySQL connection (SSL) then you have to use also
  734. the optional connection string parameters for the secure communications:
  735. ca, capath, cert, key, cipher (see
  736. http://dev.mysql.com/doc/refman/5.1/en/ssl-options.html for the
  737. command options description).
  738. XVIII. MongoDB setup
  739. The MongoDB setup is well documented on their site http://docs.mongodb.org/manual/.
  740. Note: if your system has a "standard" plain vanilla UNIX "make" utility
  741. (that is not a GNU make) then you will have to use the GNU make to compile
  742. the Mongo driver, because the Mongo compilation process was written with
  743. the "proprietary" GNU extensions. For example, in FreeBSD in will have to use
  744. "gmake" command.
  745. If the TURN server was compiled with MongoDB support (mongo-c-driver is the C client
  746. library for MongoDB), then we can use the TURN server database parameter
  747. --mongo-userdb. The value of this parameter is a connection string
  748. for the MongoDB database. The format of the connection string is described at
  749. http://hergert.me/docs/mongo-c-driver/mongoc_uri.html:
  750. "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]"
  751. So, an example of the MongoDB database parameter in the TURN server command
  752. line would be:
  753. --mongo-userdb="mongodb://localhost:27017/coturn"
  754. Or in the turnserver.conf file:
  755. mongo-userdb="mongodb://localhost:27017/coturn"
  756. The meanings of the MongoDB keys are the same as for the other databases, see the
  757. explanations for the Postgres, for example.
  758. See the file testmongosetup.sh for the database structure examples.
  759. XIX. Redis setup
  760. The Redis setup is well documented on their site http://redis.io.
  761. The TURN Server Redis database schema description can be found
  762. in schema.userdb.redis and schema.stats.redis files. Those files are located
  763. either in the turndb subdirectory of the main source code directory,
  764. or in /usr/local/share/turnserver/ after the installation, or somewhere in /usr/share/
  765. directory, depending on the OS and on the instalation package.
  766. If the TURN server was compiled with Hiredis support (Hiredis is the C client
  767. library for Redis), then we can use the TURN server database parameter
  768. --redis-userdb. The value of this parameter is a connection string
  769. for the Redis database. As "native" Redis does not have such a feature as
  770. "connection string", the TURN server parses the connection string and
  771. converts it into Redis database access parameter. The format of the Redis
  772. connection string is:
  773. "ip=<ip-addr> dbname=<database-number> password=<database-password> port=<port> connect_timeout=<seconds>"
  774. (all parameters are optional)
  775. So, an example of the Redis database parameter in the TURN server command
  776. line would be:
  777. --redis-userdb="ip=127.0.0.1 dbname=2 password=turn connect_timeout=30"
  778. Or in the turnserver.conf file:
  779. redis-userdb="ip=127.0.0.1 dbname=2 password=turn connect_timeout=30"
  780. Redis can be also used for the TURN allocation status check and for status and
  781. traffic notifications.
  782. See the explanation in the turndb/schema.stats.redis file, and an example in
  783. turndb/testredisdbsetup.sh file. One special thing about TURN Redis security
  784. setup is that you can store open passwords for long-term credentials in Redis.
  785. You cannot set open passwords for long-term credentials in SQLite or MySQL or
  786. PostgreSQL - with those DBs, you have to use the keys only. With Redis, you
  787. have a choice - keys or open passwords.
  788. You also have to take care about Redis connection parameters, the timeout and the
  789. keepalive. The following settings must be in your Redis config file
  790. (/etc/redis.conf or /usr/local/etc/redis.conf):
  791. ..........
  792. timeout 0
  793. ..........
  794. tcp-keepalive 60
  795. ..........
  796. Redis TURN admin commands:
  797. Shared secret for the TURN REST API (realm north.gov):
  798. $ bin/turnadmin -s logen -r north.gov -N "host=localhost dbname=2 user=turn password=turn"
  799. Long-term credentials mechanism:
  800. $ bin/turnadmin -a -N "host=localhost dbname=2 user=turn password=turn" -u gorst -r north.gov -p hero
  801. $ bin/turnadmin -a -N "host=localhost dbname=2 user=turn password=turn" -u ninefingers -r north.gov -p youhavetoberealistic
  802. Admin users:
  803. $ bin/turnadmin -A -N "host=localhost dbname=2 user=turn password=turn" -u gorst -p hero
  804. $ bin/turnadmin -A -N "host=localhost dbname=2 user=turn password=turn" -u ninefingers -p youhavetoberealistic -r north.gov
  805. See the file testredisdbsetup.sh for the data structure examples.
  806. XX. Performance tuning
  807. This topic is covered in the wiki page:
  808. https://github.com/coturn/coturn/wiki/TURN-Performance-and-Load-Balance
  809. XXI. TURN Server setup
  810. Read the project wiki pages: https://github.com/coturn/coturn/wiki
  811. Also, check the project from page links to the TURN/WebRTC configuration examples.
  812. It may give you an idea how it can be done.
  813. XXII. HTTPS Management Interface
  814. The turnserver process provides an HTTPS Web access as statistics and basic management
  815. interface. The turnserver listens to incoming HTTPS admin connections on the same ports
  816. as the main TURN/STUN listener. The Web admin pages are basic and self-explanatory.
  817. To make the HTTPS interface active, the database table admin_user must be
  818. populated with the admin user account(s). An admin user can be a superuser
  819. (if not assigned to a particular realm) or a restricted user (if assigned to
  820. a realm). The restricted admin users can perform only limited actions, within
  821. their corresponding realms.
  822. XXIII. Telnet CLI management interface
  823. You have a telnet interface (enabled by default) to access the turnserver process,
  824. to view its state, to gather some statistical information, and to make some changes
  825. on-the-fly.
  826. You can access that CLI interface with telnet or putty program (in telnet mode).
  827. The process by default listens to port 5766 on IP address 127.0.0.1 for the telnet
  828. connections.
  829. WARNING: all telnet communications are going unencrypted over the network. For
  830. security reasons, we advise using the loopback IP addresses for CLI (127.0.0.1
  831. or ::1). The CLI may have a password configured, but that password is
  832. transferred over the network unencrypted, too. So sticking to the local system
  833. CLI access, and accessing the turnserver system terminal with ssh only, would
  834. be a wise decision.
  835. XXIV. ALPN support.
  836. Starting with version 4.3.2.1, the TURN server supports the ALPN STUN
  837. specifications (http://tools.ietf.org/html/draft-ietf-tram-alpn-08).
  838. If the ALPN functionality is needed, then OpenSSL version 1.0.2 or
  839. newer has to be used. See OPENSSL section for the OpenSSL upgrade hints.
  840. XXV. SCTP support
  841. Starting with version 4.4.3.1, the TURN server supports 'native' SCTP.
  842. On the client side, the TURN server, additionally, supports SCTP and
  843. TLS-over-SCTP.
  844. The relay side is not changing - the relay communications will still be UDP
  845. or TCP.