使用KVM创建虚拟机

一.保持自己的Linux系统能连接上外网

二.上传实验环境所需要的软件包至/opt/目录下,配置好本地镜像包,cirros小镜像以及qemu-ifup-NAT.txt文件

三.关闭防火墙并设置开机不自启,配置selinux

systemctl stop firewalld
systemctl disable firewalld
setenforce 0

四.配置本地yum源文件

vi local.repo
[kvm]
name=kvm
baseurl=file:///opt/kvm_yum
enabled=1
gpgcheck=0

测试yum:

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum repolist 

五.下载KVM以及相关组件:

yum install qemu-kvm openssl libvirt -y
systemctl start libvirtd

六.设置软连接:

ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm

七.给之前上传的ifup脚本赋予权限:

chmod 777 qemu-ifup-NAT.txt

启动KVM虚拟机:

qemu-kvm -m 1024 -drive file=cirros-0.3.4-x86_64-disk.img,if=virtio -net nic,model=virtio -net tap,script=qemu-ifup-NAT.txt -nographic -vnc :1

$ 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

至此,KVM虚拟机搭建完成

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值