码迷,mamicode.com
首页 > 其他好文 > 详细

centos7.4 安装配置vnc

时间:2018-06-11 00:42:46      阅读:515      评论:0      收藏:0      [点我收藏+]

标签:centos 7 配置vnc

如果没有安装X-Windows 桌面的话要先安装Xwindows


[root@test-bench system]# yum check-update

[root@test-bench system]# yum groupinstall "X Window System"


启动桌面——startx

#startx      \\ 启动xwindow 进入图形化桌面


设置默认运行级别为图形化


[root@test-bench Desktop]# systemctl get-default          \\查看默认运行级别

multi-user.target

[root@test-bench Desktop]# cat /etc/inittab

# inittab is no longer used when using systemd.

#

# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.

#

# Ctrl-Alt-Delete is handled by /etc/systemd/system/ctrl-alt-del.target

#

# systemd uses 'targets' instead of runlevels. By default, there are two main targets:

#

# multi-user.target: analogous to runlevel 3                \\运行级别3:多用户界面

# graphical.target: analogous to runlevel 5                  \\运行级别5:图形化界面

# # To set a default target, run: # # ln -sf /lib/systemd/system/.target 


/etc/systemd/system/default.target #


[root@test-bench system]# systemctl set-default graphical.target    \\设置默认图形化运行级别

rm '/etc/systemd/system/default.target'

ln -s '/usr/lib/systemd/system/graphical.target' '/etc/systemd/system/default.target'



[root@test-bench Desktop]# systemctl get-default            \\查看默认运行级别

graphical.target                                                                     \\图形化设置OK



1,安装VNC packages:

[root@test-bench system]# yum install tigervnc-server -y


2,修改配置信息,在/etc/systemd/system/下建立文件夹vncserver@:1.service 把example config 文件从/lib/systemd/system/vncserver@.service复制到里面

[root@test-bench system]# cp /lib/systemd/system/vncserver@.service  /etc/systemd/system/vncserver-snp01@.service


然后打开这个配置文件/etc/systemd/system/vncserver-snp01@.service替换掉默认用户名,找到这一行

ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"

PIDFile=/home/<USER>/.vnc/%H%i.pid


如果是用root用户登录,就替换成

ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"

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


如果是其他用户的话比如john替换如下

ExecStart=/sbin/runuser -l snp01 -c "/usr/bin/vncserver %i"

PIDFile=/home/snp01/.vnc/%H%i.pid


3,重加载 systemd

[root@test-bench system]# systemctl daemon-reload


4,为VNC设密码

[root@test-bench system]# vncpasswd 或

[snp01@test-bench system]# vncpasswd


5,由于我的是Centos 7.4 是用iptable防火墙的所以

vim /etc/sysconfig/iptables

在合适位置加上

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5903 -j ACCEPT

重启iptable


service iptables restart

如果是用Centos 7 默认防火墙的可能需要

[root@test-bench ~]# firewall-cmd --permanent --add-service vnc-server

[root@test-bench ~]# systemctl restart firewalld.service


第六步,设默认启动并开启VNC

[root@test-bench ~]# systemctl enable vncserver-snp01@.service

[root@test-bench ~]# systemctl start  vncserver-snp01@.service


或者link 文件

ln -s /etc/systemd/system/vncserver-snp01@.service  /etc/systemd/system/multi-user.target.wants/vncserver-snp01@:11.service



ln -s /etc/systemd/system/vncserver-hru@.service  /etc/systemd/system/multi-user.target.wants/vncserver-hru@:12.service


ln -s /etc/systemd/system/vncserver-mta@.service  /etc/systemd/system/multi-user.target.wants/vncserver-mta@:13.service



vnc 启动报错:


 vncserver-snp01@:11.service - Remote desktop service (VNC)

   Loaded: loaded (/etc/systemd/system/vncserver-snp01@.service; enabled; vendor preset: disabled)

   Active: failed (Result: exit-code) since Sat 2018-06-02 23:32:26 CST; 25s ago

  Process: 8384 ExecStart=/usr/sbin/runuser -l snp01 -c /usr/bin/vncserver %i (code=exited, status=1/FAILURE)

  Process: 8377 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)


Jun 02 23:32:26 test-bench systemd[1]: Starting Remote desktop service (VNC)...

Jun 02 23:32:26 test-bench systemd[1]: vncserver-snp01@:11.service: control process exited, code=exited status=1

Jun 02 23:32:26 test-bench systemd[1]: Failed to start Remote desktop service (VNC).

Jun 02 23:32:26 test-bench systemd[1]: Unit vncserver-snp01@:11.service entered failed state.

Jun 02 23:32:26 test-bench systemd[1]: vncserver-snp01@:11.service failed.


除了检查/tmp/.X11-unix  .ICE-unix 等目录是否有用户文件存在外,还要检查用户是否被设置成nologin了


如果设置成了nologin状态就usermod -s /bin/bash  snp01 解开

centos7.4 安装配置vnc

标签:centos 7 配置vnc

原文地址:http://blog.51cto.com/laobaiv1/2127873

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!