libevent下載安裝
依賴libevent開源庫,需要先進行安裝:
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure
make
make install
coturn下載安裝
git clone https://github.com/coturn/coturn
cd coturn
./configure
make
make install
查看是否安裝成功
which turnserver
修改配置信息
vi /usr/local/etc/turnserver.conf
修改配置文件信息:
relay-device=eth0 #與前ifconfig查到的網卡名稱一致
listening-ip=106.75.26.76 #內網IP
listening-port=3478 #默認端口號
tls-listening-port=5349
relay-ip=10.10.128.111
external-ip=10.10.128.111 #公網IP
relay-threads=50
lt-cred-mech
cert=/etc/turn_server_cert.pem
pkey=/etc/turn_server_pkey.pem
pidfile=”/var/run/turnserver.pid”
min-port=49152 #最小端口號
max-port=65535 #最大端口號
user=ceshi:123456 #用戶名密碼,創建IceServer時用
用戶名密碼使用如下:
List<String> urls = new ArrayList<>();
urls.add("turn:106.75.26.76:3478?transport=udp");
urls.add("turn:106.75.26.76:3478?transport=tcp");
this.iceServers.add(PeerConnection.IceServer.builder(urls).setUsername("ceshi").setPassword("123456").setTlsCertPolicy(TLS_CERT_POLICY_SECURE).createIceServer());
啓動服務
turnserver -o -a -f -user=ceshi:123456 -r Beijing
遇見的問題
問題1:
[root@10-10-128-155 coturn]# ./configure
install is /usr/bin/install
pkill is /usr/bin/pkill
sqlite3 is /usr/bin/sqlite3
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
Library option -lcrypto cannot be used
ERROR: OpenSSL Crypto development libraries are not installed properly in required location.
Abort.
解決方案:
需要依賴openssl庫
yum install openssl-devel
問題2:
CONFIG ERROR: Empty cli-password, and so telnet cli interface is disabled! Please set a non empty cli-password!
解決方案:
在配置文件/usr/local/etc/turnserver.conf中,添加cli-password字段,修改後的配置文件如下:
relay-device=eth0 #與前ifconfig查到的網卡名稱一致
listening-ip=106.75.26.76 #內網IP
listening-port=3478 #默認端口號
tls-listening-port=5349
relay-ip=10.10.128.111
external-ip=10.10.128.111 #公網IP
relay-threads=50
lt-cred-mech
cert=/etc/turn_server_cert.pem
pkey=/etc/turn_server_pkey.pem
pidfile=”/var/run/turnserver.pid”
min-port=49152 #最小端口號
max-port=65535 #最大端口號
user=ceshi:123456 #用戶名密碼,創建IceServer時用
cli-password=123456
補充
如果以上步驟後發現穿透服務器無法工作,可以在執行時嘗試添加- v
參數,打印更詳細的日誌,https://blog.csdn.net/Martin_chen2/article/details/102970731也記錄了我部署coturn的問題,可供參考。
參考鏈接:
https://github.com/pchab/ProjectRTC
https://github.com/pchab/AndroidRTC
https://www.jianshu.com/p/915eab39476d