In Linux, VNC includes the following commands: vncserver, vncviewer, vncpasswd, and vncconnect. In most cases, you only need two commands: vncserver and vncviewer.
My CentOS server is connected via SSH without a graphical window, that is, Headless System. Therefore, I decided to use two lightweight applications, x11vnc and Xvfb, to meet my needs. X11vnc is a VNC service program, which itself is relatively lightweight. Therefore, the lightweight requirements for running only one or two GUI window programs are more appropriate. We know that to display a window in Linux, you must first create a display service. Xvfb is a lightweight virtual display service program that does not generate actual screen output. Therefore, the principle of the entire solution is that Xvfb creates display and x11vnc connections and converts them to vnc protocols.
First, install necessary components:
The code is as follows: |
Copy code |
Yum install xorg-x11-xauth xterm libXi libXp libXtst-devel libXext-devel
|
Install x11vnc. The script is as follows:
The code is as follows: |
Copy code |
Wget http://softlayer-ams.dl.sourceforge.net/project/libvncserver/x11vnc/0.9.13/x11vnc-0.9.13.tar.gz Tar zxf x11vnc-0.9.13.tar.gz X11vnc-0.9.13 cd tar zxf ./Configure-prefix =/usr/local/blog.creke.net/x11vnc Make Make install |
Then we use yum to install Xvfb. The script is as follows:
The code is as follows: |
Copy code |
Yum install Xvfb |
Then, you can use Xvfb with a simple x11vnc command, as shown below:
/Usr/local/x11vnc/bin/x11vnc-rfbport 12345-passwd connection password-create-forever
After running, use the vnc client to connect to port 12345 of the server. Enter the correct password to view the terminal window. The window program can be directly displayed in VNC when the terminal is started. If you want to use the window after logging out of SSH, you can run the above script in screen. If you want multiple users to connect to VNC at the same time, you can add the "-shared" parameter.