yum install kvm kmod-kvm qemu kvm-qemu-img virt-viewer virt-manager libvirt libvirt-python python-virtinst
#yum -y install qemu-kvm libvirt python-virtinst bridge-utils policycoreutils-python;
mkdir /home/vhosts;
semanage fcontext -a -t virt_image_t /home/vhosts;#这个主要是打开SELinux设定,不然虚拟机无法访问存储文件
如果没有semanage,那么安装policycoreutils-python
添加防火墙规则 vi /etc/sysconfig/iptables
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5920 -j ACCEPT;
iptables -A INPUT -p udp --dport 161 -j ACCEPT;
service iptables save;
service iptables restart;
sed -i s/192.168.122/10.1.0/g /etc/libvirt/qemu/networks/default.xml;
chkconfig libvirtd on;
service libvirtd start;
virsh pool-define-as vmpool --type dir --target /home/vhosts;定义池
virsh pool-start vmpool;开始池
virsh pool-autostart vmpool;自启动
yum install net-snmp -y;
sed -i s/'default public'/'0.0.0.0 zhxgsnmp'/g /etc/snmp/snmpd.conf; #替换
sed -i '54 aview systemview included .1' /etc/snmp/snmpd.conf; #
chkconfig snmpd on;
service snmpd start;
[root@ZHWP_01 ~]# qemu-img create -f qcow2 /home/vhosts/An_ceshi.qcow2 50G (50G硬盘,必须通过) An_ceshi 虚机名称 qemu-img创建qcow2格式文件
[root@ZHWP_01 ~]#chown qemu:qemu /home/vhosts/An_ceshi.qcow2
[root@ZHWP_01 ~]#virt-install --name zhao02_redis --ram 65536 --vcpus=8 --arch=x86_64 --disk path=/home/vhosts/zhao02_redis.qcow2,size=100,format=qcow2 --os-type=linux --os-variant='rhel6' --accelerate --cdrom=/home/software/CentOS-6.5-x86_64-minimal.iso --graphic type=vnc,port=-1,listen=0.0.0.0,password='cqmygysdss' --network bridge=br1
安装linux:
virt-install --name test_java02 --ram 8192 --vcpus=4 --arch=x86_64 --disk path=/home/vhosts/test_java02.qcow2,size=50,format=qcow2 --os-type=linux --os-variant='rhel6' --accelerate --cdrom=/home/software/CentOS-6.8-x86_64-minimal.iso --graphic type=vnc,port=-1,listen=0.0.0.0,password='cqmygysdss' --network bridge=br0
安装windows:
virt-install --name server02vm03_windows --ram 8192 --vcpus=4 --arch=x86_64 --disk path=/home/vhosts/server02vm03_windows.qcow2,size=200,format=qcow2 --os-type=windows --os-variant=win2k8 --accelerate --cdrom=/home/cn_windows_server_2012_r2_x64_dvd_2707961.iso --graphics type=vnc,port=-1,password='passw0rd',listen=0.0.0.0 --network bridge=br0
#virsh destroy centos6.5
#cd /etc/libvirt/qemu
#mv centos6.5.xml spider.xml
#vi spider.xml 修改name字段为spider
#virsh undefine centos6.5 #取消定义
#virsh define /etc/libvirt/qemu/spider.xml
#virsh start spider
virsh list --all
virsh edit test
virsh define test
virt-clone -o test -n tesst1 -f /home/vhosts/test1.qcow2
桥接网络:
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=none
NAME=br0
IPADDR=192.168.182.201
PREFIX=18
DEVICE=eth0
ONBOOT=yes
BRIDGE="br0"