新聞中心
VNC (Virtual Network Console)是虛擬網(wǎng)絡(luò)控制臺的縮寫。它 是一款優(yōu)秀的遠程控制工具軟件,由著名的 AT&T 的歐洲研究實驗室開發(fā)的。VNC 是在基于 UNIX 和 Linux 操作系統(tǒng)的免費的開源軟件,遠程控制能力強大,高效實用,其性能可以和 Windows 和 MAC 中的任何遠程控制軟件媲美,本篇文章重點為大家講解一下Centos中安裝vncserver具體方法。

img
系統(tǒng)環(huán)境
-
服務(wù)端:Centos7.7 Minimal
-
客戶端:Windows10
-
客戶端VNC-Viewer 6.20下載地址:https://www.realvnc.com/en/connect/download/viewer/
安裝桌面環(huán)境
本實驗中安裝的系統(tǒng)沒有安裝桌面環(huán)境,我們需要自己安裝,如果已經(jīng)安裝桌面了清跳過這一步。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)建一個初始配置并設(shè)置密碼:
[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服務(wù),目的就是創(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文件方便快速的啟動,停止,重啟服務(wù)
[user1@localhost ~]$ sudo cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service
編輯vncserver@:2.service,替換文件里面的為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服務(wù)
#重新加載管理器配置
[user1@localhost ~]$ sudo systemctl daemon-reload
#啟動vncserver
[user1@localhost ~]$ sudo systemctl start vncserver@:2
客戶端遠程連接測試
在windows10客戶端打開VNC Viewer,輸入地址和會話端口號:
總結(jié)
如果需要將VNC服務(wù)器配置為多個用戶啟動顯示,請使用vncserver命令創(chuàng)建初始配置并設(shè)置密碼,然后使用其他端口創(chuàng)建新的服務(wù)文件。
文章標題:Centos中安裝vncserver具體方法
地址分享:http://www.dlmjj.cn/article/dpiscch.html


咨詢
建站咨詢
