Centos7与Centos6.x有了很大的不同。

为了给一台服务器装上远程桌面,走了不少弯路。写这篇博文,纯粹为了记录,以后如果遇到相同问题,可以追溯。

1、假定你的系统没有安装vnc的任何软件,那么,首先安装vnc

1
yum -y install tigervnc-server tigervnc

2、Centos7之前的系统,如果安装vnc一般都需要配置

1
2
[root@localhost ~]# cat /etc/sysconfig/vncservers 
# THIS FILE HAS BEEN REPLACED BY /lib/systemd/system/vncserver@.service

但是,如上所述,Centos7需要配置的文件在

1
2
[root@localhost ~]# ll /lib/systemd/system/vncserver@.service
-rw-r--r--. 1 root root 1744 Jun 10 14:15 /lib/systemd/system/vncserver@.service

3、文件内有如下提示

1
2
3
4
5
6
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@:<display>.service
# 2. Edit <USER> and vncserver parameters appropriately
#   ("runuser -l <USER> -c /usr/bin/vncserver %i -arg1 -arg2")
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service

4、复制一份文件,并改名为vncserver@:1.service

1
[root@localhost ~]# cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service

5、将文件中的<User>用你当前的用户替换,将%i替换为1

1
2
3
4
5
6
7
8
9
10
11
12
[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 :1 > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver :1 -geometry 1280x720 -depth 24"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target

6、更新systemctl

1
systemctl daemon-reload

7、设置为自动启动

1
systemctl enable vncserver@:1.service

8、启动vnc服务

1
systemctl start vncserver@:1.service

9、在iptables中加入对应的端口5901(注意,如果有其他用户,那么也需要将端口加上。vnc的端口默认是5900 + n)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@localhost system]# cat /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5901 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

注意:

1、如果你不配置和启用防火墙,此时用VNC Viewer连接的话,会报:"connect:Connection timed out(10060)"错误。

2、本文是以root用户为例,如果其他用户也需要登录,那么,还需要将文件复制为

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

同时,将文件内的%i改为2,并建立对应用户的vncpasswd。

3、你可以通过UltraVNC,TigerVNC或者RealVNC Viewer进行访问,我在win7下使用这3中工具均能连接

Centos7远程桌面 vnc/vnc-server的设置的更多相关文章

  1. VNC连接CentOS7远程桌面

    1.在centos7安装图形化 先安装图形用户接口X Window System,再安装GNOME桌面. [root@centos7 ~]# yum groupinstall -y "X W ...

  2. ubuntu远程桌面、VNC(转载)

    VNC 远程桌面 配置/使用 for xfce 本贴主要目的为说明如何在windows系统下远程控制xfce桌面 Ubuntu 的默认GNOME桌面可以在系统设置中直接打开远程桌面,然后用Window ...

  3. 【一步一步走(1)】远程桌面软件VNC的安装与配置

    近期在VPS上搭建Python Web环境.走了非常多弯路,借此记下. 先说说购买的VPS(PhotonVPS),我可不是打广告.仅仅是感觉这个VPS服务提供商还不错推荐给你大家,我之前也是体验过阿里 ...

  4. Mac上远程桌面连接Windows Server 2012 R2

    在将一台服务器的操作系统由Windows Server 2012升级为Windows Server 2012 R2之后,在Mac电脑上用微软的远程桌面软件怎么也连不上服务器,错误信息如下: Remot ...

  5. xp远程桌面连接最大用户数怎么设置?

    1.首先到网上去百度下载“补丁UniversalTermsrvPatch”,这个补丁主要目的是在于去除“单用户登陆的限制”,允许多人多用户同时并行访问登录;2.然后根据自己的系统运行对应的程序:系统是 ...

  6. Win10使用VNC连接Centos7远程桌面

    一.安装VNC Viewer 1.首先win10下载安装VNC VIEWER 或者直接下载绿色版 2.linux系统安装vnc: 检查linux是否安装vnc:rpm -q tigervnc tige ...

  7. linux远程桌面连接 VNC Server

    更新源 # sudo apt-get update 安装vnc4server # sudo apt-get install vnc4server 修改vnc远程连接密码 # vncpasswd 编辑v ...

  8. ubuntu远程桌面软件vnc。

    http://www.linuxidc.com/Linux/2017-03/141936.htm 现在Linux是非常火的  很多人喜欢用它,界面简单,操作容易,有很多图形化工具如WinSCP可以与U ...

  9. centos7 远程桌面连接到xfce桌面

    1 安装xfce $ sudo yum install -y epel-release $ sudo yum groupinstall -y "Xfce" $ sudo reboo ...

随机推荐

  1. <构建之法>阅读感想

    在阅读<构建之法>之前,我所认为的软件就是通过c,c++等语言编程,制作出的一个能满足人们操作需求的一些代码,认为一个好的软件工程师,就是能够在很短的时间之内,最快的根据需求写出几段代码程 ...

  2. Leetcode题库——20.有效的括号

    @author: ZZQ @software: PyCharm @file: IsValid.py @time: 2018/9/16 20:20 要求: 给定一个只包括 '(',')','{','}' ...

  3. ReentrantLock 和 Condition的使用

    ReentrantLock  ReentrantLock可以等同于synchronized使用. ReentrantLock 类实现了Lock ,它拥有与 synchronized 相同的并发性和内存 ...

  4. Enterprise Library 1.1 参考源码索引

    http://www.projky.com/entlib/1.1/Microsoft/Practices/EnterpriseLibrary/Caching/BackgroundScheduler.c ...

  5. DRBD 实验

    跨主机的块设备镜像系统,工作在内核中完成 drbd工作原理:客户端发起一个写操作的系统调用给文件系统,写请求再到达内核缓冲区,最到达DRBD模块,此时drbd会复制写入磁盘的数据,且进行两步操作,第一 ...

  6. express和数据库(MySQL)的交互(二)

    一.安装express前面都讲了 1.express. cnpm || npm install express --save 2.中间件 a.cnpm || npm install body-pars ...

  7. iframe & cors

    iframe & cors <!DOCTYPE html> <html lang="zh-Hans"> <head> <meta ...

  8. 通过域名访问部署在服务器上的javaweb项目

    因为对域名访问什么也不了解,遇到问题就有种不知道从哪里下手的茫然,也就更不知道错在哪里,前前后后一共折腾了一天多,最后问了阿里客服才成功弄出来,因此记录一下. 关于服务器的购买.配置,及域名的备案解析 ...

  9. 【刷题】BZOJ 2693 jzptab

    Description Input 一个正整数T表示数据组数 接下来T行 每行两个正整数 表示N.M Output T行 每行一个整数 表示第i组数据的结果 Sample Input 1 4 5 Sa ...

  10. 【BZOJ2463】谁能赢呢?(博弈论)

    [BZOJ2463]谁能赢呢?(博弈论) 题面 BZOJ 洛谷 题解 洛谷上对于难度的评级我总觉有些问题. 很多人按照代码难度而并非思维难度在评级,导致很多评级很不合理啊... 不说废话了.. 对于一 ...