2026/4/16 23:11:12
网站建设
项目流程
5G网站建设要多少个,互联网协会是干嘛的,互联网怎样赚钱,校园视频网站建设从零配置 VNC 服务#xff1a;解决“目标计算机积极拒绝”连接问题完整指南本文记录了在 Linux 服务器#xff08;Ubuntu 22.04#xff09;上从零配置 TigerVNC 服务的全过程#xff0c;重点解决客户端连接时出现的错误#xff1a;“Unable to connect to socket: 由于目标…从零配置 VNC 服务解决“目标计算机积极拒绝”连接问题完整指南本文记录了在 Linux 服务器Ubuntu 22.04上从零配置 TigerVNC 服务的全过程重点解决客户端连接时出现的错误“Unable to connect to socket: 由于目标计算机积极拒绝无法连接。10061”适用于 Docker 容器、云服务器、本地虚拟机等环境最终实现通过 TigerVNC Viewer 成功连接图形桌面。一、环境说明系统Ubuntu 22.04 LTS最小化安装用户rootIP 地址内网 IPVNC 端口5901对应显示号 :1桌面环境XFCE4客户端Windows 上的 TigerVNC Viewer二、确认 VNC 服务已安装首先确认tigervnc-standalone-server已安装aptupdateaptinstall-y tigervnc-standalone-server三、设置 VNC 密码运行以下命令设置密码首次运行会提示输入vncserver密码将保存在/root/.vnc/passwd无需重复设置。四、配置 xstartup 脚本编辑~/.vnc/xstartup文件nano~/.vnc/xstartup确保内容如下#!/bin/shunsetSESSION_MANAGERunsetDBUS_SESSION_BUS_ADDRESSexecstartxfce4赋予执行权限chmodx ~/.vnc/xstartup五、启动 VNC 服务并绑定到所有网络接口vncserver -kill :12/dev/null vncserver -localhost no :1 -geometry 1280x720 -depth24-localhost no允许外部连接-geometry设置分辨率-depth设置颜色深度六、检查服务是否正常运行psaux|grepvnc输出示例root 8320 0.0 0.0 245704 67956 ? Ss 13:24 0:00 /usr/bin/Xtigervnc :1 -localhost0 -desktop 760inpb4plcdq-0:1 (root) -rfbport 5901 -PasswordFile /root/.vnc/passwd -SecurityTypes VncAuth,TLSVnc -auth /root/.Xauthority -geometry 1280x720 -depth 24检查端口监听状态netstat-tlnp|grep:5901正常输出应包含tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 8320/Xtigervnc七、安装 XFCE 桌面环境如未安装aptupdateaptinstall-y xfce4 xfce4-goodies验证安装whichstartxfce4应输出/usr/bin/startxfce4八、查看 VNC 服务日志tail-f ~/.vnc/760inpb4plcdq-0:5901.log常见错误Session startup via /root/.vnc/xstartup cleanly exited too early ( 3 seconds)!→ 检查xstartup脚本是否正确。ImportError: libQt5Core.so.5: cannot open shared object file: No such file or directory→ 无关紧要不影响 VNC 服务运行。九、测试最简模式xterm如果桌面环境启动失败可先测试最简模式vncserver -kill :1 vncserver -localhost no :1 -geometry 1280x720 -depth24-xstartup /usr/bin/xterm在客户端连接localhost:5901应看到终端窗口。十、解决“目标计算机积极拒绝”连接问题10.1 确认客户端与服务器在同一子网在 Windows 上运行ipconfig确保你的 IP 与服务器在同一网段如10.31.26.x。10.2 尝试使用 SSH 隧道连接推荐在 Windows 上运行ssh -L 5901:localhost:5901 root10.31..然后在 VNC 客户端连接localhost:590110.3 使用 x11vnc 替代 TigerVNC终极方案安装x11vncaptinstall-y x11vnc设置密码x11vnc -storepasswd /root/.vnc/passwd启动服务x11vnc -display :1 -passwd /root/.vnc/passwd -localhost no -forever -shared -rfbport5901在客户端连接localhost:5901即可看到桌面。十一、配置开机自启可选方法一使用 crontab编辑 root 的 crontabcrontab-e添加reboot /root/startvnc.sh创建启动脚本nano/root/startvnc.sh内容#!/bin/bashvncserver -kill :12/dev/null vncserver -localhost no :1 -geometry 1280x720 -depth24赋予执行权限chmodx /root/startvnc.sh十二、安全建议使用强密码不要开放 5901 端口到公网推荐使用 SSH 隧道连接如需公网访问建议配置 TLS 加密或使用反向代理。十三、常见问题排查13.1 “Connection refused” 或 “Connection timed out”检查netstat -tlnp | grep :5901是否监听0.0.0.0:5901检查防火墙是否放行 5901 端口检查客户端与服务器是否在同一子网。13.2 “Session startup via ‘/root/.vnc/xstartup’ cleanly exited too early”检查xstartup脚本是否正确确保startxfce4命令存在尝试最简模式测试。13.3 “libQt5Core.so.5: cannot open shared object file”无关紧要不影响 VNC 服务运行可忽略或安装qt5-default解决aptinstall-y qt5-default十四、总结本文从零开始配置 VNC 服务解决“目标计算机积极拒绝”连接问题最终实现通过 TigerVNC Viewer 成功连接图形桌面。关键步骤安装 TigerVNC设置密码配置xstartup脚本启动服务并绑定到所有网络接口安装 XFCE 桌面环境使用x11vnc作为终极解决方案配置开机自启安全建议。附常用命令速查表功能命令启动 VNC 服务vncserver -localhost no :1 -geometry 1280x720 -depth 24杀死 VNC 服务vncserver -kill :1检查端口监听netstat -tlnp查看 VNC 日志tail -f ~/.vnc/760inpb4plcdq-0:5901.log安装 XFCEapt install -y xfce4 xfce4-goodies安装 x11vncapt install -y x11vnc启动 x11vncx11vnc -display :1 -passwd /root/.vnc/passwd -localhost no -forever -shared -rfbport 5901本文适用于 Ubuntu 22.04 系统其他版本请根据实际情况调整命令。