一.安裝 GNOME-Desktop桌面環(huán)境
1、安裝 GNOME
# yum -y groups install"GNOME Desktop"
2贯涎、完成安裝后,使用如下命令啟動桌面
# startx
首次啟動塘雳,進行一些初始設(shè)置
選擇系統(tǒng)語言
選擇鍵盤類型
添加在線用戶(可選)
開始使用
啟動后的桌面環(huán)境败明,如下所示:
二妻顶、使用GNOME Shell
CentOS 7的默認GNOME桌面以經(jīng)典模式開始,但如果您想使用GNOME Shell沸呐,請設(shè)置如下:
方式一:如果以?startx?命令啟動GNOME呢燥,設(shè)置如下:
#echo"exec gnome-session">> ~/.xinitrc# startx
方式二:通過?systemctl set-default graphical.target?命令設(shè)置圖形化界面登陸并重啟系統(tǒng)叛氨。系統(tǒng)啟動后
單擊“登錄”按鈕旁邊的按鈕寞埠。
在列表中選擇“GNOME”。(默認為GNOME Classic模式)
GNOME shell的啟動后,如下所示:
三、安裝 TigerVNC Server
1. 安裝TigerVNC Server
建議使用非root用戶安裝使鹅,-y代表直接安裝
sudo yum install-ytigervnc-server
2. 配置VNC Service
以下方法是新方法昌抠,以前是要配置/etc/sysconfig/vncservers炊苫,現(xiàn)在第一步是將默認提供的文件復(fù)制到/etc/systemd/system侨艾,命令如下
sudo cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
注意上述命令參數(shù)重的“@:1”,可以將數(shù)字1換成30000內(nèi)的任意數(shù)字袋励,“5900+數(shù)字”即為程序的顯示(監(jiān)聽)端口插龄,如”@:1″表示監(jiān)聽5901端口。
接下來修改該配置文件
sudo vim /etc/systemd/system/vncserver@:1.service
將其中<USER>替換為你想要的用戶名糠雨,所有內(nèi)容如下:
# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@.service
# 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`
#
# 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
也可以設(shè)置成開機啟動
sudo systemctl enable vncserver@:1.service
3 修改防火墻
首先判斷firewalld是否啟動松邪,輸入以下命令判斷
sudo firewall-cmd --state
如果啟動應(yīng)該輸出
running
如果是not running逗抑,執(zhí)行下面命令
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. 設(shè)置VNC密碼
通過ssh邮府,用oracle用戶名登錄到服務(wù)器溉奕,執(zhí)行下面命令
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〉現(xiàn)在已經(jīng)有一個vnc服務(wù)在運行了卫枝,但我們需要使用剛剛配置的服務(wù)來啟動校赤,所以我們需要先殺死剛剛的vnc服務(wù)马篮,使用下面命令怜奖。
vncserver -kill :1
接下來,重啟我們配置的服務(wù)
sudo systemctl daemon-reload
sudo systemctl restart vncserver@:1.service
使用下面命令查看該服務(wù)是否正確運行
sudo systemctl status vncserver@:1.service -l
如果正確啟動掷匠,輸出應(yīng)為
● 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讹语,然后配置其中用戶名,再按以上步驟走一遍就可以了
四蜂科、客戶端連接
服務(wù)端配置完畢顽决,接下來用客戶端連接。
vnc是免費技術(shù)导匣,許多客戶端都支持該協(xié)議才菠。本文采用App Store上免費的“Remote Desktop – VNC”軟件進行連接,打開后軟件界面如下:
在輸入框填寫服務(wù)器地址:vnc://ip:port贡定,其中ip是服務(wù)器的ip或域名,port是監(jiān)聽的端口缓待,例如5901进每。輸入后按回車,彈出密碼輸入框命斧,輸入vncpasswd設(shè)置的密碼田晚。密碼正確的話就可以看到服務(wù)器的圖形桌面。
按回車鍵進入登錄界面国葬,輸入登錄用戶名和密碼進入系統(tǒng)贤徒。
接下來就可以做各種圖形操作了。