Linux編譯安裝turnserver

在 CentOS 7 上編譯安裝 TURN 服務(wù)(推薦使用 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 服務(wù)

# 創(chuàng)建配置目錄
mkdir /etc/coturn

# 復(fù)制示例配置文件
cp /usr/local/coturn/etc/turnserver.conf.default /etc/coturn/turnserver.conf

編輯 /etc/coturn/turnserver.conf,修改以下關(guān)鍵配置項(xiàng):

# 監(jiān)聽(tīng)公網(wǎng) IP(替換為你的服務(wù)器 IP)
listening-ip=0.0.0.0
external-ip=你的公網(wǎng)IP

# 用戶憑證(格式:user:password)
user=username:password

# 領(lǐng)域(可選)
realm=yourdomain.com

# 啟用長(zhǎng)期憑證機(jī)制(推薦)
lt-cred-mech

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

# 最小/最大 UDP 端口范圍(按需調(diào)整)
min-port=49152
max-port=65535

4. 創(chuàng)建系統(tǒng)服務(wù)

創(chuàng)建服務(wù)文件 /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

啟動(dòng)服務(wù)并設(shè)置開(kāi)機(jī)自啟:

systemctl daemon-reload
systemctl start coturn
systemctl enable coturn

5. 防火墻配置

# 開(kāi)放 TURN 默認(rèn)端口
firewall-cmd --permanent --add-port=3478/tcp
firewall-cmd --permanent --add-port=3478/udp

# 開(kāi)放 UDP 端口范圍(與配置的 min-port/max-port 一致)
firewall-cmd --permanent --add-port=49152-65535/udp

firewall-cmd --reload

6. 驗(yàn)證服務(wù)

檢查服務(wù)狀態(tài):

systemctl status coturn

查看日志:

tail -f /var/log/turnserver.log

使用 turnutils_uclient 測(cè)試:

/usr/local/coturn/bin/turnutils_uclient -v -u username -w password -y 你的公網(wǎng)IP

######################################
############## 離線 ###################

1. 拷貝離線包到內(nèi)網(wǎng)服務(wù)器
# 解壓離線包到 /opt
tar -xzvf offline-packages.tar.gz -C /opt

2. 配置本地倉(cāng)庫(kù)

# 創(chuàng)建倉(cāng)庫(kù)配置文件
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 倉(cāng)庫(kù)
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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容