一、安装VNC
1.安装X-Window
yum groupinstall "X Window System" -y
yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts -y
2.设置默认启动图形界面
unlink /etc/systemd/system/default.target
ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
3.安装VNC服务器
yum install tigervnc-server -y
4.配置VNC
复制模板文件过来:
1
|
cp
/
lib
/
systemd
/
system
/
vncserver@.service
/
etc
/
systemd
/
system
/
vncserver@:
1.service
|
配置/etc/systemd/system/vncserver@:1.service文件,配置用于连接VNC的用户,替换掉下面的两个<USER>,在这里用root登录vnc(也可以是别的用户):
1
2
3
4
5
6
7
8
9
|
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
如果是别的普通用户就需要加上
/
home
ExecStart
=
/
sbin
/
runuser
-
l aaa
-
c
"/usr/bin/vncserver %i"
PIDFile
=
/
home
/
aaa
/
.vnc
/
%
H
%
i.pid
|
centos 7.3.1611安装配置文件变成如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[Unit]
Description
=
Remote desktop service (VNC)
After
=
syslog.target network.target
[Service]
Type
=
forking
User
=
root
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre
=
-
/
usr
/
bin
/
vncserver
-
kill
%
i
ExecStart
=
/
usr
/
bin
/
vncserver
%
i
PIDFile
=
/
root
/
.vnc
/
%
H
%
i.pid
ExecStop
=
-
/
usr
/
bin
/
vncserver
-
kill
%
i
[Install]
WantedBy
=
multi
-
user.target
|
配置完成后应用配置一下:
systemctl daemon-reload
5.配置VNC用户
设置vnc用户密码:
vncpassword
6.开启服务,设置开机启动
systemctl enable vncserver@:1.service
systemctl start vncserver@:1.service
或者启动vncserver服务:
vncserver
7.防火墙添加规则
firewall-cmd --permanent --add-service vnc-server
关闭selinux
vi /etc/sysconfig/selinux
SELINUX=disabled
8.使用vnc viewer客户端连接VNC服务端
下载地址:https://www.realvnc.com/download/viewer/
9.查看vnc日志:
grep vnc /var/log/messages
二、安装KVM
yum install kvm kmod-kvm kvm-qemu-img qemu-kvm libvirt libpciaccess-devel python-virtinst virt-manager virt-viewer bridge-utils tunctl bridge-utils avahi dmidecode qemu-kvm-tools qemu-img virt-install net-tools libguestfs-tools -y
检查模块加载:
lsmod | grep kvm
kvm_intel 162153 0
kvm 525409 1 kvm_intel
给KVM虚拟机配置桥接网络
1.在/etc/sysconfig/network-scripts目录下创建ifcfg-br0
添加一下内容,ip地址是你可以通过真实网卡去上网的网段。
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
NM_CONTR0LLED=no
BOOTPROTO=none
IPADDR=192.168.137.30
NETMASK=255.255.255.0
GATEWAY=192.168.137.1
2.编辑连接外网的网卡,一般是eth0或者em1,使br0网卡桥接到物理网卡:
修改一下内容:
BOOTPROTO=none
ONBOOT=yes
NM_CONTR0LLED=no
BRIDGE="br0"
3.systemctl disable NetworkManager.service
4.systemctl restart network.service
5.查看设置的ip是否生效:ip addr
6.使用Virtual Machine Manager创建管理虚拟机
当制作完镜像qcow2的时候,要上传到openstack,最好压缩一下镜像。
kvm压缩qcow2:
压缩办法:
qemu-img convert -c -O qcow2 /centos7.qcow2 /Centos7.qcow2
原文件:/centos7.qcow2
目标文件:/Centos7.qcow2
本文转自506554897 51CTO博客,原文链接:http://blog.51cto.com/506554897/1926638,如需转载请自行联系原作者