关闭vncserver服务linux,setup vnc server for linux - 配置VNC Server服务

vnc是远程共享桌面用的

介绍如何在CentOS/Redhat上配置 VNC Server, 使用vnc viewer, SSH安全访问等

1. 安装vnc server

rpm -qa --qf="%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" |grep -i vnc

[root@Perf-pxy-2 ~]# rpm -qa --qf="%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" |grep -i vnc

vnc-server-4.1.2-9.el5.x86_64

vnc-4.1.2-9.el5.x86_64

[root@Perf-pxy-2 ~]#

已经安装了vnc服务和客户程序

2. 启动vncserver

登录一个用户, 启动vnc服务

[root@Perf-pxy-2 ~]# su - mysql

[mysql@Perf-pxy-2 ~]$ vncserver

You will require a password to access your desktops.

Password:

Password must be at least 6 characters - try again

Password:

Verify:

xauth: creating new authority file /var/lib/mysql/.Xauthority

New 'Perf-pxy-2.s3lab.mot.com:1 (mysql)' desktop is Perf-pxy-2.s3lab.mot.com:1

Creating default startup script /var/lib/mysql/.vnc/xstartup

Starting applications specified in /var/lib/mysql/.vnc/xstartup

Log file is /var/lib/mysql/.vnc/Perf-pxy-2.s3lab.mot.com:1.log

[mysql@Perf-pxy-2 ~]$ ls -la .vnc

total 24

drwxr-xr-x 2 mysql mysql 4096 Jan 6 07:54 .

drwxr-xr-x 3 mysql mysql 4096 Jan 6 07:54 ..

-rw------- 1 mysql mysql 8 Jan 6 07:54 passwd

-rw-r--r-- 1 mysql mysql 556 Jan 6 07:54 Perf-pxy-2.s3lab.mot.com:1.log

-rw-r--r-- 1 mysql mysql 6 Jan 6 07:54 Perf-pxy-2.s3lab.mot.com:1.pid

-rwxr-xr-x 1 mysql mysql 334 Jan 6 07:54 xstartup

[mysql@Perf-pxy-2 ~]$

第一次运行前因为还没有创建密码文件, 所以提示输入密码, 在访问VNC服务时要用到这个密码

用户$HOME家目录下创建了.vnc目录和.vnc/xstartup脚本, passwd密码文件等

然后启动了 vnc服务

信息显示出新的桌面名称是'Perf-pxy-2.s3lab.mot.com:1 (mysql)', 位于 Perf-pxy-2.s3lab.mot.com:1

New 'Perf-pxy-2.s3lab.mot.com:1 (mysql)' desktop is Perf-pxy-2.s3lab.mot.com:1

用vncpasswd命令创建或修改密码

vncpasswd <

123123

123123

EOF

[mysql@Perf-pxy-2 ~]$ vncpasswd <

> 123123

> 123123

> EOF

Password:Verify:[mysql@Perf-pxy-2 ~]$

3. vncserver的监听端口

默认的, vnc 服务监听3个TCP端口

默认端口 : 5900+显示器号

HTTP协议默认端口 : 5800+显示器号

默认端口 : 6000+显示器号

vncserver使用的显示器编号默认从1开始, 依次使用, 也可以参数指定端口号

启一个vncserver, 默认占用了5801,5901,6001端口

vncserver

/usr/sbin/lsof -p $(cat ".vnc/Perf-pxy-2.s3lab.mot.com:1.pid")

[mysql@Perf-pxy-2 ~]$ vncserver

New 'Perf-pxy-2.s3lab.mot.com:1 (mysql)' desktop is Perf-pxy-2.s3lab.mot.com:1

Starting applications specified in /var/lib/mysql/.vnc/xstartup

Log file is /var/lib/mysql/.vnc/Perf-pxy-2.s3lab.mot.com:1.log

[mysql@Perf-pxy-2 ~]$ /usr/sbin/lsof -p $(cat ".vnc/Perf-pxy-2.s3lab.mot.com:1.pid")

COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME

Xvnc 23896 mysql cwd DIR 8,2 4096 2050291 /var/lib/mysql

Xvnc 23896 mysql rtd DIR 8,2 4096 2 /

