RH254小结(十)rhel7配置VNC-Server
Centos7/Redhat7 较之前的6版本变化比较大,相应的VNC的配置也和之前也不一样了。centos6版本VNC的配置可以参看之前的文章--linux下安装配置VNC 。本篇就主要说下7版本下VNC服务的配置。
1、安装软件
在配置前需要先安装桌面环境和VNC-Server软件
1# yum groupinstall "GNOME Desktop"
2# yum -y install tigervnc-server tigervnc
2、复制配置文件
我们先尝试通过6版本中的方法,查看VNC的配置文件,得到提示信息如下:
1# cat /etc/sysconfig/vncservers
2# THIS FILE HAS BEEN REPLACED BY /lib/systemd/system/[email protected]
在去查看lib下的vncserver文件时,又给出了如下的提示
1# cat /lib/systemd/system/[email protected]
2# The vncserver service unit file
3#
4# Quick HowTo:
5# 1. Copy this file to /etc/systemd/system/vncserver@:<display>.service
6# 2. Edit <USER> and vncserver parameters appropriately
7# ("runuser -l <USER> -c /usr/bin/vncserver %i -arg1 -arg2")
8# 3. Run `systemctl daemon-reload`
9# 4. Run `systemctl enable vncserver@:<display>.service`
所以我们就按他的提示来进行操作
1# cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service
3、编辑VNC配置文件
这里我以root用户为例,/etc下复制过去的文件内容修改如下:
1[Unit]
2Description=Remote desktop service (VNC)
3After=syslog.target network.target
4[Service]
5Type=forking
6# Clean any existing files in /tmp/.X11-unix environment
7ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :'
8ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver :1 -geometry 1280x720 -depth 24" PIDFile=/root/.vnc/%H%i.pid
9ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :'
10[Install]
11WantedBy=multi-user.target
将文件中的用你当前的用户替换,将%i替换为1 。修改完成后,同样根据提示信息,重载配置,并enable服务开机自启动。
1# systemctl daemon-reload
2# systemctl enable vncserver@:1.service
3# systemctl start vncserver@:1.service
虽然服务已经启动,但由于未配置密码项,所以这时修还没法进行连接,需要通过vncpasswd命令或vncserver命令配置密码,如下:
1# vncserver
2You will require a password to access your desktops.
3Password:<--yourvncpassword
4Verify:<--yourvncpassword
5xauth: file /root/.Xauthority does not exist
6……………………省略
如果上面配置密码的步骤没有,直接连接,会发现没法连接,而且会在/var/log/message中发现如下报错:
1Sep 10 00:32:38 361way systemd: Starting Remote desktop service (VNC)...
2Sep 10 00:32:38 361way systemd: Failed to reset devices.list on /machine.slice: Invalid argument
3Sep 10 00:32:38 361way systemd: Failed to reset devices.list on /machine.slice: Invalid argument
4Sep 10 00:32:38 361way systemd: Starting Session c3 of user root.
5Sep 10 00:32:38 361way systemd: Started Session c3 of user root.
6Sep 10 00:32:38 361way systemd: Failed to reset devices.list on /machine.slice: Invalid argument
7Sep 10 00:32:38 361way runuser: You will require a password to access your desktops.
8Sep 10 00:32:38 361way runuser: getpassword error: Inappropriate ioctl for device
9Sep 10 00:32:38 361way runuser: Password:
10Sep 10 00:32:38 361way systemd: vncserver@:1.service: control process exited, code=exited status=1
11Sep 10 00:32:38 361way systemd: Failed to start Remote desktop service (VNC).
12Sep 10 00:32:38 361way systemd: Unit vncserver@:1.service entered failed state.
4、防火墙配置
如果主机上启用了防火墙,还在要其配置中将端口例外,使用的端口一般为 5910 + N ,其中N为冒号后面的桌面号。
iptables防火墙配置为:
1# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 5901 -j ACCEPT
2# service iptables save
firewalld 防火墙配置为:
1# firewall-cmd --permanent --zone=public --add-service vnc-server
2# firewall-cmd --reload
在为另外一个用户配置时,需要重复上面的步骤,并将N的值相应增加,如上面1号被占用了,为oracle 用户又新增的VNC配置为vncserver@:2.service 。还需要注意的是普通用户的家目录和root用户是不同的。通过vnc连接工具输入IP:5901连接后,桌面显示如下:
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/rh254-centos7-vnc/4890.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.