CentOS7部署VNC

CentOS 7 安装 VNC 实现远程桌面

系统环境:CentOS 7.x

1. 安装 GNOME 桌面

# 安装 GNOME Desktop
yum groups install "GNOME Desktop"
# 修改默认启动方式为图形化界面
systemctl set-default graphical.target
# 设置成命令模式
#systemctl set-default multi-user.target

# 安装开发工具和组件
yum groups install "Development Tools"
yum groups install "Compatibility Libraries"

# 重启系统【建议】
reboot
# 或者开启图形界面
startx

2. 安装 VNC 客户端和服务端

yum install tigervnc tigervnc-server -y

3. 配置 VNC 服务

# 复制 vncserver 的服务模板并配置使用
cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@\:1.service
cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@\:2.service

# 每个用户都需要单独这只一个监听服务,且配置不同
# 修改 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
------------------------------------------------------------------------------

# 修改 vncserver@\:2.service 为 huawei 用户的配置
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=/sbin/runuser -l huawei -c "/usr/bin/vncserver %i"
PIDFile=/home/huawei/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i

[Install]
WantedBy=multi-user.target
------------------------------------------------------------------------------

4. 设置 VNC 密码【VNC 的密码和系统用户密码不一样】

# 给 root 账号设置 VNC 密码
# 这里不添加只读账号密码
vncpasswd
------------------------------------------------------------------------------
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
------------------------------------------------------------------------------

# 给 huawei 账号设置 VNC 密码
# 这里不添加只读账号密码
su - huawei
vncpasswd
------------------------------------------------------------------------------
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
------------------------------------------------------------------------------

5. 关闭 firewalld 和 selinux

# 关闭防火墙
systemctl disable --now firewalld

# 禁用 selinux
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/g' /etc/selinux/config

# 重启系统【建议】
reboot

6. 启动 VNC 服务【开机自动启动】

systemctl enable --now vncserver@\:1.service
systemctl enable --now vncserver@\:2.service

猜你喜欢

转载自blog.51cto.com/6519883/2592281