Xvnc 23896 mysql txt REG 8,2 1681088 1153094 /usr/bin/Xvnc

Xvnc 23896 mysql mem REG 8,2 134400 1664137 /lib64/ld-2.5.so

Xvnc 23896 mysql mem REG 8,2 1699880 1664138 /lib64/libc-2.5.so

Xvnc 23896 mysql mem REG 8,2 615136 1664143 /lib64/libm-2.5.so

Xvnc 23896 mysql mem REG 8,2 23360 1664144 /lib64/libdl-2.5.so

Xvnc 23896 mysql mem REG 8,2 30496 1150346 /usr/lib64/libfontenc.so.1.0.0

Xvnc 23896 mysql mem REG 8,2 85608 1164877 /usr/lib64/libz.so.1.2.3

Xvnc 23896 mysql mem REG 8,2 501832 1146413 /usr/lib64/libXfont.so.1.4.1

Xvnc 23896 mysql mem REG 8,2 12040 1164881 /usr/lib64/libXau.so.6.0.0

Xvnc 23896 mysql mem REG 8,2 22032 1164882 /usr/lib64/libXdmcp.so.6.0.0

Xvnc 23896 mysql mem REG 8,2 1099816 1164883 /usr/lib64/libX11.so.6.2.0

Xvnc 23896 mysql mem REG 8,2 543824 1164878 /usr/lib64/libfreetype.so.6.3.10

Xvnc 23896 mysql mem REG 8,2 58400 1660009 /lib64/libgcc_s-4.1.2-20080102.so.1

Xvnc 23896 mysql mem REG 8,2 976312 1145904 /usr/lib64/libstdc++.so.6.0.8

Xvnc 23896 mysql DEL REG 0,8 3014672 /SYSV00000000

Xvnc 23896 mysql DEL REG 0,8 3047441 /SYSV00000000

Xvnc 23896 mysql DEL REG 0,8 3080210 /SYSV00000000

Xvnc 23896 mysql 0u IPv6 90730 TCP *:6001 (LISTEN)

Xvnc 23896 mysql 1u IPv4 90731 TCP *:6001 (LISTEN)

Xvnc 23896 mysql 2w REG 8,2 556 2051197 /var/lib/mysql/.vnc/Perf-pxy-2.s3lab.mot.com:1.log

Xvnc 23896 mysql 3u unix 0xffff81003dde2c80 90732 /tmp/.X11-unix/X1

Xvnc 23896 mysql 4u IPv4 90736 TCP *:5901 (LISTEN)

Xvnc 23896 mysql 5u IPv4 90737 TCP *:5801 (LISTEN)

Xvnc 23896 mysql 6u unix 0xffff81001b21b380 90742 /tmp/.X11-unix/X1

Xvnc 23896 mysql 7u unix 0xffff810002d83680 90744 /tmp/.X11-unix/X1

Xvnc 23896 mysql 8u unix 0xffff81000dc80c80 90746 /tmp/.X11-unix/X1

[mysql@Perf-pxy-2 ~]$

再启一个vncserver, 默认占用了5802,5902,6002端口

[root@Perf-pxy-2 ~]# vncserver

New 'Perf-pxy-2.s3lab.mot.com:2 (root)' desktop is Perf-pxy-2.s3lab.mot.com:2

Creating default startup script /root/.vnc/xstartup

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/Perf-pxy-2.s3lab.mot.com:2.log

[root@Perf-pxy-2 ~]# /usr/sbin/lsof -p $(cat ".vnc/Perf-pxy-2.s3lab.mot.com:2.pid")

COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME

...

Xvnc 23947 root 0u IPv6 90882 TCP *:6002 (LISTEN)

Xvnc 23947 root 1u IPv4 90883 TCP *:6002 (LISTEN)

Xvnc 23947 root 2w REG 8,2 556 2932502 /root/.vnc/Perf-pxy-2.s3lab.mot.com:2.log

Xvnc 23947 root 3u unix 0xffff81000a863c80 90884 /tmp/.X11-unix/X2

Xvnc 23947 root 4u IPv4 90888 TCP *:5902 (LISTEN)

Xvnc 23947 root 5u IPv4 90889 TCP *:5802 (LISTEN)

