When actually maintaining the remote Linux Server host, sometimes the pure command line mode may not meet our needs, this time need to use the remote host GUI mode, that can see the server's desktop, generally use two ways: Xmanager or VNC. I started with Xmanager, version is Xmanager5 Enterprise, but in connection with the server, you can connect (already see the host name), but unable to open the desktop, tossing a long time finally give up, choose VNC, in contrast convenient many. Below the summary of their own practical experience, the need for friends can see.
Description under I here the CentOS host has installed the GoHome desktop, not installed please install a GUI desktop.
First, the Linux host installs the VNC service 1, installs the Vnc-server
VNC is divided into servers and clients, Linux server hosts need to install VNCSERVER,CENTOS7 under general use TIGERVNC.
Execute command under root:
#yum-y tigervnc-server
Configuration is required after the installation is complete.
2, Configuration Vnc-server
Go to Catalog
#cd /lib/systemd/system#ls
We will see a service called [email protected], which is the VNC service we need. However, it needs to be configured before it can be used. Assuming that we are currently configuring Remote Desktop for the root user, the configuration process is as follows:
First, copy the service, named [email Protected]:1.service,
#cpvncserver@.service [email protected]:1.service
then modify [email Protected]:1.service
#vivncserver@:1.service
See the following text:
[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=/sbin/runuser-l < user>-C "/usr/bin/vncserver%i"
pidfile=/home/< User>/.vnc/%h%i.pid
Execstop=/bin/sh-c '/usr/bin/vncserver-kill%i >/dev/null 2>&1 | | :’
[Install]
Wantedby=multi-user.target
Here, and only one substitution is needed: Replace < user> with the user that needs to be configured. Note that because Root's home directory is/root/, not/home/root/, the following text is replaced:
[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=/sbin/runuser-l root-c "/usr/bin/vncserver%i"
Pidfile=/root/.vnc/%h%i.pid
Execstop=/bin/sh-c '/usr/bin/vncserver-kill%i >/dev/null 2>&1 | | :’
[Install]
Wantedby=multi-user.target
If a non-root user, such as user admin,pidfile, should be:
Execstart=/sbin/runuser-l admin-c "/usr/bin/vncserver%i"
Pidfile=/home/admin/.vnc/%h%i.pid
Finally Esc+:wq save exit.
3. Start Vnc-server
In the configuration file just now, there is a description:
# Quick HowTo:
# 1. Copy This file To/etc/systemd/system/[email protected]:.service
# 2. Edit and Vncserver parameters appropriately
# ("Runuser-l-c/usr/bin/vncserver%i-arg1-arg2")
# 3. Run systemctl daemon-reload
# 4. Run ' systemctl enable [email protected]:.service
When the configuration is complete, you also need to perform
#systemctl daemon-reload#systemctl enable [email protected]:1.service
Then turn on the VNC service
#systemctlstartvncserver@:1.service
To see if the launch was successful
#systemctlstatusvncserver@:1.service
If real active means to be successful. Below, set the VNC connection password,
Perform
#vncpassword
Prompt to enter the password and confirm that this is for remote connection when the authentication, you can set a bit. After configuration, you can restart the VNC service.
#systemctlrestartvncserver@:1.service
4. Configure the Firewall
The VNC service is turned on, but if the remote client needs to connect, additional configuration for the firewall is required to open the port. The general VNC service is to use 590+X as the access port, X for the configured [email protected]:x, such as [email protected]:1.service here], the port is 5901.
Execute command
#vi /etc/sysconfig/iptables
In
-A input-p tcp-m state–state new-m tcp–dport 22-j ACCEPT
Add configuration Below
-A input-p tcp-m state–state new-m tcp–dport 5901-j ACCEPT
Then save the exit and restart the firewall. Here the basic VNC server configuration is over.
Second, the Client remote connection
Once you have configured the service-side VNC service, you can connect remotely. Here is the use of Win7 under the connection, the client is using tigervnc-1.5.0, Baidu under the general have, after downloading the direct installation, the installation process can be removed as the service side of the check, but it doesn't matter. After entering the installation directory, find Vncviewer.exe, double-click Execute, enter the IP and port number, click Connection, and then follow the prompts to enter the previously configured access password, enter, you can see the remote Linux host desktop.
Three, open multiple Vncserver
Sometimes we may need more than one user's desktop environment, such as when I am remotely installing Oracle, I also need an Oracle user's desktop environment, but previously only configured the root user, the following describes the configuration of multi-user vncserver. Configuration idea is simple, is to configure multiple [email protected]:n.service.
1. Copy [email protected]
Assuming that our users are already established, here's an example of admin. First log in as root,
#cd /lib/systemd/system
directory, as described above, copy the configuration file, but this is not: 1, but: 2, the number can be set by itself, generally increment.
#cpvncserver@.service [email protected]:2.service
then modify [email Protected]:2.service
#vivncserver@:2.service
Modify Configuration
[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=/sbin/runuser-l admin-c "/usr/bin/vncserver%i"
Pidfile=/home/admin/.vnc/%h%i.pid
Execstop=/bin/sh-c '/usr/bin/vncserver-kill%i >/dev/null 2>&1 | | :’
[Install]
Wantedby=multi-user.target
Save exit. Then follow the configuration file prompts to execute
#systemctl daemon-reload#systemctl enable [email protected]:2.service
2. Modify the VNC login authentication password
After execution, switch to admin account and execute
$vncserver :2
Will ask for a verification password
You'll require a password to access your desktops.
Password:
Verify:
xauth:file/home/admin/. Xauthority does not exist
New ' localhost.localdomain:2 (admin) ' Desktop is Localhost.localdomain:2
Creating default startup Script/home/admin/.vnc/xstartup
Starting applications specified In/home/admin/.vnc/xstartup
Log file Is/home/admin/.vnc/localhost.localdomain:2.log
3. Start the service
Then switch back to root and execute
#systemctl deamon-reload#systemctl start [email protected]:2.service
When the prompt starts unsuccessfully, execute the command
#vncserver:2
Tip There is already a vncserver as:2 running, this time we want to kill this process, execute the command
#vncserver-kill:2
But generally no use, then we
# ps -ef | grep vnc
To view the process ID of the vncserver:2, such as PID 1311, execute
#kill -9 1311
And then execute
#systemctlstartvncserver@:2.service
Or an error, check the log,
#journalctl -xn
Tip You need to delete/tmp/. X2-lock
Perform
#rm /tmp/.X2-lock
Start again
#systemctlstartvncserver@:2.service
or error, check the log, prompted to delete/tmp/. X11-unix/x2
Perform
#rm /tmp/.X11-unix/X2
Start again
#systemctlstartvncserver@:2.service
Finally no error, then check the status
#systemctlstatusvncserver@:2.service
Discovery has started, then complete. Then be careful not to forget to configure the firewall as described above.
End all the configuration, in the actual startup process may encounter a variety of problems, as long as the quiet to view the log, generally can be resolved. Where there is a mistake, I also hope to correct it.
Finally, recommend a good article: CentOS7 installation configuration VNC.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Connect CentOS7 Remote Desktop using VNC under Windows