coturn配合redis使用
2022/6/15 6:20:07
本文主要是介绍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"
这篇关于coturn配合redis使用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-08阿里云Redis项目实战入门教程
- 2024-11-08阿里云Redis资料:新手入门与初级使用指南
- 2024-11-08阿里云Redis教程:新手入门及实用指南
- 2024-11-07阿里云Redis学习入门:新手必读指南
- 2024-11-07阿里云Redis学习入门:从零开始的操作指南
- 2024-11-07阿里云Redis学习:初学者指南
- 2024-11-06阿里云Redis入门教程:轻松搭建与使用指南
- 2024-11-02Redis项目实战:新手入门教程
- 2024-10-22Redis入门教程:轻松掌握数据存储与操作
- 2024-10-22Redis缓存入门教程:快速掌握Redis缓存基础知识