In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how to configure vncserver in the centos7 environment, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
When managing a Linux server, in most cases, people connect to the target server through SSH and perform various administrative operations under the command line interface, but sometimes we also want to be able to perform operations in an interfaced environment. This article will introduce you to configure the vnc service to remotely access the target server with a graphical interface.
Some children's shoes may already be familiar with vncserver during their previous work and study, so why should we introduce the way to configure vnc service here? the fundamental reason is that after entering the CentOS7 version, due to the change in the way Linux manages the service, the configuration of vncsrever is also very different from before. in order to make new contact with CentOS7 less detours, here through practice Learn how to configure VNC services in a CentOS7 environment.
Prompt
1: the operating environment in this paper is based on CentOS 7, which is also applicable to RHEL 7.
2: unless otherwise specified, the following operations are performed under root users.
First, install VNC
To access the server in an interface way, first of all, we need to make sure that the target server has installed a graphical environment. The common desktop environments under Linux systems are GNOME and KDE. Here, we first install the GNOME desktop through Group, and execute the command as follows:
# yum-y groupinstall "GNOME Desktop"
Now you can install vncserver on our Centos7 server and install the tigervnc server, and execute the command as follows:
# yum-y install tigervnc-server
2. Configure VNC
For pre-Linux7 systems, the / etc/sysconfig/vncservers file will be configured after installation. After entering version 7.0, this file still exists, but it has lost its practical meaning and has only one line:
# more / etc/sysconfig/vncservers
# THIS FILE HAS BEEN REPLACED BY / lib/systemd/system/vncserver@.service
This is related to the change in the way services are managed after Linux7, so let's demonstrate how to configure vncserver as a service that systemd can manage.
After tigervnc-server is installed, a module file named vncserver@.server is automatically created, which is the path pointed to in the previous / etc/sysconfig/vncservers file.
Let's take a look at the contents of this file:
# more / lib/systemd/system/vncserver@.service
# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to / etc/systemd/system/vncserver@.service
# 2. Edit / etc/systemd/system/vncserver@.service, replacing
# with the actual user name. Leave the remaining lines of the file unmodified
# (ExecStart=/usr/sbin/runuser-l-c "/ usr/bin/vncserver% I"
# PIDFile=/home//.vnc/%H%i.pid)
# 3. Run `systemctl daemon- reload`
# 4. Run `systemctl enable vncserver@: .service`
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted! For a secure way of using VNC, you should
# limit connections to the local host and then tunnel from
# the machine you want to view VNC on (host A) to the machine
# whose VNC output you want to view (host B)
#
# [user@hostA ~] $ssh-v-C-L 590N:localhost:590M hostB
#
# this will open a connection on port 590N of your hostA to hostB's port 590M
# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).
# See the ssh man page for details on port forwarding)
#
# You can then point a VNC client on hostA at vncdisplay N of localhost and with
# the help of ssh, you end up seeing what hostB makes available on port 590M
#
# Use "- nolisten tcp" to prevent X connections to your VNC server via TCP
#
# Use "- localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the "- via" option in the
# `man vncviewer' manual page.
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
# Clean any existing files in / tmp/.X11-unix environment
ExecStartPre=/bin/sh-c'/ usr/bin/vncserver-kill% I > / dev/null 2 > & 1 | |:'
ExecStart=/usr/sbin/runuser-l-c "/ usr/bin/vncserver I"
PIDFile=/home//.vnc/%H%i.pid
ExecStop=/bin/sh-c'/ usr/bin/vncserver-kill% I > / dev/null 2 > & 1 | |:'
[Install]
WantedBy=multi-user.target
Friends who are familiar with systemd services should be able to configure them quickly according to this module file. It doesn't matter even for friends who are not familiar with systemd, on the one hand, the content of the file has already described the process more clearly, specially written "# Quick HowTo:", on the other hand, we will demonstrate step by step to ensure that everyone can understand.
Basically, we also follow the steps in Quick HowTo
1. Copy the file to the destination path based on the template:
# cp / lib/systemd/system/vncserver@.service / etc/systemd/system/vncserver@:1.service
2. Edit the newly copied vncserver@:1.server file and replace the variable with the appropriate value according to the actual situation. The so-called actual situation mainly refers to two items: the USER to which the service runs, and the Display Number of the service. The default is: 1.
I would like to add a few more words about DisplayNumber. A single server allows multiple vncserver services to be started at the same time. There is no doubt that different vncserver runs in different processes and provides different port services. At the same time, each vncserver needs to specify a Display Number at startup. The specified Display Number is greater than 0 and is not repeated. If it is not specified when starting vncserver, the default Display Number will be incremented from 1. If more than one vncserver in the same server starts with the same Display Number specified, only one will be able to start successfully.
Next, let's edit the vncserver@:1.service file to modify the configuration item:
# vim / etc/systemd/system/vncserver@:1.service
The original configuration is as follows:
[Service]
Type=forking
# Clean any existing files in / tmp/.X11-unix environment
ExecStartPre=/bin/sh-c'/ usr/bin/vncserver-kill% I > / dev/null 2 > & 1 | |:'
ExecStart=/usr/sbin/runuser-l-c "/ usr/bin/vncserver I"
PIDFile=/home//.vnc/%H%i.pid
ExecStop=/bin/sh-c'/ usr/bin/vncserver-kill% I > / dev/null 2 > & 1 | |:'
The modified configuration is as follows:
[Service]
Type=forking
# Clean any existing files in / tmp/.X11-unix environment
ExecStartPre=/bin/sh-c'/ usr/bin/vncserver-kill: 1 > / dev/null 2 > & 1 | |:'
ExecStart=/usr/sbin/runuser-l jss-c "/ usr/bin/vncserver: 1"
PIDFile=/home/jss/.vnc/%H:1.pid
ExecStop=/bin/sh-c'/ usr/bin/vncserver-kill: 1 > / dev/null 2 > & 1 | |:'
Overall, two major changes have been made, the first is to replace% I with: 1 and the second is to replace it with jss.
Save exit.
3. Reload the configuration of systemd
# systemctl daemon-reload
4. Enable this service and set the vncserver service to boot:
# systemctl enable vncserver@:1.service
At this point, the configuration section is almost over, but note that do not start the vncserver at this time, because the access key file for vncserver has not been created yet, and we need to create the key for vncserver before starting the service item.
Because in the previous configuration process, the specified vncserver runs under the jss user, first switch to the jss user:
# su-jss
Execute vncpasswd and enter the access password as follows:
$vncpasswd
Password:
Verify:
Then return to root users, and you can use systemd to control the start and stop of the vncserver service.
For example, start the service:
# systemctl start vncserver@:1.service
View service status:
# systemctl status vncserver@:1.service
● vncserver@:1.service-Remote desktop service (VNC)
Loaded: loaded (/ etc/systemd/system/vncserver@:1.service; disabled; vendor preset: disabled)
Active: active (running) since Mon xxxx-02-06 14:23:51 CST; 1min ago
Process: 29009 ExecStart=/usr/sbin/runuser-l jss-c / usr/bin/vncserver: 1 (code=exited, status=0/SUCCESS)
Process: 29007 ExecStartPre=/bin/sh-c / usr/bin/vncserver-kill: 1 > / dev/null 2 > & 1 |: (code=exited, status=0/SUCCESS)
Main PID: 29035 (Xvnc)
CGroup: / system.slice/system-vncserver.slice/vncserver@:1.service
? 29035 / usr/bin/Xvnc: 1-desktop localhost.localdomain:1 (jss)-auth / home/jss/.Xauthority-geometry 1024x768-rfbwait 30000-rfbauth / home/jss/.vnc/pass...
Feb 06 14:23:48 localhost.localdomain systemd [1]: Starting Remote desktop service (VNC)...
Feb 06 14:23:51 localhost.localdomain systemd [1]: Started Remote desktop service (VNC).
As you can see, the service handles the active status and has been successfully started.
III. Client connection
When the vnc service starts, we can connect to the server on the client side through tools such as vncviewer. When specifying the server address, you need to fill in the IP address of the target server and the port number of the service. Generally speaking, the IP address of the target server must be known, but what should the port fill in?
The port number used by the Vnc service starts at 5900, and the first running vnc service runs on port 5901 after startup, and the others increase in turn. If you want to query in the linux system, you can use commands such as netstat or ps, such as:
# ps-ef | grep vnc
Root 10936 10780 0 14:31 pts/0 00:00:00 grep-color=auto vnc
Jss 29035 10 Feb06? 00:00:00 / usr/bin/Xvnc: 1-desktop localhost.localdomain:1 (jss)-auth / home/jss/.Xauthority-geometry 1024x768-rfbwait 30000-rfbauth / home/jss/.vnc/passwd-rfbport 5901-fp catalogue:/etc/X11/fontpath.d-pn
Here we can see that the vnc service is currently running on port 5901. If multiple vnc services are started on the server at the same time, you can also tell which service is running on which user and which port by looking at the process.
As shown in the figure above, specify the IP address and port of the target server and click "OK".
As we mentioned earlier, multiple vnc services can be run on the same server, and different vnc services can be run under different users. If you need to configure more vnc services, you can repeat the operation in step 2 to create more vncserver@.service files and specify different DisplayNumber for them.
4. Common management operations of vncserver services
Enable service boot self-startup:
# systemctl enable vncserver@:1.service
Disable service boot self-startup:
# systemctl disable vncserver@:1.service
Service startup:
# systemctl start vncserver@:1.service
Service stop:
# systemctl stop vncserver@:1.service
View service status:
# systemctl status vncserver@:1.service
The above content is how to configure vncserver in centos7 environment. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.