CentOS7安裝vncserver(啟動失敗及連接黑屏解決辦法)


CentOS7安裝vncserver(啟動失敗及連接黑屏解決辦法)

AutoSAR入門到精通系列講解
將從2019年開始更新關於AutoSAR的知識,從入門到精通,博主xyfx和大家一起進步
雪雲飛星

一.安裝

以root用戶運行以下命令來安裝vncserver;

yum install tigervnc-server 

同樣運行以下命令來安裝vncviewer;

yum install vnc

停止並禁用防火牆;

  1.  
    systemctl stop firewalld.service
  2.  
    systemctl disable firewalld.service

二.配置

vncviewer基本上不用配置;
vncserver的配置,創建一個新的配置文件,以開啟1號窗口為例(也可以同時開啟多個窗口,修改數字即可),方法如下:

cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service

或者再增加一個窗口:

cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:2.service

編輯/lib/systemd/system/vncserver@:1.service,設置用戶root相關參數,最終內容如下:

  1.  
    [Unit]
  2.  
    Description=Remote desktop service (VNC)
  3.  
    After=syslog.target network.target
  4.  
    [Service]
  5.  
    Type=forking
  6.  
    #Clean any existing files in /tmp/.X11-unix environment
  7.  
    ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
  8.  
    ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
  9.  
    PIDFile=/root/.vnc/%H%i.pid
  10.  
    ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

1.設置為非root用戶報錯:

  1.  
    [root@localhost system] # systemctl status -l vncserver@:2.service
  2.  
    vncserver@ :2.service - Remote desktop service (VNC)
  3.  
    Loaded: loaded (/etc/systemd/system/vncserver@:2.service; enabled; vendor preset:
  4.  
    disabled)
  5.  
    Active: failed (Result: exit-code) since 一 2016-04-25 19:07:23 CST; 7s ago
  6.  
    Process: 10305 ExecStart=/usr/sbin/runuser -l fang -c /usr/bin/vncserver %i (code=exited,
  7.  
    status= 1/FAILURE)
  8.  
    Process: 10291 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || :
  9.  
    (code=exited, status= 0/SUCCESS)
  10.  
    4月 25 19:07:23 localhost.localdomain systemd[1]: Starting Remote desktop service (VNC)...
  11.  
    4月 25 19:07:23 localhost.localdomain systemd[1]: vncserver@:2.service: control process
  12.  
    exited, code=exited status= 1
  13.  
    4月 25 19:07:23 localhost.localdomain systemd[1]: Failed to start Remote desktop service
  14.  
    (VNC).
  15.  
    4月 25 19:07:23 localhost.localdomain systemd[1]: Unit vncserver@:2.service entered failed
  16.  
    state.
  17.  
    4月 25 19:07:23 localhost.localdomain systemd[1]: vncserver@:2.service failed.

2.Type=forking報錯,改為Type=simple

  1.  
    [root@localhost system] # systemctl start vncserver@:2.service
  2.  
    Job for vncserver@:2.service failed because the control process exited with error code. See
  3.  
    "systemctl status vncserver@:2.service" and "journalctl -xe" for details.
  4.  
    [root@localhost system] # systemctl status -l vncserver@:2.service
  5.  
    ● vncserver@ :2.service - Remote desktop service (VNC)
  6.  
    Loaded: loaded (/etc/systemd/system/vncserver@:2.service; enabled; vendor preset:
  7.  
    disabled)
  8.  
    Active: failed (Result: exit-code) since 一 2016-04-25 19:09:41 CST; 6s ago
  9.  
    Process: 12367 ExecStart=/usr/sbin/runuser -l root -c /usr/bin/vncserver %i (code=exited,
  10.  
    status= 98)
  11.  
    Process: 12354 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || :
  12.  
    (code=exited, status= 0/SUCCESS)
  13.  
    4月 25 19:09:41 localhost.localdomain systemd[1]: Starting Remote desktop service (VNC)...
  14.  
    4月 25 19:09:41 localhost.localdomain systemd[1]: vncserver@:2.service: control process
  15.  
    exited, code=exited status= 98
  16.  
    4月 25 19:09:41 localhost.localdomain systemd[1]: Failed to start Remote desktop service
  17.  
    (VNC).
  18.  
    4月 25 19:09:41 localhost.localdomain systemd[1]: Unit vncserver@:2.service entered failed
  19.  
    state.
  20.  
    4月 25 19:09:41 localhost.localdomain systemd[1]: vncserver@:2.service failed.

3.vnc viewer客戶端連接黑屏

改變xstartup的權限
這個問題是很多人容易忽視的問題,也是造成連接成功后黑屏的原因之一。
在CentOS中,xstartup的文件路徑為:/root/.vnc/ (可以通過locate xstartup來查看xstartup的文件路徑)
所以需要執行:chmod 777 /root/.vnc/xstartup


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM