共计 1727 个字符,预计需要花费 5 分钟才能阅读完成。
Centos7 上面使用 root 用户运行 vnc
1. 安装
yum groupinstall "GNOME Desktop" -y | |
#安装 vnc 服务 | |
yum install tigervnc-server -y |
2. 配置启动文件
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service | |
#编辑文件 | |
vi /etc/systemd/system/vncserver@:1.service |
3. 配置文件, 注意此步骤很重要!!
把 i 改成:1, 使用 root 用户
[Unit] | |
Description=Remote desktop service (VNC) | |
After=syslog.target network.target | |
[Service] | |
Type=forking | |
# Clean any existing files in /tmp/.X11-unix environment | |
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :' | |
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i" | |
PIDFile=/root/.vnc/%H%i.pid | |
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :' | |
[Install] | |
WantedBy=multi-user.target |
网上很多配置只改了用户没有更改用户 pid 目录,这样的后果是 systemctl 启动失败,但是实际上以及启动成功
一定要确定目录已经存在,否则启动会报错
PIDFile=/home/root/.vnc/%H%i.pid
4. 防火墙开放服务
firewall-cmd --permanent --zone=public --add-service vnc-server | |
firewall-cmd --reload |
5. 设置密码
[duduniao@server1 ~]$ vncserver | |
You will require a password to access your desktops. | |
Password:<--yourvncpassword | |
Verify:<--yourvncpassword | |
xauth: file /home/srijan/.Xauthority does not exist | |
New 'server1.example.com:1 (srijan)' desktop is server1.example.com:1 | |
Creating default startup script /home/kishore/.vnc/xstartup | |
Starting applications specified in /home/kishore/.vnc/xstartup | |
Log file is /home/srijan/.vnc/server1.example.com:1.log |
6. 启动服务
systemctl daemon-reload | |
systemctl enable vncserver@:1.service | |
#reboot | |
systemctl start vncserver@:1.service |
报错解决
Job for vncserver@:1.service failed because a configured resource limit was exceeded. See "systemctl status vncserver@:1.service" and "journalctl -xe" for details.
这个报错大部分都是因为启动文件配置错误导致的,解决办法如下
1,kill -9 杀死所有 vnc 进程
通过 ps 过滤 pid 然后杀死
2. 删除 pid 文件,上图所示我的 pid 文件在 /root/.vnc 下面
rm -fr /root/.vnc/*.pid
3. 删除 tmp 目录下 unix 文件
rm -fr /tmp/.X*
4. 启动服务
systemctl daemon-reload | |
systemctl start vncserver@:1 | |
systemctl status vncserver@:1 |
正文完