Install, configure, and use the VNC service in Linux
1. Check whether the VNC is installed.
By default, the Red Hat Enterprise Linux installer installs the VNC service on the system.
Check whether the VNC service has been installed and check the installed VNC version.
[root@testdb ~]# rpm -q vnc-servervnc-server-4.1.2-9.el5[root@testdb ~]#
If the system is not installed, you can find the RPM installation package vnc-server-4.1.2-9.el5.x86_64.rpm for the VNC service under the Server Directory of the operating system installation disk, the installation command is as follows
rpm -ivh /mnt/Server/vnc-server-4.1.2-9.el5.x86_64.rpm
2. Start the VNC service
Run the vncserver command to start the VNC service. The command format is "vncserver: desktop Number". The "desktop number" is represented by a number. Each user needs to occupy one desktop.
An example of starting a desktop with ID 1 is as follows:
[root@testdb ~]# vncserver :1You will require a password to access your desktops.Password:Verify:xauth: creating new authority file /root/.XauthorityNew 'testdb:1 (root)' desktop is testdb:1Creating default startup script. /root/.vnc/xstartupStarting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/testdb:1.log
During the preceding command execution, a password is required for the first execution. The password is encrypted and stored in the user's home directory. vnc subdirectory (/root /. in vnc/passwd. in the vnc subdirectory, The xstartup configuration file (/root /. vnc/xstartup), the configuration information in this file is read every time the VND service is started.
BTW:/root /. there is also a "testdb: 1. pid file, which records the process number corresponding to the operating system the day after the VNC is started, used to accurately locate the process number when the VNC service is stopped.
3. Relationship between the port number used by the VNC service and the desktop number
The port number used by the VNC service is related to the desktop number. The VNC uses the TCP port starting from 5900. The corresponding relationship is as follows:
Desktop number is "1" -- port number is 5901
Desktop number "2" -- port number is 5902
Desktop number "3" -- port number is 5903
......
The TCP port of the Java-based VNC client Web service starts from 5800 and is also related to the desktop number. The corresponding relationship is as follows:
Desktop number is "1" -- port number is 5801
Desktop number "2" -- port number is 5802
Desktop number "3" -- port number is 5803
......
Based on the above introduction, if the firewall function is enabled in Linux, You need to manually enable the corresponding port. For example, to enable the corresponding port with the desktop number "1", the command is as follows:
[root@testdb ~]# iptables -I INPUT -p tcp --dport 5901 -j ACCEPT[root@testdb ~]# iptables -I INPUT -p tcp --dport 5801 -j ACCEPT
4. Test the VNC service
The first method is to log on to the test using the VNC Viewer software. The procedure is as follows:
Start the VNC Viewer software and enter "144.194.192.183" on the Server: 1 "-> click" OK "-> enter the Login Password-> click" OK "to log on to the X-Window Graphic desktop environment-> test successful
The second method is to use a Web browser (such as Firefox, IE, Safari) to log on to the test. The procedure is as follows:
Enter http: // 144.194.192.183: 5801/-> in the address bar, the VNC viewer for Java (this tool is a VNC client program written in Java) interface appears, and The VNC viewer dialog box is displayed, on the Server, enter "144.194.192.183: 1" and click "OK"-> Password, enter the login Password-> click "OK" to log on to the X-Window Graphic desktop environment-> the test is successful.
(Note: VNC viewer for Java requires JRE support. If the page cannot be displayed, it indicates that JRE is not installed. You can download the latest jrefor installation at http://java.sun.com/javase/downloads/index_jdk5.jsp)
5. Configure the VNC graphic desktop environment as KDE or GNOME Desktop Environment
If you configured it according to my above method, it would be very simple to log on to the desktop and only one Shell is available. Why? How can we see the cute and beautiful KDE or GNOME desktop environment? The answer is as follows:
The reason for this is that the VNC service uses the twm graphical desktop environment by default. You can modify it in the VNC configuration file xstartup. Let's take a look at this configuration file.
[root@testdb ~]# vi /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/.Xresourcesxsetroot -solid greyvncconfig -iconic &xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &twm &
Change the last line of the xstartup file to "startkde &", restart the vncserver service, and then log on to the KDE Desktop Environment.
Change the last line of the xstartup file to "gnome-session &", restart the vncserver service, and then log on to the GNOME desktop environment.
To restart the vncserver service, follow these steps:
[root@testdb ~]# vncserver -kill :1[root@testdb ~]# vncserver :1
6. Configure multiple desktops
You can use the following method to start VNC for multiple desktops
Vncserver: 1
Vncserver: 2
Vncserver: 3
......
However, this manual start method will expire after the server is restarted. Therefore, the following describes how to enable the system to automatically manage VNC on multiple desktops, add the information to be automatically managed to the/etc/sysconfig/vncservers configuration file. Configure desktop 1 as root user desktop 2 as an oracle user as follows:
Format: VNCSERVERS = "desktop number: used user name"
[root@testdb ~]# vi /etc/sysconfig/vncserversVNCSERVERS="1:root 2:oracle"VNCSERVERARGS[1]="-geometry 1024x768"VNCSERVERARGS[2]="-geometry 1024x768"
7. Modify the VNC access password
Use the command vncpasswd to modify the VNC password of different users. Note that if the VNC of different users is configured, they must be modified in their respective users, for example, in my experiment, the root user and the oracle user must be modified separately. The modification process is as follows:
[root@testdb ~]# vncpasswdPassword:Verify:[root@testdb ~]#
8. Start and Stop the VNC service
1) Start the VNC service command
[root@testdb ~]# /etc/init.d/vncserver startStarting VNC server: 1:rootNew 'testdb:1 (root)' desktop is testdb:1Starting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/testdb:1.log
2:oracle
New 'testdb:2 (oracle)' desktop is testdb:2Starting applications specified in /home/oracle/.vnc/xstartupLog file is /home/oracle/.vnc/testdb:2.log [ OK ]
2) Stop the VNC service command
[root@testdb ~]# /etc/init.d/vncserver stopShutting down VNC server: 1:root 2:oracle [ OK ]
3) restart the VNC service command
[root@testdb ~]# /etc/init.d/vncserver restartShutting down VNC server: 1:root 2:oracle [ OK ]Starting VNC server: 1:rootNew 'testdb:1 (root)' desktop is testdb:1Starting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/testdb:1.log
2:oracle
New 'testdb:2 (oracle)' desktop is testdb:2Starting applications specified in /home/oracle/.vnc/xstartupLog file is /home/oracle/.vnc/testdb:2.log [ OK ]
4) set the VNC service to automatically load as the system starts
Method 1: run the "ntsysv" command to start the graphical service configuration program. Add an asterisk to The vncserver service and click "OK". The configuration is complete.
Method 2: Use "chkconfig" to operate in command line mode. Use the following command (for more information about how to use chkconfig, see self-help man)
[root@testdb ~]# chkconfig vncserver on[root@testdb ~]# chkconfig --list vncservervncserver 0:off 1:off 2:on 3:on 4:on 5:on 6:off
9. Summary
The detailed configuration method of VNC has been completed, and I hope it will be helpful to you. VNC is very lightweight and convenient for remotely calling graphical interfaces!