Centos 7.0 安装VNC 并开机启动
零、 停止并禁用防火墙;
[root@7_test ~]# systemctl stop firewalld.service [root@7_test ~]# systemctl disable firewalld.service
一、安装图形界面,已安装的就跳过。
[root@7_test ~]# yum groupinstall "X Window System" [root@7_test ~]# yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts [root@7_test ~]# unlink /etc/systemd/system/default.target [root@7_test ~]# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target [root@7_test ~]# reboot
二、yum 安装vnc包
[root@7_test ~]# yum install tigervnc-server -y
三、修改配置信息
[root@7_test ~]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service [root@7_test ~]# vim /etc/systemd/system/vncserver@:1.service
修改前配置:
ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i" PIDFile=/home/<USER>/.vnc/%H%i.pid
修改后配置:
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i" PIDFile=/root/.vnc/%H%i.pid
四、重新加载systemd
[root@7_test ~]# systemctl daemon-reload
五、为vnc设定密码
[root@7_test ~]# vncpasswd
六、设置开机自动和启动服务
[root@7_test ~]# systemctl enable vncserver@:1.service Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver@:1.service to /etc/systemd/system/vncserver@:1.service.
启动报错:
[root@7_test ~]# systemctl start vncserver@:1.service Job for vncserver@:1.service failed because the control process exited with error code. See "systemctl status vncserver@:1.service" and "journalctl -xe" for details.
处理方法:1.
[root@7_test ~]# rm -rf /tmp/.X11-unix/*
处理方法:2.
有人说把 vncserver@:1.service 中的 Type 参数必为: simple (本人未验证)
[root@7_test ~]# systemctl enable vncserver@:1.service
Failed to issue method call: File exists
A: 此错误一般发生在systemctl enable创建系统连接到/etc/systemd/system/的时候。一般是在切换显示管理器(例如从 GDM 到 KDM)时出现,这时/etc/systemd/system/vncserver@:1.service 已经存在。 要解决此问题,使用 systemctl -f enable 覆盖原有链接,或者删除已经存在的链接:
[root@7_test ~]# rm -rf /etc/systemd/system/vncserver@:1.service.