VNC协议本身不原生支持双向语音传输,需通过额外工具组合实现。以下是两种常见方案及详细步骤:
该方案通过Guacamole作为VNC代理,结合WebRTC实现实时双向语音,支持浏览器端访问,无需安装额外客户端。
(1) 安装Guacamole Server与Web组件
# 添加Guacamole YUM仓库
wget https://downloads.apache.org/guacamole/1.4.0/binary/guacamole-1.4.0-rpm.tar.gz
tar -xzvf guacamole-1.4.0-rpm.tar.gz
cd guacamole-1.4.0-rpm
sudo rpm -Uvh *.rpm
# 安装Guacamole Web应用(Tomcat)
sudo yum install -y tomcat
sudo systemctl enable --now tomcat
(2) 配置Guacamole启用WebRTC
编辑/etc/guacamole/guacamole.properties,添加以下参数:
# 启用WebRTC
enable-webrtc: true
enable-websocket: true
websocket-enabled: true
webrtc-enabled: true
# 配置TURN服务器(coturn)
webrtc-stun-server: stun:coturn.example.com:3478
webrtc-turn-server: turn:coturn.example.com:3478
webrtc-turn-username: guacamole_user
webrtc-turn-password: your_secure_password
# 启用音频输入
enable-audio: true
enable-audio-input: true
(3) 配置coturn(TURN/STUN服务器)
编辑/etc/turnserver.conf,设置NAT穿透参数:
# 监听所有网络接口
listening-ip=0.0.0.0
# 标准TURN端口
listening-port=3478
# 内部/外部IP(内网IP/公网IP)
relay-ip=192.168.1.100 # 替换为服务器内网IP
external-ip=203.0.113.10 # 替换为服务器公网IP
# 认证配置(长期凭证)
lt-cred-mech
user=guacamole_user:your_secure_password
# 日志与性能
verbose
max-bps=0 # 无带宽限制
启动coturn服务:
sudo systemctl enable --now coturn
(4) 部署信令服务器(Node.js)
创建signaling-server.js,实现WebSocket信令交换(用于协商WebRTC连接):
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
const clients = new Map();
wss.on('connection', (ws) => {
const clientId = Math.random().toString(36).substr(2, 9);
clients.set(clientId, ws);
ws.send(JSON.stringify({ type: 'your-id', id: clientId }));
ws.on('message', (message) => {
const data = JSON.parse(message);
const targetClient = clients.get(data.targetId);
if (targetClient && targetClient.readyState === WebSocket.OPEN) {
data.senderId = clientId;
targetClient.send(JSON.stringify(data));
}
});
ws.on('close', () => clients.delete(clientId));
});
启动信令服务器:
npm init -y
npm install ws
node signaling-server.js
(5) 前端页面实现(HTML/JS)
创建index.html,集成Guacamole客户端与WebRTC音频逻辑(参考Guacamole官方文档的Web集成示例,添加音频流处理代码)。
http://服务器IP/guacamole,登录Guacamole;若无需纯VNC方案,可直接使用TeamViewer或AnyDesk等工具,它们原生支持双向语音与远程桌面,配置简单:
wget https://download.teamviewer.com/download/linux/teamviewer.x86_64.rpm
sudo yum install -y teamviewer.x86_64.rpm
Settings -> Privacy -> Microphone设置);sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --permanent --add-port=3478/tcp
sudo firewall-cmd --permanent --add-port=3478/udp
sudo firewall-cmd --reload
以上方案均可实现CentOS VNC的双向语音,其中Guacamole+WebRTC适合需要Web接入的场景,第三方工具适合追求简单易用的场景。