chzhiyi / -KnowledgeShare

6 stars 1 forks source link

20190521 - vncserver的介绍 - bailian #72

Open 15175036183 opened 5 years ago

15175036183 commented 5 years ago

vnc的介绍参考网址:http://xstarcd.github.io/wiki/Linux/vnc-server.html

VNC属于一种显示系统,也就是说他能将完整的窗口界面通过网络,传输到另一台计算机的屏幕上。VNC由两部分组成:一部分是客户端的应用程序(vncviewer),另外一部分是服务器端的应用程序(vncserver)。也就是说vnc远程服务起了之后,我们就可以在客户端通过ip+端口号的形式来访问UNIX和Linux主机服务了。特点:vnc可以远程连入操作系统, 所有操作在UNIX、Linux主机服务端进行,即使操作过程中"本地电脑与操作主机网络断开”,也不影响操作的顺利进行,vnc还有一个重要的特点:它是开源的、免费的。

远程连接vncserver的步骤

输入命令:vncserver

出现提示Warning: localhost:1 is taken because of /tmp/.X1-lock
Remove this file if there is no X server localhost:1

New 'localhost:7 (sysop)' desktop is localhost:7

Starting applications specified in /home/su//.vnc/xstartup
Log file is /home/su//.vnc/localhost:7.log

根据提示可以看出vncserver已经启动了,我们可以新建一个VNCServer远程桌面。用ip加端口号:ip:1、ip:2、ip:3 来标识、区分,需要注意的是,使用同一端口号会使另外登录的用户自动退出。为了避免这种情况发生,我们可以查看都开启了哪些远程桌面。

148001 ?        S      1:10 Xvnc4 :2 -desktop localhost:2 (root) -auth /root/.Xauthority -geometry 1024x768 -depth 16 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5902 -pn -fp /usr/X11R6/lib/X11/fonts/Type1/,/usr/X11R6/lib/X11/fonts/Speedo/,/usr/X11R6/lib/X11/fonts/misc/,/usr/X11R6/lib/X11/fonts/75dpi/,/usr/X11R6/lib/X11/fonts/100dpi/,/usr/share/fonts/X11/misc/,/usr/share/fonts/X11/Type1/,/usr/share/fonts/X11/75dpi/,/usr/share/fonts/X11/100dpi/ -co /etc/X11/rgb

根据结果可以看到端口号5902被占用了,这时我们可以自定义并启动一个VNCServer

需要注意的是":8"前面一定要加空格。

New 'localhost:8 (sysop)' desktop is localhost:8

Starting applications specified in /home/su.vnc/xstartup
Log file is /home/su/.vnc/localhost:8.log

看到这个提示说明localhost:8远程桌面已经创建成功了,同时生成了vncserver的配置文件和日志文件。这时我们就可以去vnc的客户端连接了,并且可以对Linux服务器进行界面化操作了。

在本机打开VNC Viewer--新建连接--输入vncserver的ip也就是上面提到的 localhost:8--输入密码--连接

如果我们不想要8这个端口号了,可以通过杀死进程

kill -s 9 1827

报错信息如下:

Warning: localhost:8 is taken because of /tmp/.X8-lock
Remove this file if there is no X server localhost:8
A VNC server is already running as :8vncserver :8

根据提示可以猜测以前的临时文件还存在导致的 执行:rm -f /tmp/.X8-lock 命令将临时文件删除

再次输入vncserver :8还会报错:
Warning: localhost:8 is taken because of /tmp/.X11-unix/X8
Remove this file if there is no X server localhost:8
A VNC server is already running as :8

再次根据错误提示执行:rm -f /tmp/.X11-unix/X8