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

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

\u53ef\u80fd\u7a0b\u5e8f\u4e0d\u517c\u5bb9\uff0c \u53ef\u4ee5\u66f4\u6362\u4e2a\u7248\u672c\u8bd5\u8bd5\u3002\u53e6\u5916\u5efa\u8bae\u53c2\u8003\u4e0b\u7a0b\u5e8f\u5bf9\u914d\u7f6e\u7684\u8981\u6c42\u3002
\u6216\u8005\u53f3\u952e\u9700\u8981\u8fd0\u884c\u7684\u7a0b\u5e8f \u9009\u62e9\u517c\u5bb9\u6027 \u7528\u517c\u5bb9\u6a21\u5f0f\u8fd0\u884c\u8bd5\u8bd5\u3002

1.\u5b89\u88c5 VNC \u670d\u52a1\u5668\uff0c\u73b0\u5728\u8981\u5728 CentOS 7 \u4e0a\u5b89\u88c5 VNC \u670d\u52a1\u5668\u4e86\u3002\u9700\u8981\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\u3002
2.# yum install tigervnc-server -y
\u914d\u7f6e VNC\uff0c\u9700\u8981\u5728 /etc/systemd/system/ \u76ee\u5f55\u91cc\u521b\u5efa\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u3002\u53ef\u4ee5\u5c06/lib/systemd/sytem/[email protected] \u62f7\u8d1d\u4e00\u4efd\u914d\u7f6e\u6587\u4ef6\u8303\u4f8b\u8fc7\u6765\u3002
3.# cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service
\u63a5\u7740\u7528\u81ea\u5df1\u6700\u559c\u6b22\u7684\u7f16\u8f91\u5668\uff08\u8fd9\u513f\u6211\u4eec\u7528\u7684 nano \uff09\u6253\u5f00 /etc/systemd/system/vncserver@:1.service \uff0c\u627e\u5230\u4e0b\u9762\u8fd9\u51e0\u884c\uff0c\u7528\u81ea\u5df1\u7684\u7528\u6237\u540d\u66ff\u6362\u6389 \u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u7528\u6237\u540d\u662f linoxide \u6240\u4ee5\u6211\u7528 linoxide \u6765\u66ff\u6362\u6389 \uff1a
ExecStart=/sbin/runuser -l -c "/usr/bin/vncserver %i"
PIDFile=/home//.vnc/%H%i.pid\u66ff\u6362\u6210
ExecStart=/sbin/runuser -l linoxide -c "/usr/bin/vncserver %i"
PIDFile=/home/linoxide/.vnc/%H%i.pid
\u5f00\u542f\u670d\u52a1\uff0c\u7528\u4e0b\u9762\u7684\u547d\u4ee4\uff08\u6c38\u4e45\u5730\uff09\u5f00\u542f\u670d\u52a1\uff1a

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 客户端。



