CentOS7 deploy VNC

CentOS 7 install VNC to achieve remote desktop

System environment: CentOS 7.x

1. Install GNOME Desktop

# 安装 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. Install VNC client and server

yum install tigervnc tigervnc-server -y

3. Configure VNC Service

# 复制 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. Set VNC password [VNC password is different from system user password]

# 给 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. Close firewalld and selinux

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

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

# 重启系统【建议】
reboot

6. Start VNC service [Auto start after boot]

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

Guess you like

Origin blog.51cto.com/6519883/2592281