Opening VNCServer on CentOS7 and dealing with pitfalls encountered

When logging in remotely through SSH, having a graphical desktop will make people feel much more comfortable. Our server often has many people logging in at the same time, and TeamViewer is not easy to open many times. In this case, VNC is a good alternative solution.


2019/04/23

The server's CentOS7 system comes with TigerVNC. Shell execution

vncserver

You can start VNCServer with one click. This can be followed by parameters to set various configurations, including users, ports, resolutions, etc. For example

vncserver :1 -rfbport 5902

Among them: 1 specifies VNCServer No. 1 to be opened as system, and its port defaults to port 5900+1=5901 in the system. However, -rfbport 5902 specifies the use of port 5902. When actually enabled, port 5902 will be used instead of port 5901.

When you execute VNCServer for the first time, you will be prompted to set a password and generate some files in the user's Home directory.

~/
├ .Xauthority
└ .vnc [Folder]
  ├ config
  ├ passwd
  └ xstartup

The xstartup file is executed after the VNCServer is established, which uses the X Window System to start the graphical desktop.

Every time VNCServer is executed, a log file will be generated in the ~/.vnc/ directory. By browsing the log, you can determine whether VNCServer is running normally. (This is important

In addition, we can execute Shell at any time

vncserver -list

to view the running VNCServer belonging tothis user; to close process No. 2, you can execute it with Shell

vncserver -kill :2

In addition, if port preemption occurs, the server loses contact (the PID file is missing), etc., you can execute the Shell

ps -aux | grep Xvnc

To viewall users running VNCServer processes.

For the console, I chose VNC Viewer to connect. If VNCServer No. 1 is opened on the controlled end, the connection address of the control end is written as xxx.xxx.xxx.xxx:1.


In fact, the reason why I wrote this article is because I spent nearly a day going through the pitfalls of VNCServer...

  1. By observing the log, it was found that VNCServer did not start normally.

    As mentioned earlier, xstartup is used to start the graphical desktop. If only the graphical desktop does not start, VNC Viewer should be able to connect to VNCServer normally, but a black screen will be displayed. Here I only stepped on the trap about xstartup.

  • xstartup has no permission

sudo chmod a+x /etc/X11/xinit/xinitrc
  • xstartup is running, but an error is reported

     One reason is that Anaconda conflicts with the operating environment. Check whether Anaconda is installed and is before /usr/bin in the environment variable $PATH.

    If it is determined that a conflict in the running environment causes xstartup to run incorrectly, you can add it at the beginning and end of the ~/.vnc/xstartup file.

PATH_TEMP="$PATH"
export PATH="/usr/bin:$PATH"
export PATH=PATH_TEMP

    The above method avoids running environment conflicts by temporarily increasing the search priority of /usr/bin in the environment variable $PATH when xstartup is running. I think it is a simple, convenient and pollution-free approach.

  2. VNCServer is running normally, but the control terminal cannot connect to VNCServer.

    After confirming that VNCServer is running normally, there is a high probability that the connection to the VNC port is blocked. One of the suspects is the firewall of the server Linux system, and the other is the firewall of the server management software. It is necessary to check whether the VNC designated port (such as port 5901) is allowed to communicate.

Guess you like

Origin blog.csdn.net/hizcard/article/details/86585217