A.准备:
1.安装GNOME D
esktop
[root@p161 ~]#yum groupinstall 'GNOME Desktop'
2.确认GNOME Desktop 安装
[
root@p161 ~]# rpm -qa |grep gnome-desktop
gnome-desktop3-3.8.4-4.el7.x86_64
3.默认启动图形界面
[root@p161 ~]#
unlink /etc/systemd/system/default.target
[root@p161 ~]#
ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
4.查看CentOS 版本
[root@p161 ~]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
5.由于是第一次使用图形界面,需要在本机用root或要配置的账户登录一次才能进行VNC设置
B.安装
1.
[
root@p161
~]# yum -y install
tigervnc-server
2.
[
root@p161
~]#
cp /lib/systemd/system/
[email protected]
/lib/systemd/system/vncserver@:1.service
3.[root@p161 ~]# vim /lib/syste
md/system/vncserver@:1.service
将配置文件中<USER>改为用户名,如root
[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
root -c "/usr/bin/vncserver %i"
PIDFile=/
root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
注意默认的PIDFile后面有/home,当配置用户为root是要删除
4.重新加载系统配置
[root@p161 ~]#systemctl daemon-reload
5.关闭防火墙,或者增加VNCSERVER 配置,二选一
a.关闭
[
root@p161
~]#systemctl stop firewalld.service
[root@p161 ~]#systemctl disable firewalld.service
b.或者增加vnc-server通过:
[
root@p161
~]#
firewall-cmd --permanent --add-service vnc-server
success
[
root@p161
~]#
systemctl restart firewalld.service
6.设置用户VNC密码:
[
root@p161
~]#vncpasswd root
Password:
Verify:
注意:若不是用root账户,而是用hadoop用户,设置vncpasswd要到hadoop用户下面即先执行:
[
root@p161
~]#su hadoop
[
hadoop@p161
~]$vncpasswd hadoop
Password:
Verify:
在root下执行vncpasswd hadoop 不行,原因未知
7.服务配置
开启服务
[root@p161 ~]# systemctl start vncserver@:1.service
关闭服务:
[root@p161 ~]# systemctl stop vncserver@:1.service
重启服务:
[root@p161 ~]# systemctl restart vncserver@:1.service
自动启动
[
root@p161
~]# systemctl enable vncserver@:1.service
ln -s '/usr/lib/systemd/system/vncserver@:1.service' '/etc/systemd/system/multi-user.target.wants/vncserver@:1.service'
查询状态
[
root@p161
~]# systemctl status vncserver@:1.service
vncserver@:1.service - Remote desktop service (VNC)
Loaded: loaded (/usr/lib/systemd/system/vncserver@:1.service; enabled)
Active: active (running) since 一 2015-12-14 18:41:29 CST; 16s ago
Main PID: 5335 (Xvnc)
CGroup: /system.slice/system-vncserver.slice/vncserver@:1.service
‣ 5335 /usr/bin/Xvnc :1 -desktop p161:1 (root) -auth /root/.Xauthority -geometry 1024x768 -rfbwait 30000 -rfbauth /root/.vnc/passw...
12月 14 18:41:25 p161 systemd[1]: Starting Remote desktop service (VNC)...
12月 14 18:41:29 p161 systemd[1]: Started Remote desktop service (VNC).
8.在vnc viewer中连接地址里写上:
192.168.1.161:1
表示连接第一个桌面