系统环境:CentOS Linux release 7.6.1810
Kernel:3.10.0-957.el7.x86_64
系统现状:最小化安装,没有安装任何图形支持软件

安装图形化支持


不建议安装GNOME Desktop,它会占用大量系统资源,安装完后大约要占用1G左右的空间,而且安装过程也较长。以root权限安装“X Window System”即可

# yum groups install "X Window System" -y
# yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts -y

修改系统启动级别

# systemctl set-default graphical.target  #graphical.target相当于level5,multi-user.target相当于level3

安装vncserver


# yum install tigervnc-server -y

配置vncserver实例


分别配置root用户和test用户,配置略有不同,如果只配置root用户,跳过test用户部分的设定

root用户,服务名是vncserver@:1.service:

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

修改拷贝过来的模板配置文件,主要是[Service]部分

# vi /etc/systemd/system/vncserver@\:1.service
[Service]
Type=forking
User=root
# 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 || :'

test用户,服务名是vncserver@:2.service:

# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service
# vi /etc/systemd/system/vncserver@\:2.service
[Service]
Type=forking
User=test
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=-/usr/bin/vncserver -kill %i
ExecStart=/usr/bin/vncserver %i
PIDFile=/home/test/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i

普通用户的ExecStart不同于root,加/sbin/runuser则会在启动服务时报以下错误

Job for vncserver@:2.service failed because the control process exited with error code. See "systemctl status
vncserver@:2.service" and "journalctl -xe" for details.

设置vncpasswd


# vncpasswd #root用户实例的vnc密码
# su - test
$ vncpasswd #普通用户一定要切换到用户自己的环境下

密码设置完成后回到root权限下,启动服务

加载进程,启动服务


# systemctl daemon-reload #由于在systemd中修改了内容,得让系统重新加载
# systemctl start vncserver@:1.service #启动root用户的vnc服务1
# systemctl start vncserver@:2.service #启动test用户的vnc服务2

设置服务开机启动

# systemctl enable vncserver@:1.service #开机启动服务1
# systemctl enable vncserver@:2.service #开机启动服务2

配置防火墙


# firewall-cmd --permanent --add-service vnc-server #防火墙添加相关规则,添加访问权限

# firewall-cmd --permanent --zone=public --add-port=5901/tcp  #permanent,永久生效,没有此参数重启后失效
# firewall-cmd --permanent --zone=public --add-port=5902/tcp

更新防火墙规则


# firewall-cmd --reload
# firewall-cmd --complete-reload

两者的区别就是第一个无需断开连接,就是firewalld特性之一动态添加规则,第二个需要断开连接,类似重启服务

至此结束,vnc已经配置好防火墙,设置了开机自启,设置了访问密码

其他VNC操作


# emctl restart vncserver@:1.service #重启动
# systemctl status vncserver@:1.service #状态
# systemctl is-enabled vncserver@:1.service #是否开机启动

可能的问题:


1、重启后,发现vncserver起不来了,报错:

[root@CentOS7 ~]# systemctl start vncserver@:1.service
Job for vncserver@:1.service failed because a configured resource limit was exceeded.
See "systemctl status vncserver@:1.service" and "journalctl -xe" for details.
将vncserver@\:1.service中的type改为simple,重新启动服务或者系统即可
vim /etc/systemd/system/vncserver@\:1.service
[Service]
Type=simple

其他防火墙操作


# systemctl start firewalld.service #启动防火墙服务
# systemctl stop firewalld.service #关闭防火墙
#systemctl restart firewalld.service #重启 #systemctl enable firewalld.service #开机启动
#systemctl disable firewalld.service #禁止开机启动
[root@CentOS7 ~]# systemctl status firewalld #查看状态
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since 二 2019-01-22 11:35:34 CST; 3h 36min ago
Docs: man:firewalld(1)
Main PID: 3670 (firewalld)
CGroup: /system.slice/firewalld.service
└─3670 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid 1月 22 11:35:33 CentOS7.Caojie systemd[1]: Starting firewalld - dynamic fir....
1月 22 11:35:34 CentOS7.Caojie systemd[1]: Started firewalld - dynamic fire....
Hint: Some lines were ellipsized, use -l to show in full.
[root@CentOS7 ~]# firewall-cmd --state #查看状态
running
[root@CentOS7 ~]# firewall-cmd --list-all # 查看防火墙规则(只显示/etc/firewalld/zones/public.xml中防火墙策略)
public (active)
target: default
icmp-block-inversion: no
interfaces: enp2s1
sources:
services: ssh dhcpv6-client vnc-server
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules: [root@CentOS7 ~]# firewall-cmd --query-service vnc-server #查看服务的启用状态
yes
[root@CentOS7 ~]# firewall-cmd --list-all-zones # 查看所有的防火墙策略(即显示/etc/firewalld/zones/下的所有策略)
block
target: %%REJECT%%
icmp-block-inversion: no
interfaces:
sources:
services:
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
dmz
target: default
icmp-block-inversion: no
interfaces:
sources:
services: ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
drop
target: DROP
icmp-block-inversion: no
interfaces:
sources:
services:
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
external
target: default
icmp-block-inversion: no
interfaces:
sources:
services: ssh
ports:
protocols:
masquerade: yes
forward-ports:
source-ports:
icmp-blocks:
rich rules:
home
target: default
icmp-block-inversion: no
interfaces:
sources:
services: ssh mdns samba-client dhcpv6-client
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
internal
target: default
icmp-block-inversion: no
interfaces:
sources:
services: ssh mdns samba-client dhcpv6-client
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
public (active)
target: default
icmp-block-inversion: no
interfaces: enp2s1
sources:
services: ssh dhcpv6-client vnc-server
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
trusted
target: ACCEPT
icmp-block-inversion: no
interfaces:
sources:
services:
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
work
target: default
icmp-block-inversion: no
interfaces:
sources:
services: ssh dhcpv6-client
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:

