Linux编译安装turnserver

在 CentOS 7 上编译安装 TURN 服务(推荐使用 coturn,它是 rfc5766-turn-server 的活跃分支)的步骤如下:

1、 安装依赖

yum install -y epel-release
yum groupinstall -y "Development Tools"
yum install -y openssl-devel libevent-devel

2. 下载并编译 Coturn

wget https://github.com/coturn/coturn/archive/refs/tags/4.6.2.tar.gz
tar -zxvf 4.6.2.tar.gz
cd coturn-4.6.2
# 编译安装
./configure --prefix=/usr/local/coturn
make -j$(nproc)
make install

3. 配置 TURN 服务

# 创建配置目录
mkdir /etc/coturn

# 复制示例配置文件
cp /usr/local/coturn/etc/turnserver.conf.default /etc/coturn/turnserver.conf

编辑 /etc/coturn/turnserver.conf,修改以下关键配置项:

# 监听公网 IP(替换为你的服务器 IP)
listening-ip=0.0.0.0
external-ip=你的公网IP

# 用户凭证(格式:user:password)
user=username:password

# 领域(可选)
realm=yourdomain.com

# 启用长期凭证机制(推荐)
lt-cred-mech

# 日志文件路径
log-file=/var/log/turnserver.log

# 最小/最大 UDP 端口范围(按需调整)
min-port=49152
max-port=65535

4. 创建系统服务

创建服务文件 /etc/systemd/system/coturn.service:

[Unit]
Description=Coturn TURN Server
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/coturn/bin/turnserver -c /etc/coturn/turnserver.conf
Restart=always

[Install]
WantedBy=multi-user.target

启动服务并设置开机自启:

systemctl daemon-reload
systemctl start coturn
systemctl enable coturn

5. 防火墙配置

# 开放 TURN 默认端口
firewall-cmd --permanent --add-port=3478/tcp
firewall-cmd --permanent --add-port=3478/udp

# 开放 UDP 端口范围(与配置的 min-port/max-port 一致)
firewall-cmd --permanent --add-port=49152-65535/udp

firewall-cmd --reload

6. 验证服务

检查服务状态:

systemctl status coturn

查看日志:

tail -f /var/log/turnserver.log

使用 turnutils_uclient 测试:

/usr/local/coturn/bin/turnutils_uclient -v -u username -w password -y 你的公网IP

######################################
############## 离线 ###################

1. 拷贝离线包到内网服务器
# 解压离线包到 /opt
tar -xzvf offline-packages.tar.gz -C /opt

2. 配置本地仓库

# 创建仓库配置文件
cat > /etc/yum.repos.d/local.repo <<
EOF
[local-offline]
name=Local Offline Repository
baseurl=file:///opt/offline-packages
enabled=1
gpgcheck=0
EOF

# 安装 EPEL 仓库
rpm -ivh  /opt/offline-packages/epel-release-7-14.noarch.rpm

# 更新缓存
yum clean all
yum makecache

3. 安装依赖和 Development Tools 组
# 安装 Development Tools 组
yum groupinstall  -y "Development Tools"

# 安装其他依赖
yum  install -y openssl-devel libevent-devel
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容