一、安装VNC Viewer
1.首先win10下载安装VNC VIEWER 或者直接下载绿色版
2.linux系统安装vnc:
检查linux是否安装vnc:rpm -q tigervnc tigervnc-server
3.以root用户运行以下命令来安装vncserver;
#yum install tigervnc-server
同样运行以下命令来安装vncviewer;
#yum install vnc
4.配置VNC-Server
进入目录: #cd /lib/systemd/system #ls
首先,复制该service,命名为[email protected]:1.service
#cp [email protected] [email protected]:1.service
然后,修改[email protected]:1.service
#vi [email protected]:1.service
修改前:
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
User=<USER>
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=-/usr/bin/vncserver -kill %i
ExecStart=/usr/bin/vncserver %i
PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i
[Install]
WantedBy=multi-user.target
修改后:
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
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
最后Esc+:wq保存退出。
6、重新加载 systemd
#由于在systemd中添加了东东,得让系统重新加载 systemctl daemon-reload
启动[email protected]:1.service服务,并设置开机自启
systemctl start [email protected]:1.service
systemctl enable [email protected]:1.service
注:若系统无法正常关机,则再次启动,此服务无法启动,解决办法参照以下步骤
、问题解决
1.报错:Job for [email protected]:1.service failed because the control process exited with error code. See "systemctl status [email protected]:1.service" and "journalctl -xe" for details.
处理方法:
rm -rf /tmp/.X11-unix/*
7、为[email protected]:1.service设置密码
vncpasswd
8、关闭防火墙
CentoS7默认采用新防火墙firewall,不在用iptables
[使用firewall]
firewall-cmd --permanent --add-service vnc-server#添加访问权限
systemctl restart firewalld.service#重启firewalld
#systemctl stop firewalld.service #停止firewall(start,启动)
#systemctl disable firewalld.service #设置开机禁止firewall(enable 开机启动)
[使用iptables]
yum -y install iptables-services#安装iptables
vi /etc/sysconfig/iptables#修改iptables防火规则,在合适的位置加上如下一句
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5903 -j ACCEPT
systemctl restart iptables.service #重启防火墙使配置生效-----systemctl status iptables.service#查看状态
systemctl stop iptables.service #启动iptables(start)
systemctl disable iptables.service #禁止防火墙开机启动(enable)#设置防火墙开机启动
[注意]安装iptables后可以使用
service iptables status#查看防火墙状态
service iptables stop#关闭防火墙
chkconfig iptables --list#查看防火墙开机启动状态
chkconfig iptables off#关闭防火墙开机启动
9、启动VNC服务(设置开机启动)
systemctl enable [email protected]:1.service #设置开机启动 systemctl start [email protected]:1.service #启动vnc会话服务#systemctl status [email protected]:1.service #查看nvc会话服务状态#systemctl stop [email protected]:1.service #关闭nvc会话服务
访问
使用你的ip加上一个1即可
原文地址:https://www.cnblogs.com/guyuehuanhuan/p/10253194.html