天天看点

Centos7安装TigerVNC Server及服务无法启动问题解决

[转载自](https://blog.csdn.net/qq_37534835/article/details/81236041)

1.安装

yum install -y tigervnc-server           

2.配置(以root用户登录)

  1. .拷贝
  2. cp /lib/systemd/ system/[email protected] /lib/systemd/ system/[email protected]: .service
  3. .修改配置文件:(主要是修改root用户)
  4. vim /lib/systemd/ system/[email protected]: .service
  5. [Unit]
  6. Description=Remote desktop service (VNC)
  7. After=syslog.target network.target
  8. [Service]
  9. Type=forking
  10. User=root
  11. # Clean any existing files in /tmp/.X11-unix environment
  12. ExecStartPre= /bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
  13. ExecStart= /sbin/runuser -l root -c "/usr/bin/vncserver %i -geometry 1280x720"
  14. PIDFile= /root/.vnc/%H%i.pid
  15. ExecStop= /bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
  16. [Install]
  17. WantedBy=multi-user.target
  18. .加载配置:
  19. systemctl daemon-reload
  20. .设置开机启动:
  21. systemctl enable [email protected]: .service

3.防火墙设置

  1. 查看防火墙状态:
  2. firewall-cmd --state
  3. 关闭防火墙:
  4. systemctl stop firewalld
  5. systemctl disable firewalld
  6. 或者开启防火墙添加 端口(这里只开启一个端口,如有多个界面可以开启多个端口):
  7. systemctl start firewalld
  8. firewall-cmd --permanent --zone=public --add-port=5901/tcp

4.设置VNC密码

vncserver passwd           

5.启动VNC Server

systemctl restart [email protected]:ervice           

6.systemctl启动异常解决

  1. [ [email protected]wyx system]# systemctl start [email protected]: service
  2. Job for [email protected]: service failed because the control process exited with error code.
  3. See "systemctl status [email protected]:1.service" and "journalctl -xe" for details.
  4. [ [email protected]wyx system]# systemctl status [email protected]: service
  5. ● [email protected]: service - Remote desktop service (VNC)
  6. Loaded: loaded (/usr/lib/systemd/system/ [email protected]: service; enabled; vendor preset:
  7. disabled)
  8. Active: failed (Result: exit-code) since Fri : : CST; min s ago
  9. Process: ExecStart=/sbin/runuser -l oracle -c /usr/bin/vncserver %i -geometry
  10. x720 (code=exited, status= /FAILURE)
  11. Process: ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/ null >&
  12. || : (code=exited, status= /SUCCESS)
  13. Jul : : wyx.pc.com systemd[ ]: Starting Remote desktop service (VNC)...
  14. Jul : : wyx.pc.com runuser[ ]: runuser: user oracle does not exist
  15. Jul : : wyx.pc.com systemd[ ]: [email protected]: service: control process...=
  16. Jul : : wyx.pc.com systemd[ ]: Failed to start Remote desktop servic...).
  17. Jul : : wyx.pc.com systemd[ ]: Unit [email protected]: service entered fai...e.
  18. Jul : : wyx.pc.com systemd[ ]: [email protected]: service failed.

  如果启动过程中遇到异常,报错已经有进程存在,可以通过以下命令查看到

  1. [[email protected] system] # netstat -antulp | grep 5901
  2. tcp . . . : . . . :* LISTEN /Xvnc
  3. tcp6 ::: :::* LISTEN /Xvnc
  4. [[email protected] system] # ps -ef | grep vnc
  5. root : pts/ : : /usr/bin/Xvnc : -auth /root/.Xauthority -
  6. desktop wyx.pc.com: (root) -fp catalogue: /etc/X11/fontpath.d -geometry x768 -pn
  7. -rfbauth /root/.vnc/passwd -rfbport -rfbwait
  8. root : pts/ : : grep --color=auto vnc

  可以看到,存在vnc进程监听5901端口,此时我们已经可以通过vnc viewer客户端来连接使用服务器,服务启动失败是因为其配    置默认启动第一个用户界面也就是5901(5900+1)端口

  设置我们可以在/usr/bin/vncserver看到$vncPort = 5900 + $displayNumber,这里也可以通过修改5900来更改默认的端口设置

  此时,$displayNumber=1

  1. 关闭服务:
  2. vncserver - kill :
  3. 启动服务
  4. vncserver :n (端口号= +n)
  5. 启动时可以同时启动过个进程来分配给不同用户,n不同即可
  6. vncserver :
  7. vncserver :
  8. vncserver :
  9. netstat -antulp | grep
  10. tcp . . . : . . . :* LISTEN /Xvnc
  11. tcp . . . : . . . :* LISTEN /Xvnc
  12. tcp . . . : . . . :* LISTEN /Xvnc
  13. tcp . . : . : ESTABLISHED /Xvnc
  14. tcp6 ::: :::* LISTEN /Xvnc
  15. tcp6 ::: :::* LISTEN /Xvnc
  16. tcp6 ::: :::* LISTEN /Xvnc

  如果我们要使用刚才配置的服务来管理,需要杀死存在的进程

  1. 杀掉已经启动的进程
  2. pkill vnc
  3. 清空配置缓存(删除X1即可,也可以根据需要全部删除)
  4. [[email protected] .X11-unix]# ls /tmp/.X11-unix
  5. X0 X1 X2 X3 X4 X5 X6
  6. 保留config passwd xstartup即可
  7. [[email protected] .vnc]# ls /root/.vnc/
  8. config wyx.pc.com: og wyx.pc.com: pid wyx.pc.com: pid wyx.pc.com: pid
  9. passwd wyx.pc.com: og wyx.pc.com: og wyx.pc.com: og xstartup
  10. 现在可以通过systemd管理服务了
  11. systemctl start [email protected]: ervice
  12. netstat -antulp | grep
  13. tcp : :* LISTEN /Xvnc
  14. tcp6 ::: :::* LISTEN /Xvnc

[转载自](https://blog.csdn.net/qq_37534835/article/details/81236041)

1.安装

继续阅读