1.添加多用户(规划kingbase使用5901窗口,root使用5903);
javascript
adduser kingbase
2.配置文件;
javascript
cp -rp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
cp -rp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:3.service
以root用户访问 VNC 为例,修改为以下内容:
javascript
vim /etc/systemd/system/vncserver@:3.service
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
WorkingDirectory=/root
User=root
Group=root
PIDFile=/root/.vnc/%H%i.pid
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver -autokill %i
ExecStop=/usr/bin/vncserver -kill %i
Restart=on-success
RestartSec=15
[Install]
WantedBy=multi-user.target
以kingbase用户访问 VNC 为例,编辑刚复制的新文件
javascript
vim /etc/systemd/system/vncserver@:1.service
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
WorkingDirectory=/home/<USER>
User=<USER>
Group=<USER>
PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver -autokill %i
ExecStop=/usr/bin/vncserver -kill %i
Restart=on-success
RestartSec=15[Install]
WantedBy=multi-user.target
修改为以下内容:
javascript
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=simple
WorkingDirectory=/home/kingbase
User=kingbase
Group=kingbase
PIDFile=/home/kingbase/.vnc/%H%i.pid
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l kingbase -c "/usr/bin/vncserver :1"
ExecStop=/usr/bin/vncserver -kill %i
Restart=on-success
RestartSec=15
[Install]
WantedBy=multi-user.target
3.设置root访问VNC的密码并启动服务;
javascript
[root]#systemctl daemon-reload //重新加载系统配置文件(系统新增或配置文件发生变化时,都需要执行 daemon-reload 子命令)
[root]#systemctl enable vncserver@:3.service //设置开机启动
[root]#systemctl start vncserver@:3.service //启动服务
[root]#vncpassword
Password: //输入密码
Verify: //在输入一遍确认密码
Would you like to enter a view-only password (y/n)? n
[root]#vncserver :3 //启动VNC的5903窗口
4.设置kingbase访问VNC的密码并启动服务;
javascript
[kingbase]$vncpassword
Password: //输入密码
Verify: //在输入一遍确认密码
Would you like to enter a view-only password (y/n)? n
[kingbase]$vncserver :1 //启动VNC的5901窗口
5.如果系统启用了防火墙,需要配置相应规则,否则连接不上:
javascript
//添加端口
firewall-cmd --add-port=5901/tcp --permanent
firewall-cmd --add-port=5903/tcp --permanent
firewall-cmd --reload
javascript
//彻底关闭防火墙(安全方面不推荐)
systemctl stop firewalld
systemctl disabled firewalld
6.测试可以正常登录访问。