溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Centos7.7安裝vncserver虛擬網絡控制臺

發(fā)布時間:2020-08-04 21:05:30 來源:ITPUB博客 閱讀:395 作者:安全劍客 欄目:建站服務器
虛擬網絡控制臺(VNC)是一個圖形桌面共享軟件,允許您使用鍵盤和鼠標遠程控制另一臺計算機。
系統(tǒng)環(huán)境
  • 服務端: Centos7.7 Minimal
  • 客戶端:Windows10
  • 客戶端VNC-Viewer 6.20下載地址:https://www.realvnc.com/en/connect/download/viewer/
安裝桌面環(huán)境

本實驗中安裝的系統(tǒng)沒有安裝桌面環(huán)境,我們需要自己安裝,如果已經安裝桌面了清跳過這一步。Centos7提供了"Cinnamon Desktop","MATE Desktop","GNOME Desktop","KDE Plasma Workspaces","LXQt Desktop","Xfce"讓我們安裝。

下面的 命令列出可用環(huán)境組:

[root@localhost ~]# yum grouplist
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Cinnamon Desktop
   MATE Desktop
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Cinnamon
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Educational Software
   Electronic Lab
   Fedora Packager
   General Purpose Desktop
   Graphical Administration Tools
   Haskell
   LXQt Desktop
   Legacy UNIX Compatibility
   MATE
   Milkymist
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
   TurboGears application framework
   Xfce
Done

我們可以選擇自己喜歡的桌面環(huán)境,在這里選擇安裝Xfce桌面:

[root@localhost ~]# yum -y install epel-release && yum groupinstall Xfce
創(chuàng)建一個用戶
[root@localhost ~]# useradd user1
[root@localhost ~]# echo '123456'|passwd --stdin user1
[root@localhost ~]# usermod -a -G wheel user1
安裝VNC Server

在Centos倉庫默認提供的是TigerVNC安裝包,我們就安裝這個:

[root@localhost ~]# yum -y install tigervnc-server tigervnc-server-module

切換到user1用戶,運行 vncserver 命令創(chuàng)建一個初始配置并設置密碼:

[root@localhost ~]# su - user1
[user1@localhost ~]$ vncserver :2
You will require a password to access your desktops.
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
New 'localhost.localdomain:2 (user1)' desktop is localhost.localdomain:2
Starting applications specified in /home/user1/.vnc/xstartup
Log file is /home/user1/.vnc/localhost.localdomain:2.log

然后停止vncserver服務,目的就是創(chuàng)建密碼和.vnc下面的文件。

[user1@localhost ~]$ vncserver -kill :2
配置VNC Server

編輯用戶家目錄下面的.vnc/xstartup文件

[user1@localhost ~]$ vim ~/.vnc/xstartup
#!/bin/sh
xrdb $HOME/.Xresources
#xsetroot -solid grey
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &
startxfce4 &

如果需要修改屏幕分辨率,可以修改~/.vnc/config文件,取消gemoetry前面的注釋。

[user1@localhost ~]$ vim .vnc/config
## Supported server options to pass to vncserver upon invocation can be listed
## in this file. See the following manpages for more: vncserver(1) Xvnc(1).
## Several common ones are shown below. Uncomment and modify to your liking.
##
# securitytypes=vncauth,tlsvnc
# desktop=sandbox
geometry=1920x1080
# localhost
# alwaysshared
創(chuàng)建 Systemd Unit文件

Unit文件方便快速的啟動,停止,重啟服務

[user1@localhost ~]$ sudo cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service

編輯vncserver@:2.service,替換文件里面的<user>為user1用戶, Type由默認的forking改為simple

[user1@localhost ~]$ vim /etc/systemd/system/vncserver\@\:2.service
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=simple
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l user1 -c "/usr/bin/vncserver %i"
PIDFile=/home/user1/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target

啟動vncserver服務

#重新加載管理器配置
[user1@localhost ~]$ sudo systemctl daemon-reload
#啟動vncserver
[user1@localhost ~]$ sudo systemctl start vncserver@:2
客戶端遠程連接測試

在windows10客戶端打開VNC Viewer,輸入地址和會話端口號:
Centos7.7安裝vncserver虛擬網絡控制臺
Centos7.7安裝vncserver虛擬網絡控制臺
Centos7.7安裝vncserver虛擬網絡控制臺

總結

如果需要將VNC服務器配置為多個用戶啟動顯示,請使用vncserver命令創(chuàng)建初始配置并設置密碼,然后使用其他端口創(chuàng)建新的服務文件。

原文地址: https://www.linuxprobe.com/centos7-virtual-network-console.html

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI