当前位置: 移动技术网 > 科技>操作系统>Linux > VNC 安装 (适用Redhat 9.0 和 CentOS 7.0+)

VNC 安装 (适用Redhat 9.0 和 CentOS 7.0+)

2019年01月30日  | 移动技术网科技  | 我要评论

remote service
本文转自

vnc 安装 (适用redhat 9.0 和 centos 7.0+)

  • 目的: vnc来实现远程我们的linux服务器
  • 实验环境: red hat enterprise linux server release 7.6 (maipo)
    cat /etc/redhat-release

    1. 安装vnc server (tigervnc-server)

    yum -y install vnc-server

    2. 复制vnc server的配置模板

    cd /lib/systemd/system
    cp vncserver@.service vncserver@:1.service
    注:vnc 服务本身使用的是5900端口。鉴于有不同的用户使用 vnc ,每个人的连接都会获得不同的端口。配置文件名里面的数字告诉 vnc 服务器把服务运行在5900的子端口上。在我们这个例子里,第一个 vnc 服务会运行在5901(5900 + 1)端口上,之后的依次增加,运行在5900 + x 号端口上。其中 x 是指之后用户的配置文件名 vncserver@:x.service 里面的 x 。
    如果要用更多的用户连接,需要创建配置文件和端口,添加一个新的用户和端口。你需要创建 vncserver@:2.service 并替换配置文件里的用户名和之后步骤里相应的文件名、端口号。请确保你登录 vnc 服务器用的是你之前配置 vnc 密码的时候使用的那个用户名。

    3. 编辑配置模板:vim vncserver@:1.service

    vim vncserver@:1.service

    修改后内容如下: (替换< user >为root)

[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 -geometry 1376x730"
pidfile=/home/root/.vnc/%h%i.pid
execstop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

4. 重新载入 systemd,扫描新的或有变动的单元:

systemctl daemon-reload

5. 启动vnc桌面

vncserver :1

you will require a password to access your desktops.

password:输入你的密码
verify:再次输入你的密码

6. 开启自启动服务

systemctl enable vncserver@:1.service

7. 配置防火墙 (:1 默认5901 端口)

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

8. vnc viewer 访问即可

### 备注

关闭vnc服务:

systemctl stop vncserver@:1.service

禁止 vnc 服务开机启动:

systemctl disable vncserver@:1.service

关闭防火墙:

systemctl stop firewalld.service


如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网