centos7.4 安装配置vnc

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7.4 安装配置vnc相关的知识,希望对你有一定的参考价值。

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


[[email protected] system]# yum check-update

[[email protected] system]# yum groupinstall "X Window System"


启动桌面——startx

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


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


[[email protected] Desktop]# systemctl get-default          \查看默认运行级别

multi-user.target

[[email protected] 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 #


[[email protected] 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'



[[email protected] Desktop]# systemctl get-default            \查看默认运行级别

graphical.target                                                                     \图形化设置OK



1,安装VNC packages:

[[email protected] system]# yum install tigervnc-server -y


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

[[email protected] system]# cp /lib/systemd/system/[email protected]  /etc/systemd/system/[email protected]


然后打开这个配置文件/etc/systemd/system/[email protected]替换掉默认用户名,找到这一行

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

[[email protected] system]# systemctl daemon-reload


4,为VNC设密码

[[email protected]test-bench system]# vncpasswd 或

[[email protected] 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 默认防火墙的可能需要

[[email protected] ~]# firewall-cmd --permanent --add-service vnc-server

[[email protected] ~]# systemctl restart firewalld.service


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

[[email protected] ~]# systemctl enable [email protected]

[[email protected] ~]# systemctl start  [email protected]


或者link 文件

ln -s /etc/systemd/system/[email protected]  /etc/systemd/system/multi-user.target.wants/[email protected]:11.service



ln -s /etc/systemd/system/[email protected]  /etc/systemd/system/multi-user.target.wants/[email protected]:12.service


ln -s /etc/systemd/system/[email protected]  /etc/systemd/system/multi-user.target.wants/[email protected]:13.service



vnc 启动报错:


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

   Loaded: loaded (/etc/systemd/system/[email protected]; 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]: [email protected]: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 [email protected]:11.service entered failed state.

Jun 02 23:32:26 test-bench systemd[1]: [email protected]:11.service failed.


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


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

以上是关于centos7.4 安装配置vnc的主要内容,如果未能解决你的问题,请参考以下文章

怎样在CentOS 7.0上安装和配置VNC服务器

Centos7安装配置VNC远程

Linux上的桌面及VNC的安装和配置

VNCLinux环境VNC服务安装配置与使用 [转]

Redhat安装配置VNC服务器

CentOS8安装并配置 VNC Server