[转载自](https://blog.csdn.net/qq_37534835/article/details/81236041)
1.安装
yum install -y tigervnc-server
2.配置(以root用户登录)
- .拷贝
- cp /lib/systemd/ system/[email protected] /lib/systemd/ system/[email protected]: .service
- .修改配置文件:(主要是修改root用户)
- vim /lib/systemd/ system/[email protected]: .service
- [Unit]
- Description=Remote desktop service (VNC)
- After=syslog.target network.target
- [Service]
- Type=forking
- User=root
- # 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 -geometry 1280x720"
- PIDFile= /root/.vnc/%H%i.pid
- ExecStop= /bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
- [Install]
- WantedBy=multi-user.target
- .加载配置:
- systemctl daemon-reload
- .设置开机启动:
- systemctl enable [email protected]: .service
3.防火墙设置
- 查看防火墙状态:
- firewall-cmd --state
- 关闭防火墙:
- systemctl stop firewalld
- systemctl disable firewalld
- 或者开启防火墙添加 端口(这里只开启一个端口,如有多个界面可以开启多个端口):
- systemctl start firewalld
- firewall-cmd --permanent --zone=public --add-port=5901/tcp
4.设置VNC密码
vncserver passwd
5.启动VNC Server
systemctl restart [email protected]:ervice
6.systemctl启动异常解决
- [ [email protected]wyx system]# systemctl start [email protected]: service
- Job for [email protected]: service failed because the control process exited with error code.
- See "systemctl status [email protected]:1.service" and "journalctl -xe" for details.
- [ [email protected]wyx system]# systemctl status [email protected]: service
- ● [email protected]: service - Remote desktop service (VNC)
- Loaded: loaded (/usr/lib/systemd/system/ [email protected]: service; enabled; vendor preset:
- disabled)
- Active: failed (Result: exit-code) since Fri : : CST; min s ago
- Process: ExecStart=/sbin/runuser -l oracle -c /usr/bin/vncserver %i -geometry
- x720 (code=exited, status= /FAILURE)
- Process: ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/ null >&
- || : (code=exited, status= /SUCCESS)
- Jul : : wyx.pc.com systemd[ ]: Starting Remote desktop service (VNC)...
- Jul : : wyx.pc.com runuser[ ]: runuser: user oracle does not exist
- Jul : : wyx.pc.com systemd[ ]: [email protected]: service: control process...=
- Jul : : wyx.pc.com systemd[ ]: Failed to start Remote desktop servic...).
- Jul : : wyx.pc.com systemd[ ]: Unit [email protected]: service entered fai...e.
- Jul : : wyx.pc.com systemd[ ]: [email protected]: service failed.
如果启动过程中遇到异常,报错已经有进程存在,可以通过以下命令查看到
- [[email protected] system] # netstat -antulp | grep 5901
- tcp . . . : . . . :* LISTEN /Xvnc
- tcp6 ::: :::* LISTEN /Xvnc
- [[email protected] system] # ps -ef | grep vnc
- root : pts/ : : /usr/bin/Xvnc : -auth /root/.Xauthority -
- desktop wyx.pc.com: (root) -fp catalogue: /etc/X11/fontpath.d -geometry x768 -pn
- -rfbauth /root/.vnc/passwd -rfbport -rfbwait
- root : pts/ : : grep --color=auto vnc
可以看到,存在vnc进程监听5901端口,此时我们已经可以通过vnc viewer客户端来连接使用服务器,服务启动失败是因为其配 置默认启动第一个用户界面也就是5901(5900+1)端口
设置我们可以在/usr/bin/vncserver看到$vncPort = 5900 + $displayNumber,这里也可以通过修改5900来更改默认的端口设置
此时,$displayNumber=1
- 关闭服务:
- vncserver - kill :
- 启动服务
- vncserver :n (端口号= +n)
- 启动时可以同时启动过个进程来分配给不同用户,n不同即可
- vncserver :
- vncserver :
- vncserver :
- netstat -antulp | grep
- tcp . . . : . . . :* LISTEN /Xvnc
- tcp . . . : . . . :* LISTEN /Xvnc
- tcp . . . : . . . :* LISTEN /Xvnc
- tcp . . : . : ESTABLISHED /Xvnc
- tcp6 ::: :::* LISTEN /Xvnc
- tcp6 ::: :::* LISTEN /Xvnc
- tcp6 ::: :::* LISTEN /Xvnc
如果我们要使用刚才配置的服务来管理,需要杀死存在的进程
- 杀掉已经启动的进程
- pkill vnc
- 清空配置缓存(删除X1即可,也可以根据需要全部删除)
- [[email protected] .X11-unix]# ls /tmp/.X11-unix
- X0 X1 X2 X3 X4 X5 X6
- 保留config passwd xstartup即可
- [[email protected] .vnc]# ls /root/.vnc/
- config wyx.pc.com: og wyx.pc.com: pid wyx.pc.com: pid wyx.pc.com: pid
- passwd wyx.pc.com: og wyx.pc.com: og wyx.pc.com: og xstartup
- 现在可以通过systemd管理服务了
- systemctl start [email protected]: ervice
- netstat -antulp | grep
- tcp : :* LISTEN /Xvnc
- tcp6 ::: :::* LISTEN /Xvnc
[转载自](https://blog.csdn.net/qq_37534835/article/details/81236041)
1.安装