Xvnc 23947 root 6u unix 0xffff81001b21b080 90895 /tmp/.X11-unix/X2

Xvnc 23947 root 7u unix 0xffff81000dc80680 90897 /tmp/.X11-unix/X2

Xvnc 23947 root 8u unix 0xffff81003dde2980 90899 /tmp/.X11-unix/X2

[root@Perf-pxy-2 ~]#

4. 访问VNC服务

连接vnc服务器的1号显示器(桌面/display)

vncviewer perf-pxy-2:1

[s3op1@DEV-Blur-DB-1 ~]$ vncviewer perf-pxy-2:1

VNC Viewer Free Edition 4.1.2 for X - built Mar 14 2007 23:13:57

Copyright (C) 2002-2005 RealVNC Ltd.

See http://www.realvnc.com for information on VNC.

Tue Jan 6 08:04:58 2009

CConn: connected to host perf-pxy-2 port 5901

CConnection: Server supports RFB protocol version 3.8

CConnection: Using RFB protocol version 3.8

Tue Jan 6 08:05:57 2009

TXImage: Using default colormap and visual, TrueColor, depth 24.

CConn: Using pixel format depth 6 (8bpp) rgb222

CConn: Using ZRLE encoding

Tue Jan 6 08:05:58 2009

CConn: Throughput 15714 kbit/s - changing to hextile encoding

CConn: Throughput 15714 kbit/s - changing to full colour

CConn: Using pixel format depth 24 (32bpp) little-endian rgb888

CConn: Using hextile encoding

写端口号也行, 比如 vncviewer perf-pxy-2::5901 &

提示输入密码091010215912.png登入远程桌面

091010220009.png

桌面默认使用twm窗口管理器

登入的用户就是启vncserver的那个用户

免输入密码登录

运行vncpasswd 生成密码文件, 文件名任意

mkdir -p ~/.vnc && (echo "123123";echo "123123")|vncpasswd ~/.vnc/passwd--perf-pxy-2--1; echo

[root@CentOS-1 ~]# mkdir -p ~/.vnc && (echo "123123";echo "123123")|vncpasswd ~/.vnc/passwd--perf-pxy-2--1; echo

Password:Verify:

[root@CentOS-1 ~]#

参数-passwd指定密码文件

vncviewer -passwd ~/.vnc/passwd--perf-pxy-2--1 perf-pxy-2:1 &

[root@CentOS-1 ~]# vncviewer -passwd ~/.vnc/passwd--perf-pxy-2--1 perf-pxy-2:1 &

[1] 15607

[root@CentOS-1 ~]#

VNC Viewer Free Edition 4.1.2 for X - built Mar 14 2007 22:51:02

Copyright (C) 2002-2005 RealVNC Ltd.

See http://www.realvnc.com for information on VNC.

Thu Jan 8 05:35:35 2009

CConn: connected to host perf-pxy-2 port 5901

CConnection: Server supports RFB protocol version 3.8

CConnection: Using RFB protocol version 3.8

TXImage: Using default colormap and visual, TrueColor, depth 24.

CConn: Using pixel format depth 6 (8bpp) rgb222

CConn: Using ZRLE encoding

Thu Jan 8 05:35:36 2009

CConn: Throughput 15000 kbit/s - changing to hextile encoding

CConn: Throughput 15000 kbit/s - changing to full colour

CConn: Using pixel format depth 24 (32bpp) little-endian rgb888

CConn: Using hextile encoding

5. 更改桌面

改成其它窗口管理器

退出vncviewer

091010220147.png

vnc的好处在于, 桌面是在服务器端运行的, 下次再进入能够继续上次的工作, 只要不关闭/重启vnc服务

还有网络带宽要求比SSH的X11 Forwarding低

停止vnc服务

vncserver -kill :1

[mysql@Perf-pxy-2 ~]$ ps -ef|grep vnc

mysql 18021 1 0 07:54 pts/0 00:00:00 Xvnc :1 -desktop Perf-pxy-2.s3lab.mot.com:1 (mysql) -httpd /usr/share/vnc/classes -auth /var/lib/mysql/.Xauthority -geometry 1024x768 -depth 16 -rfbwait 30000 -rfbauth /var/lib/mysql/.vnc/passwd -rfbport 5901 -pn

