基于性能和通用性等因素考虑,阿里云官方公共Linux系统镜像默认没有安装VNC(Virtual Network Computing)服务组件。如果您希望图形化访问Linux实例,需要先在实例上安装VNC Server并安装图形界面。本文主要介绍如何在CentOS 6.8、CentOS 7.2和Ubuntu 14.04系统中安装配置VNC Server,实现图形化访问Linux实例。
如果您的实例使用CentOS镜像,可以使用脚本自动安装VNC Server和GNOME桌面环境。具体操作,请参考在Linux实例上自动安装并运行VNC Server。
确认已经在本地安装了VNC连接工具,比如TightVNC Viewer。
参考以下步骤,在CentOS 6.8系统中安装并配置TigerVNC Server和GNOME。
1 | yum groupinstall GNOME Desktop Environment -y |
注:安装需要较长时间,请耐心等待。
1 | yum install -y tigervnc-server |
1 | chkconfig --level 345 vncserver on |
1 | vncserver |
注:首次启动VNC Server会要求设置密码,或者您可以运行
vncpasswd
命令修改连接密码。
/root/.vnc/xstartup
文件,配置GNOME桌面。vim /root/.vnc/xstartup
命令 。twm &
,并添加一行gnome-session &
。:wq
保存并退出。/etc/sysconfig/vncservers
文件中,配置监听端口和环境参数。
vim /etc/sysconfig/vncservers
命令。1 | VNCSERVERS= "1:root" <br>VNCSERVERARGS[ 1 ]= "-geometry 1200x800" |
:wq
保存并退出。1 | sed -i 's/.!= root./#&/' /etc/pam.d/gdm |
dbus-uuidgen >/var/lib/dbus/machine-id
命令,生成新的machine-id。 1 | D-Bus library appears to be incorrectly set up; failed to read<br>machine uuid: Failed to open "/var/lib/dbus/machine-id" : No such file or directory |
1 | vi /etc/selinux/config |
1 | chkconfig --del NetworkManager |
1 | service vncserver restart |
1 | ps -ef | grep vnc |
1 | iptables -A INPUT -p tcp --dport 5901 -j ACCEPT |
1 | service iptables save |
参考以下步骤,在CentOS 7.2系统中安装TigerVNC Server和GNOME。
1 | yum groupinstall GNOME Desktop Environment -y |
注:安装需要较长时间,请耐心等待。
1 | yum install tigervnc-server -y |
vim /lib/systemd/system/vncserver@.service
命令。User=<User>
、ExecStart
和PIDFile
的内容替换为以下内容。 1 | User=root<br># Clean any existing files in /tmp/.X11-unix environment<br>ExecStartPre=-/usr/bin/vncserver -kill %i<br>ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i" <br>PIDFile=/root/.vnc/%H%i.pid |
:wq
保存并退出。/lib/systemd/system/vncserver@.service
文件重命名。 1 | mv /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@: 1 .service |
1 | systemctl daemon-reload |
1 | vncpasswd |
1 | vi /etc/selinux/config |
1 | chkconfig --del NetworkManager |
1 | systemctl enable vncserver@: 1 .service |
1 | ps -ef | grep vnc |
1 | firewall-cmd --permanent --add-service vnc-server |
1 | service iptables save |
参考以下步骤,在Ubuntu 14.04系统中安装并配置TigerVNC Server和GNOME。
1 | apt-get update |
1 | apt-get install vnc4server -y |
1 | vnc4server |
注:首次启动VNC Server会要求设置密码,或者您可以运行
vncpasswd
命令修改连接密码。
系统显示类似如下,如果返回结果中出现类似下图所示的内容,表示vnc4server启动成功。程序会自动在当前用户的主目录下产生一个.vnc
目录。本文以root用户为例。1 | ps -ef | grep vnc |
1 | apt-get install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal |
注:安装需要较长时间,请耐心等待。
1 | cp ~/.vnc/xstartup ~/.vnc/xstartup.bak |
vim ~/.vnc/xstartup
命令。1 | #!/bin/sh<br># Uncomment the following two lines for normal desktop:<br># unset SESSION_MANAGER<br># exec /etc/X11/xinit/xinitrc<br>[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup<br>[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources<br>xsetroot -solid grey<br>vncconfig -iconic &<br>#x-terminal-emulator -geometry 80x24+ 10 + 10 -ls -title "$VNCDESKTOP Desktop" &<br>#x-window-manager &<br>gnome-panel &<br>gnome-settings-daemon &<br>metacity &<br>nautilus &<br>gnome-terminal & |
:wq
保存并退出。1 | vncserver -kill : 1 <br>vncserver : 1 |
注:本文以原有的桌面进程为:1为例。