Trang chủ » Hướng dẫn tạo máy ảo trên KVM – CentOS 7 (phần 1)

Hướng dẫn tạo máy ảo trên KVM – CentOS 7 (phần 1)

bởi Vinh Leo
2,3K views
5/5 - (2 bình chọn)

Cài đặt GuestOS và tạo một máy ảo cho KVM trên CentOS 7.

Cài đặt GuestOS

[root@hocmangmaytinh ~]# mkdir -p /var/kvm/images # create a new Storage Pool
[root@hocmangmaytinh ~]# virt-install \
# tên của máy ảo
--name centos7 \
# số lượng bộ nhớ Ram của máy ảo
--ram 4096 \
# vị trí của ổ đĩa của máy ảo và số lượng đĩa của máy ảo
--disk path=/var/kvm/images/centos7.img,size=30 \
# các CPU ảo
--vcpus 2 \
# loại GuestOS
--os-type linux \
--os-variant rhel7 \
# các loại mạng của máy ảo
--network bridge=br0 \
# coại hình đồ họa
--graphics none \
# kiểu điều khiển
--console pty,target_type=serial \
# xác định vị trí lắp đặt từ

--location 'http://ftp.iij.ad.jp/pub/linux/centos/7/os/x86_64/' \
#  các tham số được đặt trong kernel
--extra-args 'console=ttyS0,115200n8 serial'
Starting install...# bắt đầu cài đặt

Sau khi cài đặt xong, khởi động lại và đăng nhập

CentOS Linux 7 (Core)
Kernel 3.10.0-123.el7.x86_64 on an x86_64

localhost login:
[root@localhost ~]# # nhấn Ctrl + ]
[root@hocmangmaytinh ~]# # Host's console
[root@hocmangmaytinh ~]# virt-clone --original centos7 --name template --file /var/kvm/images/template.img 
Allocating 'template.img' | 20 GB 01:44
Clone 'template' created successfully.

# disk image

[root@hocmangmaytinh ~]# ll /var/kvm/images/template.img
-rwxr-xr-x 1 root root 32212254720 Jul 11 23:34 /var/kvm/images/template.img

# xml file

[root@hocmangmaytinh ~]# ll /etc/libvirt/qemu/template.xml  
-rw------- 1 root root 1843 Jul 11 23:32 /etc/libvirt/qemu/template.xml

Xác định một Storage Pool mới.

[root@hocmangmaytinh ~]# mkdir /etc/libvirt/storage
[root@hocmangmaytinh ~]# vi /etc/libvirt/storage/disk01.xml

# xác định pool

[root@hocmangmaytinh ~]# virsh pool-define /etc/libvirt/storage/disk01.xml
Pool disk01 defined from /etc/libvirt/storage/disk01.xml

# bắt đầu pool

[root@hocmangmaytinh ~]# virsh pool-start disk01
Pool disk01 started

# đặt auto-start

[root@hocmangmaytinh ~]# virsh pool-autostart disk01
Pool disk01 marked as autostarted

# xác nhận hiển thị danh sách pool

[root@hocmangmaytinh ~]# virsh pool-list
Name State Autostart
-----------------------------------------
disk01 active yes

# hiện thị pool chi tiết

[root@hocmangmaytinh ~]# virsh pool-info disk01
Name:           disk01
UUID:           2de62477-7132-4512-b5d8-003e28da105c
State:          running
Persistent:     yes
Autostart:      yes
Capacity:       197.17 GiB
Allocation:     2.90 GiB
Available:      194.27 GiB

Chúc các bạn thành công! Mọi thắc mắc, cần hỗ trợ hãy bình luận bên dưới hoặc qua Fanpage Facebook, form liên hệ.

Xem tiếp các bài trong Series Học CentOS 7 căn bản

CÓ THỂ BẠN QUAN TÂM

Subscribe
Thông báo cho
guest
0 Góp ý
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x