mysql 18025 1 0 07:54 pts/0 00:00:00 vncconfig -iconic

mysql 18156 17935 0 08:21 pts/0 00:00:00 grep vnc

[mysql@Perf-pxy-2 ~]$ vncserver -kill :1

Killing Xvnc process ID 18021

[mysql@Perf-pxy-2 ~]$ ps -ef|grep vnc

mysql 18165 17935 0 08:21 pts/0 00:00:00 grep vnc

[mysql@Perf-pxy-2 ~]$

编辑.vnc/xstartup启动脚本, 去掉其中两行注释

unset SESSION_MANAGER

exec /etc/X11/xinit/xinitrc

vncserver服务启动时运行/etc/X11/xinit/xinitrc, 启动缺省的桌面

sed -i '/unset SESSION_MANAGER\|exec \/etc\/X11\/xinit\/xinitrc/{s/ˆ#*//g;s/ˆ //g}' .vnc/xstartup

cat .vnc/xstartup

[mysql@Perf-pxy-2 ~]$ sed -i '/unset SESSION_MANAGER\|exec \/etc\/X11\/xinit\/xinitrc/{s/ˆ#*//g;s/ˆ //g}' .vnc/xstartup

[mysql@Perf-pxy-2 ~]$ cat .vnc/xstartup

#!/bin/sh

# Uncomment the following two lines for normal desktop:

unset SESSION_MANAGER

exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup

[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources

xsetroot -solid grey

vncconfig -iconic &

xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &

twm &

[mysql@Perf-pxy-2 ~]$

重启vncserver

[mysql@Perf-pxy-2 ~]$ vncserver

New 'Perf-pxy-2.s3lab.mot.com:1 (mysql)' desktop is Perf-pxy-2.s3lab.mot.com:1

Starting applications specified in /var/lib/mysql/.vnc/xstartup

Log file is /var/lib/mysql/.vnc/Perf-pxy-2.s3lab.mot.com:1.log

[mysql@Perf-pxy-2 ~]$

第二次运行vncserver不用输入密码

客户端访问

vncviewer perf-pxy-2:1

[s3op1@DEV-Blur-DB-1 ~]$ vncviewer perf-pxy-2:1

VNC Viewer Free Edition 4.1.2 for X - built Mar 14 2007 23:13:57

Copyright (C) 2002-2005 RealVNC Ltd.

See http://www.realvnc.com for information on VNC.

Tue Jan 6 08:33:24 2009

CConn: connected to host perf-pxy-2 port 5901

CConnection: Server supports RFB protocol version 3.8

CConnection: Using RFB protocol version 3.8

Tue Jan 6 08:33:28 2009

TXImage: Using default colormap and visual, TrueColor, depth 24.

CConn: Using pixel format depth 6 (8bpp) rgb222

CConn: Using ZRLE encoding

CConn: Throughput 20256 kbit/s - changing to hextile encoding

CConn: Throughput 20256 kbit/s - changing to full colour

CConn: Using pixel format depth 24 (32bpp) little-endian rgb888

CConn: Using hextile encoding

进入了好看的GNOME桌面091010220748.png

6. 浏览器访问vnc server

JAVA方式默认访问端口是5800加显示器号

firefox &091010220825.png

要安装java插件, 该插件在32位的jre中

安装jre

[root@CentOS-1 ~]# sh /u01/software/oracle/java/jre-6u11-linux-i586-rpm.bin

Sun Microsystems, Inc. Binary Code License Agreement

...

Do you agree to the above license terms? [yes or no]

yes

Unpacking...

Checksumming...

Extracting...

UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).

inflating: jre-6u11-linux-i586.rpm

Preparing... ########################################### [100%]

1:jre warning: /etc/.java/.systemPrefs/.system.lock created as /etc/.java/.systemPrefs/.system.lock.rpmnew

warning: /etc/.java/.systemPrefs/.systemRootModFile created as /etc/.java/.systemPrefs/.systemRootModFile.rpmnew

########################################### [100%]

Unpacking JAR files...

rt.jar...

jsse.jar...

charsets.jar...

localedata.jar...

plugin.jar...

javaws.jar...

deploy.jar...

Done.

[root@CentOS-1 ~]#

