计算机网络/计算机科学与应用/系统/运维/开发

Linux 链接VNC工具

一、什么是VNC

vnc是一个辅助工具,使用kvm技术,通过vnc连接到图形界面,对虚拟机安装、配置和管理


二、VNC使用

1、查询是否安装 Tigervnc-server服务

[root@Linux myshell]# rpm -q tigervnc-server


2、安装Tigervnc-server服务

[root@Linux myshell]# yum install tigervnc-server


3、启动VNC服务器

[root@Linux ~]# vncserver
You will require a password to access your desktops.
Password:
Verify:
Passwords don't match - try again
Password:              #设置用户root的VNC登录密码
Verify:       # 再次设置用户root vnc登录密码
Would you like to enter a view-only password (y/n)? y
Password:
Verify:
xauth:  file /root/.Xauthority does not exist
# 密码设置成功显示 1
New 'Linux:1 (root)' desktop is Linux:1
Creating default startup script /root/.vnc/xstartup
Creating default config /root/.vnc/config
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/Linux:1.log


4、查看进程

[root@Linux ~]# ps -ef|grep Xvnc
root     18398     1  0 14:23 pts/3    00:00:00 /usr/bin/Xvnc :1 -auth /root/.Xauthority -desktop Linux:1 (root) -fp catalogue:/etc/X11/fontpath.d -geometry 1024x768 -pn -rfbauth /root/.vnc/passwd -rfbport 5901 -rfbwait 30000
root     18957 11897  0 14:34 pts/3    00:00:00 grep --color=auto Xvnc


进程号 18398  端口5901 虚拟桌面号1


5、查看端口:

[root@Linux ~]# netstat -antu|grep 5901
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN     
tcp6       0      0 :::5901                 :::*                    LISTEN


三、VNC配置

vnc服务器配置和启动好之后,会自动创建/root/.vnc目录

目录中生成记录密码、日志、PID和启动脚本的文件

[root@Linux ~]# ls /root/.vnc/
config  Linux:1.log  Linux:1.pid  Linux:2.log  Linux:2.pid  passwd  xstartup


/root/.vnc目录下的文件描述:

[root@Linux ~]# cd /root/.vnc/
[root@Linux .vnc]# ll
total 28
-rw-r--r-- 1 root root 332 Oct 31 14:24 config
-rw-r--r-- 1 root root 422 Oct 31 14:23 Linux:1.log
-rw-r--r-- 1 root root   6 Oct 31 14:23 Linux:1.pid
-rw-r--r-- 1 root root 422 Oct 31 14:48 Linux:2.log
-rw-r--r-- 1 root root   6 Oct 31 14:48 Linux:2.pid
-rw------- 1 root root  16 Oct 31 14:23 passwd
-rwxr-xr-x 1 root root 540 Oct 31 14:24 xstartup


passwd 访问密码文件

Linux:1.log 访问日志

Linux:1.pid 第一个虚拟桌面的PID文件,保存第一个进程号码

xstartup 启动脚本文件


创建或更改vnc登录密码

语法:

vncpasswd [密码文件]

vncpasswd [选项]


选项:

-f  过滤模式


管理VNC服务器:

vncserver [:虚拟桌面号码] [选项] [Xvnc选项]


选项:

-name <桌面名称>

-kill :<虚拟的桌面号码>

-autokill 当xstartup脚本退出时自动杀死Xvnc

-geometry 宽*高  指定vnc桌面要创建的尺寸

-depth <深度>  指定vnc桌面要创建的像素(位) 默认24

-pixelformat <格式>

-fg 以前台进程运行Xvnc

-list 列出VNC虚拟桌面


实例:列出当前用户的vnc虚拟桌面

[root@Linux .vnc]# vncserver -list
TigerVNC server sessions:
X DISPLAY #PROCESS ID
:118398
:219703


实例:杀死号码为1的vnc虚拟桌面

[root@Linux .vnc]# vncserver -kill :1
Killing Xvnc process ID 18398


实例:启动号码为1的vnc虚拟桌面

[root@Linux .vnc]# vncserver :1
New 'Linux:1 (root)' desktop is Linux:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/Linux:1.log


实例:启动尺寸为1024x768的vnc虚拟桌面

[root@Linux .vnc]# vncserver -geometry 1024x768
New 'Linux:3 (root)' desktop is Linux:3
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/Linux:3.log



vnc

人生在世,不如意事十之八九;人生的滋味,哪怕是酸甜或苦辣,也要靠自己去品。人活一口气:气质看一个人的过去,气度看一个人的未来

评论

^