零、运行环境
Centos7 x86_64 、Ubuntu Server 18.04.1 LTS(注意权限)
一、配置 Mongodb 构建环境
mongodb 安装:参考 mongodb之远程连接
coturn 中虽然支持 mongodb 但是编译运行后显示 MongoDB is not supported
查资料发现:You are using the Ubuntu coturn package that has no MongoDB support compiled in
it (because mongo C driver is ot a standard Debian package). If you do want
Mongo DB support, then you have to recompile the coturn manually (as a generic
installation) on a system that has Mongo C driver.
原来需要自己装环境:mongo-c-driver
原文:Bad configuration format: mongo-userdb
注意事项:
-
前置环境:gcc cdbs automake autoconf libtool make libssl-devel libsasl2-devel git python-lxml pkg-config (根据实际情况安装,也可以不安装根据报错来补充前置环境)
-
在下载解压 mongo-c-driver 后,准备构建,需要在父级执行 cmake 而不是 mongo-c-driver 解压文件里面,同时建议新建文件夹在里面构建。
例如:
解压 mongo-c-driver 到 /mongoc
mkdir /mongocdist
cd /mongocdist
cmake /mongoc
make
make install -
使用cmake命令安装软件时,报如下错误:(提示CMake版本低,需要更高版本)
CMake Error at CMakeLists.txt:4 (CMAKE_MINIMUM_REQUIRED):
CMake 3.0.2 or higher is required. You are running version 2.8.12.2
Configuring incomplete, errors occurred!移除旧版本 yum remove cmake
安装高版本(3.1及以上)如果遇到 cmake command not found,则需要添加环境变量在 /etc/profile 中,添加后 执行 source /etc/profile 更新环境
二、构建 coturn 服务
构建版本 :4.5.1.1
- 下载 coturn 项目:coturn
- 解压
- 进入解压目录,执行 ./configure --prefix=/usr/local/coturn (–prefix 指定路径 根据实际情况调整)
- make
- make install
注意事项:
-
执行 ./configure 报错
-
install libevent-devel(ubuntu 为 libevent-dev)
ERROR: Libevent2 development libraries are not installed properly in required location.
-
install libssl-dev(ubuntu 为 libssl-dev)
ERROR: OpenSSL Crypto development libraries are not installed properly in required location
-
-
一般都为缺少前置环境(同时注意区分 centos 与 ubuntu 包)
三、配置 coturn
- 执行 make install 后
1) If your system supports automatic start-up system daemon services, then to enable the turnserver as a system service that is automatically started, you have to: // 配置文件相关 a) Create and edit /etc/turnserver.conf or /usr/local/etc/turnserver.conf . Use /usr/local/etc/turnserver.conf.default as an example. b) For user accounts settings: set up SQLite or PostgreSQL or MySQL or MongoDB or Redis database for user accounts. Use /usr/local/share/turnserver/schema.sql as SQL database schema, or use /usr/local/share/turnserver/schema.userdb.redis as Redis database schema description and/or /usr/local/share/turnserver/schema.stats.redis as Redis status & statistics database schema description. If you are using SQLite, the default database location is in /var/db/turndb or in /usr/local/var/db/turndb or in /var/lib/turn/turndb. c) add whatever is necessary to enable start-up daemon for the /usr/local/bin/turnserver. 2) If you do not want the turnserver to be a system service, then you can start/stop it "manually", using the "turnserver" executable with appropriate options (see the documentation). 3) To create database schema, use schema in file /usr/local/share/turnserver/schema.sql. 4) For additional information, run: $ man turnserver $ man turnadmin $ man turnutils ==================================================================
配置文件放在: /etc/turnserver.conf 方便直接运行
默认配置文件 注意看 make install 执行后的(1.a)
在构建的 coturn 项目 ./etc/ 中存在 turnserver.conf.default - 我的配置
listening-port=端口号 listening-ip=内网ip external-ip=公网ip min-port=40000 (注意开放防火墙端口) max-port=60000 (注意开放防火墙端口) verbose fingerprint lt-cred-mech user=turntest:testpwd(需要通过 turnadmin 创建) realm=www.xxx.cn (根据创建的角色来指定) #cli-password=xxxx(可以不填) cert=/etc/turn_server_cert.pem pkey=/etc/turn_server_pkey.pem no-loopback-peers no-multicast-peers no-tcp no-tls no-cli mongo-userdb="mongodb://127.0.0.1:端口"(mongodb)
四、long-term TURN用户
-
指定数据库
如果需要指定数据库(这里使用mongodb,-J 或者 --mongo-userdb )
turnadmin -J mongodb://127.0.0.1:端口(详细其他配置查看下面 turnadmin) -
添加
格式:turnadmin -a -u -r -p
turnadmin -a -u turntest -p testpwd -r www.xxx.cn
添加用户名为 turntest,密码为 testpwd ,realm 域为 www.xxx.cn 的用户。如果遇到 turnadmin command not found,则需要添加环境变量在 /etc/profile 中,添加后 执行 source /etc/profile 更新环境
注意:如果不用默认db也可以通过命令行配置需要使用的db文件路径,详情参考 turnadmin 或者命令行 turnadmin -h
-
查看
格式:turnadmin -l
五、TURN服务配置文件
- 自签名证书生成:
openssl req -x509 -newkey rsa:2048 -keyout /etc/turn_server_pkey.pem -out /etc/turn_server_cert.pem -days 99999 -nodes The `req` command primarily creates and processes certificate requests in PKCS#10 format -x509 请求签名,输出一个自签名证书,自己充当CA认证 -days 1000 默认30天,用于-x509天数设置 -newkey rsa:2048 生成新的认证和私钥 -nodes 对生成的私钥不加密
六、启动和测试
- 指定数据库
如果需要指定数据库(这里使用mongodb,-J 或者 --mongo-userdb )
turnserver -J mongodb://127.0.0.1:端口(详细其他配置查看下面 turnadmin) - 启动
turnserver (-c 配置文件路径)
如果遇到 turnserver command not found,则需要添加环境变量在 /etc/profile 中,添加后 执行 source /etc/profile 更新环境
注意:如果不用默认db也可以通过命令行配置需要使用的db文件路径,详情参考 turnserver 或者命令行 turnserver -h
- 启动结果
==== Show him the instruments, Practical Frost: ==== 0: TLS supported 0: DTLS supported 0: DTLS 1.2 supported 0: TURN/STUN ALPN supported 0: Third-party authorization (oAuth) supported 0: GCM (AEAD) supported 0: OpenSSL compile-time version: OpenSSL 1.0.2k-fips 26 Jan 2017 (0x100020bf) 0: 0: SQLite is not supported 0: Redis is not supported 0: PostgreSQL is not supported 0: MySQL is not supported 0: MongoDB supported 0: 0: Default Net Engine version: 3 (UDP thread per CPU core) ===================================================== 0: Domain name: 0: Default realm: www.xxx.cn 0: ERROR: CONFIG ERROR: Empty cli-password, and so telnet cli interface is disabled! Please set a non empty cli-password! 0: DTLS: Certificate file found: /etc/turn_server_cert.pem 0: DTLS: Private key file found: /etc/turn_server_pkey.pem 0: DTLS1.2: Certificate file found: /etc/turn_server_cert.pem 0: DTLS1.2: Private key file found: /etc/turn_server_pkey.pem 0: DTLS cipher suite: DEFAULT 0: Relay address to use: 10.0.4.5 0: pid file created: /var/run/turnserver.pid 0: IO method (main listener thread): epoll (with changelist) 0: WARNING: I cannot support STUN CHANGE_REQUEST functionality because only one IP address is provided 0: Wait for relay ports initialization... 0: relay 10.0.4.5 initialization... 0: relay 10.0.4.5 initialization done 0: Relay ports initialization done 0: IO method (general relay thread): epoll (with changelist) 0: turn server id=0 created 0: IO method (general relay thread): epoll (with changelist) 0: turn server id=1 created 0: IPv4. DTLS/UDP listener opened on: 10.0.4.5:23456 0: IPv4. DTLS/UDP listener opened on: 10.0.4.5:5349 0: Total General servers: 2 0: IO method (auth thread): epoll (with changelist) 0: Opened MongoDB URI <mongodb://127.0.0.1:8888> 0: IO method (auth thread): epoll (with changelist) 0: IO method (admin thread): epoll (with changelist)
- 测试(注意开放防火墙端口)
trickle-ice - 结果 (错误701不影响,具体查看 coturn issue ,数据库默认为 turn,可自行调整名称)