KVM安装部署
KVM安装部署
一、先创建新虚拟机,配置好ip地址,关闭防火墙和selinux
#关闭selinux
[root@tools ~]# getenforce
Permissive
#关闭防火墙
[root@tools ~]# systemctl stop firewalld && systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
#配置ip地址
[root@tools ~]# tail -4 /etc/sysconfig/network-scripts/ifcfg-ens33
IPADDR=192.168.2.13
PREFIX=24
GATEWAY=192.168.2.2
DNS1=114.114.114.114
二、配置yum
#移动yum.repos.d下的所有文件到media中
[root@tools ~]# mv /etc/yum.repos.d/* /media/ | ll /etc/yum.repos.d/
total 0
#传输需要的yum文件进行挂载和制作repo源
[root@tools ~]# mv kvm_yum /opt/
[root@tools ~]# ll /opt/
total 0
drwxr-xr-x. 5 root root 53 Apr 6 12:44 kvm_yum
#制作yum源
[root@tools ~]# vim /etc/yum.repos.d/kvm.repo
[root@tools ~]# head -n 6 /etc/yum.repos.d/kvm.repo
[kvm]
name=kvm
baseurl=file:///opt/kvm_yum
gpgcheck=0
enabled=1
#验证源
[root@tools ~]# yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
kvm | 3.6 kB 00:00:00
(1/2): kvm/group_gz | 166 kB 00:00:00
(2/2): kvm/primary_db | 3.1 MB 00:00:00
repo id repo name status
kvm kvm 4,021
repolist: 4,021
三、安装kvm软件和工具并启动虚拟机
usage: qemu-kvm [options] [disk_image]
'disk_image' is a raw hard disk image for IDE hard disk 0
#需要安装的软件
[root@tools ~]# yum -y install qemu-kvm openssl libvirt
#启动libvirt服务
[root@tools ~]# systemctl start libvirtd
#给文件可执行权限
[root@tools ~]# chmod +x qemu-ifup-NAT.txt
[root@tools ~]# ll
-rw-r--r--. 1 root root 13287936 Apr 6 12:43 cirros-0.3.3-x86_64-disk.img
-rwxr-xr-x. 1 root root 2094 Apr 6 12:43 qemu-ifup-NAT.txt
#建立软连接,连接kvm的源文件
[root@tools ~]# ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm
[root@tools ~]# ll -d /usr/bin/qemu-kvm
lrwxrwxrwx. 1 root root 21 Apr 6 13:14 /usr/bin/qemu-kvm -> /usr/libexec/qemu-kvm
#启动kvm程序,启动虚拟机
[root@tools ~]# qemu-kvm -m 1024 -drive file=/root/cirros-0.3.3-x86_64.img,if=virtio -net nic,model=virtio -net tap,script=/root/qemu-ifup-NAT.txt -nographic -vnc :1
____ ____ ____
/ __/ __ ____ ____ / __ \/ __/
/ /__ / // __// __// /_/ /\ \
\___//_//_/ /_/ \____/___/
http://cirros-cloud.net
login as 'cirros' user. default password: 'cubswin:)'. use 'sudo' for root.
cirros login: cirros
Password:
$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.76/24 brd 192.168.122.255 scope global eth0
inet6 fe80::5054:ff:fe12:3456/64 scope link
valid_lft forever preferred_lft forever
本文来自博客园,作者:knsec,转载请注明原文链接:https://www.cnblogs.com/knsec-cnblogs/p/16582268.html