Appearance
VNC
vnc-server
安装vnc-server
yum install -y *配置单用户单界面
拷贝模板:
cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@.service编辑配置文件:
# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@.service
# 2. Replace <USER> with the actual user name and edit vncserver
# parameters in the wrapper script located in /usr/bin/vncserver_wrapper
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.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=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 root %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target注意:
启动服务的用户为 root,添加
User=root,这样VNC Client访问时可以看到菜单栏将
<USER>替换为 user (本机的非 root 用户), 这样用户登录到 user 的界面;
:wq保存配置之后,重启 systemdsystemctl daemon-reload
配置访问密码 本例使用 user 用户的桌面环境,如果使用其他用户,请先切换到 user 用户
su user
$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n开启服务
sudo systemctl enable vncserver@:1.service
sudo systemctl start vncserver@:1.service注意 服务的文件 /etc/systemd/system/vncserver@.service没有 :1 :1 使当参数启动服务器,表示启动第一个界面
打开防火墙
我们需要配置防火墙, 打开 VNC 服务
bash
$ sudo firewall-cmd --permanent --add-service vnc-server
success
$ sudo firewall-cmd --reload
success错误
bash
[root@oracle-server ~]# systemctl status vncserver@:1.service
● vncserver@:1.service - Remote desktop service (VNC)
Loaded: loaded (/etc/systemd/system/vncserver@.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 四 2019-01-10 15:16:39 CST; 4min 40s ago
Main PID: 19103 (code=exited, status=2)
1月 10 15:16:38 oracle-server systemd[1]: Starting Remote desktop service (VNC)...
1月 10 15:16:38 oracle-server systemd[1]: Started Remote desktop service (VNC).
1月 10 15:16:39 oracle-server vncserver_wrapper[19103]: Warning: oracle-server:1 is taken because of /tmp/.X11-unix/X1
1月 10 15:16:39 oracle-server vncserver_wrapper[19103]: Remove this file if there is no X server oracle-server:1
1月 10 15:16:39 oracle-server vncserver_wrapper[19103]: A VNC server is already running as :1
1月 10 15:16:39 oracle-server vncserver_wrapper[19103]: FATAL: 'runuser -l root' failed!
1月 10 15:16:39 oracle-server systemd[1]: vncserver@:1.service: main process exited, code=exited, status=2/INVALIDARGUMENT
1月 10 15:16:39 oracle-server systemd[1]: Unit vncserver@:1.service entered failed state.
1月 10 15:16:39 oracle-server systemd[1]: vncserver@:1.service failed.
Hint: Some lines were ellipsized, use -l to show in full.处理方式
rm -rf /tmp/.X*