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

\u600e\u6837\u5728 CentOS 7.0 \u4e0a\u5b89\u88c5\u548c\u914d\u7f6e VNC \u670d\u52a1\u5668

\u5b89\u88c5 TigerVNC Server
yum install tigervnc-server
\u542f\u52a8\uff1a
vncserver :1 -geometry 1024x768 -depth 24#\u76f4\u63a5\u542f\u52a8\u8bbe\u7f6e\u5206\u8fa8\u7387\u548c\u8272\u5f69\u5373\u53ef
\u9996\u6b21\u542f\u52a8\u65f6\u4f1a\u63d0\u793a\u8bbe\u7f6e\u5bc6\u7801\uff0c\u767b\u5f55\u7684\u7528\u6237\u4e3a\u542f\u52a8\u8be5vnc\u4f1a\u8bdd\u7684\u7528\u6237\u3002
\u6ce8\u610f\u9632\u706b\u5899\u548cSELinux\u7684\u8bbe\u7f6e\uff0c\u7531\u4e8e\u6211\u5728\u5185\u7f51\uff0c\u76f4\u63a5\u5c06\u5b83\u4eec\u90fd\u5173\u95ed\u4e86\uff1a
\u9632\u706b\u5899\uff1asystemctl stop firewalld\uff08\u4e5f\u53ef\u4ee5\u5b8c\u5168\u8ba9\u5b83\u4e0d\u542f\u52a8 systemctl disable firewalld\uff09
SELinux\uff1a\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6 vi /etc/selinux/config\uff0c\u4fee\u6539\u72b6\u6001\u4e3aSELINUX=disabled\uff0c\u9700\u8981\u91cd\u542f\u4e00\u4e0b\u3002
\u63a5\u4e0b\u6765\u5c31\u53ef\u4ee5\u7528realvnc\u6216\u8005ultravnc\u8f93\u5165ip:1\u4ece\u5ba2\u6237\u7aef\u8bbf\u95ee
\u6211\u7684\u670d\u52a1\u5668\u7528\u7684\u662f\u5c0f\u9e1f\u4e91\u7684\uff0c\u5f88\u7a33\u5b9a\uff0c\u6027\u4ef7\u6bd4\u5f88\u9ad8\u3002

\u4e00\u4e9b VNC \u670d\u52a1\u5668\u7684\u4f18\u70b9\uff1a
\u8fdc\u7a0b\u7684\u56fe\u5f62\u7ba1\u7406\u65b9\u5f0f\u8ba9\u5de5\u4f5c\u53d8\u5f97\u7b80\u5355\u65b9\u4fbf\u3002
\u526a\u8d34\u677f\u53ef\u4ee5\u5728 CentOS \u670d\u52a1\u5668\u4e3b\u673a\u548c VNC \u5ba2\u6237\u7aef\u673a\u5668\u4e4b\u95f4\u5171\u4eab\u3002
CentOS \u670d\u52a1\u5668\u4e0a\u4e5f\u53ef\u4ee5\u5b89\u88c5\u56fe\u5f62\u5de5\u5177\uff0c\u8ba9\u7ba1\u7406\u80fd\u529b\u53d8\u5f97\u66f4\u5f3a\u5927\u3002
\u53ea\u8981\u5b89\u88c5\u4e86 VNC \u5ba2\u6237\u7aef\uff0c\u901a\u8fc7\u4efb\u4f55\u64cd\u4f5c\u7cfb\u7edf\u90fd\u53ef\u4ee5\u7ba1\u7406 CentOS \u670d\u52a1\u5668\u4e86\u3002
\u6bd4 ssh \u56fe\u5f62\u8f6c\u53d1\u548c RDP \u8fde\u63a5\u66f4\u53ef\u9760\u3002
\u90a3\u4e48\uff0c\u8ba9\u6211\u4eec\u5f00\u59cb\u5b89\u88c5 VNC \u670d\u52a1\u5668\u4e4b\u65c5\u5427\u3002\u6211\u4eec\u9700\u8981\u6309\u7167\u4e0b\u9762\u7684\u6b65\u9aa4\u4e00\u6b65\u4e00\u6b65\u6765\u642d\u5efa\u4e00\u4e2a\u53ef\u7528\u7684 VNC\u3002
\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u53ef\u7528\u7684\u684c\u9762\u73af\u5883\uff08X-Window\uff09\uff0c\u5982\u679c\u6ca1\u6709\u7684\u8bdd\u8981\u5148\u5b89\u88c5\u4e00\u4e2a\u3002
\u6ce8\u610f\uff1a\u4ee5\u4e0b\u547d\u4ee4\u5fc5\u987b\u4ee5 root \u6743\u9650\u8fd0\u884c\u3002\u8981\u5207\u6362\u5230 root \uff0c\u8bf7\u5728\u7ec8\u7aef\u4e0b\u8fd0\u884c\u201csudo -s\u201d\uff0c\u5f53\u7136\u4e0d\u5305\u62ec\u53cc\u5f15\u53f7\uff08\u201c\u201d\uff09
1. \u5b89\u88c5 X-Window
\u9996\u5148\u6211\u4eec\u9700\u8981\u5b89\u88c5 X-Window\uff0c\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4e0b\u9762\u7684\u547d\u4ee4\uff0c\u5b89\u88c5\u4f1a\u82b1\u8d39\u4e00\u70b9\u65f6\u95f4\u3002
# yum check-update
# yum groupinstall "X Window System"

#yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts

### \u8bbe\u7f6e\u9ed8\u8ba4\u542f\u52a8\u56fe\u5f62\u754c\u9762
# unlink /etc/systemd/system/default.target
# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target

# reboot
\u5728\u670d\u52a1\u5668\u91cd\u542f\u4e4b\u540e\uff0c\u6211\u4eec\u5c31\u6709\u4e86\u4e00\u4e2a\u5de5\u4f5c\u7740\u7684 CentOS 7 \u684c\u9762\u73af\u5883\u4e86\u3002
\u73b0\u5728\uff0c\u6211\u4eec\u8981\u5728\u670d\u52a1\u5668\u4e0a\u5b89\u88c5 VNC \u670d\u52a1\u5668\u4e86\u3002
2. \u5b89\u88c5 VNC \u670d\u52a1\u5668
\u73b0\u5728\u8981\u5728\u6211\u4eec\u7684 CentOS 7 \u4e0a\u5b89\u88c5 VNC \u670d\u52a1\u5668\u4e86\u3002\u6211\u4eec\u9700\u8981\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\u3002
# yum install tigervnc-server -y

1、先确认VNC是否安装(环境中用的是redhat)

默认情况下,Red Hat Enterprise Linux安装程序会将VNC服务安装在系统上,centos通过yum在线安装vnc
可以通过rpm命令检查是否安装了vnc,如果安装了就显示软件名称:

[root@redhat01 /]# rpm -qa | grep vnc
vnc-server-4.1.2-14.el5_6.6.x86_64

如果未安装就不会显示软件名称,可以到操作系统安装盘挂载起来,然后通过rpm安装vnc-server-4.1.2-9.el5.x86_64.rpm。

[root@redhat01 home]# rpm -ivh vnc-server-4.1.2-14.el5_6.6.x86_64.rpm

参考 linux部署远程桌面



1. 安装 X-Window

首先我们需要安装 X-Window,在终端中运行下面的命令,安装会花费一点时间。

# yum check-update# yum groupinstall "X Window System"

installing x windows

#yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts

install gnome classic session

### 设置默认启动图形界面# unlink /etc/systemd/system/default.target# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target

configuring graphics

# reboot

在服务器重启之后,我们就有了一个工作着的 CentOS 7 桌面环境了。

现在,我们要在服务器上安装 VNC 服务器了。

2. 安装 VNC 服务器

现在要在我们的 CentOS 7 上安装 VNC 服务器了。我们需要执行下面的命令。

# yum install tigervnc-server -y

vnc server

3. 配置 VNC

然后,我们需要在 /etc/systemd/system/ 目录里创建一个配置文件。我们可以将 /lib/systemd/sytem/[email protected] 拷贝一份配置文件范例过来。

# cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service

copying vnc server configuration

接着我们用自己最喜欢的编辑器(这儿我们用的 nano )打开 /etc/systemd/system/vncserver@:1.service ,找到下面这几行,用自己的用户名替换掉 。举例来说,我的用户名是 linoxide 所以我用 linoxide 来替换掉 :

ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"PIDFile=/home/<USER>/.vnc/%H%i.pid

替换成

ExecStart=/sbin/runuser -l linoxide -c "/usr/bin/vncserver %i"PIDFile=/home/linoxide/.vnc/%H%i.pid

如果是 root 用户则

ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"PIDFile=/root/.vnc/%H%i.pid

configuring user

好了,下面重启 systemd 。

# systemctl daemon-reload

最后还要设置一下用户的 VNC 密码。要设置某个用户的密码,必须要有能通过 sudo 切换到用户的权限,这里我用 linoxide 的权限,执行“su linoxide”就可以了。

# su linoxide$ sudo vncpasswd

setting vnc password

确保你输入的密码多于6个字符

4. 开启服务

用下面的命令(永久地)开启服务:

$ sudo systemctl enable vncserver@:1.service

启动服务。

$ sudo systemctl start vncserver@:1.service

5. 防火墙设置

我们需要配置防火墙来让 VNC 服务正常工作。

$ sudo firewall-cmd --permanent --add-service vnc-server$ sudo systemctl restart firewalld.service

allowing firewalld

现在就可以用 IP 和端口号(LCTT 译注:例如 192.168.1.1:1 ,这里的端口不是服务器的端口,而是视 VNC 连接数的多少从1开始排序)来连接 VNC 服务器了。

6. 用 VNC 客户端连接服务器

好了,现在已经完成了 VNC 服务器的安装了。要使用 VNC 连接服务器,我们还需要一个在本地计算机上安装的仅供连接远程计算机使用的 VNC 客户端。

remote access vncserver from vncviewer

你可以用像 Tightvnc viewer 和 Realvnc viewer 的客户端来连接到服务器。

要用更多的用户连接,需要创建配置文件和端口,请回到第3步,添加一个新的用户和端口。你需要创建 vncserver@:2.service 并替换配置文件里的用户名和之后步骤里相应的文件名、端口号。请确保你登录 VNC 服务器用的是你之前配置 VNC 密码的时候使用的那个用户名。

VNC 服务本身使用的是5900端口。鉴于有不同的用户使用 VNC ,每个人的连接都会获得不同的端口。配置文件名里面的数字告诉 VNC 服务器把服务运行在5900的子端口上。在我们这个例子里,第一个 VNC 服务会运行在5901(5900 + 1)端口上,之后的依次增加,运行在5900 + x 号端口上。其中 x 是指之后用户的配置文件名 vncserver@:x.service 里面的 x 。

在建立连接之前,我们需要知道服务器的 IP 地址和端口。IP 地址是一台计算机在网络中的独特的识别号码。我的服务器的 IP 地址是96.126.120.92,VNC 用户端口是1。

执行下面的命令可以获得服务器的公网 IP 地址(LCTT 译注:如果你的服务器放在内网或使用动态地址的话,可以这样获得其公网 IP 地址)。

# curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

总结

好了,现在我们已经在运行 CentOS 7 / RHEL 7 的服务器上安装配置好了 VNC 服务器。VNC 是自由开源软件中最简单的一种能实现远程控制服务器的工具,也是一款优秀的 Teamviewer Remote Access 替代品。VNC 允许一个安装了 VNC 客户端的用户远程控制一台安装了 VNC 服务的服务器。下面还有一些经常使用的相关命令。好好玩!

其他命令:



扩展阅读:u盘安装centos7安装教程 ... x79平台 u盘安装centos7 ... 服务器安装centos7步骤 ... centos7.0修改root密码 ... u盘安装centos7.6图解 ... centos安装软件的方法 ... 国产centos系统 ... centos7.3进入单用户模式 ... pe安装centos真机安装步骤 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网