Centos7远程桌面 vnc-server设置

1, 要以界面化方式访问服务器,首先要确认目标服务器安装了图形化环境,Linux系统下常见的桌面环境有GNOME和KDE,这里安装GNOME桌面,执行命令如下:

yum -y groupinstall "GNOME Desktop"

2,安装vncserver服务


yum install -y tigervnc-server tigervnc

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

#替换文件中的两行,其实就是将换成root

vi /etc/systemd/system/[email protected]:1.service

ExecStart=/usr/sbin/runuser -l -c "/usr/bin/vncserver %i"

PIDFile=/home//.vnc/%H%i.pid

改为下面的:

ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"

PIDFile=/root/.vnc/%H%i.pid

1) 关闭防火墙
centos的防火墙是firewalld,关闭防火墙的命令
[[email protected] ~]# systemctl stop firewalld.service #停止firewall
[[email protected] ~]# systemctl disable firewalld.service #禁止firewall开机启动

如果防火墙开了,需要开通一下规则:
[[email protected] ~]# firewall-cmd --permanent --add-service vnc-server
[[email protected] ~]# systemctl restart firewalld.service

[[email protected] ~]# setenforce 0
[[email protected] ~]# getenforce
[[email protected] ~]# cat /etc/sysconfig/selinux //关闭selinux
SELINUX=disabled

#注意这个密码是登陆vnc时候要用的

VNC设密码(比如密码设置为123456
[[email protected] ~]# vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n #注意表示"是否输入一个只能查看的密码,选择否",否则连接vnc会出现黑屏
A view-only password is not used

New 'localhost.localdomain:1 (bin.wang)' 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

#这次的端口号是1,

systemctl daemon-reload

systemctl enable [email protected]:1.service

systemctl start [email protected]:1.service

yum install –y net-tools

netstat -na | grep 5901 //检查端口

[[email protected] ~]# netstat -na | grep 5901

tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN

tcp 0 0 192.168.1.9:5901 192.168.1.8:50331 ESTABLISHED

tcp6 0 0 :::5901

在windows下载vncvivewer,安装,打开,在ip中输入: 10.81.1.158:1 (ip+端口号) 在passwd中输入:刚才设置的vnc密码123456。 即可登陆

再打开一个的话,输入vncserver

[[email protected] ~]# vncserver

New 'db:2 (root)' desktop is db:2

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/db:2.log

在ip中输入:10.81.1.158:2

标签: root, localhost, Centos7, systemctl, service, 远程桌面, vncserver, vnc

相关文章推荐

添加新评论,含*的栏目为必填