vnc-server 安装和配置

CentOS

检查CentOS 是否安装了桌面环境

yum group list
yum group install "GNOME Desktop" -y
yum group install "Server with GUI" -y
# yum group list
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.sjtu.edu.cn
 * centos-sclo-rh: ftp.sjtu.edu.cn
 * centos-sclo-sclo: ftp.sjtu.edu.cn
 * epel: epel.mirror.angkasa.id
 * extras: ftp.sjtu.edu.cn
 * updates: ftp.sjtu.edu.cn
Installed Environment Groups:
   Server with GUI
   GNOME Desktop
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Cinnamon Desktop
   MATE Desktop
   Basic Web Server
   Virtualization Host
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Cinnamon
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Educational Software
   Electronic Lab
   Fedora Packager
   General Purpose Desktop
   Graphical Administration Tools
   Haskell
   LXQt Desktop
   Legacy UNIX Compatibility
   MATE
   Milkymist
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
   TurboGears application framework
   Xfce
Done

##安装

安装命令

在线安装,“-y” 表示 有交互时,都选“yes”

yum -y install tigervnc-server
更改配置
cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service

复制后修改 /etc/systemd/system/vncserver@:1.service
/root/.vnc 而不是 /home/root/.vnc
root 用户比较特别,不带 home/
注释掉原先的 ExecStart PIDFile
修改如下


[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
#ExecStart=/usr/sbin/runuser -l  -c "/usr/bin/vncserver %i"
#PIDFile=/home//.vnc/%H%i.pid
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

配置示例:

[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  %i
#ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'


[Install]
WantedBy=multi-user.target

加载配置
systemctl daemon-reload
开机自启动
systemctl enable vncserver@:1.service

设置密码
vncpasswd 
#提示输入密码
Password:
#提示确认密码
Verify:

注意秘密是需要设置的

# vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
启动服务
systemctl start vncserver@:1.service
或
vncserver :1 
报错 解决
#遇到 这些报错信息,执行以下命令。Job for vncserver@:1.service failed because a configured resource limit was exceeded. See "systemctl status vncserver@:1.service" and "journalctl -xe" for details.
rm -rf /tmp/.X11-unix/*

如遇这种错误,检查密码有没有设置

● vncserver@:1.service - Remote desktop service (VNC)
   Loaded: loaded (/etc/systemd/system/vncserver@:1.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2022-04-26 10:40:04 CST; 8s ago
  Process: 152729 ExecStart=/sbin/runuser -l root -c /usr/bin/vncserver %i (code=exited, status=1/FAILURE)
  Process: 152725 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
 Main PID: 152729 (code=exited, status=1/FAILURE)

停止服务
vncserver -kill :1
或
systemctl stop vncserver@:1.service
关闭 防火墙
临时关闭防火墙命令。重启电脑后,防火墙自动起来。
systemctl stop firewalld
永久关闭防火墙命令。重启后,防火墙不会自动启动。
systemctl disable firewalld

使用客户端 vnc viewer 连接 vncserver

默认链接端口是 IP:5901

共享当前桌面

上述连接方式 是不能共享同一桌面的。
共享当前桌面 需要使用以下命令

x0vncserver -PasswordFile=/root/.vnc/passwd display=':0.0'
使用客户端 vnc viewer 重新连接 vncserver

IP:5900 或 IP:0

Ubuntu

安装 基本的UI 环境

apt install ubuntu-desktop 

安装VNC

apt install tigervnc-standalone-server -y
adduser uservncsu - uservnc
vncpasswd

注意事项

Password:Verify:Would you like to enter a view-only password (y/n)? n

启动VNC

vncserver -localhost no 

查看 vnc 运行状态

# vncserver -list

TigerVNC server sessions:

X DISPLAY #     RFB PORT #      PROCESS ID
:1              5901            335736

关闭vnc 服务

vncserver -kill :1
useful links

https://copyfuture.com/blogs-details/20210328144344970d

FQA

ubuntu 桌面登录密码失败

vnc-server 安装和配置_第1张图片

sorry,that didn’t work.please try again

修改 autologin 配置

vi /etc/pam.d/gdm-autologin
#注释 “auth requied pam_succeed_if.so user != root quiet success”

修改 password 配置

vi /etc/pam.d/gdm-password
#注释行 “auth requied pam_succeed_if.so user != root quiet success”

无需重启机器。 即可生效

你可能感兴趣的:(工作实践,VNC,linux,运维,服务器)