linux7 vnc 黑屏,CentOS7安装vncserver(启动失败及连接黑屏解决办法)(示例代码)

一.安装

以root用户运行以下命令来安装vncserver;

yum install tigervnc-server

同样运行以下命令来安装vncviewer;

yum install vnc

停止并禁用防火墙;

systemctl stop firewalld.service

systemctl disable firewalld.service

二.配置

vncviewer基本上不用配置;

vncserver的配置,创建一个新的配置文件,以开启1号窗口为例(也可以同时开启多个窗口,修改数字即可),方法如下:

cp /lib/systemd/system/[email protected] /lib/systemd/system/[email protected]:1.service

或者再增加一个窗口:

cp /lib/systemd/system/[email protected] /lib/systemd/system/[email protected]:2.service

编辑/lib/systemd/system/[email protected]:1.service,设置用户root相关参数,最终内容如下:

[Unit]

Description=Remote desktop service (VNC)

After=syslog.target network.target

[Service]

Type=forking

#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"

PIDFile=/root/.vnc/%H%i.pid

ExecStop=/bin/sh -c ‘/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :‘

1.设置为非root用户报错:

[[email protected] system]# systemctl status -l [email protected]:2.service

[email protected]:2.service - Remote desktop service (VNC)

Loaded: loaded (/etc/systemd/system/[email protected]:2.service; enabled; vendor preset:

disabled)

Active: failed (Result: exit-code) since 一 2016-04-25 19:07:23 CST; 7s ago

Process: 10305 ExecStart=/usr/sbin/runuser -l fang -c /usr/bin/vncserver %i (code=exited,

status=1/FAILURE)

Process: 10291 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || :

(code=exited, status=0/SUCCESS)

?4月 25 19:07:23 localhost.localdomain systemd[1]: Starting Remote desktop service (VNC)...

4月 25 19:07:23 localhost.localdomain systemd[1]: [email protected]:2.service: control process

exited, code=exited status=1

4月 25 19:07:23 localhost.localdomain systemd[1]: Failed to start Remote desktop service

(VNC).

4月 25 19:07:23 localhost.localdomain systemd[1]: Unit [email protected]:2.service entered failed

state.

4月 25 19:07:23 localhost.localdomain systemd[1]: [email protected]:2.service failed.

2.Type=forking报错,改为Type=simple

[[email protected] system]# systemctl start [email protected]:2.service

Job for [email protected]:2.service failed because the control process exited with error code. See

"systemctl status [email protected]:2.service" and "journalctl -xe" for details.

[[email protected] system]# systemctl status -l [email protected]:2.service

● [email protected]:2.service - Remote desktop service (VNC)

Loaded: loaded (/etc/systemd/system/[email protected]:2.service; enabled; vendor preset:

disabled)

Active: failed (Result: exit-code) since 一 2016-04-25 19:09:41 CST; 6s ago

Process: 12367 ExecStart=/usr/sbin/runuser -l root -c /usr/bin/vncserver %i (code=exited,

status=98)

Process: 12354 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || :

(code=exited, status=0/SUCCESS)

?4月 25 19:09:41 localhost.localdomain systemd[1]: Starting Remote desktop service (VNC)...

4月 25 19:09:41 localhost.localdomain systemd[1]: [email protected]:2.service: control process

exited, code=exited status=98

4月 25 19:09:41 localhost.localdomain systemd[1]: Failed to start Remote desktop service

(VNC).

4月 25 19:09:41 localhost.localdomain systemd[1]: Unit [email protected]:2.service entered failed

state.

4月 25 19:09:41 localhost.localdomain systemd[1]: [email protected]:2.service failed.

3.vnc viewer客户端连接黑屏

改变xstartup的权限

这个问题是很多人容易忽视的问题,也是造成连接成功后黑屏的原因之一。

在CentOS中,xstartup的文件路径为:/root/.vnc/ (可以通过locate xstartup来查看xstartup的文件路径)

所以需要执行:chmod 777 /root/.vnc/xstartup

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值