兩種方法安裝,第一種最簡單
- sudo apt install coturn
- 到https://github.com/coturn/coturn下載最新穩定版回來安裝。
一開始在coturn資料夾下執行./configure會出現下面錯誤訊息
ginstall: not found
install is /usr/bin/install
pkill is /usr/bin/pkill
sqlite3: not foundsqlite: not found
Use TMP dir /var/tmp
Compiler: cc
Library option -lsocket cannot be used
Library option -lwldap32 cannot be used
Library option -lwldap64 cannot be used
Library option -lintl cannot be used
Sockets code is fine: no sin_len field present
Ignore IP_RECVERR
Crypto SSL lib found.
SSL lib found.
Libevent2 development is not installed properly
ERROR: Libevent2 development libraries are not installed properly in required location.
ERROR: may be you have just too old libevent tool - then you have to upgrade it.
See the INSTALL file.
Abort.
解決辦法:
先到https://libevent.org/下載最新穩定版libevent,然後解壓縮,到解壓縮目錄下執行
- ./configure #產生makefile
- make
- sudo make install
libevent是一個事件通知庫,適用於windows、linux、bsd等多種平台,內部使用select、epoll、kqueue、IOCP等系統調用管理事件機制。著名分佈式緩存軟件memcached也是基於libevent,而且libevent在使用上可以做到跨平台,而且根據libevent官方網站上公佈的數據統計,似乎也有著非凡的性能。coturn 的底層網絡部分依賴libevent. 所以需要先安裝libevent2。
回到coturn目錄下繼續安裝,prefix後面是自已指定安裝的位置
- ./configure --prefix=/home/work/turn-server
- make
- sudo 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
安裝完之後進行配置config
執行turnadmin -k -u coturntest -p 12345678 -r coturntest.com後
- -k, --key generate long-term credential mechanism key for a user
- -u, --user Username
- -p, --password Password
- -r, --realm Realm
會產生一段key:0x7e3a2ed35d3cf7f19e2f8b015a186f54,填到後面的config檔裡。
產生ssl要用的key和憑證
sudo openssl req -x509 -newkey rsa:2048 -keyout /home/user/config/coturn/turn_server_pkey.pem -out /home/user/config/coturn/turn_server_cert.pem -days 99999 -nodes
然後會要你依照問題填一些訊息,照問題填寫就可以了。
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:TW
State or Province Name (full name) [Some-State]:Taiwan
Locality Name (eg, city) []:Taipei
Organization Name (eg, company) [Internet Widgits Pty Ltd]:coturntest
Organizational Unit Name (eg, section) []:ct
Common Name (e.g. server FQDN or YOUR name) []:coturntest
Email Address []:test@coturntest.com
把下面的配置加到/etc/turnserver.conf的最下面,不動到前面原來的部份,前面看起來跟Apache類似,是用開關註解的方式使用配置。
listening-device=eno1 #此處eno1是電腦網絡卡名稱
listening-ip=127.0.0.1
listening-ip=192.168.0.156 #內部監聽的IP
external-ip=114.35.37.234 #外部監聽的IP
listening-port=3478 #turn伺服器的埠號
tls-listening-port=5349
relay-device=eno1 #此處eno1是電腦網絡卡名稱
min-port=49152
max-port=65535
Verbose
fingerprint
lt-cred-mech
use-auth-secret
static-auth-secret=inesadt #此處要和房間伺服器配置時constants.py檔案中的CODE_KEY保持一致。
user=inesadt:0x7e3a2ed35d3cf7f19e2f8b015a186f54
user=inesadt:inesadt
stale-nonce
cert=/home/user/config/coturn/turn_server_cert.pem #前面用openssl產生的憑證
pkey=/home/user/config/coturn/turn_server_pkey.pem #用openssl產生的key
no-loopback-peers
no-multicast-peers
mobility
no-cli
realm=coturntest.com
cli-password=qwerty #不設定在執行turnserver時會報錯:CONFIG ERROR: Empty cli-password, and so telnet cli interface is disabled! Please set a non empty cli-password!,TURN
在網路上看到啟動coturn伺服器的方法有三種
- service coturn start
- sudo turnserver
- systemctl start coturn
還有各種帶參數的啟動方式
- turnserver -v -r ylbs -a -o -c /etc/turnserver.conf
- turnserver -o -a -f -v -r coturntest.com #-r coturntest.com意為指定realm,後來我都用這種。
測試:
把自已的STUN Server 位址如後格式stun:211.10.77.156:3478,拿到這個測試網站做測試。
或自己要用的程式裡去跑跑看就知道囉~
目前在本機實測之後確實可以取代google的免費STUN Server(stun.l.google.com:19302)
沒有留言:
張貼留言