用户工具

站点工具


linux:vnc

1. VNC

这里主要讨论vncserver服务,它是支持多种的vncviewer软件接入的。

主要有两种,一是tigervnc,另外一个是realvnc。

tigervnc是免费开源的vnc软件,在多数的linux发行版中,都已经自带了,而realvnc是商业的vnc软件,有个人版也有商业版。

tigervnc的教程较多,realvnc的教程少,官网文档不易理解。

TigerVNC不支持文件传输功能,REALVNC默认支持文件传输。

参考下面两个连接:

https://www.mail-archive.com/tigervnc-devel@lists.sourceforge.net/msg00252.html

https://github.com/TigerVNC/tigervnc/issues/419

1.1 VNC建立vncserver服务

一般情况下,是采用如下命令来建立vncserver服务:

vncserver -geometry 1900x980 :1

:1是port号, 可以根据实际情况进行修改,如果有人已经占住该端口号,那么就需要更换一个端口号。不指定的话,系统会自动分配一个port号

-geometry 1900×980是设置屏幕分辨率。

如果需要建立多个vncserver服务的话,那么就需要执行多次上述的命令。

1.2 设置防火墙

1.2.1 CentOS 6

vncserver默认从端口开始5900,需要设置防火墙开放相应端口或者是关闭防火墙

[root@ayls-s3 init.d]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5900 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
[root@ayls-s3 init.d]#  /etc/init.d/iptables  restart

2. REALVNC

注意: realvnc在CentOS6上可以正常使用,在CentOS7上桌面没有任务栏,导致基本无法使用。

2.1 REALVNC server开机启动

realvnc方式跟tigervnc不一样,realvnc支持 server mode, user mode, vitual mode。

mode 描述
server mode 远端机与受控主机看到的是同一个桌面,类比如向日葵,teamview之类的远程桌面。
user mode 跟上面类似,商业版才有
virtual mode 类似于建立vncserver服务,是虚拟出来的画面,就像vncserver :1这样方式建立的服务,商业版才有
  • vncserver-virtuald 对应virtual模式
  • vncserver-x11-serviced 对应server模式

CentOS6配置:

# 开启服务 
/etc/init.d/vncserver-x11-serviced   start
/etc/init.d/vncserver-virtuald    start
 
# 开机启动 
chkconfig   vncserver-x11-serviced   on 
chkconfig   vncserver-virtuald   on

CentOS7配置:

# 开机启动
systemctl enable vncserver-virtuald.service
# 开启服务
systemctl start vncserver-virtuald.service
# 查看状态
systemctl status vncserver-virtuald.service

2.2 REALVNC CONFIG

VNC configuration files

Parameters can be specified as command line OPTIONS, but preferably in VNC configuration files. VNC configuration files are available for:

  • All programs, or just VNC Server
  • All users of the computer, or just the user starting VNC Server
  • Policy, in order to lock down VNC Server

When VNC Server starts, parameters are applied in the following order:

  1. System-wide VNC configuration files
  2. Per-user VNC configuration files
  3. Command line OPTIONS
  4. Policy VNC configuration files

注释:

  1. system-wide VNC Server configuration file (for example /etc/vnc/config.d/common.custom)
  2. Per-user vnc config file是指用户目录~/.vnc/里面的配置文件
  3. command line options, 是指加在vnc命令上的参数,比如vncserver命令
  4. policy files to the /etc/vnc/policy.d directory

This means that a particular parameter specified at the command line overrides the same parameter specified in a per-user or in a system-wide VNC configuration file, but is itself overridden by the same parameter specified in a policy VNC configuration file. Policy cannot be changed by users.

Note there is a disadvantage to specifying parameters at the command line: parameters cannot be reloaded while VNC Server is running. VNC configuration files can be reloaded, however, which means that VNC Server can be reconfigured without downtime.

For a full list of available VNC configuration files, visit Configuring VNC Connect Using Parameters

https://help.realvnc.com/hc/en-us/articles/360002250797-Remotely-Configuring-and-Locking-Down-VNC-Connect-Using-Policy

Process Policy template file Contains parameters for... Notes
core Xvnc Connectivity, security, locale, performance, logging, and more.
User interface vncserverui-virtual Locale, file transfer, and chat.
Daemon vncserver-virtuald Connectivity, security, logging. Performance controlled per-user by Xvnc.

2.3 realvnc默认分辨率修改

参考网页:https://mlog.club/article/4538833

vnc virtual mode的默认分辨率是1024×768, 很多时候需要定制默认分辨率,方法如下:

创建文件/etc/vnc/config.custom,文件内容如下:

-geometry 1366x768

# 联想小新pad Pro 2021更适合 1280x768分辨率。

