Linux Centos7.x下安装部署VNC的实操详述 经测试 好使。
Linux Centos7.x下安装部署VNC的实操详述
VNC (Virtual Network Console)是虚拟网络控制台的缩写。它 是一款优秀的远程控制工具软件,由著名的AT&T的欧洲研究实验室开发的。VNC 是在基于 UNIX和 Linux 操作系统的免费的开源软件,远程控制能力强大,高效实用,其性能可以和Windows和 MAC 中的任何远程控制软件媲美。 在 Linux 中,VNC 包括以下四个命令:vncserver,vncviewer,vncpasswd,和 vncconnect。大多数情况下用户只需要其中的两个命令:vncserver 和 vncviewer。
一、Linux CentOS 7.X下安装部署VNC如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
1、获取当前系统启动模式[root@localhost ~]# systemctl get-defaultmulti-user.target2、查看配置文件[root@localhost ~]# cat /etc/inittab# inittab is no longer used when using systemd.## ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.## Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target## systemd uses 'targets' instead of runlevels. By default, there are two main targets:## multi-user.target: analogous to runlevel 3 //命令行模式# graphical.target: analogous to runlevel 5 //图形界面模式## To view current default target, run:# systemctl get-default## To set a default target, run:# systemctl set-default TARGET.target[root@localhost ~]# systemctl set-default graphical.target //由命令行模式更改为图形界面模式[root@localhost ~]# systemctl set-default multi-user.target //由图形界面模式更改为命令行模式[root@localhost ~]# systemctl get-defaultgraphical.target3、关闭防火墙centos的防火墙是firewalld,关闭防火墙的命令[root@localhost ~]# systemctl stop firewalld.service #停止firewall[root@localhost ~]# systemctl disable firewalld.service #禁止firewall开机启动[root@localhost ~]# setenforce 0 [root@localhost ~]# getenforce [root@localhost ~]# cat /etc/sysconfig/selinux SELINUX=disabledSELINUXTYPE=targeted4、安装软件:[root@localhost ~]# yum update[root@localhost ~]# yum groupinstall "GNOME Desktop" "X Window System" "Desktop" [root@localhost ~]# yum install tigervnc-server tigervnc vnc vnc-server5、配置vnc连接[root@localhost ~]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service 修改/etc/systemd/system/vncserver@:1.service找到这一行ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"PIDFile=/home/<USER>/.vnc/%H%i.pid这里直接用root 用户登录,所以我替换成ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"PIDFile=/root/.vnc/%H%i.pid如果是其他用户的话比如eason替换如下ExecStart=/sbin/runuser -l eason -c "/usr/bin/vncserver %i"PIDFile=/home/john/.vnc/%H%i.pid由于直接root用户登录,所以配置如下:[root@localhost ~]# cat /etc/systemd/system/vncserver@:1.service.........[Unit]Description=Remote desktop service (VNC)After=syslog.target network.target[Service]Type=forking# Clean any existing files in /tmp/.X11-unix environmentExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"PIDFile=/root/.vnc/%H%i.pidExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'[Install]WantedBy=multi-user.target为VNC设密码(比如密码设置为123456)[root@localhost ~]# vncpasswdPassword:Verify:Would you like to enter a view-only password (y/n)? n //注意表示"是否输入一个只能查看的密码,选择否",否则连接vnc会出现黑屏A view-only password is not used[root@localhost ~]# vim /etc/libvirt/qemu.conf vnc_password = "123456"vnc_listen = "0.0.0.0"6、重加载 systemd[root@localhost ~]# systemctl daemon-reload7、启动vnc[root@localhost ~]# systemctl enable vncserver@:1.service[root@localhost ~]# systemctl start vncserver@:1.service注意,此处关闭了防火墙如果防火墙开了,需要开通一下规则:[root@localhost ~]# firewall-cmd --permanent --add-service vnc-server[root@localhost ~]# systemctl restart firewalld.service如果是iptable,则需要在/etc/sysconfig/iptables里添加:-A INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5903 -j ACCEPT8、关闭vnc连接[root@localhost ~]# /usr/bin/vncserver -kill :19、测试连接也可以在本地windows机器上安装vnc viewer,远程访问在windows下安装vnc客户端, VNC远程连接信息(下面ip是VNC服务端的地址):VNC Server: 112.112.113.56:5901Encrytion:Let VNC Server choose 然后输入vncpasswd的密码即可完成VNC远程连接! |
如图:输入VNC密码即可登录。

---------------------------------------------书山有路勤为径,学海无涯苦作舟--------------------------------------------------------
分类: Linux基础知识


浙公网安备 33010602011771号