Centos7 安装桌面及VNC远程连接

Centos7 安装桌面及VNC远程连接

#查看防火墙状态
$ firewall-cmd --state
#关闭防火墙及禁止开机启动
$ systemctl stop firewalld.service
$ systemctl disable firewalld.service

#换国内源(下载软件包更快点)
$ cd /etc/yum.repos.d
$ cp CentOS-Base.repo CentOS-Base.repo.bak
$ wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 刷新缓存
$ yum clean all
$ yum makecache

#安装GNOME桌面
$ yum groupinstall "GNOME Desktop" "Graphical Administration Tools"
# 安装完成后,修改默认启动方式为图形化界面
$ systemctl set-default graphical.target  //设置成图形模式
#启动x会话
$ startx

#安装vnc服务
$ yum -y install tigervnc-server
# 复制一个服务设置的模板
$ cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service
 
# 修改此服务配置
# 以下为root用户的配置,每一个用户,都需要单独设置一个监听服务。且配置不同
$ vim /etc/systemd/system/vncserver@\:1.service
----------------------------------------------------------------------------------------------------------
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
 
[Service]
Type=forking
User=root
 
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=-/usr/bin/vncserver -kill %i
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i
 
[Install]
WantedBy=multi-user.target
----------------------------------------------------------------------------------------------------------
 
# 对于普通用户,加入用户名为:Amos
# 下面举例进行设置: 首先一样复制一个server配置。改名为vncserver@:2.service
$ cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:2.service
# 然后进行修改
$ vim /etc/systemd/system/vncserver@\:2.service
--------------------------------------------------------------------------------------------------------
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
 
[Service]
Type=forking
User=root
 
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=-/usr/bin/vncserver -kill %i
ExecStart=/usr/bin/vncserver %i
PIDFile=/home/Amos/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i
 
[Install]
WantedBy=multi-user.target

以上安装好了之后需要启动

#设置vnc密码
$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
# 这里不添加只读账号密码
# 每个不用的系统用户,设置密码时,需要切换到该用户下,执行此命令
# 如:su Amos  切换到Amos用户再执行上vncpasswd设置密码

#启动vnc
$ systemctl start vncserver@:1
$ systemctl enable vncserver@:1    # 设为开机启动

#查看服务状态
$ systemctl status vncserver@:1
 
# 查看服务监听的端口
$ netstat -lnpt|grep Xvnc

你可能感兴趣的:(centos7)