中标麒麟V7服务器VNC远程连接

中标麒麟V7服务器VNC远程连接

##### 查看当前系统版本

**[root@192 system]# cat /etc/.productinfo** 
**NeoKylin Linux Advanced Server release V7Update6/(Chromium)-x86_64 b4.lic/20190820
##### 查看是否安装VNC**

**[root@192 system]# rpm -qa | grep vnc**
**tigervnc-server-minimal-1.8.0-13.el7.x86_64**
**gtk-vnc2-0.7.0-3.el7.x86_64**
**tigervnc-1.8.0-13.el7.x86_64**
**tigervnc-icons-1.8.0-13.el7.noarch**
**tigervnc-server-1.8.0-13.el7.x86_64**
**gvnc-0.7.0-3.el7.x86_64**
**tigervnc-license-1.8.0-13.el7.noarch
安装VNC

yum install tigervnc-server

拷贝配置文件

cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

启动 vncserver

第一次执行会要求设置用于客户端通过vnc连接该用户的密码,以后想更改可以通过vncpasswd更改该连接密码。注意最后问是否设置一个只读密码要选否,否则客户端登陆只会看到一个黑屏: 默认是从1开始

[root@192 system]# vncserver

You will require a password to access your desktops.

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

New '192.168.92.152:1 (kylin)' desktop is 192.168.92.152:1

Creating default startup script /root/.vnc/xstartup
Creating default config /root/.vnc/config
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/192.168.92.152:1.log
修改配置文件

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=/usr/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
修改配置文件之后重新载入载入system配置
systemctl daemon-reload
启动vncserver@:1.service服务
systemctl start vncserver@:1.service     -----启动

systemctl enable vncserver@:1.service    -----开机自启
关闭防火墙
systemctl stop firewalld          --关闭防火墙
systemctl disable firewalld       --开机关闭

 或者开启防火墙添加5901端口(这里只开启一个端口,如有多个界面可以开启多个端口):

systemctl start firewalld

firewall-cmd *--permanent --zone=public --add-port=5901/tcp

输入vncservice 开启服务,输入提示登陆的ip:prot

服务重启正常,网络连接正常,使用VNC Viewer

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

systemctl启动异常解决

修改配置文件中对应的用户/.vnc/路径,如果是root用户/root/ .vnc 如果是普通用户/home/kylin/ .vnc

如果使用VNC客户端连接服务器超时,查看防火墙是否关闭,服务是否正常,vncservice启动VNC

常用命令

[root@wyx system]*# netstat -antulp | grep 5901*

tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      5008/Xvnc           

tcp6       0      0 :::5901                 :::*                    LISTEN      5008/Xvnc           

[root@wyx system]*# ps -ef | grep vnc*

root      5008     1  0 19:45 pts/0    00:00:00 /usr/bin/Xvnc :1 -auth /root/.Xauthority -

desktop wyx.pc.com:1 (root) -fp catalogue:/etc/X11/fontpath.d -geometry 1024x768 -pn 

-rfbauth /root/.vnc/passwd -rfbport 5901 -rfbwait 30000

root      5678  1640  0 19:48 pts/0    00:00:00 grep --color=auto vnc



关闭服务:
vncserver -kill :1
启动服务
vncserver :n  (端口号=5900+n)
 
启动时可以同时启动过个进程来分配给不同用户,n不同即可
vncserver :1
vncserver :2
vncserver :3
 
netstat -antulp | grep 59
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      6510/Xvnc           
tcp        0      0 0.0.0.0:5902            0.0.0.0:*               LISTEN      11064/Xvnc          
tcp        0      0 0.0.0.0:5903            0.0.0.0:*               LISTEN      12457/Xvnc          
tcp        0      0 192.168.0.103:5901      125.71.203.215:65313    ESTABLISHED 6510/Xvnc           
tcp6       0      0 :::5901                 :::*                    LISTEN      6510/Xvnc           
tcp6       0      0 :::5902                 :::*                    LISTEN      11064/Xvnc          
tcp6       0      0 :::5903                 :::*                    LISTEN      12457/Xvnc

杀掉已经启动的进程
pkill -9 vnc
 
清空配置缓存(删除X1即可,也可以根据需要全部删除)
[root@wyx .X11-unix]# ls /tmp/.X11-unix
X0  X1  X2  X3  X4  X5  X6
 
保留config passwd xstartup即可
[root@wyx .vnc]# ls /root/.vnc/
config  wyx.pc.com:1.log  wyx.pc.com:2.pid  wyx.pc.com:3.pid  wyx.pc.com:4.pid
passwd  wyx.pc.com:2.log  wyx.pc.com:3.log  wyx.pc.com:4.log  xstartup
 
现在可以通过systemd管理服务了
systemctl start vncserver@:1.service
 
netstat -antulp | grep 59
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      5611/Xvnc           
tcp6       0      0 :::5901                 :::*                    LISTEN      5611/Xvnc 


查看报错信息:grep vnc /var/log/messages

.0.0:* LISTEN 5611/Xvnc
tcp6 0 0 :::5901 ::😗 LISTEN 5611/Xvnc

查看报错信息:grep vnc /var/log/messages


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值