LINUX入门:Ubuntu 16.10安装Xfce桌面与VNC远程连接

《LINUX入门:Ubuntu 16.10安装Xfce桌面与VNC远程连接》要点:
本文介绍了LINUX入门:Ubuntu 16.10安装Xfce桌面与VNC远程连接,希望对您有用。如果有疑问,可以联系我们。

在长途服务器上运行桌面

通常在远程Linux服务器上工作时,您可以使用ssh终端. 但是,有时您需要在服务器上运行GUI应用程序,并坚持运行一段时间.

最近我不得不做类似的事情,所以我设置一个Ubuntu服务器与桌面,并通过VNC拜访它.

这个想法实现很简单. 在服务器上安装您选择的任何桌面情况. 在本教程中,我们将使用Xfce,因为它与Gnome和KDE相比更具小巧.

然后使用vnc服务器启动桌面环境,并创建一个X显示会话,我们将通过vnc客户端从本地台式机拜访.

安装桌面情况和VNC服务器

Xfce是一款轻量级桌面,非常适合在长途服务器上使用. 首先安装xfce软件包和tightvnc服务器. 在进行实际安装之前,最好先更新包缓存.

sudo apt-get update
sudo apt-get install xfce4 xfce4-goodies tightvncserver

请注意,这将只安装包,而不是启动任何器械. 我们将在本指南后面自行启动具体设置的vncserver.

如果dpkg进程意外退出,则可能必需运行以下命令 -
#sudo dpkg --configure -a

为vnc创立一个新用户

接下来要做的是创立一个将在vnc会话期间使用的unix用户. 用户名可以是任何东西. 使用adduser命令.

