不做过多介绍了,下面直接记录下CentOS7系统下安装配置vncserver的操作记录(测试机ip是192.168.1.8)
0)更改为启动桌面或命令行模式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
1)关闭防火墙
centos的防火墙是firewalld,关闭防火墙的命令
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
[root@localhost ~]# cat /etc/sysconfig/selinux
SELINUX=disabled
SELINUXTYPE=targeted
2)安装软件:
[root@localhost ~]# yum update
[root@localhost ~]# yum groupinstall "GNOME Desktop" "X Window System" "Desktop"
[root@localhost ~]# yum install tigervnc-server tigervnc vnc vnc-server
3)配置vnc连接
[root@localhost ~]# cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service
修改/etc/systemd/system/vncserver@:1.service
找到这一行
ExecStart=/sbin/runuser -l
PIDFile=/home/
这里直接用root 用户登录,所以我替换成
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
如果是其他用户的话比如john替换如下
ExecStart=/sbin/runuser -l john -c "/usr/bin/vncserver %i"
PIDFile=/home/john/.vnc/%H%i.pid
由于直接root用户登录,所以配置如下:
[root@localhost ~]# cat /etc/systemd/system/vncserver@:1.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 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
为VNC设密码(比如密码设置为123456)
[root@localhost ~]# vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n #注意表示"是否输入一个只能查看的密码,选择否",否则连接vnc会出现黑屏
A view-only password is not used
[root@localhost ~]# vim /etc/libvirt/qemu.conf
vnc_password = "123456"
vnc_listen = "0.0.0.0"
重加载 systemd
[root@localhost ~]# systemctl daemon-reload
启动vnc
[root@localhost ~]# systemctl enable vncserver@:1.service
[root@localhost ~]# systemctl start vncserver@:1.service
确认VNC服务端口(用于远程vnc连接使用,这里查看vnc端口是5901)
[root@localhost ~]# ps -ef|grep Xvnc
root 141698 1 0 13:09 ? 00:00:14 /usr/bin/Xvnc :11 -auth /root/.Xauthority -desktop kvm-server:11 (root) -fp catalogue:/etc/X11/fontpath.d -geometry 1024x768 -pn -rfbauth /root/.vnc/passwd -rfbport 5901 -rfbwait 30000
注意,这里测试机器关闭了防火墙
如果防火墙开了,需要开通一下规则:
[root@localhost ~]# firewall-cmd --permanent --add-service vnc-server
[root@localhost ~]# systemctl restart firewalld.service
如果是iptable,则需要在/etc/sysconfig/iptables里添加:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5903 -j ACCEPT
关闭vnc连接
[root@localhost ~]# /usr/bin/vncserver -kill :1
测试vnc连接(这种方式可用于在浏览器里通过http方式远程连接VNC,代替VNC客户端连接。注意这里vnc端口是5901)
[root@localhost ~]# novnc_server --vnc 192.168.1.8:5901 --listen 6081 #注意:"yum install -y novnc"安装novnc后才会有novnc_server命令工具
Warning: could not find self.pem
Starting webserver and WebSockets proxy on port 6081
WebSocket server settings:
- Listen on :6081
- Flash security policy server
- Web server. Web root: /usr/share/novnc
- No SSL/TLS support (no cert file)
- proxying from :6081 to 192.168.1.8:5901
Navigate to this URL:
http://kvm-server:6081/vnc.html?host=kvm-server&port=6081 #注意:这个是http方式连接vnc的地址
Press Ctrl-C to exit # 注意:如在浏览器里以http方式连接vnc,则这里不能按"Ctrl + C"结束,浏览器连接的日志信息会在这行下面输出
由于kvm-server的主机名对应ip是112.112.113.56,所以在浏览器里输入:
http://112.112.113.56:6081/vnc.html?host=112.112.113.56&port=6081 ,然后输入密码,就可以在浏览器里以http方式连接VNC服务了
1 2 3 4 5 6 7 8 9 10 |
|
问题:Could not make bus activated clients aware of XDG_CURRENT_DESKTOP=GNOME environment variable:
Could not connect: Connection refused
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
启动vncserver出现报错:
Error: Too many open files
Error getting authority: Error initializing authority: GDBus.Error:org.freedesktop.DBus.Error.LimitsExceeded: The maximum number of active connections for UID 0 has been reached (g-dbus-error-quark, 8)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|