在安装vnc server首先要确保有图形界面,所以我们先安装gnome
首先查看可以安装的软件包组表单
[root@localhost ~]# yum grouplist
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Available Environment Groups:
Minimal Install
Infrastructure Server
File and Print Server
Basic Web Server
Virtualization Host
Server with GUI
Available Groups:
Compatibility Libraries
Console Internet Tools
Development Tools
Graphical Administration Tools
Legacy UNIX Compatibility
Scientific Support
Security Tools
Smart Card Support
System Administration Tools
System Management
Done
然后安装server with gui
yum groupinstall -y "Server with GUI"
然后就可以启动图形界面了
[root@localhost ~]# startx
最后设置图形界面为开机启动的
[root@localhost ~]# systemctl get-default
multi-user.target
You have new mail in /var/spool/mail/root
[root@localhost ~]# cat /etc/inittab
# inittab is no longer used when using systemd.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
#
# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
#
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
#
# To view current default target, run:
# systemctl get-default
#
# To set a default target, run:
# systemctl set-default TARGET.target
#
[root@localhost ~]# systemctl set-default graphical.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.
[root@localhost ~]# systemctl get-default
graphical.target
[root@localhost ~]# reboot
最后安装vnc
[root@localhost ~]# yum -y install vnc *vnc-server*
设置vnc
[root@localhost ~]# cd /lib/systemd/system
[root@localhost system]# ls | grep vnc
[email protected]
[root@localhost system]# cp [email protected] vncserver@:1.service
编辑vncserver@:1.service
将ExecStart和PIDFile中的
[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=/usr/sbin/runuser -l -c "/usr/bin/vncserver %i"
PIDFile=/home//.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
[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=/usr/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 || :'
[Install]
WantedBy=multi-user.target
然后重新载入systemd
[root@vnc system]# systemctl daemon-reload
开启vnc发现报错
[root@vnc system]# 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.
换一种启动方式
[root@vnc ~]# vncserver :1
You will require a password to access your desktops.
Password:
Verify:
xauth: (stdin):1: bad display name "vnc:1" in "add" command
New 'vnc:1 (root)' desktop is vnc:1
Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/vnc:1.log
设置vnc root登录的密码
[root@vnc system]# vncpasswd root
Password:
Verify:
再次使用systemctl的方式启动依然报错
[root@vnc ~]# 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.
但是在windows上使用vnc软件可以连接了 输入ip:1的方式连接
最后设置vnc服务为自启动
[root@vnc ~]# systemctl enable vncserver@:1.service
经测试重启后vnc服务依然可用,且vncserver@:1.service服务已可用
[root@vnc ~]# systemctl status vncserver@\:1.service
● vncserver@:1.service - Remote desktop service (VNC)
Loaded: loaded (/usr/lib/systemd/system/vncserver@:1.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2018-11-06 10:24:06 CST; 57s ago
Process: 861 ExecStart=/usr/sbin/runuser -l root -c /usr/bin/vncserver %i (code=exited, status=0/SUCCESS)
Process: 803 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
Main PID: 1158 (Xvnc)
CGroup: /system.slice/system-vncserver.slice/vncserver@:1.service
‣ 1158 /usr/bin/Xvnc :1 -desktop vnc:1 (root) -auth /root/.Xauthority -geometry 10...
Nov 06 10:24:01 vnc systemd[1]: Starting Remote desktop service (VNC)...
Nov 06 10:24:06 vnc systemd[1]: Started Remote desktop service (VNC).
[root@vnc ~]# systemctl restart vncserver@:1.service
[root@vnc ~]#
所以我认为应该是执行vncserver :1后直接重启即无异常
如果要添加其他用户的话
[root@vnc system]# cp vncserver\@.service vncserver\@:2.service
[root@vnc system]# vim vncserver\@:2.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=/usr/sbin/runuser -l cddba -c "/usr/bin/vncserver %i"
PIDFile=/home/cddba/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
[root@vnc system]# su - cddba
[cddba@vnc ~]$ vncserver :2
You will require a password to access your desktops.
Password:
Verify:
xauth: file /home/cddba/.Xauthority does not exist
xauth: (stdin):1: bad display name "vnc:2" in "add" command
New 'vnc:2 (cddba)' desktop is vnc:2
Creating default startup script /home/cddba/.vnc/xstartup
Starting applications specified in /home/cddba/.vnc/xstartup
Log file is /home/cddba/.vnc/vnc:2.log
其他用户因为权限问题,不能用systemctl 设置开机自启动.
thanks~
.
.
!