Centos7 installation and configuration of VNC server-openbox articles


If you use GNOME for the graphical interface, see here: Centos7 installation and configuration of VNC server-GNOME
If you use Xfce for the graphical interface, see here: Centos7 installation and configuration of VNC server-Xfce

Introduction to VNC

VNC (Virtual Network Computing), is a screen sharing and remote operation software using RFB protocol. This software can send keyboard and mouse actions and real-time screen images through the network.

VNC has nothing to do with the operating system, so it can be used across platforms. For example, you can connect to a Linux computer with Windows, and vice versa. Even in a computer that does not have a client program installed, it can be used as long as there is a browser that supports JAVA.

VNC was developed by the Olivetti & Oracle research room, which was merged into the American Telephone and Telegraph Company (AT&T) in 1999. AT&T suspended the operation of this laboratory in 2002 and released VNC under GPL.

Because it is free and can be used in a large number of different operating systems, its simplicity, reliability, and backward compatibility make it the most widely used remote control software. Multi-platform support is very important for network administrators. Importantly, this allows network administrators to use one tool to manage almost any system.

Install TigerVNC

sudo yum install tigervnc-server

note! It is not recommended to use the root user for system security, so create a user dedicated to vnc.
Create user vncuser

sudo adduser vncuser

set password

sudo passwd vncuser

For example: the password I set here is2021@vnc

After creating vncuser and setting the login password, you also need to set a unique VNC password for this user

su - vncuser
vncpasswd

For example: the password I set here is2021@vncpass

Would you like to enter a view-only password (y/n)? n
(Do you want to enter a view-only password ?) I don’t need it. Choose according to the actual situation.
My detailed operation is as follows:
Insert picture description here
Create a VNC configuration file for vncuser.
The following commands will be executed as root user by default if there is no special instructions.

su root

The fastest way to do this is to copy the shared VNC template file located in the /lib/systemd/system/ folder, and then change it:

cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service

The number 1 in the new file here will be used with the display number of the specific instance of this service, which is very important. Because it will also determine the TCP port that our VNC server will use, which is equal to 5900 + display number. The first is 5901, then 5902, and so on.

vim /etc/systemd/system/vncserver@:1.service

Insert picture description here
My configuration is as follows:

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver_wrapper vncuser %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

After completing the operation, you can reload the VNC daemon, and then use the following command to run vncserver #1:

systemctl daemon-reload
systemctl start vncserver@:1

Insert picture description here
Query whether the current service is started normally:

systemctl status vncserver@:1

Insert picture description here
Set boot up

systemctl enable vncserver@:1

Another test you can perform before attempting to connect to the server is to use the ss command to view the active network sockets: if everything is working properly, you should see that the VNC server is working properly and uses TCP port 5901. Excuting an order:

ss -tulpn| grep vnc

Insert picture description here
If you see this, everything is set up correctly.

Firewall settings

Since our VNC service is listening on TCP port 5901, the firewall must allow it. It is not recommended to simply and rudely turn off the firewall.

firewall-cmd --add-port=5901/tcp
firewall-cmd --add-port=5901/tcp --permanent

Refer to: "CentOS7 Firewall Management and Configuration"

Install the graphical user interface (GUI)

If you have already installed GNOME, KDE or other desktop environments, you can skip this step. Otherwise, you need to install one of them: TigerVNC server will start a parallel instance of this desktop environment for each login session, which means we must have at least one GUI.

If you use GNOME for the graphical interface, see here: Centos7 installation and configuration of VNC server-GNOME
If you use Xfce for the graphical interface, see here: Centos7 installation and configuration of VNC server-Xfce

openbox

Install epel source

yum install epel-release

X Window System necessary for graphical interface

yum -y groupinstall "X Window System"

Install a series of software

yum -y install openbox xfce4-terminal tint2 network-manager-applet ibus ibus-libpinyin cjkuni-ukai-fonts lightdm
  • openbox a small desktop environment
  • xfce4-terminal is a graphical terminal for the xfce desktop
  • tint2 a useful taskbar panel
  • network-manager-applet is nm-applet network widget
  • Install ibus platform and ibus-libpinyin Chinese Pinyin input method, Chinese font cjkuni-ukai-fonts

If Chinese fonts are not installed, the ibus input method cannot input Chinese normally.

  • Install lightdm display manager

Configure openbox auto-start file

vi /etc/xdg/openbox/autostart
# 开启 D-bus daemon
if which dbus-launch >/dev/null && test -z "$DBUS_SESSION_BUS_ADDRESS"; then
       eval `dbus-launch --sh-syntax --exit-with-session`
fi
# 开启ibus 输入法
ibus-daemon -d -x &
# 开启tint2面板
tint2 &
# 开启网络图标
nm-applet  &
# 开启xfce4终端
xfce4-terminal &

lightdm

Disable gdm

systemctl disable gdm

Enable lightdm as the default display manager

systemctl enable lightdm

Open the lightdm display manager

systemctl stop gdm
systemctl start lightdm

At this time, I found the interface appeared.

For details, see:
"CentOS7 with a simple desktop environment openbox"
https://blog.csdn.net/lxyoucan/article/details/113207823

Modify the configuration file

Switch to the vncuser user

su - vncuser

Modify the configuration file ~/.vnc/xstartup:

 vim ~/.vnc/xstartup
#!/data/data/com.termux/files/usr/bin/sh
# Start Openbox.
openbox-session &

In theory, this is fine. If you find that only the mouse is connected and nothing else can be seen, restart the VNC service.
Close service

systemctl stop vncserver@:1

Open service

systemctl start vncserver@:1

VNC client connection

Now that everything is set up, we can try to connect to our VNC service using a VNC client, such as TightVNC, UltraVNC or RealVNC, VNC Viewer. Remember to specify TCP port 5901 (if you follow our guide).

Personally use VNC Viewer https://www.realvnc.com/en/connect/download/viewer/

Insert picture description here
Enter 172.16.184.5:5901 in the address bar and press Enter directly.
Insert picture description here
When the pop-up box appears, click Confirm, and enter the password when it appears.
Insert picture description here

The effect is as follows:
Insert picture description here

Turn off the VNC service

Sometimes the VNC service cannot be used several times a year. For example, when I install oracle, I will start the VNC service, and I will not use it after the installation. Turning it on will waste server resources.

Close service

systemctl stop vncserver@:1

Open service

systemctl start vncserver@:1

Check service status

systemctl status vncserver@:1

Set boot up

systemctl enable vncserver@:1

Cancel startup

systemctl disable vncserver@:1

Reference documents

https://zh.wikipedia.org/wiki/VNC

《Installing and configuring a VNC server on CentOS 7》
https://serverspace.io/support/help/installing-and-configuring-a-vnc-server-on-centos-7/

"Centos 7 install xfce 4 desktop environment"
https://blog.csdn.net/whatday/article/details/105053918

Guess you like

Origin blog.csdn.net/lxyoucan/article/details/113210891