如何在redhat 7上安装VNC服务器

安装VNC Server

参考命令: yum -y install vnc-server

复制vnc server的配置模板:

参考命令:cp vncserver@.service vncserver@:1.service

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

注:VNC 服务本身使用的是5900端口。鉴于有不同的用户使用 VNC ,每个人的连接都会获得不同的端口。配置文件名里面的数字告诉 VNC 服务器把服务运行在5900的子端口上。在我们这个例子里,第一个 VNC 服务会运行在5901(5900 + 1)端口上,之后的依次增加,运行在5900 + x 号端口上。其中 x 是指之后用户的配置文件名 vncserver@:x.service 里面的 x 。
如果要用更多的用户连接,需要创建配置文件和端口,添加一个新的用户和端口。你需要创建 vncserver@:2.service 并替换配置文件里的用户名和之后步骤里相应的文件名、端口号。请确保你登录 VNC 服务器用的是你之前配置 VNC 密码的时候使用的那个用户名。

编辑配置模板

参考命令:vim vncserver@:1.service

把root用户加入登陆用户中,以及修改登陆后的vnc分辨率

修改前:

[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 %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l  -c "/usr/bin/vncserver %i"
PIDFile=/home//.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

修改后:

[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 %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i -geometry 1376x730"
PIDFile=/home/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

配置VNC远程用户

(1)重新载入 systemd,扫描新的或有变动的单元:systemctl daemon-reload

[root@xwq system]# systemctl daemon-reload

(2)为登陆的root用户添加一个密码

[root@xwq system]# vncpasswd root

Password:输入你的密码

Verify:再次输入你的密码

(3)启动vnc桌面

[root@xwq system]# vncserver :1

You will require a password to access your desktops.

Password:输入你的密码

Verify:再次输入你的密码

xauth:  file /root/.Xauthority does not exist

xauth: (stdin):1:  bad display name "xwq:1" in "add" command

New 'xwq:1 (root)' desktop is xwq:1

Creating default startup script /root/.vnc/xstartup

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/xwq:1.log

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

[root@xwq system]# systemctl enable vncserver@:1.service

如果输入systemctl enable vncserver@:1.service命令输出了如下代码,

[root@xwq system]# systemctl enable vncserver@:1.service

ln -s '/usr/lib/systemd/system/vncserver@:1.service' '/etc/systemd/system/multi-user.target.wants/vncserver@:1.service'

请在终端输入这行命令:echo "127.0.0.1 xwq"> /etc/hosts

(5)输入以下命令配置防火墙规则:

[root@xwq ~]# firewall-cmd --permanent --zone=public --add-port=5901/tcp

success

[root@xwq ~]# firewall-cmd --reload

success

访问redhat

使用windows端安装vnc viewer访问redhat,可以成功访问。

其他命令

关闭vnc服务:systemctl stop vncserver@:1.service

禁止 VNC 服务开机启动:systemctl disable vncserver@:1.service

关闭防火墙:systemctl stop firewalld.service

0 1 post publish 0 1 1 1 0 787 0 2 0 22 redhat 7安装CentOS 7 yum源 22 1493171760 1565422225 ## 查看已安装的包
首先查看redhat 7.0系统本身所安装的那些yum 软件包:

```
[root@pan ~]# rpm -qa | grep yum
yum-utils-1.1.31-24.el7.noarch
yum-langpacks-0.4.2-3.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-rhn-plugin-2.0.1-4.el7.noarch
PackageKit-yum-0.8.9-11.el7.x86_64
yum-3.4.3-118.el7.noarch
```
## 卸载这些软件包

```
[root@pan ~]# rpm -e yum-3.4.3-118.el7.noarch --nodeps
[root@pan ~]# rpm -e yum-utils-1.1.31-24.el7.noarch --nodeps
[root@pan ~]# rpm -e yum-rhn-plugin-2.0.1-4.el7.noarch --nodeps
[root@pan ~]# rpm -e yum-metadata-parser-1.1.4-10.el7.x86_64 --nodeps
[root@pan ~]# rpm -e yum-langpacks-0.4.2-3.el7.noarch --nodeps
[root@pan ~]# rpm -e PackageKit-yum-0.8.9-11.el7.x86_64 --nodeps
```

## 保证本机电脑能上网

```
[root@pan ~]# ping www.baidu.com
PING www.a.shifen.com (163.177.151.110) 56(84) bytes of data.
64 bytes from 163.177.151.110: icmp_seq=1 ttl=49 time=13.1 ms
64 bytes from 163.177.151.110: icmp_seq=2 ttl=49 time=6.80 ms
64 bytes from 163.177.151.110: icmp_seq=3 ttl=49 time=6.77 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2007ms
rtt min/avg/max/mdev = 6.777/8.917/13.168/3.006 ms

```
进入以下网站上面查看软件包的版本是否升级或者找到自己系统所对应的文件包版本更新;

网易163网络源地址:http://mirrors.163.com/
CentOS网络源地址:http://centos.ustc.edu.cn/centos/

## 找到自己所需要的版本下载

```
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-150.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-40.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-40.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-40.el7.noarch.rpm
```
查看下载完成结果;

```
[root@pan ~]# ls
anaconda-ks.cfg yum-plugin-fastestmirror-1.1.31-40.el7.noarch.rpm
initial-setup-ks.cfg yum-updateonboot-1.1.31-40.el7.noarch.rpm
yum-3.4.3-150.el7.centos.noarch.rpm yum-utils-1.1.31-40.el7.noarch.rpm
yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
```

## 安装软件包

```
[root@pan ~]# rpm -ivh yum-*
warning: yum-3.4.3-150.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
python-urlgrabber >= 3.10-8 is needed by yum-3.4.3-150.el7.centos.noarch

```

这里出现了一个小问题:
安装的python-urlgrabber版本不符合您尝试安装的RPM的依赖关系,我目前没有能力解决这个问题的办法,后来想了一个折中的办法,FQ去一个国外的yum源网站下载上面这五个较低版本的安装包,在来安装就不会有问题了
在这里附上链接各位可以FQ出去下载对应版本的rpm包
链接:http://rpm.pbone.net/
不报错版本安装包:

```
yum-3.4.3-132.el7.centos.0.1.noarch.rpm
yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
yum-updateonboot-1.1.31-34.el7.noarch.rpm
yum-utils-1.1.31-34.el7.noarch.rpm

```

![yum安装1](https://blog.yjscloud.com/usr/themes/VOID/images/yum/yum%E5%AE%89%E8%A3%851.png)

![yum安装2](https://blog.yjscloud.com/usr/themes/VOID/images/yum/yum%E5%AE%89%E8%A3%852.png)

我把这五个rpm包下载到我的windows电脑里,然后用WinSCP这个软件上传到redhat 7 系统里,WinSCP这个软件的使用方法就不在这里赘述了

![yum安装3](https://blog.yjscloud.com/usr/themes/VOID/images/yum/yum%E5%AE%89%E8%A3%853.png)

## 下载好后重新安装

```
[root@pan ~]# ls
yum-3.4.3-132.el7.centos.0.1.noarch.rpm yum-updateonboot-1.1.31-34.el7.noarch.rpm
yum-metadata-parser-1.1.4-10.el7.x86_64.rpm yum-utils-1.1.31-34.el7.noarch.rpm
yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
[root@pan ~]# rpm -ivh yum-*
warning: yum-3.4.3-132.el7.centos.0.1.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 20%]
2:yum-plugin-fastestmirror-1.1.31-3################################# [ 40%]
3:yum-3.4.3-132.el7.centos.0.1 ################################# [ 60%]
4:yum-updateonboot-1.1.31-34.el7 ################################# [ 80%]
5:yum-utils-1.1.31-34.el7 ################################# [100%]
[root@pan ~]#
```
这次没有报错了,安装完成!!!

## 新建repo 配置文件

```

[root@pan ~]# vim /etc/yum.repos.d/CentOS-Base.repo

#CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$7 - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$7 - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$7 - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$7 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

```
## 清除缓存

```
[root@pan ~]# yum clean all
Loaded plugins: fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: base extras updates
Cleaning up everything
```

## 测试安装是否正常

```
[root@pan ~]# yum -y install lftp
Loaded plugins: fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): extras/x86_64/primary_db | 139 kB 00:00:00
(2/4): base/x86_64/group_gz | 155 kB 00:00:00
(3/4): updates/x86_64/primary_db | 3.9 MB 00:00:01
(4/4): base/x86_64/primary_db | 5.6 MB 00:00:02
Determining fastest mirrors
Resolving Dependencies
--> Running transaction check
---> Package lftp.x86_64 0:4.4.8-8.el7_3.2 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================
Installing:
lftp x86_64 4.4.8-8.el7_3.2 updates 751 k

Transaction Summary
=======================================================================================================================
Install 1 Package

~~~~~此处省略安装输出内容~~~~
Installed:
lftp.x86_64 0:4.4.8-8.el7_3.2

Complete!

```
到这里安装完成,以后安装所需包,可以不用本地yum源了,直接使用网络yum源。

|| 版权声明
作者:废权
链接:https://blog.yjscloud.com/archives/15
声明:如无特别声明本文即为原创文章仅代表个人观点,版权归《废权的博客》所有,欢迎转载,转载请保留原文链接。
THE END
分享
二维码
如何在redhat 7上安装VNC服务器
安装VNC Server 参考命令: yum -y install vnc-server 复制vnc server的配置模板: 参考命令:cp vncserver@.service vncserver@:1.service [root@xwq ~]……
<<上一篇
下一篇>>
文章目录
关闭
目 录