转载请注明文章出处:https://tlanyan.me/install-gu...web
用基于浏览器(webdriver)的selenium技术爬取数据,因此程序需运行在GUI环境下。本文分三个部分简要介绍安装GUI界面及远程链接的步骤。centos
大多数云服务器厂商提供的镜像都无GUI界面,因此要先安装图形环境。本文使用GNOME桌面环境:浏览器
yum -y groups install "GNOME Desktop"
服务器
这条命令将安装GNOME桌面的必要软件包,执行完后配置X系统使用GNOME:session
echo "exec gnome-session" >> ~/.xinitrc
app
安装KDE或者MATE桌面环境的两个命令稍微不同:ssh
<pre class="sh"># kde
yum -y groups install "KDE Plasma Workspaces"
echo "exec startkde" >> ~/.xinitrctcp
yum --enablerepo=epel -y groups install "MATE Desktop"
echo "exec /usr/bin/mate-session" >> ~/.xinitrc
</pre>ui
以上便安装好了GUI桌面环境。this
启动桌面环境有两种方式:
startx
;systemctl set-default graphical.target
,而后重启;有了桌面环境,通常能够经过云服务器厂商提供的web终端远程链接进入桌面。用web终端每次都须要打开浏览器,而后登录云管理后台再链接,比较麻烦。咱们采起直接从桌面客户端远程链接的方式,省去打开浏览器和登陆云管理后台的操做。
远程桌面技术有多种,例如VNC, TeamViewer, RDP等,本文使用免费且普遍使用的VNC。
在服务器上先安装服务端(tigervnc是tightvnc的分支):
yum install -y tigervnc-server
接着复制一份VNC配置:
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
注意上述命令参数重的“@:1”,能够将数字1换成30000内的任意数字
,“5900+数字”即为程序的显示(监听)端口,如"@:1"表示监听5901端口。
编辑该配置文件,将文件内的<USER>
替换成远程链接时的登陆用户名(若是是root,注意将第二个<USER>
所在行的"/home"移除掉)。以root身份的配置示例:
# The vncserver service unit file # # Quick HowTo: # 1. Copy this file to /etc/systemd/system/vncserver@.service # 2. Replace <USER> with the actual user name and edit vncserver # parameters appropriately # (ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i" # PIDFile=/home/<USER>/.vnc/%H%i.pid) # 3. Run `systemctl daemon-reload` # 4. Run `systemctl enable vncserver@:<display>.service` # # DO NOT RUN THIS SERVICE if your local area network is # untrusted! For a secure way of using VNC, you should # limit connections to the local host and then tunnel from # the machine you want to view VNC on (host A) to the machine # whose VNC output you want to view (host B) # # [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB # # this will open a connection on port 590N of your hostA to hostB's port 590M # (in fact, it ssh-connects to hostB and then connects to localhost (on hostB). # See the ssh man page for details on port forwarding) # # You can then point a VNC client on hostA at vncdisplay N of localhost and with # the help of ssh, you end up seeing what hostB makes available on port 590M # # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP. # # Use "-localhost" to prevent remote VNC clients connecting except when # doing so through a secure tunnel. See the "-via" option in the # `man vncviewer' manual page. [Unit] Description=Remote desktop service (VNC) After=syslog.target network.target [Service] Type=forking # Clean any existing files in /tmp/.X11-unix environment ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i" PIDFile=/root/.vnc/%H%i.pid ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' [Install] WantedBy=multi-user.target
接下来设置vnc链接密码
:
vncpasswd
注意链接密码与登陆密码
不一样:链接密码用于显示远程桌面,登陆密码用于用户登陆系统。
设置好后,启动vnc服务:
systemctl daemon-reload systemctl start vncserver@:1 systemctl enable vncserver@:1
若是开启了防火墙,注意放行相应端口。
服务端配置完毕,接下来用客户端链接。
vnc是免费技术,许多客户端都支持该协议。本文采用App Store上免费的“Remote Desktop - VNC”软件进行链接,打开后软件界面以下:
在输入框填写服务器地址:vnc://ip:port,其中ip是服务器的ip或域名,port是监听的端口,例如5901。输入后按回车,弹出密码输入框,输入vncpasswd
设置的密码。密码正确的话就能够看到服务器的图形桌面,例如:
按回车键进入登陆界面,输入登陆
用户名和密码进入系统:
接下来就能够作各类图形操做了。