- CentOS 7安裝TigerVNC Server
本文介紹如何在CentOS 7上安裝VNC Server侠草,以便遠程訪問。本文參照了DigitalOcean的教程犁嗅,加入了一些安裝經(jīng)驗边涕。
- 安裝TigerVNC Server
建議使用非root用戶安裝,-y代表直接安裝
sudo yum install -y tigervnc-server1
- 配置VNC Service
以下方法是新方法褂微,以前是要配置/etc/sysconfig/vncservers功蜓,現(xiàn)在第一步是將默認(rèn)提供的文件復(fù)制到/etc/systemd/system,命令如下
sudo cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service1
接下來修改該配置文件
sudo vim /etc/systemd/system/vncserver@:1.service1
將其中替換為你想要的用戶名宠蚂,我這里是oracle式撼,添加設(shè)置分辨率的參數(shù)-geometry 1280x720,所有內(nèi)容如下
# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@:.service
# 2. Edit and vncserver parameters appropriately
# ("runuser -l -c /usr/bin/vncserver %i -arg1 -arg2")
# 3. Run systemctl daemon-reload
# 4. Run systemctl enable vncserver@:<display>.service
#
. . .
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[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=/sbin/runuser -l oracle -c "/usr/bin/vncserver %i -geometry 1280x720"
PIDFile=/home/oracle/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target1234567891011121314151617181920212223242526
保存文件并退出vim求厕,重新加載配置
sudo systemctl daemon-reload1
也可以設(shè)置成開機啟動
sudo systemctl enable vncserver@:1.service1
- 修改防火墻
首先判斷firewalld是否啟動著隆,輸入以下命令判斷
sudo firewall-cmd --state1
如果啟動應(yīng)該輸出
running1
如果是not running,執(zhí)行下面命令
sudo systemctl start firewalld1
添加端口號5901-5905
sudo firewall-cmd --permanent --zone=public --add-port=5901-5905/tcp1
重新加載防火墻
sudo firewall-cmd --reload1
可以使用下面命令查看端口號是否被加入
firewall-cmd --list-all-zones1
- 設(shè)置VNC密碼
通過ssh呀癣,用oracle用戶名登錄到服務(wù)器美浦,執(zhí)行下面命令
vncserver1
終端會提示你輸入密碼,如下
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.log12345678910
如果想修改密碼项栏,可以使用vncpasswd∑直妫現(xiàn)在已經(jīng)有一個vnc服務(wù)在運行了,但我們需要使用剛剛配置的服務(wù)來啟動沼沈,所以我們需要先殺死剛剛的vnc服務(wù)流酬,使用下面命令。
vncserver -kill :11
接下來列另,重啟我們配置的服務(wù)
sudo systemctl daemon-reload
sudo systemctl restart vncserver@:1.service12
使用下面命令查看該服務(wù)是否正確運行
sudo systemctl status vncserver@:1.service -l1
如果正確啟動芽腾,輸出應(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).
123456789101112
如果想配置多用戶同時訪問,需要將上面vncserver@:1.service页衙,改為vncserver@:2.service摊滔,然后配置其中用戶名、分辨率參數(shù)拷姿,再按我的步驟走一遍就可以了