参考资料:

CentOS7安装配置vncserver

centos7安装图形化界面并远程连接

CentOS7.1安装VNC,让Win7远程桌面Linux

CentOS Linux下VNC Server远程桌面配置详解

关于centos7的firewall防火墙命令使用

CentOS 7 中firewall-cmd命令

CentOS7中firewall防火墙详解和配置,.xml服务配置详解

CentOS7下安装配置vncserver

CentOS7 安装VNC的更多相关文章

  1. centos7 安装vnc服务

    一,安装服务器端 1,添加用户: # useradd vnc # passwd vnc 2,安装gnome桌面 # yum groupinstall "GNOME Desktop" ...

  2. centos7 安装vnc远程服务

    避免一些系统方面的意外错误,最好更新yum到最新,生产环境有业务在运行不建议更新 yum update 安装GNOME Desktop图形桌面服务 yum groupinstall "GNO ...

  3. CentOS7安装VNC

    #安装 yum -y install tigervnc-server 将配置表复制到etc .service 修改配置文件 vim /etc/systemd/system/vncserver@\:.s ...

  4. Centos7 安装VNC实现远程桌面

    1.设置root用户方法: 1.# 复制一个服务设置的模板,命令如下: cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vn ...

  5. centos6和7安装vnc

    centos6安装vnc yum安装 yum groupinstall -y "Desktop" yum install -y tigervnc-server tigervnc-s ...

  6. centos7下安装vnc更改vnc默认端口号

    应用场景:某些情景下,需要用的linux的桌面环境,Ubuntu的桌面性能在linux发行版中算是数一数二的,如果不熟悉Debian系统,Centos/RHEL系列也行:   我这里的场景是开发人员不 ...

  7. CentOS7.x下安装VNC

    1.检查是否安装VNC rpm -q tigervnc tigervnc-server 2.安装X-Window yum check-update yum groupinstall "X W ...

  8. CentOS7.x安装VNC

    VNC需要系统安装的有桌面,如果是生产环境服务器,安装时使用的最小化安装,那么进行下面操作安装GNOME 桌面. # 列出的组列表里有GNOME Desktop. yum grouplist #安装 ...

  9. 【VNCserver】Centos7.4安装VNC连接华为云或亚马逊云

    1.1 文档背景 CentOS 7 / RHEL 7部署图形化界面 安装VNCserver实现linux系统云主机桌面化,通过普通用户实现桌面化操作 2.  Vncserver服务端部署 2.1 安装 ...

随机推荐

  1. 对map集合按照value从大到小进行排序

    概述: 基本特点: 该集合存储键值对,而且要保证键的惟一性 子类: |--HashTable 底层是哈希数据表结构,不可以使用Null作为键或者值:该集合线程是同步的 |--hashMap   底层是 ...

  2. python slenium 中CSS定位

    以百度为例 一.通过id.class定位 1.#id:python:driver.find_element_by_css_selector('input#kw') 2..class:python:dr ...

  3. c# datatable 分组

    DataTable dt = new DataTable(); IEnumerable<IGrouping<, ));//按行政区代码前两位分组

  4. 快速获取IP地址的各种方法

    调用百度的IP定位API(首先需要去百度开放平台注册申请key值http://lbsyun.baidu.com/apiconsole/key) http://api.map.baidu.com/loc ...

  5. 2018-2019-2 20165205 《网络对抗技术》 Exp6 信息收集与漏洞扫描

    2018-2019-2 20165205 <网络对抗技术> Exp6 信息收集与漏洞扫描 实验目标 掌握信息收集的最基本技能与常用工具的方式 实验内容 各种搜索技巧的应用 DNS IP注册 ...

  6. New York is 3 hours ahead of California

    New York is 3 hours ahead of California, 纽约时间比加州时间早三个小时, but it does not make California slow. 但加州时间 ...

  7. Django应用app创建及ORM

    一.重要知识点回顾: 1. form表单提交数据的注意事项: 1. 是form不是from,必须要有method和action (action用来指定你的数据提交到后台哪个地方,method用来指定你 ...

  8. golang基于etcd实现分布式锁(转)

    下面描述使用 Etcd 实现分布式锁的业务流程,假设对某个共享资源设置的锁名为:/lock/mylock 步骤 1: 准备 客户端连接 Etcd,以 /lock/mylock 为前缀创建全局唯一的 k ...

  9. 同步pod时区与node主机保持一致

    一.通过环境变量设置 apiVersion: v1 kind: Pod metadata: name: pod-env-tz spec: containers: - name: ngx image: ...

  10. Dear Menuhin

    2017-11-26 Sa Nov 11:05 AM @ HOME, TOSBE Nicole assigned us a composition about the Thanksgiving day ...