That requires passing a geometry parameter on the commandline, of course. RealVNC also supports configuration of the VNC service through various configuration files. However, confusingly, config for “Xvnc” (the underlying RealVNC server used on UNIX systems that communicates with X, and which needs to take the geometry config parameter) has to go in a different location from the “normal” RealVNC config files; either /etc/vnc/config.custom for server-wide settings, or ~/.vnc/config for user-specific settings. These are wholly separate from the other RealVNC config files and finding this out was pretty tough. As I said, the docs on this are terrible. So, in order to not have to specify resolution at the commandline, create the file /etc/vnc/config.custom and give it the following contents:

-geometry 1280×1024

2.4 centos7安装信息

NOTICE: common configuration in /etc/pam.d contains the following modules:
   pam_faildelay.so
   pam_fprintd.so
The default vncserver PAM configuration only enables pam_unix. See 
'man vncinitconfig' for details on any manual configuration required.
 
 
Looking for font path... not found.
Installed systemd unit for VNC Server in Service Mode daemon
Start or stop the service with:
  systemctl (start|stop) vncserver-x11-serviced.service
Mark or unmark the service to be started at boot time with:
  systemctl (enable|disable) vncserver-x11-serviced.service
 
Installed systemd unit for VNC Server in Virtual Mode daemon
Start or stop the service with:
  systemctl (start|stop) vncserver-virtuald.service
Mark or unmark the service to be started at boot time with:
  systemctl (enable|disable) vncserver-virtuald.service
 
Installed firewalld service configuration. To enable access to VNC services from the public zone, use the following commands:
For VNC Server in Service Mode:
  firewall-cmd --zone=public --permanent --add-service=vncserver-x11-serviced
For VNC Server in Virtual Mode daemon:
  firewall-cmd --zone=public --permanent --add-service=vncserver-virtuald

2.5 REALVNC 下载

一、软件下载(VNC-Server-6.2.0-Linux-x64.rpm)

RealVNC下载:http://pan.baidu.com/s/1sl0Wzql, 也可以去官网直接下载最新的安装包。

四、安装序列号

/usr/bin/vnclicense -add VKUPN-MTHHC-UDHGS-UWD76-6N36A
69NCN-JRLBC-QD28Y-5KLY2-UEE6A
6GQQQ-HXLBS-U2H8Q-B6UB7-R7R6A
8XWCU-ZRJBF-U7BXZ-G5EAE-ZPQ2A
6XQQQ-WXL4Q-NN4KX-NUTC6-8ZK6A
PGUFQ-HTZBB-WNHU7-YHDQC-A7R6A

3. tigervnc On CentOS 6

3.1 tigervnc server开机批量启动

需要软件tigervnc,直接yum安装即可, yum install -y tigervnc*

3.1.1 设置开机启动

chkconfig vncserver on

3.1.2 重启服务

service vncserver restart

3.1.3 多用户

编辑文件,vi /etc/sysconfig/vncservers
如果是单用户:

VNCSERVERS="1:user1"
VNCSERVERARGS[1]="-geometry 800x600"

如果是多用户:

VNCSERVERS="1:user1 2:user2 3:user3"
VNCSERVERARGS[1]="-geometry 800x600"
VNCSERVERARGS[2]="-geometry 800x600"
VNCSERVERARGS[3]="-geometry 800x600"

以此类推

默认情况下,1:user1对应5901,2:user2对应5902(VNC的默认监听端口是5900,监听端口规则为590+usernumber),如下

VNCSERVERS="usernumber:myusername"

#下面这项配置为登录桌面配置,其中的“1”为用户序号,800×600为分辨率,-nolisten tcp为阻止tcp包,-localhost代表只监听本地,

VNCSERVERARGS[1]="-geometry 800x600 -nolisten tcp -localhost"

如果想阻止http包,可以使用如下配置

VNCSERVERARGS[1]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"

按照上述操作,在每次机器开机时,都会自动开启多个vncserver服务,直接使用vncviewer连接即可。

4. tigervnc on CentOS7

4.1 tigervnc在centos7的安装

  1. 卸载其它类弄的vnc,说白了,就是如果有装realvnc,就需要先把它给卸载掉。
  2. 安装tigervnc, yum install -y tigervnc*

4.2 配置

cp /usr/lib/systemd/system/vncserver@.service  /usr/lib/systemd/system/vncserver@:1.service
# 修改vncserver@:1.service文件,把其中的<USER>替换成具体的linux某个用户名,比如zhangsan
 
cp /usr/lib/systemd/system/vncserver@.service  /usr/lib/systemd/system/vncserver@:2.service
# 修改vncserver@:2.service文件,把其中的<USER>替换成具体的linux某个用户名,比如lisi
 
#继续添加其它用户, 注意这个文件的个数是与用户个数相对应的。
 
 
 
#启动服务 start|stop|restart
systemctl start vncserver@:1.service
systemctl start vncserver@:2.service
systemctl start vncserver@:3.service
#...
 
# 查看服务状态, 显示的Active: active (running) 就是正常在运行的状态
systemctl status vncserver@:1.service
systemctl status vncserver@:2.service
systemctl status vncserver@:3.service
# ...
 
# 设置开机启动, enable|disable
systemctl enable vncserver@:1.service
systemctl enable vncserver@:2.service
systemctl enable vncserver@:3.service
#...
 
 
 
