Centos7.x 安装VNC远程桌面
1、配置yum源,使用阿里镜像
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
2、安装Linux图形桌面
yum -y groups install "GNOME Desktop"
3、设置服务器启动到图形界面并重启
mv /etc/systemd/system/default.target /etc/systemd/system/default.target.bak
ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target
4、关闭防火墙及selinux,重启
systemctl stop firewalld
systemctl disable firewalld
sed -i "s#^SELINUX.*#SELINUX disabled#g" /etc/selinux/config
reboot
5、安装vncserver
yum install tigervnc-server -y
6、设置vnc密码
vncpasswd
Password:GBase123
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
7、设置服务
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
8、修改此服务配置
vim /etc/systemd/system/vncserver@\:1.service
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
User=root
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i -geometry 1280x1024"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
9、加载服务
systemctl daemon-reload
10、启动服务
systemctl start vncserver@:1
systemctl enable vncserver@:1
11、在windows使用vnc viewer连接linux
官方下载地址:https://www.realvnc.com/en/connect/download/viewer/
输入格式:IP::端口,如192.168.1.1::5901
密码为第6步设置的密码
其他:修改vnc端口:
vi /usr/bin/vncserver
$vncPort = 5900 + $displayNumber;