centos安装配置vnc

目的, windows主机可以远程访问centos主机。当然,只要安装了vnc客户端之后,都能访问。

  1. 在centos上查看是否安装vnc
[root@localhost ~]# rpm -qa  |grep vnc
tigervnc-icons-1.8.0-19.el7.noarch
tigervnc-server-minimal-1.8.0-13.el7.x86_64
gtk-vnc2-0.7.0-3.el7.x86_64
gvnc-0.7.0-3.el7.x86_64
tigervnc-1.8.0-19.el7.x86_64
tigervnc-license-1.8.0-13.el7.noarch
tigervnc-server-1.8.0-19.el7.x86_64
  1. 如果没有vnc-server, 安装命令如下
yum -y install tigervnc-server
  1. 配置
    打开/lib/systemd/system/[email protected]
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/[email protected]
# 2. Replace <USER> with the actual user name and edit vncserver
#    parameters in the wrapper script located in /usr/bin/vncserver_wrapper
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service`

按照如上方法做
3.1 拷贝配置文件, 1这个是显示号,用2 3 4 等也行,标识而已

cp /lib/systemd/system/[email protected] /lib/systemd/system/vncserver@:1.service

3.2 替换用户名
如果用户是root,就把替换成root
vim /lib/systemd/system/vncserver@:1.service

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver_wrapper root %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

3.3 设置密码,设置自动启服务,运行服务

vncpasswd 
systemctl enable vncserver@:1.service
systemctl start vncserver@:1.service
  1. 客户端连接 x.x.x.x:1 ,输入连接密码,进行连接测试

  2. 如果连不上vnc很可能是被防火墙给阻挡住了,要么很暴力的关闭防火墙。要么配置以下,操作如下,推荐。

[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=vnc-server
success
[root@localhost ~]# firewall-cmd --reload

猜你喜欢

转载自blog.csdn.net/niu91/article/details/109528621