############ 调整分辨率 #############
可以直接在每个用户的home目录下,编辑~/.vnc/config文件。
[root@localhost ~]# cat .vnc/config
## Supported server options to pass to vncserver upon invocation can be listed
## in this file. See the following manpages for more: vncserver(1) Xvnc(1).
## Several common ones are shown below. Uncomment and modify to your liking.
##
# securitytypes=vncauth,tlsvnc
# desktop=sandbox
geometry=1920x1080
# localhost
# alwaysshared
 
###########将geometry 取消注释,然后修改成你期望的分辨率就行
 
 
#然后reboot机器,等机器启动好后,用vnc viewer连接,就应该会看到设置好的GUI界面,从而不能再手动地创建vncserver桌面。

4.3 问题debug

systemctl start vncserver@:4.service有概率启动不成功的问题,此处只是用:4端口举例,其它端口也会出现类似的情况。

If you kill your vncserver or unexpected dead, Please read /var/log/messages and you can find .X started files with errors like below. At first, please verify Xvnc process not running.

Dec 15 14:11:11 www runuser: Warning: www.example.com:4 is taken because of /tmp/.X4-lock
...
Dec 15 14:12:52 www runuser: Warning: www.example.com:4 is taken because of /tmp/.X11-unix/X4

then you remove

# rm -f /tmp/.X4-lock
# rm -f /tmp/.X11-unix/X4

and restart your vncserver.

# systemctl restart vncserver@:4.sevice

#注: 如果启动不成功,需要检查临时文件有没有删除

rm -f /tmp/.X11-unix/X1 # 对应@:1.service rm -f /tmp/.X11-unix/X2 # 对应@:2.service rm -f /tmp/.X11-unix/X3 # 对应@:3.service # 以此类推

所以是不是可以不管啥,都把.X4-lock 和 X4给删除一遍?

5. vnc viewer软件下载

6. 其它远程软件

https://download.csdn.net/download/u013244517/12793900

https://download.csdn.net/download/hitzhu2000/12747760?utm_source=iteye_new

以下内容转自于https://www.eda365.com/portal.php?mod=view&aid=69418

目前小公司普遍采用的登录软件有Xmanager/Exceed/VNC/FreeNX,而大公司普遍采用的有Xenapp/NX/EoD/Go-Global等。对于以上软件,我都有一定程度的接触,所以在此做一个简单评价。

Xmanger和Exceed,属于利用X协议,在windows平台实现的X Server,优点是使用方便,使用的人很多,性能在局域网也不错。缺点就是,一旦用户端跟服务器之间的网络意外终端,或者客户端关机,所有正在服务器上运行的job丢失。

VNC免费版使用非常广泛,其实现了网络断开也不会丢失正在运行的工作。但是免费版限制很多,比如需要用户设置专用的vnc登陆密码,无法禁止用户Copy&Paste服务器数据到本地。另外,VNC协议实现对网络带宽消耗很大,不适合于WAN网络连接。

FreeNX是基于No-Machine免费开源的library实现的免费远程登陆软件。目前有另外一个如日中天的类似软件,叫做X2Go。FreeNX基于SSH协议,实现了压缩传输等功能,效率比VNC提高很多。但是其基于SSH协议实现,给系统安全留下了隐患。

VNC Enterprise,实现了更高级的功能,包括验证集成了系统验证,不需要额外设置vnc登陆密码,也可以禁用剪切板等高级功能,还可以通过policy设置。对于小型设计环节,目前是一个非常值得考虑的选择。

Xenapp是citrix基于ICA协议实现的登陆方式,最新的基于Unix的是2008年前后发布的Unix 4.0 FP2版本。Citrix的中心已经转向了windows,及时是最新发布xendesktop linux版本,也并没认真去做,集成很困难。不过,当年Broadcom是基于solaris 10+ citrix for unix fp2实现的登陆环境,不知道五年过去了,是否已经改变。

Nomachine公司发布的NX商业版本可以支持更多功能,国内有几个公司在使用,具体功能不了解,比如如何实现及时采用SSH协议,也不担心被设置转发隧道,从而解决安全问题的。

EoD的全称是Exceed On Demand。软件费用昂贵,国内使用的人很少,目前我知道的是IBM基于EoD实现登陆。EoD软件可以禁用Copy&Paste,同时gateway模式可以让用户无法直接在EoD服务器上工作,让EoD服务器实现gateway转发即可。EoD可实现share 桌面,对于远程会议共享桌面和需要远程协助debug的时候非常有用。推荐不差钱的大公司选择EoD,是我见过最佳的登陆软件了。

Go-Global是另外一个登陆软件,分为for windows和for unix版本。实现上比VNC要快,国内也有商业支持,也比较成熟和稳定。不过其客户端目前只支持windows系统,这点需要注意。如果是中小型公司,可以考虑采用。

linux/vnc.txt · 最后更改: 2023/03/17 10:12 由 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki