Centos7安装VNC

发布时间 2023-08-29 16:27:16作者: whtjyt

安装vnc

#检查可用版本
[root@vnc ~]# yum --showduplicates list tigervnc-server
#安装vnc
[root@vnc ~]# yum install -y tigervnc-server
#设置密码
[root@vnc ~]# vncpasswd
Password:	#最低六位
Verify:
Would you like to enter a view-only password (y/n)? n #是否创建只读密码
A view-only password is not used
#查找vnc service文件
[root@vnc ~]# find / -name vnc*service
/usr/lib/systemd/system/vncserver@.service

#这里新文件中的数字1将用与此服务特定实例的显示编号,这一点很重要。因为它还将确定我们的 VNC 服务器将使用的 TCP 端口,等于5900 + 显示编号。第一个是5901,然后是5902,等等。
[root@vnc ~]# cp /usr/lib/systemd/system/vncserver@.service /usr/lib/systemd/system/vncserver@:1.service

#将ExecStart中的<USER>改为自己的启动用户,我的为root,service文件如下
[root@vnc ~]# cat /usr/lib/systemd/system/vncserver@:1.service |grep ^[^#]
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=simple
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver_wrapper root %i -geometry 1152x864 securitytypes=none
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target

启动

[root@vnc ~]# systemctl daemon-reload
[root@vnc ~]# systemctl start vncserver@:1
[root@vnc ~]# systemctl status vncserver@:1

设置免密

[root@vnc ~]# systemctl stop vncserver@:1
[root@vnc ~]# vncpasswd -f > ~/.vnc/passwd
	#这里直接回车
#修改config文件,securitytypes=vncauth,tlsvnc修改为securitytypes=none,tlsvnc
[root@vnc ~]# vim ~/.vnc/config
[root@vnc ~]# systemctl start vncserver@:1
[root@vnc ~]# systemctl status vncserver@:1
#查看端口
[root@vnc ~]# ss -nlt
State      Recv-Q Send-Q Local Address:Port           Peer Address:Port              
LISTEN     0      100        127.0.0.1:25                    *:*                  
LISTEN     0      128        127.0.0.1:6010           		 *:*                  
LISTEN     0      5                  *:5901                  *:*                  
LISTEN     0      128                *:6001                  *:*                  
LISTEN     0      128                *:22                    *:*                  
LISTEN     0      100            [::1]:25                    [::]:*                  
LISTEN     0      128            [::1]:6010                  [::]:*                  
LISTEN     0      5               [::]:5901                  [::]:*                  
LISTEN     0      128             [::]:6001                  [::]:*                  
LISTEN     0      128             [::]:22                    [::]:*

安装Xfce

[root@vnc ~]# systemctl stop vncserver@:1
#yum groupinstall "Xfce" -y 报错就在后面加上--skip-broken
[root@vnc ~]# yum groupinstall "Xfce" -y
#安装字体和xfce终端
[root@vnc ~]# yum install -y xfce4-terminal wqy-microhei-fonts
#修改图形化界面设置
[root@vnc ~]# vim ~/.vnc/xstartup
#将/etc/X11/xinit/xinitrc修改为/usr/bin/startxfce4
[root@vnc ~]# which startxfce4 #确认startxfce4路径

安装火狐游览器

[root@vnc ~]# wget https://download-ssl.firefox.com.cn/releases/firefox/116.0/zh-CN/Firefox-latest-x86_64.tar.bz2

#tar解压.tar.bz2需要lbzip2依赖
[root@vnc ~]# yum -y install lbzip2
[root@vnc ~]# tar -xf Firefox-latest-x86_64.tar.bz2 -C /opt/

#设置桌面图标
[root@vnc ~]# mkdir ~/Desktop
[root@vnc ~]# cat > ~/Desktop/firefox.desktop << EOF
[Desktop Entry]
Version=1.0
Type=Application
Name=Firefox
Comment=Web Browser
Exec=/opt/firefox/firefox
Icon=/opt/firefox/browser/chrome/icons/default/default128.png
Terminal=false
Categories=Network;WebBrowser;
EOF
[root@vnc ~]# chmod +x ~/Desktop/firefox.desktop
#启动
[root@vnc ~]# systemctl start vncserver@:1
[root@vnc ~]# systemctl status vncserver@:1