注册插件

mkdir -p /usr/lib/firefox-3.0b5/plugins

ln -s /usr/java/jre1.6.0_11/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/firefox-3.0b5/plugins/

[root@CentOS-1 ~]# mkdir -p /usr/lib/firefox-3.0b5/plugins

[1]+ Done firefox

[root@CentOS-1 ~]# ln -s /usr/java/jre1.6.0_11/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/firefox-3.0b5/plugins/

[root@CentOS-1 ~]# ls -l /usr/lib/firefox-3.0b5/plugins/

total 0

lrwxrwxrwx 1 root root 58 Jan 7 05:42 libjavaplugin_oji.so -> /usr/java/jre1.6.0_11/plugin/i386/ns7/libjavaplugin_oji.so

firefox about:plugins &091010221009.png

firefox &091010221039.png

输入密码091010221117.png

显示桌面091010221152.png

7. 系统服务方式自动运行

编辑 /etc/sysconfig/vncservers 配置文件

cat >/etc/sysconfig/vncservers

VNCSERVERARGS[1]="-geometry 1152x864 -nohttpd -nolisten tcp -AlwaysShared -SecurityTypes None"

VNCSERVERARGS[5]="-geometry 1152x864 -nohttpd -nolisten tcp -localhost"

EOF

[root@Perf-pxy-2 ~]# cat >/etc/sysconfig/vncservers <

> VNCSERVERS="1:mysql 5:root"

> VNCSERVERARGS[1]="-geometry 1152x864 -nohttpd -nolisten tcp -AlwaysShared -SecurityTypes None"

> VNCSERVERARGS[5]="-geometry 1152x864 -nohttpd -nolisten tcp -localhost"

> EOF

[root@Perf-pxy-2 ~]#

VNCSERVERS="1:mysql 5:root"

表示启3个vnc服务, 显示器(display)1,5, 分别对应用户 mysql,root

VNCSERVERARGS是为每个vnc显示器配置的参数

-geometry 桌面大小,缺省是1024x768

-nohttpd 不监听HTTP端口

-nolisten tcp 不监听X端口

-localhost 只允许从本机访问

-AlwaysShared 默认的, 同时只能有一个vncviewer连接(跟客户端配置也有关), 一旦第2个连上去, 第1个就被断开了. 此参数允许同时连多个vncviewer

-SecurityTypes None登录不需要密码认证 VncAuth默认值,要密码认证

创建vncserver认证密码

runuser -l mysql -c "(echo '123123';echo '123123')|vncpasswd;echo"

runuser -l root -c "(echo '123123';echo '123123')|vncpasswd;echo"

[root@Perf-pxy-2 ~]# runuser -l mysql -c "(echo '123123';echo '123123')|vncpasswd;echo"

Password:Verify:

[root@Perf-pxy-2 ~]# runuser -l root -c "(echo '123123';echo '123123')|vncpasswd;echo"

Password:Verify:

[root@Perf-pxy-2 ~]#

加入自动启动

chkconfig --level 345 vncserver on

