INSTALL 37 KB

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