您好,登录后才能下订单哦!
这篇文章主要为大家展示了“Red Hat 7 vncserver如何配置”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Red Hat 7 vncserver如何配置”这篇文章吧。
首先, 配置好yum源,查询vncserver需要安装什么包,然后安装。
[root@localhost ~]# yum provides vncserver Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. yum | 4.1 kB 00:00:00 (1/2): yum/group_gz | 134 kB 00:00:00 (2/2): yum/primary_db | 3.4 MB 00:00:00 yum/filelists_db | 3.0 MB 00:00:00 tigervnc-server-1.2.80-0.30.20130314svn5065.el7.x86_64 : A TigerVNC server Repo : yum Matched from: Filename : /usr/bin/vncserver [root@localhost ~]# yum install tigervnc-server-1.2.80-0.30.20130314svn5065.el7.x86_64 -y .... Installed: tigervnc-server.x86_64 0:1.2.80-0.30.20130314svn5065.el7 Complete!
这样vncserver就安装好了,通过命令vncserver可以启动或进行管理,首次启动vncserver,会提示修改密码。此密码为vnc客户端连接时使用。
[root@localhost ~]# vncserver New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1 Starting applications specified in /root/.vnc/xstartup Log file is /root/.vnc/localhost.localdomain:1.log 用vncserver启动,默认会从最低端口(1)启动,之后依次递增,如果想指定vnc端口,可以使用ncserver [:<port_number>] [root@localhost ~]# vncserver :2016 New 'localhost.localdomain:2016 (root)' desktop is localhost.localdomain:2016 Starting applications specified in /root/.vnc/xstartup Log file is /root/.vnc/localhost.localdomain:2016.log 通过vncserver -list 可以查看当前运行的vnc信息 [root@localhost ~]# vncserver -list TigerVNC server sessions: X DISPLAY # PROCESS ID :1 8167 :2016 8670 通过vncserver -kill :<port_number> 可以关闭vnc端口 [root@localhost ~]# vncserver -kill :1 Killing Xvnc process ID 8167
当然,客户端要访问vnc还得经过防火墙的同意,需要在防火墙放行vnc或者直接关闭防火墙。这里测试了下,在防火墙放行之后,默认通过vncserver启动的端口访问,但是通过vncserver :port_number指定端口启动的还是无法访问,求解。
防火墙配置放行vncserver [root@localhost ~]# firewall-cmd --permanent --add-service=vnc-server success [root@localhost ~]# firewall-cmd --reload success 或者关闭防火墙,并且禁止防火墙开机自启。 [root@localhost ~]# systemctl stop firewalld [root@localhost ~]# systemctl disable firewalld rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service' rm '/etc/systemd/system/basic.target.wants/firewalld.service'
以上,vnc的安装配置就基本完成了。 接下来需要配置vncserver开机启动了。
使用rpm- qc tigervnc-server查询vncserver的配置。
得知配置文件被转移到了/lib/systemd/system/vncsercer@.server,文件的头部有详细的说明。
[root@localhost ~]# rpm -qc tigervnc-server /etc/sysconfig/vncservers [root@localhost ~]# cat /etc/sysconfig/vncservers # THIS FILE HAS BEEN REPLACED BY /lib/systemd/system/vncserver@.service [root@localhost ~]# head /lib/systemd/system/vncserver@.service # The vncserver service unit file # # Quick HowTo: # 1. Copy this file to /etc/systemd/system/vncserver@:<display>.service # 2. Edit <USER> and vncserver parameters appropriately # ("runuser -l <USER> -c /usr/bin/vncserver %i -arg1 -arg2") # 3. Run `systemctl daemon-reload` # 4. Run `systemctl enable vncserver@:<display>.service` # # DO NOT RUN THIS SERVICE if your local area network is
配置方法:
1.复制当前文件(/lib/systemd/system/vncsercer@.server)到/etc/systemd/system/vncserver@:<display>.server 这里<display>为启动的端口
2.编辑复制后的文档,把两处<USER>替换成需要启动的用户。需要注意的是如果用root启动,root的家目录为/root,而非/home/root
3.运行systemctl daemon-reload 重新加载配置
4.运行systemctl enable vncserver@:<display>.service 配置成开机自启
[root@localhost ~]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service [root@localhost ~]# vim /etc/systemd/system/vncserver@:1.service [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 %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 [root@localhost ~]# systemctl daemon-reload [root@localhost ~]# systemctl start vncserver@:1.service (此处手动启动) [root@localhost ~]# systemctl status vncserver@:1.service (查看运行情况 为active) vncserver@:1.service - Remote desktop service (VNC) Loaded: loaded (/etc/systemd/system/vncserver@:1.service; enabled) Active: active (running) since Fri 2016-01-22 17:00:34 CST; 7s ago [root@localhost ~]# vncserver -list TigerVNC server sessions: X DISPLAY # PROCESS ID :1 9959 [root@localhost ~]# systemctl enable vncserver@:1.service 确定手动启动没问题后加入自启) [root@localhost ~]# reboot (重启测试) Last login: Fri Jan 22 16:30:36 2016 from 192.168.175.1 [root@localhost ~]# vncserver -list (重启后查看vnc 已经启动了。) TigerVNC server sessions: X DISPLAY # PROCESS ID :1 1522 [root@localhost ~]# ps -ef |grep vnc root 1522 1 1 17:10 ? 00:00:00 /usr/bin/Xvnc :1 -desktop localhost.localdomain:1 (root) -auth /root/.Xauthority -geometry 1024x768 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5901 -fp catalogue:/etc/X11/fontpath.d -pn root 1907 1 0 17:10 ? 00:00:00 /usr/bin/vncconfig -iconic root 3167 3120 0 17:11 pts/0 00:00:00 grep --color=auto vnc
至此,vncserver的配置就已经完成了。
过程中,有一次不知道误操作了什么,1号端口一直启动不了。查看不到进程,却一直提示已经启动,重启自启也失败。
[root@kvm02 ~]# systemctl status vncserver@\:1.service vncserver@:1.service - Remote desktop service (VNC) Loaded: loaded (/usr/lib/systemd/system/vncserver@:1.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since Fri 2016-01-22 21:28:33 CST; 1min 35s ago Process: 1154 ExecStart=/sbin/runuser -l root -c /usr/bin/vncserver %i (code=exited, status=2) Process: 1132 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/ SUCCESS) [root@kvm02 .vnc]# vncserver :1 A VNC server is already running as :1 [root@kvm02 .vnc]# ps -ef |grep vnc root 7146 1667 0 22:29 pts/0 00:00:00 grep --color=auto vnc
最后在一次启动中发现了/tmp/.X11-unix/下有个文件锁住了。切换到目录下删除文件,就可以了。
报错信息: Warning: kvm02:1 is taken because of /tmp/.X11-unix/X1 Remove this file if there is no X server kvm02:1 解决: [root@kvm02 ~]# cd /tmp/.X11-unix [root@kvm02 .X11-unix]# rm -rf * (删除了所有文件,此处冲动了,其实只要删除X1就好了) [root@kvm02 .X11-unix]# vncserver (删除过后就可以正常启动了) xauth: (stdin):1: bad display name "kvm02:1" in "add" command New 'kvm02:1 (root)' desktop is kvm02:1 Starting applications specified in /root/.vnc/xstartup Log file is /root/.vnc/kvm02:1.log
以上是“Red Hat 7 vncserver如何配置”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。