ls -l /etc/rc*.d/*vncserver

[root@Perf-pxy-2 ~]# chkconfig --level 345 vncserver on

[root@Perf-pxy-2 ~]# ls -l /etc/rc*.d/*vncserver

lrwxrwxrwx 1 root root 19 Jan 8 03:34 /etc/rc0.d/K35vncserver -> ../init.d/vncserver

lrwxrwxrwx 1 root root 19 Jan 8 03:34 /etc/rc1.d/K35vncserver -> ../init.d/vncserver

lrwxrwxrwx 1 root root 19 Jan 8 03:34 /etc/rc2.d/K35vncserver -> ../init.d/vncserver

lrwxrwxrwx 1 root root 19 Jan 8 03:34 /etc/rc3.d/S91vncserver -> ../init.d/vncserver

lrwxrwxrwx 1 root root 19 Jan 8 03:34 /etc/rc4.d/S91vncserver -> ../init.d/vncserver

lrwxrwxrwx 1 root root 19 Jan 8 03:34 /etc/rc5.d/S91vncserver -> ../init.d/vncserver

lrwxrwxrwx 1 root root 19 Jan 8 03:34 /etc/rc6.d/K35vncserver -> ../init.d/vncserver

[root@Perf-pxy-2 ~]#

启动服务

service vncserver start

[root@Perf-pxy-2 ~]# service vncserver start

Starting VNC server: 1:mysql

New 'Perf-pxy-2.s3lab.mot.com:1 (mysql)' desktop is Perf-pxy-2.s3lab.mot.com:1

Starting applications specified in /var/lib/mysql/.vnc/xstartup

Log file is /var/lib/mysql/.vnc/Perf-pxy-2.s3lab.mot.com:1.log

5:root

New 'Perf-pxy-2.s3lab.mot.com:5 (root)' desktop is Perf-pxy-2.s3lab.mot.com:5

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/Perf-pxy-2.s3lab.mot.com:5.log

[ OK ]

[root@Perf-pxy-2 ~]#

停止服务

service vncserver stop

[root@Perf-pxy-2 ~]# service vncserver stop

Shutting down VNC server: 1:mysql 5:root [ OK ]

[root@Perf-pxy-2 ~]#

8. 通过SSH隧道安全访问vnc

有时出于安全考虑加密网络传输内容或网络不能直接访问, 可使用SSH隧道

运行

ssh -L localhost:9905:localhost:5905 -f mysql@perf-pxy-2 "sleep 10" && vncviewer localhost::9905

此命令将perf-pxy-2上的localhost:5905端口转发到本机的localhost:9905端口

输入密码

[root@CentOS-1 ~]# ssh -L localhost:9905:localhost:5905 -f mysql@perf-pxy-2 "sleep 10" && vncviewer localhost::9905

mysql@perf-pxy-2's password:

VNC Viewer Free Edition 4.1.2 for X - built Mar 14 2007 22:51:02

Copyright (C) 2002-2005 RealVNC Ltd.

See for information on VNC.

Thu Jan 8 05:51:39 2009

CConn: connected to host localhost port 9905

CConnection: Server supports RFB protocol version 3.8

CConnection: Using RFB protocol version 3.8

Thu Jan 8 05:51:44 2009

TXImage: Using default colormap and visual, TrueColor, depth 24.

CConn: Using pixel format depth 6 (8bpp) rgb222

CConn: Using ZRLE encoding

[root@CentOS-1 ~]#

然后输入vncserver密码登入桌面

当关闭vncviewer后,ssh端口转发进程自动退出

或用 -via 参数

将mysql@perf-pxy-2上的localhost::5905转发到本地某个端口

vncviewer -via mysql@perf-pxy-2 localhost::5905

[root@CentOS-1 ~]# vncviewer -via mysql@perf-pxy-2 localhost::5905

VNC Viewer Free Edition 4.1.2 for X - built Mar 14 2007 22:51:02

Copyright (C) 2002-2005 RealVNC Ltd.

See for information on VNC.

mysql@perf-pxy-2's password:

Thu Jan 8 06:50:50 2009

CConn: connected to host localhost port 5599

CConnection: Server supports RFB protocol version 3.8

CConnection: Using RFB protocol version 3.8

Thu Jan 8 06:50:53 2009

TXImage: Using default colormap and visual, TrueColor, depth 24.

CConn: Using pixel format depth 6 (8bpp) rgb222

CConn: Using ZRLE encoding

[root@CentOS-1 ~]#

写成显示器号也可以, vncviewer -via mysql@perf-pxy-2 localhost:5

ps 查到后台自动调用了ssh命令(设置VNC_VIA_CMD等环境变量可以改变自动调用的命令和参数), 建立了SSH隧道, 转发到本地5599端口

[root@CentOS-1 ~]# ps -ef|grep "[s]sh "

root 15830 15829 0 06:45 pts/0 00:00:00 /usr/bin/ssh -f -L 5599:localhost:5905 mysql@perf-pxy-2 sleep 20

[root@CentOS-1 ~]#

9. 访问服务器本身的桌面

检查是否安装了X的vnc模块

ls -l /usr/lib64/xorg/modules/extensions/libvnc.so

[root@Perf-pxy-2 ~]# ls -l /usr/lib64/xorg/modules/extensions/libvnc.so

-rwxr-xr-x 1 root root 415112 Mar 15 2007 /usr/lib64/xorg/modules/extensions/libvnc.so

[root@Perf-pxy-2 ~]#

编辑X的配置文件

Module段增加加载vnc模块

Screen段增加安全方式等

Section "Module"

Load "vnc"

EndSection

Section "Screen"

Option "SecurityTypes" "VncAuth"

Option "UserPasswdVerifier" "VncAuth"

Option "PasswordFile" "/root/.vnc/passwd"

EndSection

cat /etc/X11/xorg.conf

[root@Perf-pxy-2 ~]# cat /etc/X11/xorg.conf

# Xorg configuration created by pyxf86config

Section "ServerLayout"

Identifier "Default Layout"

Screen 0 "Screen0" 0 0

InputDevice "Keyboard0" "CoreKeyboard"

EndSection

Section "InputDevice"

Identifier "Keyboard0"

Driver "kbd"

Option "XkbModel" "pc105"

Option "XkbLayout" "us"

EndSection

Section "Device"

Identifier "Videocard0"

Driver "radeon"

EndSection

Section "Screen"

Identifier "Screen0"

Device "Videocard0"

DefaultDepth 16

SubSection "Display"

Viewport 0 0

Depth 16

EndSubSection

Option "SecurityTypes" "VncAuth"

Option "UserPasswdVerifier" "VncAuth"

Option "PasswordFile" "/root/.vnc/passwd"

EndSection

Section "Module"

Load "vnc"

EndSection

[root@Perf-pxy-2 ~]#

已经有密码文件了, 所以不用再生成了

[root@Perf-pxy-2 ~]# ls -l /root/.vnc/passwd

-rw------- 1 root root 8 Jan 8 03:36 /root/.vnc/passwd

[root@Perf-pxy-2 ~]#

重启GNOME桌面

gdm-restart

[root@Perf-pxy-2 ~]# gdm-restart

[root@Perf-pxy-2 ~]# ps -ef|grep gdm

root 6075 1 0 Jan02 ? 00:00:00 /usr/sbin/gdm-binary -nodaemon

root 30411 6075 0 08:59 ? 00:00:00 /usr/sbin/gdm-binary -nodaemon

root 30413 1 0 08:59 ? 00:00:00 /usr/libexec/gdm-rh-security-token-helper

root 30415 30411 4 08:59 tty7 00:00:00 /usr/bin/Xorg :0 -br -audit 0 -auth /var/gdm/:0.Xauth -nolisten tcp vt7

gdm 30437 30411 3 08:59 ? 00:00:00 /usr/libexec/gdmgreeter

root 30439 23750 0 08:59 pts/0 00:00:00 grep gdm

[root@Perf-pxy-2 ~]# lsof -p 30415

COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME

...

Xorg 30415 root 7u IPv4 105949 TCP *:5900 (LISTEN)

...

[root@Perf-pxy-2 ~]#

X服务器进程(/usr/bin/Xorg)监听5900这个端口

vncviewer登录

vncviewer perf-pxy-2:0

[root@CentOS-1 ~]# vncviewer perf-pxy-2:0

VNC Viewer Free Edition 4.1.2 for X - built Mar 14 2007 22:51:02

Copyright (C) 2002-2005 RealVNC Ltd.

See http://www.realvnc.com for information on VNC.

Thu Jan 8 09:00:13 2009

CConn: connected to host perf-pxy-2 port 5900

CConnection: Server supports RFB protocol version 3.8

CConnection: Using RFB protocol version 3.8

Thu Jan 8 09:00:17 2009

TXImage: Using default colormap and visual, TrueColor, depth 24.

CConn: Using pixel format depth 6 (8bpp) rgb222

CConn: Using ZRLE encoding

[root@CentOS-1 ~]#

091010222222.png确实是远程服务器上的桌面, 是同步的

091010222324.png

另一种方式, 运行

x0vncserver -rfbport 5910 -PasswordFile '/root/.vnc/passwd'

[root@Perf-pxy-2 ~]# x0vncserver -rfbport 5910 -PasswordFile '/root/.vnc/passwd'

Thu Jan 8 09:25:41 2009

main: XTest extension present - version 2.2

main: Listening on port 5910

Thu Jan 8 09:26:23 2009

Connections: accepted: 192.168.13.160::48939

SConnection: Client needs protocol version 3.8

SConnection: Client requests security type VncAuth(2)

Thu Jan 8 09:26:28 2009

VNCSConnST: Server default pixel format depth 24 (32bpp) little-endian rgb888

VNCSConnST: Client pixel format depth 6 (8bpp) rgb222

Thu Jan 8 09:26:29 2009

VNCSConnST: Client pixel format depth 24 (32bpp) little-endian rgb888

Thu Jan 8 09:26:30 2009

Timer: time has moved forwards!

Thu Jan 8 09:26:32 2009

Timer: time has moved forwards!

Thu Jan 8 09:26:34 2009

Timer: time has moved forwards!

Thu Jan 8 09:26:36 2009

Timer: time has moved forwards!

Thu Jan 8 09:26:39 2009

Timer: time has moved forwards!

Thu Jan 8 09:26:41 2009

Timer: time has moved forwards!

Thu Jan 8 09:26:43 2009

Timer: time has moved forwards!

Thu Jan 8 09:26:45 2009

Timer: time has moved forwards!

Thu Jan 8 09:26:47 2009

Timer: time has moved forwards!

Thu Jan 8 09:26:50 2009

Timer: time has moved forwards!

Thu Jan 8 09:26:52 2009

Timer: time has moved forwards!

Thu Jan 8 09:26:54 2009

Connections: closed: 192.168.13.160::48939 (write: Broken pipe (32))

SMsgWriter: framebuffer updates 12

SMsgWriter: hextile rects 145, bytes 19473667

SMsgWriter: ZRLE rects 1, bytes 12999

SMsgWriter: raw bytes equivalent 42738404, compression ratio 2.193213

~Image called - usingShm 0

效率相当低下,而且显示有严重问题091010222508.png

10. vncconfig

修改vnc服务器一些配置什么的

以同样用户运行vncconfig, 列出所有参数

vncconfig -display :1 -list

[mysql@Perf-pxy-2 ~]$ vncconfig -display :1 -list

localhost

desktop

rfbport

rfbwait

httpPort

httpd

rfbauth

QueryConnectTimeout

AlwaysSetDeferUpdateTimer

DeferUpdate

Log

QueryConnect

SendCutText

AcceptCutText

AcceptPointerEvents

AcceptKeyEvents

DisconnectClients

NeverShared

AlwaysShared

Protocol3.3

CompareFB

ClientWaitTimeMillis

IdleTimeout

Password

PasswordFile

ReverseSecurityTypes

SecurityTypes

BlacklistTimeout

BlacklistThreshold

RemapKeys

ZlibLevel

MaxCutText

[mysql@Perf-pxy-2 ~]$

vncconfig也是个助手程序(helper application),只有运行了它,客户机和服务器之间才可以使用剪贴板复制粘贴数据

11. 反向连接

客户机监听端口, 等待服务器连接

vncviewer -listen

[root@CentOS-1 ~]# vncviewer -listen

VNC Viewer Free Edition 4.1.2 for X - built Mar 14 2007 22:51:02

Copyright (C) 2002-2005 RealVNC Ltd.

See http://www.realvnc.com for information on VNC.

Fri Jan 9 11:21:28 2009

main: Listening on port 5500

服务器去连接客户机

vncconfig -display :1 -connect centos-1

[mysql@Perf-pxy-2 ~]$ vncconfig -display :1 -connect centos-1

[mysql@Perf-pxy-2 ~]$

客户机弹出远程桌面091010222727.png

用完后断开连接

[mysql@Perf-pxy-2 ~]$ vncconfig -display :1 -disconnect

[mysql@Perf-pxy-2 ~]$

12. vnc中终端的环境变量

vnc中的terminal终端窗口(所有子进程)继承的是vnc服务器进程(父进程)的环境变量, 当修改了.bash_profile后, 再开启一个新的终端窗口并不能使环境变量生效

解决方法是将环境变量写入.bashrc,即可

13. 重新登录桌面

如果不小心登出(logout)了vnc的桌面, 那只有重启vnc服务.

这里有个办法,但是如果连这个终端也退出了, 一样没办法了

外部连接:

VNC for Unix Documentation - VNC Free Edition 4.1

VNC软件: , ,

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值