# adduser mike
Adding user `mike' ...
Adding new group `mike' (1001) ...
Adding new user `mike' (1001) with group `mike' ...
Creating home directory `/home/mike' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for mike
Enter the new value,or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]
#

vncserver将使用此unix用户启动桌面环境. 这意味着,在长途桌面上工作时,您将成为此用户

为用户设置“vnc暗码”

vnc服务器维护一个单独的暗码,用于通过vnc客户端登录到vnc服务器. 该暗码与unix用户暗码不同. 它使用vncpasswd命令配置.

首先切换到上一步中创建的用户“mike”,并设置vnc服务器暗码.

su - mike

接下来使用vncpasswd敕令

$ vncpasswd
Using password file /home/mike/.vnc/passwd
VNC directory /home/mike/.vnc does not exist,creating.
Password:
Verify:
Would you like to enter a view-only password (y/n)?
mike@bunty:~$

请注意,passwd文件不存在,并在此步调中首次创建.

如果您以前已经运行vncserver命令,那么它将创立文件. 当您第一次运行vncserver时,它会创立一个默认启动脚本

$ vncserver

You will require a password to access your desktops.

Password:
Password too short
enlightened@desktop:~$ vncserver

You will require a password to access your desktops.

Password:
Verify:
Would you like to enter a view-only password (y/n)? n

New 'X' desktop is desktop:1

Creating default startup script /home/enlightened/.vnc/xstartup
Starting applications specified in /home/enlightened/.vnc/xstartup
Log file is /home/enlightened/.vnc/desktop:1.log

但是,我们不必要运行vncserver命令. 它将使用启动脚本自动启动.

创立xstartup脚本

下一个重要的文件是xstartup脚本. 它包括有关哪些X应用程序开始的说明. 桌面环境是我们必须开始的X应用程序.

如果文件已经存在,起首要备份该文件
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak

现在用nano编纂它

vnc@server:~$ nano .vnc/xstartup

注 - 这是用户vnc的主目次,即/home/mike/.vnc/xstartup

在xstartup剧本中输入以下几行

#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &

startxfce4命令将启动xfce桌面. 保留文件并关闭它.

使xstartup文件可执行. 这是需要的,以便vncserver可以执行此文件.

$ chmod +x ~/.vnc/xstartup

创立vnc服务文件

下一步是创立vnc服务文件,以便我们可以使用service命令启动vnc服务器,而不必每次都运行vncserver命令.

确保在USER变量中输入正确的用户名. 这是vnc服务器将用于启动桌面会话的用户.

root@linuxidc:~# sudo nano /etc/init.d/vncserver

粘贴以下剧本

#!/bin/bash
PATH="$PATH:/usr/bin/"
export USER="mike"
DISPLAY="1"
DEPTH="16"
GEOMETRY="1024x768"
OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
. /lib/lsb/init-functions

case "$1" in
start)
log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
;;

stop)
log_action_begin_msg "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
;;

restart)
$0 stop
$0 start
;;
esac
exit 0

保留文件并关闭它. 使其可执行

# chmod +x /etc/init.d/vncserver

开端服务

开始并测试我们的步调.

首先重新加载systemctl,以便它可以使用vncserver启动脚本.
systemctl守护过程重新加载

如今启动vncserver. 它在端口5901上启动服务器
#service vncserver start

反省它的运行

root@linuxidc:~# service vncserver status
● vncserver.service
Loaded: loaded (/etc/init.d/vncserver; bad; vendor preset: enabled)
Active: active (exited) since Thu 2017-03-02 05:36:42 UTC; 6s ago
Docs: man:systemd-sysv-generator(8)
Process: 24877 ExecStart=/etc/init.d/vncserver start (code=exited,status=0/SUCCESS)

Mar 02 05:36:40 linuxidc systemd[1]: Starting vncserver.service...
Mar 02 05:36:40 linuxidc vncserver[24877]: * Starting vncserver for user 'vnc' on localhost:1...
Mar 02 05:36:40 linuxidc su[24885]: Successful su for vnc by root
Mar 02 05:36:40 linuxidc su[24885]: + ??? root:vnc
Mar 02 05:36:40 linuxidc su[24885]: pam_unix(su:session): session opened for user vnc by (uid=0)
Mar 02 05:36:42 linuxidc vncserver[24877]: New 'X' desktop is linuxidc:1
Mar 02 05:36:42 linuxidc vncserver[24877]: Starting applications specified in /home/vnc/.vnc/xstartup
Mar 02 05:36:42 linuxidc vncserver[24877]: Log file is /home/vnc/.vnc/linuxidc:1.log
Mar 02 05:36:42 linuxidc systemd[1]: Started vncserver.service.$ cat ~/.vnc/*.pid
18577
18731# ps -ef | grep tightvnc
vnc 24574 1 0 05:32 ? 00:00:00 Xtightvnc :1 -desktop X -auth /home/vnc/.Xauthority -geometry 1024x768 -depth 16 -rfbwait 120000 -rfbauth /home/vnc/.vnc/passwd -rfbport 5901 -fp /usr/share/fonts/X11/misc/,/usr/share/fonts/X11/Type1/,/usr/share/fonts/X11/75dpi/,/usr/share/fonts/X11/100dpi/ -co /etc/X11/rgb
root 24744 10412 0 05:33 pts/0 00:00:00 grep --color=auto tightvnc
root@linuxidc:~#

检查vnc服务器的打开端口. 从vnc客户端连接时,必要正确的端口号

# netstat -nlp | grep vnc
tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 24574/Xtightvnc
tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 24574/Xtightvnc
unix 2 [ ACC ] STREAM LISTENING 5225386 24574/Xtightvnc /tmp/.X11-unix/X1

Vnc server can also be started by calling the script directly.

也可以通过直接调用脚原来启动Vnc服务器.

# /etc/init.d/vncserver start
[ ok ] Starting vncserver (via systemctl): vncserver.service.
root@linuxidc:~#

结束vncserver

# service vncserver stop

在桌面上安装vncviewer客户端

现在,我们将vnc服务器启动并运行GUI桌面情况.

在Ubuntu上安装xtightvncviewer.

$ sudo apt-get install xtightvncviewer

现在使用vncviewer命令连接到长途vnc服务器.

$ vncviewer -quality 5 -encodings“copyrect tight hextile zlib corre rre raw”-compresslevel 5 IPADDR:5901

我们使用较低质量和紧缩编码来紧缩正在传输的图像数据并使其更快.

使用像KRDC这样的其他vnc查看器可能会更慢.

CentOS7.1安装VNC,让Win7长途桌面Linux

CentOS 7 安装设置装备摆设 VNC 详解

Ubuntu下安装配置VNC长途工具

更多Ubuntu相关信息见Ubuntu 专题页面 /topicnews.aspx?tid=2

本文永远更新链接地址:

脚本之家PHP培训学院每天发布《LINUX入门:Ubuntu 16.10安装Xfce桌面与VNC远程连接》等实战技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培养人才。

dawei

【声明】:唐山站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。