vnc server的安装

时间:2023-03-08 21:52:18

vnc是一款使用广泛的服务器管理软件,可以实现图形化管理。我在安装vnc server碰到一些问题,也整理下我的安装步骤,希望对博友们有一些帮助。

1 安装对应的软件包

[root@centos6 ~]# yum search vnc
[root@centos6 ~]# yum -y install tigervnc-server

2 设置vnc远程连接密码

[root@centos6 ~]# vncpasswd
Password:
Verify:

3 修改vncserver配置文件

[root@centos6 ~]# vim /etc/sysconfig/vncservers
VNCSERVERS="2:root"
VNCSERVERARGS[]="-geometry 1024x768"

注意:1024x768的中间的那个符号是小写字母x。

4 重启服务并查看服务

[root@centos6 ~]# service vncserver restart #重启vncserver
Shutting down VNC server: [ OK ]
Starting VNC server: :root xauth: file /root/.Xauthority does not exist
xauth: (stdin):: bad display name "centos6.magedu.com:2" in "add" command New 'centos6.magedu.com:2 (root)' desktop is centos6.magedu.com: Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/centos6.magedu.com:.log [ OK ]
[root@centos6 ~]# netstat -tunlp |grep vnc #发现监听在5902端口上
tcp 0.0.0.0: 0.0.0.0:* LISTEN /Xvnc
tcp 0.0.0.0: 0.0.0.0:* LISTEN /Xvnc
tcp ::: :::* LISTEN /Xvnc

5 测试vnc服务

我这里在windows机器使用vncview进行测试。在vncview连接种输入ip:5902,发现连不上去。百度了下,从下面的这个参考地址获取到帮助

参考地址:https://*.com/questions/20367822/vnc-server-installed-and-running-but-not-visible-over-the-network)

整理下需要3个步骤:

  1. 确保能ping通vnc server所在的服务器
  2. 临时关闭防火墙
  3. 临时关闭selinux
[root@centos6 ~]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
ACCEPT all -- 0.0.0.0/ 0.0.0.0/ state RELATED,ESTABLISHED
ACCEPT icmp -- 0.0.0.0/ 0.0.0.0/
ACCEPT all -- 0.0.0.0/ 0.0.0.0/
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
REJECT all -- 0.0.0.0/ 0.0.0.0/ reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT)
num target prot opt source destination
REJECT all -- 0.0.0.0/ 0.0.0.0/ reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT)
num target prot opt source destination [root@centos6 ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@centos6 ~]# getenforce
Enforcing
[root@centos6 ~]# setenforce

执行上面的操作就可以远程连接了。后续我们还需要把启用防火墙把对应的端口放行,并且设置selinux支持vncserver。

vnc server的安装