Centos7远程桌面的安装与vnc/vnc | 您所在的位置:网站首页 › vnc怎么用ssh › Centos7远程桌面的安装与vnc/vnc |
一.安装 GNOME-Desktop桌面环境 1、安装 GNOME # yum -y groups install"GNOME Desktop" 2、完成安装后,使用如下命令启动桌面 # startx 首次启动,进行一些初始设置 选择系统语言 选择键盘类型 添加在线用户(可选) 开始使用 启动后的桌面环境,如下所示: 二、使用GNOME ShellCentOS 7的默认GNOME桌面以经典模式开始,但如果您想使用GNOME Shell,请设置如下: 方式一:如果以 startx 命令启动GNOME,设置如下: #echo"exec gnome-session">> ~/.xinitrc# startx 方式二:通过 systemctl set-default graphical.target 命令设置图形化界面登陆并重启系统。系统启动后 单击“登录”按钮旁边的按钮。 在列表中选择“GNOME”。(默认为GNOME Classic模式) GNOME shell的启动后,如下所示: 三、安装 TigerVNC Server1. 安装TigerVNC Server建议使用非root用户安装,-y代表直接安装 sudo yum install-ytigervnc-server 2. 配置VNC Service以下方法是新方法,以前是要配置/etc/sysconfig/vncservers,现在第一步是将默认提供的文件复制到/etc/systemd/system,命令如下 sudo cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service 注意上述命令参数重的“@:1”,可以将数字1换成30000内的任意数字,“5900+数字”即为程序的显示(监听)端口,如”@:1″表示监听5901端口。 接下来修改该配置文件 sudo vim /etc/systemd/system/vncserver@:1.service 将其中替换为你想要的用户名,所有内容如下: # The vncserver service unit file # # Quick HowTo: # 1. Copy this file to /etc/systemd/system/[email protected] # 2. Replace 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@:.service` # # DO NOT RUN THIS SERVICE if your local area network is # untrusted! For a secure way of using VNC, you should # limit connections to the local host and then tunnel from # the machine you want to view VNC on (host A) to the machine # whose VNC output you want to view (host B) # # [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB # # this will open a connection on port 590N of your hostA to hostB's port 590M # (in fact, it ssh-connects to hostB and then connects to localhost (on hostB). # See the ssh man page for details on port forwarding) # # You can then point a VNC client on hostA at vncdisplay N of localhost and with # the help of ssh, you end up seeing what hostB makes available on port 590M # # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP. # # Use "-localhost" to prevent remote VNC clients connecting except when # doing so through a secure tunnel. See the "-via" option in the # `man vncviewer' manual page. [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 保存文件并退出vim,重新加载配置 sudo systemctl daemon-reload 也可以设置成开机启动 sudo systemctl enable vncserver@:1.service 3 修改防火墙首先判断firewalld是否启动,输入以下命令判断 sudo firewall-cmd --state 如果启动应该输出 running 如果是not running,执行下面命令 sudo systemctl start firewalld 添加端口号5901-5905 sudo firewall-cmd --permanent --zone=public --add-port=5901-5905/tcp 重新加载防火墙 sudo firewall-cmd --reload 可以使用下面命令查看端口号是否被加入 firewall-cmd --list-all-zones 5. 设置VNC密码 通过ssh,用oracle用户名登录到服务器,执行下面命令 vncserver 终端会提示你输入密码,如下 You will require a password to access your desktops. Password: Verify: xauth: file /home/oracle/.Xauthority does not exist New 'localhost.localdomain:1 (oracle)' desktop is localhost.localdomain:1 Creating default startup script /home/oracle/.vnc/xstartup Starting applications specified in /home/oracle/.vnc/xstartup Log file is /home/oracle/.vnc/localhost.localdomain:1.log 如果想修改密码,可以使用vncpasswd。现在已经有一个vnc服务在运行了,但我们需要使用刚刚配置的服务来启动,所以我们需要先杀死刚刚的vnc服务,使用下面命令。 vncserver -kill :1 接下来,重启我们配置的服务 sudo systemctl daemon-reload sudo systemctl restart vncserver@:1.service 使用下面命令查看该服务是否正确运行 sudo systemctl status vncserver@:1.service -l 如果正确启动,输出应为 ● vncserver@:2.service - Remote desktop service (VNC) Loaded: loaded (/etc/systemd/system/vncserver@:2.service; enabled; vendor preset: disabled) Active: active (running) since 日 2017-07-23 21:55:35 CST; 12h ago Process: 8720 ExecStart=/usr/sbin/runuser -l oracle -c /usr/bin/vncserver %i -geometry 1280x720 (code=exited, status=0/SUCCESS) Process: 8716 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS) Main PID: 8744 (Xvnc) CGroup: /system.slice/system-vncserver.slice/vncserver@:2.service ‣ 8744 /usr/bin/Xvnc :2 -desktop 127.0.0.1:2 (oracle) -auth /home/oracle/.Xauthority -geometry 1280x720 -rfbwait 30000 -rfbauth /home/oracle/.vnc/passwd -rfbport 5902 -fp catalogue:/etc/X11/fontpath.d -pn 7月 23 21:55:32 127.0.0.1 systemd[1]: Starting Remote desktop service (VNC)... 7月 23 21:55:35 127.0.0.1 systemd[1]: Started Remote desktop service (VNC). 如果想配置多用户同时访问,需要将上面vncserver@:1.service,改为vncserver@:2.service,然后配置其中用户名,再按以上步骤走一遍就可以了 四、客户端连接服务端配置完毕,接下来用客户端连接。 vnc是免费技术,许多客户端都支持该协议。本文采用App Store上免费的“Remote Desktop – VNC”软件进行连接,打开后软件界面如下: 在输入框填写服务器地址:vnc://ip:port,其中ip是服务器的ip或域名,port是监听的端口,例如5901。输入后按回车,弹出密码输入框,输入vncpasswd设置的密码。密码正确的话就可以看到服务器的图形桌面。 按回车键进入登录界面,输入登录用户名和密码进入系统。 接下来就可以做各种图形操作了。 |
CopyRight 2018-2019 实验室设备网 版权所有 |