Centos6.3 install KVM
One, install kvm
1 You can choose to install kvm when installing CentOS6.3
2 If kvm is not installed, please install it in the following way
[ Create local yum source]
Mount the iso file
mount -o loop -t iso9660 CentOS-6.3-x86_64-bin-DVD1.iso /mnt
Set up local yum source
Create a "arbitrary file name.repo" file in /etc/yum.repos.d/
vi Edit the file name just created
[Localyum] Any name without spaces.
name = local yum any name
baseurl=file:////mnt/Packages This path is customized. Server is the Server directory in the CD, and Packages and Server are placed in the same directory. That is under the /software directory
enabled=1 means effective 0 means not effective
gpgcheck=1 Check gpgkey 1 is effective 0 is not effective
gpgkey=file:///software There is this file in the installation CD. Not specified. During installation, you may be prompted that there is no registration
Save and exit
Execute the command yum clean all
(1) kvm needs to have CPU support (Intel VT or AMD SVM)
[ root@moniter ~]#egrep '^flags.*(vmx|svm)' /proc/cpuinfo
If there is a return value, the cpu supports virtualization
(2) Install kvm libvirted
yum install kvm kmod-kvm qemu kvm-qemu-img virt-viewer virt-manager libvirt libvirt-python python-virtinst
(3) Start libvirted
service messagebus start
service haldaemon start
service libvirtd start
chkconfig messagebus on
chkconfig haldaemon on
chkconfig libvirtd on
1 redhat6.3 running
(5) kvm module
[ root@myKVM ~]# lsmod | grep kvm
kvm_intel 52570 0
kvm 314739 1 kvm_intel
Second, configure the bridge
vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
BROADCAST=10.207.20.255
IPADDR=10.207.20.200
NETMASK=255.255.255.0
NETWORK=10.207.20.0
ONBOOT=yes
b、
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
BRIDGE=br0
c、
Restart the network service to take effect
service network restart
d、
echo 1> /proc/sys/net/ipv4/ip_forward #Virtual machine goes online
e、
Check the bridged network
[ root@moniter ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.842b2b74e1b6 no eth0
virbr0 8000.000000000000 yes
br0 is the bridged network card we configured, and virbr0 is the NAT network card automatically configured by the system script
Three, install vnc
Note: CentOS6.3 VNC is named rpm as tiggervnc-server
(1)
yum install tiggervnc-server
(2)
vi /etc/sysconfig/vncservers
VNCSERVERS="1:root"
(3)
vncpasswd
create password
(4)
/etc/init.d/vncserver start
(5)
tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 29167/Xvnc
tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 29167/Xvnc
tcp 0 0 :::6001 :::* LISTEN 29167/Xvnc
Indicates that vnc can be used
Modify the qemu.conf configuration, remove the comments in the following places, and then change the value of dynamic_ownership to 0 to prohibit libvirtd from dynamically modifying the file ownership: # vi /etc/libvirt/qemu.conf ...
user = "root"
group = "root"
dynamic_ownership = 0
...
Restart the libvirtd service and install it with the virt-install command above. At this time, the default binding of vnc is the local 127.0.0.1. If other machines want to use the vnc client to access the ubuntu that this kvm server is installing, then you need to bind vnc to the server's IP address or bind to the global 0.0.0.0 . Modify the qemu.conf file to cancel the comment in front of the vnc_listen line, remember to restart libvirtd: # vi /etc/libvirt/qemu.conf ...
vnc_listen = "0.0.0.0"
Fourth, create a kvm virtual machine
virsh-install
Parameter description Note that each line must be blank
-n virtual machine name
-r allocate virtual machine memory size
--vcpus allocates the number of virtual cpu
-c image file location
--vnc --vncport=5901 --vnclisten=0.0.0.0 start the graphical installation interface
--virt-type virtual machine mode
-f virtual machine system [file storage] (https://cloud.tencent.com/product/cfs?from=10680) directory
-s allocate disk size (GB)
-w networking mode (birdge bridge:br0/nat bridge:virbr0)
--os-type='windows' --os-variant=win2k3 It is best to add this to install windows, otherwise an error will be reported
After the virt-install tool installs the virtual machine, the xml configuration file is generated under the directory /etc/libvirt/qemu/
-s is used to specify the size of the virtual disk in GB
-m specifies the hardware address of the virtual network card, which is automatically generated by virt-install by default
-p Create a virtual machine in a paravirtualized manner
-l Specify the installation source
-x EXTRA, --extra-args=EXTRA When executing the client installation from the location specified by the "--location" option, append the kernel command line parameters to the installer.
-v, --hvm set full virtualization
virt-install --name=centos6.3 --ram 1024 --vcpus=2 --disk path=/data0/centos-6.3.x86_64.img.img,size=20 --accelerate --cdrom /data0/CentOS-6.3-x86_64-bin-DVD1.iso --graphics vnc,listen=0.0.0.0,port=5920, --network bridge=br0 --force --autostart
After execution, netstat -nulpt | grep 5920 to see if the port is enabled
Five, use vnc to connect 5920 to complete the installation
IP:5920
Six, manage kvm virtual machine
virsh --connect qemu:///system
a. If you modify the xml file of a client (located in the /etc/libvirt/qemu/ directory), you must redefine the client:
define /etc/libvirt/qemu/vm10.xml
b. Start and stop the client, run:
start vm10
c. Stop a client and run
shutdown vm10
d. Immediately interrupt a client (similar to turning off the power directly) and run
destroy vm10
e. Suspend a client:
suspend vm10
f. Restore the client:
resume vm10
Seven, clone
virt-clone --connect=qemu:///system \
New virtual machine configuration files need to pay attention: after the virtual machine is cloned, the vnc port needs to be modified; the MAC address also needs to be paid attention to.
Eight, load disk space
The added part is:
Make the configuration file effective
virsh --connect qemu:///system
virsh #define /etc/libvirt/qemu/winxp.xml
Restart the virtual machine to take effect
virsh # shutdown centos1
virsh # start centos1
Enter the virtual machine:
mkfs.ext3 /dev/hdb
mkdir /data
mount /dev/hdb /data
virt-install --name xp1 --hvm --ram 512 --vcpus 1 --disk path=/root/xp1.img,size=20 --network network:default --accelerate --vnc --vncport=5901 --cdrom /root/xp.iso -d
virt-install --name=wintest01 --ram 512 --vcpus=2 --disk path=/data/wintest01.img,size=8 --accelerate --cdrom /data/iso/Windows2003.iso --vnc --vncport=5911 --vnclisten=0.0.0.0 --network bridge=br0 --force --autostart
[ root@localhost ~]#virsh change-media win3test hdc /home/iso/virtio-win-0.1-52.iso
succeeded to complete action update on media
[ root@localhost ~]#virsh change-media win3test hdc --eject
Format conversion
qemu-img convert -f raw -O qcow2 disk2.img disk2.qcow2
Recommended Posts