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

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

1.安装

yum install -y tigervnc-server
 
 

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


 
 
  1. 1.拷贝
  2. cp /lib/systemd/ system/vncserver@.service /lib/systemd/ system/vncserver@: 1.service
  3. 2.修改配置文件:(主要是修改root用户)
  4. vim /lib/systemd/ system/vncserver@: 1.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. 3.加载配置:
  19. systemctl daemon-reload
  20. 4.设置开机启动:
  21. systemctl enable vncserver@: 1.service

3.防火墙设置


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

4.设置VNC密码

vncserver passwd
 
 

5.启动VNC Server

systemctl restart vncserver@:1.service
 
 

6.systemctl启动异常解决


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

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


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

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

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

 

  此时,$displayNumber=1


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

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


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

 

  

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值