类别:原创 服务器
linux 下vnc服务的配置
1、软件安装
[root@jedy ~]# yum install -y tigervnc-server
2、修改配置文件
[root@tian ~]# cat /etc/sysconfig/vncservers \\更改配置文件
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the lines below to start a VNC server on display :2
# as my 'myusername' (adjust this to your own). You will also
# need to set a VNC password; run 'man vncpasswd' to see how
# to do that.
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted! For a secure way of using VNC, see this URL:
# http://kbase.redhat.com/faq/docs/DOC-7028
# 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.
# VNCSERVERS="2:myusername"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"
VNCSERVERS="1:root 10:aa 20:bb 30:tt" \\增加root和tt用户的vnc配置 ,注意 下面两行要去掉 "-localhost",要不然就只会在 127.0.0.1 端口开启vnc服务了。
VNCSERVERARGS[1]="-geometry 800x600 -nolisten tcp"
VNCSERVERARGS[10]="-geometry 800x600 -nolisten tcp"
VNCSERVERARGS[20]="-geometry 800x600 -nolisten tcp"
VNCSERVERARGS[30]="-geometry 800x600 -nolisten tcp
[root@tian ~]#
3、启动报务
[root@tian ~]# service vncserver restart
Shutting down VNC server: 1:root 10:aa 20:bb 30:tt [FAILED]
Starting VNC server: 1:root
New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log
10:aa
New 'localhost.localdomain:10 (aa)' desktop is localhost.localdomain:10
Starting applications specified in /home/aa/.vnc/xstartup
Log file is /home/aa/.vnc/localhost.localdomain:10.log
20:bb
VNC password for user bb is not configured
[FAILED] \\ 这里报错是因为 没有设置vnc密码。必须手工设置vnc密码
[root@tian ~]#
[root@tian ~]# su bb
[bb@localhost root]$ vncserver :20
You will require a password to access your desktops.
Password:
Verify:
xauth: creating new authority file /home/bb/.Xauthority
New 'localhost.localdomain:20 (bb)' desktop is localhost.localdomain:20
Creating default startup script /home/bb/.vnc/xstartup
Starting applications specified in /home/bb/.vnc/xstartup
Log file is /home/bb/.vnc/localhost.localdomain:20.log
[bb@localhost root]$ vncserver -kill :20
Killing Xvnc process ID 12653
[bb@localhost root]$ exit
exit
[root@tian ~]# service vncserver restart
Shutting down VNC server: 1:root 10:aa 20:bb 30:tt [FAILED]
Starting VNC server: 1:root
New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log
10:aa
New 'localhost.localdomain:10 (aa)' desktop is localhost.localdomain:10
Starting applications specified in /home/aa/.vnc/xstartup
Log file is /home/aa/.vnc/localhost.localdomain:10.log
20:bb
New 'localhost.localdomain:20 (bb)' desktop is localhost.localdomain:20
Starting applications specified in /home/bb/.vnc/xstartup
Log file is /home/bb/.vnc/localhost.localdomain:20.log
30:tt
New 'localhost.localdomain:30 (tt)' desktop is localhost.localdomain:30
Starting applications specified in /home/tt/.vnc/xstartup
Log file is /home/tt/.vnc/localhost.localdomain:30.log
[ OK ]
[root@tian ~]# netstat -tlnp | grep vnc
tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 13099/Xvnc
tcp 0 0 0.0.0.0:5910 0.0.0.0:* LISTEN 13158/Xvnc
tcp 0 0 0.0.0.0:5920 0.0.0.0:* LISTEN 13524/Xvnc
tcp 0 0 0.0.0.0:5930 0.0.0.0:* LISTEN 13871/Xvnc
[root@tian ~]#
使用客户端连接时只要加上桌面号就行了10,
[root@tian ~]# vncviewer 127.0.0.1:10
补充内容
1、更改默认端口号
[root@tian ~]# which vncserver
/usr/bin/vncserver
[root@tian ~]#
[root@tian ~]# more `which vncserver` | grep 5900
$vncPort = 5900 + $displayNumber;
# n is taken if something is listening on the VNC server port (5900+n) or the
# (5900+n) or the X server port (6000+n).
if (!bind(S, pack('S n x12', $AF_INET, 5900 + $n))) {
[root@tian ~]#
[root@tian ~]# sed -i.bak 's/5900/6900/g' /usr/bin/vncserver
[root@tian ~]# more `which vncserver` | grep 6900
$vncPort = 6900 + $displayNumber;
# n is taken if something is listening on the VNC server port (6900+n) or the
# (6900+n) or the X server port (6000+n).
if (!bind(S, pack('S n x12', $AF_INET, 6900 + $n))) {
[root@tian ~]#
[root@tian ~]# service vncserver restart
Shutting down VNC server: 1:root 10:aa 20:bb 30:tt [ OK ]
Starting VNC server: 1:root
New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log
10:aa
New 'localhost.localdomain:10 (aa)' desktop is localhost.localdomain:10
Starting applications specified in /home/aa/.vnc/xstartup
Log file is /home/aa/.vnc/localhost.localdomain:10.log
20:bb
New 'localhost.localdomain:20 (bb)' desktop is localhost.localdomain:20
Starting applications specified in /home/bb/.vnc/xstartup
Log file is /home/bb/.vnc/localhost.localdomain:20.log
30:tt
New 'localhost.localdomain:30 (tt)' desktop is localhost.localdomain:30
Starting applications specified in /home/tt/.vnc/xstartup
Log file is /home/tt/.vnc/localhost.localdomain:30.log
[ OK ]
[root@tian ~]# netstat -tlnp | grep vnc
tcp 0 0 0.0.0.0:6930 0.0.0.0:* LISTEN 15369/Xvnc
tcp 0 0 0.0.0.0:6901 0.0.0.0:* LISTEN 14648/Xvnc
tcp 0 0 0.0.0.0:6910 0.0.0.0:* LISTEN 14705/Xvnc
tcp 0 0 0.0.0.0:6920 0.0.0.0:* LISTEN 15065/Xvnc
[root@tian ~]#
注意:更改了端口号后,使用客户端连接时要加上完整的端口号 如
[root@tian ~]# vncviewer 127.0.0.1:6910
配置完成