• centos kvm


    http://linux.dell.com/files/whitepapers/KVM_Virtualization_in_RHEL_6_made_easy.pdf
    http://linux.dell.com/files/whitepapers/KVM_Virtualization_in_RHEL_6_Made_Easy_Part2.pdf

    # grep -E 'svm|vmx' /proc/cpuinfo
    vmx is for Intel processors
    svm is for AMD processors
    
    # lsmod  |grep kvm
    kvm_intel              54285  0 
    kvm                   333172  1 kvm_intel
    
    # yum install kvm python-virtinst libvirt libvirt-python virt-manager virt-viewer libguestfs-tools device-mapper-event-libs
    
    # cat > /etc/sysconfig/network-scripts/ifcfg-br0 << _EOF_
    DEVICE=br0
    TYPE=Bridge
    BOOTPROTO=static
    IPADDR=10.160.1.221
    NETMASK=255.255.255.0
    ONBOOT=yes
    _EOF_
    
    # cat > /etc/sysconfig/network-scripts/ifcfg-em1 << _EOF_
    DEVICE=em1
    BRIDGE=br0
    ONBOOT=yes
    _EOF_
    
    # /etc/init.d/libvirtd start && chkconfig libvirtd on
    
    qemu-img create -f qcow2 -o preallocation=metadata /opt/kvm/kvm-1-91.qcow2 300g
    
    #http安装(ip地址dhcp分配)
    virt-install 
    --name=kvm-1-91 --os-variant=rhel6 
    --ram=4096 --vcpus=2 
    --network bridge=br0,model=virtio,mac=00:58:ef:00:00:01 
    --disk path=/opt/kvm/kvm-1-91.qcow2,size=300,format=qcow2,bus=virtio,cache=writeback 
    --noapic --accelerate 
    --location=http://us.install.suntv.tv/centos6 
    --extra-args='ks=http://us.install.suntv.tv/kickstart/00:58:ef:00:00:01 ksdevice=link ramdisk_size=102400 console=ttyS0,115200'
    
    如果ip地址是静态的话,修改2个地方
    1 00:58:ef:00:00:01 kickstart文件里 network部分
    2 extra-args='ks=http://us.install.suntv.tv/kickstart/00:58:ef:00:00:01 ksdevice=link ramdisk_size=102400 console=ttyS0,115200'里需要添加ip=xxx.xxx.xxx.xxx netmask=xxx.xxx.xxx.xxx gateway=xxx.xxx.xxx.xxx nameserver=xxx.xxx.xxx.xxx
    
    
    # 线上使用
    qemu-img create -f qcow2 -o preallocation=metadata /opt/kvm/kvm-48-115.qcow2 30g
    
    virt-install --name=kvm-48-115 --os-variant=rhel6 --ram=2048 --vcpus=1 --network bridge=br0,model=virtio,mac=00:58:ef:00:00:05 --disk path=/opt/kvm/kvm-48-115.qcow2,size=30,format=qcow2,bus=virtio,cache=writeback --graphics none --noapic --accelerate --location=http://install.local/centos-6 --extra-args='ks=http://install.local/kickstart/kvm-centos-6.cfg ksdevice=link ramdisk_size=102400 console=ttyS0,115200'
    
    #pxe安装
    virt-install 
    --name=la-kvm-01 --os-variant=rhel6 
    --ram=4096 --vcpus=2 
    --network bridge=br0,model=virtio,mac=00:58:ef:00:00:01 
    --disk path=/opt/kvm/la-kvm-01.qcow2,size=500,format=qcow2,bus=virtio,cache=writeback 
    --noapic --accelerate 
    --pxe
    
    #iso安装
    virt-install 
    --os-variant=rhel7 
    --name=centos7 
    --ram=2048 --vcpus=1 
    --network bridge=br0,model=virtio 
    --disk path=/data/vm/centos7.qcow2,size=30,format=qcow2,bus=virtio,cache=writeback 
    --noapic --accelerate 
    --location=/data/iso/CentOS-7-x86_64-Minimal-1810.iso 
    --graphics none 
    --extra-args='console=ttyS0,115200n8 serial'
    # 上面是文本界面,图形界面最后2行替换
    --graphics  vnc,listen=0.0.0.0
    --noautoconsole
    
    Q: ERROR    Guest name 'la-kvm-01' is already in use.
    A:
    virsh destroy la-kvm-01
    virsh undefine la-kvm-01
    
    connect: virsh console la-kvm-01
    disconnect: Ctrl+]
    
    /etc/libvirt/qemu
    /var/lib/libvirt/qemu
    
    # 初始配置完成后建立第1个快照,用于快速恢复环境
    virsh snapshot-create-as kvm-70-101 init
    
    
    # 利用初始化好的虚拟机,克隆快速建立多台虚拟机 
    virsh shutdown kvm-70-101
    virt-clone -o kvm-70-101 -n kvm-70-102 -f /opt/kvm/kvm-70-102.qcow2
    
    # 改变虚拟机的cpu核数,最大内存及当前内存
    virsh setmaxmem kvm-70-105 4G --config
    virsh setmem kvm-70-105 4G --live
    virsh setvcpus kvm-70-105 4
    
    virsh dominfo kvm-70-105 (或者查看/etc/libvirt/qemu/kvm-70-105.xml)
    
    # 虚拟机的vcpu绑定物理cpu
    virsh vcpupin kvm-70-101 0 0
    virsh vcpupin kvm-70-101 1 1
    
    virsh vcpupin kvm-70-102 0 2
    virsh vcpupin kvm-70-102 1 3
    
    virsh vcpupin kvm-70-103 0 4
    virsh vcpupin kvm-70-103 1 5
    
    virsh vcpupin kvm-70-104 0 6
    virsh vcpupin kvm-70-104 1 7
    
    virsh vcpupin kvm-70-105 0 8
    virsh vcpupin kvm-70-105 1 9
    
    # 变更虚拟机配置
    1. 关闭虚拟机
    virsh shutdown vm1
    
    2. 修改内存大小、vcpu个数
    virsh edit vm1
    
    3. 配置文件启动虚拟机
    virsh create /etc/libvirt/qemu/vm1.xml
    
  • 相关阅读:
    uiautomator2自动化测试
    APP性能测试(电池电量、流量、CPU、内存)
    python虚拟环境搭建
    unittest报错(return self._request(command_info[0], url, body=data))
    python pip错误处理
    adb 实用命令
    大数据学习(一)
    windows 下Virtualenv搭建mysql环境
    python奇怪毛病集合
    python作业
  • 原文地址:https://www.cnblogs.com/liujitao79/p/5531277.html
Copyright © 2020-2023  润新知