coturn配合redis使用
作者:互联网
最近搭建coturn服务踩了许多坑,分享给大家,纯干货!
环境:ubuntu-server 18.04
1.安装redis
sudo apt install redis
2.安装coturn
sudo apt install coturn
3.配置coturn
sudo vim /etc/default/coturn
TURNSERVER_ENABLED=1 (去掉打头的#号)
sudo vim /etc/turnserver.conf
listening-device=enp1s0
listening-port=3478
tls-listening-port=5349
listening-ip=192.168.1.2
relay-device=enp1s0
relay-ip=192.168.1.2
external-ip=xx.xx.xx.xx
min-port=40000
max-port=50000
lt-cred-mech
server-name=turn.mydomain.com
realm=turn.mydomain.com
redis-userdb="ip=127.0.0.1 dbname=2 port=6379 connect_timeout=30"
redis-statsdb="ip=127.0.0.1 dbname=3 port=6379 connect_timeout=30"
cert=/etc/turn_server_cert.pem
pkey=/etc/turn_server_pkey.pem
allow-loopback-peers
cli-ip=127.0.0.1
cli-port=5766
重启coturn服务
sudo service coturn restart
4.redis中添加coturn用户
turnadmin -a -N "ip=127.0.0.1 dbname=2 port=6379 connect_timeout=30" -u user1 -r turn.mydomain.com -p password1
验证数据库中是否添加成功,方法1:
turnadmin -l --redis-userdb="ip=127.0.0.1 dbname=2 port=6379 connect_timeout=30"
0: log file opened: /var/tmp/turn_28375_2022-06-14.log
0: Redis DB sync connection success: ip=127.0.0.1 dbname=2 port=6379 connect_timeout=30
user1[turn.mydomain.com]
验证数据库中是否添加成功,方法2:
redis-cli
select 2
keys *
1) "turn/realm/turn.mydomain.com/user/user1/key"
也可手动添加
turnadmin -k -u user1 -r turn.mydomain.com -p password1
0xedeb8dc3c867171d1fcd1a64eada558c
redis-cli
select 2
set turn/realm/turn.mydomain.com/user/user1/key edeb8dc3c867171d1fcd1a64eada558c (不需要0x打头)
5.客户端登陆连接测试
turnutils_uclient -v -u user1 -w password1 turn.mydomain.com
0: IPv4. Connected from: 192.168.1.105:44006
0: IPv4. Connected to: xx.xx.xx.xx:3478
0: allocate sent
0: allocate response received:
0: allocate sent
0: allocate response received:
0: success
0: IPv4. Received relay addr: xx.xx.xx.xx:45686
0: clnet_allocate: rtv=16164354831909234861
0: refresh sent
0: refresh response received:
0: success
0: IPv4. Connected from: 192.168.1.105:40997
0: IPv4. Connected to: xx.xx.xx.xx:3478
0: IPv4. Connected from: 192.168.1.105:58754
0: IPv4. Connected to: xx.xx.xx.xx:3478
0: allocate sent
0: allocate response received:
0: allocate sent
0: allocate response received:
0: success
0: IPv4. Received relay addr: xx.xx.xx.xx:45687
0: clnet_allocate: rtv=0
0: refresh sent
0: refresh response received:
0: success
0: allocate sent
0: allocate response received:
0: allocate sent
0: allocate response received:
0: success
0: IPv4. Received relay addr: xx.xx.xx.xx:46390
0: clnet_allocate: rtv=15065301322524967146
0: refresh sent
0: refresh response received:
0: success
0: channel bind sent
0: cb response received:
0: channel bind: error 403 (Forbidden IP)
说明用户验证连接成功。
服务器端redis也可查看状态日志:
127.0.0.1:6379[3]> keys *
1) "turn/realm/turn.mydomain.com/user/user1/allocation/012000000000000001/status"
2) "turn/realm/turn.mydomain.com/user/user1/allocation/022000000000000001/status"
3) "turn/realm/turn.mydomain.com/user/user1/allocation/009000000000000001/status"
标签:mydomain,redis,配合,port,turn,xx,allocate,sent0,coturn 来源: https://www.cnblogs.com/fairychild/p/16376965.html