OpenStack入门篇之KVM虚拟机介绍和管理
Posted linuxk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenStack入门篇之KVM虚拟机介绍和管理相关的知识,希望对你有一定的参考价值。
-
1.查看虚拟机,启动虚拟机
[[email protected] ~]# virsh list --all Id Name State ---------------------------------------------------- - CentOS-7-x86_64 shut off [[email protected]-node1 ~]# virsh start CentOS-7-x86_64
通过TightVNC连接,修改网络vi /etc/sysconfig/network-scripts/ifcfg-eth0
tips:
KVM虚拟机在宿主机上的体现是一个进程,可以通过ps axu |grep kvm进行查看。对KVM的管理,就是在宿主机上对KVM的进程进行管理。
-
2.libvirt介绍
libvirt组成部分:libvirt daemon后台进程,libvirt API库,User-space management tools
tips:
(1)如果libvirtd服务停用了,会影响命令行管理虚拟机,但不会影响虚拟机本身的运行。
(2)kvm是为openstack进行创建虚拟机,如果openstack服务停用,可以使用libvirtd服务命令行进行管理。
-
3.KVM常用管理:CPU,内存,网络
(1)libvirt通过对xml文件进行管理
[[email protected] ~]# cd /etc/libvirt/qemu [[email protected]-node1 qemu]# ls -l total 8 -rw-------. 1 root root 3855 Nov 27 10:00 CentOS-7-x86_64.xml drwx------. 3 root root 4096 Nov 27 09:33 networks
(2)CentOS-7-x86_64.xml是自动生成的,无法进行修改。如果需要修改,需要通过virsh edit进行编辑。但是在openstack上是无法进行修改的。
[[email protected] qemu]# virsh edit CentOS-7-x86_64
(3)KVM修改热添加:virsh edit CentOS-7-x86_64,热添加会影响系统的性能,不适合在生产环境使用
tips:KVM支持热添加,公有云是不支持热添加的。需要宿主机和虚拟机的系统保持一致性。
①cpu的热添加,将cpu核数改为2,openstack不支持
修改为:
[[email protected] qemu]# virsh setvcpus CentOS-7-x86_64 2 --live
②内存热添加
a.查看KVM内存:
[[email protected] ~]# virsh qemu-monitor-command CentOS-7-x86_64 --hmp --cmd info balloon balloon: actual=1024
b.修改,将内存调成512M:
[[email protected] ~]# virsh qemu-monitor-command CentOS-7-x86_64 --hmp --cmd balloon 512
c.增加内存:修改xml文件,修改完xml文件需要重启虚拟机
<memory unit=‘KiB‘>1048576</memory> 修改为: <memory unit=‘KiB‘>1548576</memory> <currentMemory unit=‘KiB‘>1048576</currentMemory> [[email protected]-node1 ~]# virsh shutdown CentOS-7-x86_64 [[email protected]-node1 ~]# virsh start CentOS-7-x86_64
(4)网络管理,配置KVM的桥接网络
[[email protected] ~]# brctl show bridge name bridge id STP enabled interfaces virbr0 8000.52540067fb26 yes virbr0-nic vnet
①创建桥接网卡,写成脚本
[[email protected] ~]# vim bridge.sh #!/bin/bash brctl addbr br0 brctl addif br0 ens33 ip addr del dev ens33 192.168.56.11/24 ifconfig br0 192.168.56.11/24 up route add default gw 192.168.56.2 [[email protected]-node1 ~]# brctl show bridge name bridge id STP enabled interfaces br0 8000.000c2903f3fe no eth0 virbr0 8000.52540067fb26 yes virbr0-nic vnet0
②修改xml
[[email protected] ~]# virsh edit CentOS-7-x86_64 interface type=‘network‘ 修改为 interface type=‘bridge‘ source network=‘default‘/ 修改为 source bridge=‘br0‘/
③重启KVM虚拟机
[[email protected] ~]# virsh shutdown CentOS-7-x86_64 Domain CentOS-7-x86_64 is being shutdown [[email protected]-node1 ~]# virsh start CentOS-7-x86_64 Domain CentOS-7-x86_64 started
④修改虚拟机网卡配置
[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 TYPE=Ethernet BOOTPROTO=static NAME=eth0 ONBOOT=yes IPADDR=192.168.56.111 NETMASK=255.255.255.0 GATEWAY=192.168.56.2 [[email protected] ~]# systemctl restart network
⑤验证宿主机上能否登陆
[[email protected] ~]# ping 192.168.56.111 PING 192.168.56.111 (192.168.56.111) 56(84) bytes of data. 64 bytes from 192.168.56.111: icmp_seq=1 ttl=64 time=0.618 ms 64 bytes from 192.168.56.111: icmp_seq=2 ttl=64 time=0.387 ms 64 bytes from 192.168.56.111: icmp_seq=3 ttl=64 time=0.264 ms 64 bytes from 192.168.56.111: icmp_seq=4 ttl=64 time=0.328 ms ^C --- 192.168.56.111 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3002ms rtt min/avg/max/mdev = 0.264/0.399/0.618/0.134 ms [[email protected]-node1 ~]# ssh 192.168.56.111 The authenticity of host ‘192.168.56.111 (192.168.56.111)‘ can‘t be established. ECDSA key fingerprint is SHA256:k6ODnQ4pdtSMtYrfti2wB8eB5/XfCENW0SWApJrHTgY. ECDSA key fingerprint is MD5:06:9f:34:32:b8:b2:a3:91:12:f9:3b:8c:dd:c0:e7:63. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added ‘192.168.56.111‘ (ECDSA) to the list of known hosts. [email protected]192.168.56.111‘s password: Last login: Mon Nov 27 11:44:22 2017
以上是关于OpenStack入门篇之KVM虚拟机介绍和管理的主要内容,如果未能解决你的问题,请参考以下文章
OpenStack入门篇之nova服务(控制节点)的部署与测试