1. 程式人生 > >centos7 安裝VNCserver

centos7 安裝VNCserver

desktop package example 服務器 system

首先試試服務器裝了VNC沒

[[email protected] ~]# rpm -q tigervnc tigervnc-server

沒安裝的話會直接出現

package tigervnc is not installed
package tigervnc-server is not installed

如果沒有安裝桌面的話要先安裝GNOME Desktop

[[email protected] ~]# yum groupinstall GNOME Desktop

第一步,安裝VNC packages:

[[email protected] ~]# yum install tigervnc-server -y

第二步,修改配置信息,在/etc/systemd/system/下建立文件夾vncserver@:1.service 把example config 文件從/lib/systemd/system/[email protected]復制到裏面

[[email protected] ~]# cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service

然後打開這個配置文件/etc/systemd/system/vncserver@:1.service替換掉默認用戶名

找到這一行

ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
PIDFile=/home/<USER>/.vnc/%H%i.pid

這裏我直接用root 用戶登錄,所以我替換成

ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid

第三步,重加載 systemd

[[email protected] ~]# systemctl daemon-reload

第四步,為VNC設密碼

[[email protected] ~]# vncpasswd

第五步,由於我這邊的Centos 7 是用iptable防火墻的所以

vim /etc/sysconfig/iptables

在合適位置加上

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

重啟iptable

service iptables restart

如果是用Centos 7 默認防火墻的可能需要

[[email protected] ~]# firewall-cmd --permanent --add-service vnc-server
[[email protected] ~]# systemctl restart firewalld.service

第六步,設默認啟動並開啟VNC

[[email protected] ~]# systemctl enable vncserver@:1.service
[[email protected] ~]# systemctl start vncserver@:1.service

這樣基本上Centos 端就設好了,Windows 端要去下一個VNC Viewer 的軟件。連接一下VNCSERVER_IP:1試試看著有點簡陋但是上去了的


centos7 安裝VNCserver