centos远程桌面vncserver安装

VNC 可以实现对另外的计算机的操作:

A : 可以访问另一个计算机,采用命令终端 或者窗口界面。

B : 可以远程控制另一个计算机,两台同步显示操作。

安装vncserver

检查是否安装VNC

rpm -q tigervnc tigervnc-server

安装VNC

yum update

yum install tigervnc-server -y	

vncserver配置

从VNC备份库中复制service文件到系统service服务管理目录下:

 cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
 

修改配置文件:

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking
User=<Username>

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=-/usr/bin/vncserver -kill %i
ExecStart=/usr/bin/vncserver %i -geometry 1920x1080
PIDFile=/home/<Username>/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i

[Install]
WantedBy=multi-user.target	

主要有三行:

  1. 需要修改为有root权限的用户;

  2. ExecStart后面使用-geometry指定默认vnc的分辨率,默认情况下是1024x768

加载vncserver服务

systemctl daemon-reload

vncpasswd <username>

修改vnc远程用户的密码

关闭防火墙

CentoS7默认采用新防火墙firewall,不在用iptables

[使用firewall]

firewall-cmd --permanent --add-service vnc-server
#添加访问权限

systemctl restart firewalld.service 
#重启firewalld

#systemctl stop firewalld.service 
#停止firewall(start,启动)

#systemctl disable firewalld.service 
#设置开机禁止firewall(enable 开机启动)

[使用iptables]

yum -y install iptables-services
#安装iptables

vi /etc/sysconfig/iptables
#修改iptables防火规则,在合适的位置加上如下一句

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5903 -j ACCEPT

systemctl restart iptables.service 
#重启防火墙使配置生效-----systemctl status iptables.service#查看状态

systemctl stop iptables.service 
#启动iptables(start)

systemctl disable iptables.service 
#禁止防火墙开机启动(enable)#设置防火墙开机启动

[注意]安装iptables后可以使用

service iptables status
#查看防火墙状态

service iptables stop
#关闭防火墙

chkconfig iptables --list
#查看防火墙开机启动状态

chkconfig iptables off
#关闭防火墙开机启动	

启动VNC服务

systemctl enable vncserver@:1.service 
#设置开机启动

systemctl start vncserver@:1.service 
#启动vnc会话服务

#systemctl status vncserver@:1.service 
#查看nvc会话服务状态

#systemctl stop vncserver@:1.service 
#关闭nvc会话服务

检查vnc服务正在监听的端口:

# netstat -tulpn | grep vnc	

[root@localhost ~]# netstat -tulpn | grep vnc
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      18218/Xvnc
tcp        0      0 0.0.0.0:6001            0.0.0.0:*               LISTEN      18218/Xvnc
tcp6       0      0 :::5901                 :::*                    LISTEN      18218/Xvnc
tcp6       0      0 :::6001                 :::*                    LISTEN      18218/Xvnc	

参考文章:

CentOS7.1安装VNC,让Win7远程桌面Linux
VPS安装和访问CentOS 7远程桌面