CentOS系统中VNC配置,检查VNC客户端和服务器端、将用户名加入到配置文件、启动VNC服务、修改VNC SERVER的窗口治理器等必要问题。
1.检查VNC客户端和服务器端是否已经安装
执行如下命令:
[root@localhost ~]# rpm -qa vnc vnc-server
package vnc is not installed
package vnc-server is not installed
表示系统没有安装VNC服务端,那我们就用yum安装VNC服务端。
[root@localhost ~]# yum -y install vnc vnc-server
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package tigervnc.i686 0:1.0.90-0.10.20100115svn3945.el6 set to be updated
---> Package tigervnc-server.i686 0:1.0.90-0.10.20100115svn3945.el6 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================================================
Installing:
tigervnc i686 1.0.90-0.10.20100115svn3945.el6 base 252 k
tigervnc-server i686 1.0.90-0.10.20100115svn3945.el6 base 1.1 M
Transaction Summary
=================================================================================================================================================================================
Install 2 Package(s)
Upgrade 0 Package(s)
Total download size: 1.3 M
Installed size: 3.6 M
Downloading Packages:
(1/2): tigervnc-1.0.90-0.10.20100115svn3945.el6.i686.rpm | 252 kB 00:00
(2/2): tigervnc-server-1.0.90-0.10.20100115svn3945.el6.i686.rpm | 1.1 MB 00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 137 kB/s | 1.3 MB 00:09
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : tigervnc-1.0.90-0.10.20100115svn3945.el6.i686 1/2
Installing : tigervnc-server-1.0.90-0.10.20100115svn3945.el6.i686 2/2
Installed:
tigervnc.i686 0:1.0.90-0.10.20100115svn3945.el6 tigervnc-server.i686 0:1.0.90-0.10.20100115svn3945.el6
Complete!
启动VNC Server服务:使用vncserver命令(在当前用户主目录下生成.vnc文件夹)
[root@localhost ~]# vncserver
You will require a password to access your desktops.
Password:
Verify:
xauth: creating new authority file /root/.Xauthority
New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1
Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log
2. 在CentOS系统中将用户名加入到配置文件中
编辑vncservers的配置文件
[root@localhost ~]# vi /etc/sysconfig/vncservers
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the lines below to start a VNC server on display :2
# as my 'myusername' (adjust this to your own). You will also
# need to set a VNC password; run 'man vncpasswd' to see how
# to do that.
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted! For a secure way of using VNC, see this URL:
# http://kbase.redhat.com/faq/docs/DOC-7028
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the "-via" option in the
# `man vncviewer' manual page.
# VNCSERVERS="2:myusername"
VNCSERVERS="2:root" #用户名root
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"
VNCSERVERARGS[2]="-geometry 1024x768" #尺寸大小
3.设置 root用户的密码
使用如下命令设置密码:
[root@localhost ~]# vncpasswd
Password:abc123
Verify:abc123
当提示Verify时,再次输入密码确认。
4.启动VNC服务
使用如下命令启动VNC SERVER
[root@localhost ~]# /sbin/service vncserver start
正在启动 VNC 服务器:2:root
New 'localhost.localdomain:2 (root)' desktop is localhost.localdomain:2
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:2.log
[确定]
[root@localhost ~]#
当显示如下信息时,表示启动成功.
5.修改VNC SERVER的窗口治理器
vnc server默认使用的窗口治理器是twn,这是一个非常简单的窗口治理器,我们可以改成常用的GNOME或者KDE。
先使用如下命令进入用户的home目录:cd /.vnc
编辑启动项:vi xstartup
按照如下方式修改启动项:
[root@localhost ~]# vi /root/.vnc/xstartup
#!/bin/sh
vncconfig -iconic &
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
OS=`uname -s`
if [ $OS = 'Linux' ]; then
case "$WINDOWMANAGER" in
*gnome*)
if [ -e /etc/SuSE-release ]; then
PATH=$PATH:/opt/gnome/bin
export PATH
fi
;;
esac
fi
if [ -x /etc/X11/xinit/xinitrc ]; then
exec /etc/X11/xinit/xinitrc
fi
if [ -f /etc/X11/xinit/xinitrc ]; then
exec sh /etc/X11/xinit/xinitrc
fi
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
gnome-session & #以GNOME作为VNC的窗口治理器
#startkde #kde desktop
#twm &
#twm # 注掉CentOS系统默认的窗口治理器
6.重启VNC SERVER
当CentOS系统提示如下信息时,表示重启成功
[root@localhost ~]# /sbin/service vncserver restart
关闭 VNC 服务器:2:root [确定]
正在启动 VNC 服务器:2:root
New 'localhost.localdomain:2 (root)' desktop is localhost.localdomain:2
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:2.log
[确定]
查看VNC SERVER 监听的端口:
[root@localhost ~]# netstat -antulp |grep 59
tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 3162/Xvnc
tcp 0 0 0.0.0.0:5902 0.0.0.0:* LISTEN 4193/Xvnc
tcp 0 0 0.0.0.0:59473 0.0.0.0:* LISTEN 1153/rpc.statd
tcp 0 0 :::5989 :::* LISTEN 1501/cimserver
tcp 0 0 :::5900 :::* LISTEN 3123/vino-server
tcp 0 0 ::ffff:192.168.0.124:5900 ::ffff:192.168.0.145:3072 ESTABLISHED 3123/vino-server
防火墙开放的端口:
[root@localhost ~]# /sbin/iptables -A INPUT -p tcp -m multiport

扩展阅读:服务器安装centos7步骤 ... centos安装软件的方法 ... 国产centos系统 ... u盘安装centos7找不到硬盘 ... centos7.3 单用户 ... centos7.0装网卡驱动 ... 怎么把centos 设置成中文 ... centos7.0如何修改主机名 ... pe安装centos真机安装步骤 ...

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