Centos6.3 install KVM

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

(4) Check if kvm is installed successfully
[ root@jiayuan ~]# virsh -c qemu:///system list
Id name status

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

Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet

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

Add a line

VNCSERVERS="1:root"

(3)
vncpasswd

create password
(4)
/etc/init.d/vncserver start

(5)

netstat -nulpt | grep vnc

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

  1. Enter the name of the virtual machine
  2. How much memory is allocated
  3. The number of processors
  4. In this step, you can directly enter the iso location or url
  5. Virtual machine type KVM
  6. Define the location of the virtual machine disk image
  7. The size of the disk
  8. Specify which bridge or multiple bridges can be specified
  9. Additional console and KS files
  10. Connect to system parameters

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

qemu-img create -f qcow2 disk1.img 50G

vi /etc/libvirt/qemu/centos1.xml

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

Change iso image file

[ root@localhost ~]#virsh change-media win3test hdc /home/iso/virtio-win-0.1-52.iso
succeeded to complete action update on media

Popup image file

[ root@localhost ~]#virsh change-media win3test hdc --eject
Format conversion
qemu-img convert -f raw -O qcow2 disk2.img disk2.qcow2

  • f Source image format
  • O target image format

Recommended Posts

Centos6.3 install KVM
1.5 Install Centos7
Centos6 install Python2.7.13
Centos7.3 install nginx
CentOS7.2 install Mysql5.7.13
Centos7 install Python 3.6.
CentOS7 install MySQL
Centos7 install protobuf
CentOS 7 install Docker
CentOS7 install GlusterFS
CentOS7 install Docker
Centos6.5 install Tomcat
CentOS install Python 3.6
Vmware install CentOS6
centos7 install docker-ce 18.01.0
CentOS 7.2 install MariaDB
CentOS 7 install Hadoop 3.0.0
Centos7 install Python2.7
Centos 7.6 install seleniu
CentOS 7.3 install Zabbix3
Centos7 install LAMP+PHPmyadmin
CentOS install mysql
CentOS install openjdk 1.8
CENTOS6.5 install CDH5.12.1 (1)
CentOS install PHP
Centos7 install Docker
CentOS7 install mysql
centOs install rabbitMQ
CentOS 7 install MySQL 5.6
Centos7 install Nginx
CentOS6.5 install CDH5.13
Centos7 install docker18
Centos install Python3
centos7 install nginx-rtmp
CentOS8 install MySQL8.0
CentOS install PostgreSQL 9.1
CentOS7 install mysql8
CentOS 7 install Java 1.8
CentOS8 install fastdfs6.06
CentOS 7 install Gitlab
Centos 7 install PostgreSQL
CentOS7 install MySQL8
CentOS 7 install Java 1.8
CentOS 6 install Docker
centos 6.5 install zabbix 4.4
Centos8 install Docker
CentOS6.8 install python2.7
CentOS install nodejs 8
CentOS6.5 install GNS3
centos 7.5 install mysql5.7.17
Centos7 install MySQL8.0-manual
CentOS7 install Kubernetes 1.16.3
VirtualBox install centos7
centos7 install lamp
Graphic KVM to install CentOS7.6 operating system
Install Docker on Centos7
Centos7 install docker-18.x original
install LNMP on centos7.4
Centos7 YUM install MariaDB 10.0
CentOS 8 install ZABBIX4.4 guide
Install Java on Centos 7