VNC是基于UNIX和Linux操作系统的免费的开源软件,由于其远程控制能力强大且高效实用的特点深受大家的青睐。众所周知,在创建Oracle数据库的过程中我们一般要使用到dbca和netca图像化来进行建库和创建监听的工作,而在Linux操作系统中比较主流的图形化操作软件莫过于VNC了。那么我们如何在Linux系统中安装使用VNC呢?为此在本文中课课家笔者就为大家介绍在Linux中安装使用VNC服务的具体方法和步骤供大家参考参考。
①确认VNC是否安装
我们首先要确认一下VNC是否已经安装。一般在默认的情况下Red Hat Enterprise Linux安装程序会将VNC服务安装在系统上。
下面是确认是否已经安装VNC服务及查看安装的VNC版本的命令设置:
[root@testdb ~]# rpm -q vnc-server
vnc-server-4.1.2-9.el5
[root@testdb ~]#
如果系统没有安装的话我们可以到操作系统安装盘的Server目录下找到VNC服务的RPM安装包vnc-server-4.1.2-9.el5.x86_64.rpm,具体的安装命令如下:
rpm -ivh /mnt/Server/vnc-server-4.1.2-9.el5.x86_64.rpm
②启动VNC服务
在安装完毕后我们使用vnc server命令来启动VNC服务,命令格式为“vncserver :桌面号”,其中“桌面号”用“数字”的方式来表示,通常每个用户需要占用1个桌面。
下面是启动编号为1的桌面示例:
[root@testdb ~]# vncserver :1
You will require a password to Access your desktops.
Password:
Verify:
xauth: creating new authority file /root/.Xauthority
New 'testdb:1 (root)' desktop is testdb:1
Creating default startup script. /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/testdb:1.log
以上命令执行的过程中因为是第一次执行,所以我们需要输入密码,通常这个密码被加密保存在用户主目录下的.vnc子目录(/root/.vnc/passwd)中;同时在用户主目录下的.vnc子目录中为用户自动建立xstartup配置文件(/root/.vnc/xstartup)然后在每次启动VND服务时都会读取该文件中的配置信息。另外在BTW:/root/.vnc/目录下还有一个“testdb:1.pid”文件,一般这个文件记录着启动VNC后对应后天操作系统的进程号,用于停止VNC服务时准确定位进程号。
③VNC服务使用的端口号与桌面号的关系
第三步我们开启桌面号,在开启前我们先要了解VNC服务使用的端口号和桌面号的关系。
● VNC服务使用的端口号与桌面号相关,VNC使用TCP端口从5900开始,对应关系如下:
桌面号为“1” ---- 端口号为5901
桌面号为“2” ---- 端口号为5902
桌面号为“3” ---- 端口号为5903
……
● 基于java的VNC客户程序Web服务TCP端口从5800开始,也是与桌面号相关,对应关系如下
桌面号为“1” ---- 端口号为5801
桌面号为“2” ---- 端口号为5802
桌面号为“3” ---- 端口号为5803
……
一般来说,如果Linux开启了防火墙功能我们就需要手工开启相应的端口。下面笔者以开启桌面号为“1”相应的端口为例给大家介绍,具体的命令如下:
[root@testdb ~]# iptables -I INPUT -p tcp --dport 5901 -j ACCEPT
[root@testdb ~]# iptables -I INPUT -p tcp --dport 5801 -j ACCEPT
④测试VNC服务
接下来我们进行测试VNC服务的操作,具体的方法有两个。
● 测试方法一:
启动VNC Viewer软件 --> Server输入“144.194.192.183:1” --> 点击“OK” --> Password输入登陆密码 --> 点击“OK”登陆到X-Window图形桌面环境 --> 测试成功
● 测试方法二:
使用Web浏览器登陆测试,具体的操作流程如下:
地址栏输入http://144.194.192.183:5801/ --> 出现VNC viewer for Java(这个工具是使用Java编写的VNC客户端程序)界面,同时跳出VNC viewer对话框,在Server处输入“144.194.192.183:1”点击“OK” --> Password输入登陆密码 --> 点击“OK”登陆到X-Window图形桌面环境 --> 测试成功
PS:VNC viewer for Java需要JRE支持,如果页面无法显示则表示没有安装JRE。
⑤配置VNC图形桌面环境为KDE或GNOME桌面环境
如果按照笔者的方法进行的配置的会发现桌面效果简单且只有一个Shell可供使用,原因在于为VNC服务默认使用的是twm图形桌面环境所导致的。解决方法是我们可以在VNC的配置文件xstartup中对其进行修改,具体的命令设置如下:
[root@testdb ~]# cat /root/.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 &
● 对于设置KDE桌面环境,我们可以将xstartup文件的最后一行修改为“startkde &”,再重新启动vncserver服务后就可以登陆到KDE桌面环境
● 对于设置GNOME桌面环境,我们可以将xstartup文件的最后一行修改为“gnome-session &”,再重新启动vncserver服务后就可以登陆到GNOME桌面环境
重新启动vncserver服务的方法:
[root@testdb ~]# vncserver -kill :1
[root@testdb ~]# vncserver :1
⑥配置多个桌面
vncserver :1
vncserver :2
vncserver :3
……
部分人通过以上这种方法来实现配置多个桌面,但是这种手工启动的方法在服务器重新启动之后将失效。那么有什么一劳永逸的方法来进行配置多个桌面呢?其实方法也很简单,我们将需要自动管理的信息添加到/etc/sysconfig/vncservers配置文件中就可以了。
下面笔者以桌面1为root用户,桌面2为oracle用户为例进行配置:
格式:VNCSERVERS="桌面号:使用的用户名 桌面号:使用的用户名"
[root@testdb ~]# vi /etc/sysconfig/vncservers
VNCSERVERS="1:root 2:oracle"
VNCSERVERARGS[1]="-geometry 1024x768"
VNCSERVERARGS[2]="-geometry 1024x768"
⑦修改VNC访问的密码
当我们使用命令vncpasswd对不同用户的VNC的密码进行修改时一定要注意,如果配置了不同用户的VNC我们则需要分别到各自用户中进行修改,比如在笔者的例子中root用户和oracle用户需要分别进行修改,其修改过程如下:
[root@testdb ~]# vncpasswd
Password:
Verify:
[root@testdb ~]#
⑧启动和停止VNC服务
下面是启动和停止VNC服务的相关命令设置。
● 启动VNC服务命令
[root@testdb ~]# /etc/init.d/vncserver start
Starting VNC server: 1:root
New 'testdb:1 (root)' desktop is testdb:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/testdb:1.log
2:oracle
New 'testdb:2 (oracle)' desktop is testdb:2
Starting applications specified in /home/oracle/.vnc/xstartup
Log file is /home/oracle/.vnc/testdb:2.log
[OK]
● 停止VNC服务命令
[root@testdb ~]# /etc/init.d/vncserver stop
Shutting down VNC server: 1:root 2:oracle
[OK]
● 重新启动VNC服务命令
[root@testdb ~]# /etc/init.d/vncserver restart
Shutting down VNC server: 1:root 2:oracle
[OK]
Starting VNC server: 1:root
New 'testdb:1 (root)' desktop is testdb:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/testdb:1.log
2:oracle
New 'testdb:2 (oracle)' desktop is testdb:2
Starting applications specified in /home/oracle/.vnc/xstartup
Log file is /home/oracle/.vnc/testdb:2.log
[OK]
● 设置VNC服务随系统启动自动加载
设置方法一:使用“ntsysv”命令启动图形化服务配置程序,在vncserver服务前加上星号,点击确定配置完成。
设置方法二:使用“chkconfig”在命令行模式下进行操作,命令使用如下:
[root@testdb ~]# chkconfig vncserver on
[root@testdb ~]# chkconfig --list vncserver
vncserver
0:off
1:off
2:on
3:on
4:on
5:on
6:off
以上就是在Linux中安装使用VNC服务的方法和步骤。
本次的轻松几步在Linux中安装使用VNC服务的讲解到此就暂告一段落,如果以后有什么相关的内容继续进行补充或者修改的话,笔者会在此继续进行相关的内容的补充或者修改的工作,同时也欢迎大家对本次的讲解提出自己的建议和补充。最后笔者希望本次的讲解对大家学习Linux和Linux认证能够起到一定的帮助作用!
¥399.00
¥299.00
¥399.00
¥699.00