CentOS7.x安装VNC
1、安装GNOME Desktop
yum groupinstall "GNOME Desktop"
修改默认启动方式为图形化界面
systemctl set-default graphical.target
如果要换回成命令模式
systemctl set-default multi-user.target
2、安装VNC
yum install tigervnc-server
复制VNC启动脚本
cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service
vncserver@:1.service
中的:1表示"桌面号",启动的端口号就是5900+桌面号,即是5901,如果再有一个就是2啦,端口号加1就是5902,以此类推。
编辑服务启动脚本vi /etc/systemd/system/vncserver@\:1.service
# the help of ssh, you end up seeing what hostB makes available on port 590M
#
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
#
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the "-via" option in the
# `man vncviewer' manual page.
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=simple
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver_wrapper <USER> %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
找到其中的<USER>
,修改成自己的用户名,如 :root
设置vnc密码
vncpasswd
启动服务
systemctl start vncserver@\:1.service
新增和修改配置文件发生变化时都需要执行daemon-reload
子命令重新加载配置文件
systemctl daemon-reload
加入开机启动
systemctl enable vncserver@\:1.service
3、开放防火墙的5901端口:
firewall-cmd --zone=public --add-port=5901/tcp --permanent