实验环境: 在RHEL 7.5 中模拟给两个用户 jerry、tom 配置vnc
Note
Unlike in previous Red Hat Enterprise Linux distributions, TigerVNC in Red Hat Enterprise Linux 7 uses the systemd system management daemon for its configuration. The /etc/sysconfig/vncserver configuration file has been replaced by /etc/systemd/system/vncserver@.service.
Installing VNC Server
To install the TigerVNC server, issue the following command as root
[root@vm-server ~]# yum install tigervnc-server
Configuring VNC Server
The VNC server can be configured to start a display for one or more users, provided that accounts for the users exist on the system, with optional parameters such as for display settings, network address and port, and security settings.
-
A configuration file named /etc/systemd/system/vncserver@.service is required. To create this file, copy the /usr/lib/systemd/system/vncserver@.service file as root:
[root@vm-server ~]# cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver-jerry@.service[root@vm-server ~]# cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver-tom@.service
-
Edit /etc/systemd/system/vncserver-USER@.service, replacing USER with the actual user name. Leave the remaining lines of the file unmodified. The -geometry argument specifies the size of the VNC desktop to be created; by default, it is set to 1024x768.
34 [Unit] 35 Description=Remote desktop service (VNC) 36 After=syslog.target network.target 37 38 [Service] 39 Type=forking 40 41 # Clean any existing files in /tmp/.X11-unix environment 42 ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' 43 ExecStart=/usr/sbin/runuser -l jerry -c "/usr/bin/vncserver %i -geometry 1366x768" 44 PIDFile=/home/jerry/.vnc/%H%i.pid 45 ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' 46 47 [Install] 48 WantedBy=multi-user.target
- Save the changes.
-
To make the changes take effect immediately, issue the following command:
[root@vm-server ~]# systemctl daemon-reload
-
Set the password for the user or users defined in the configuration file. Note that you need to switch from root to USER first.
[root@vm-server ~]# su - jerry[jerry@vm-server ~]$ vncpasswd Password:Verify:Would you like to enter a view-only password (y/n)? nA view-only password is not used[jerry@vm-server ~]$ exitlogout[root@vm-server ~]# su - tom[tom@vm-server ~]$ vncpasswd Password:Verify:Would you like to enter a view-only password (y/n)? nA view-only password is not used[tom@vm-server ~]$ exitlogout[root@vm-server ~]#
Important
The stored password is not encrypted; anyone who has access to the password file can find the plain-text password.
Starting VNC Server
To start or enable the service, execute the following command:
[root@vm-server ~]# systemctl start vncserver-jerry@:1[root@vm-server ~]# systemctl start vncserver-tom@:2
You can also enable the service to start automatically at system start. Then, when you log in, vncserver is automatically started. As root, issue a command as follows:
[root@vm-server ~]# systemctl enable vncserver-jerry@:1Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver-jerry@:1.service to /etc/systemd/system/vncserver-jerry@.service.[root@vm-server ~]# systemctl enable vncserver-tom@:2Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver-tom@:2.service to /etc/systemd/system/vncserver-tom@.service.[root@vm-server ~]#
检查服务状态
[root@vm-server ~]# systemctl status vncserver-jerry@\:1.service ● vncserver-jerry@:1.service - Remote desktop service (VNC) Loaded: loaded (/etc/systemd/system/vncserver-jerry@.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2018-09-09 13:22:11 CST; 18min ago Main PID: 6971 (Xvnc) CGroup: /system.slice/system-vncserver\x2djerry.slice/vncserver-jerry@:1.service ‣ 6971 /usr/bin/Xvnc :1 -auth /home/jerry/.Xauthority -desktop vm-server:1 (jerry) -fp catalogue:/etc/X11/fontpath.d -geometry 1366x768 ...Sep 09 13:22:08 vm-server systemd[1]: Starting Remote desktop service (VNC)...Sep 09 13:22:11 vm-server systemd[1]: Started Remote desktop service (VNC).[root@vm-server ~]# systemctl status vncserver-tom@\:2.service ● vncserver-tom@:2.service - Remote desktop service (VNC) Loaded: loaded (/etc/systemd/system/vncserver-tom@.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2018-09-09 13:22:29 CST; 18min ago Main PID: 7598 (Xvnc) CGroup: /system.slice/system-vncserver\x2dtom.slice/vncserver-tom@:2.service ‣ 7598 /usr/bin/Xvnc :2 -auth /home/tom/.Xauthority -desktop vm-server:2 (tom) -fp catalogue:/etc/X11/fontpath.d -geometry 1366x768 -pn ...Sep 09 13:22:25 vm-server systemd[1]: Starting Remote desktop service (VNC)...Sep 09 13:22:29 vm-server systemd[1]: Started Remote desktop service (VNC).[root@vm-server ~]#
At this point, other users are able to use a VNC viewer program to connect to the VNC server using the display number and password defined. Provided a graphical desktop is installed, an instance of that desktop will be displayed. It will not be the same instance as that currently displayed on the target machine.
参考:
测试
jerry vnc接入
tom vnc接入
后记:
vnc肯定不止这么一点,还有好多要学。这东西很占资源,1个G的内存