centos7安装kvm/dhcp随笔bash脚本

发布于 2021-12-28  1876 次阅读


挂载点iso
yum源文档123.repo

vim ifcfg-ens33
systemctl restart network重启网络服务

mkdir /mnt/iso
mount -o loop /dev/cdrom /mnt/iso
mkdir /etc/yum-backup
cp /etc/yum.repos.d/* /etc/yum-backup
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/123.repo
rm -rf /etc/yum.repos.d/Cent*
vi /etc/yum.repos.d/123.repo

[base]
name=CentOS-$releasever - Base
baseurl=file:///mnt/iso
gpgcheck=0
enabled=1

yum clean all
yum -y install httpd
rpm -qa |grep httpd

systemctl stop firewalld.service && sudo systemctl disable firewalld.service
setenforce 0
yum -y install libvirt-client virt-host-validate
virt-host-validate

kvm安装
yum install qemu-kvm qemu-img -y
yum install virt-manager libvirt libvirt-python python-virtinst libvirt-client -y
systemctl start libvirtd
systemctl enable libvirt-guests.service libvirtd

ftp镜像获取
/etc/sysconfig/network-scripts/ifcfg-ens33
systemctl restart network

/etc/libvirt/qemu
/var/lib/libvirt/images
9 <name>vm</name>
10 <uuid>0d36468a-7b8b-4463-9703-ae6a4856cfbb</uuid>
41 <source file='/var/lib/libvirt/images/vm.img'/>
74 <mac address='52:54:00:87:89:2a'/>

 

关闭虚拟机为自动开始:
virsh autostart --disable centos7

强行关闭某虚拟机:
virsh destroy ubuntu14

dhcp配置
服务端
nmtui
yum -y install dhcp
vim /etc/dhcp/dhcpd.conf

default-lease-time 21600;
max-lease-time 43200;
subnet 192.168.1.0
netmask 255.255.255.0
{
option broadcast-address 192.168.1.255;
range 192.168.1.2 192.168.1.100;
option routers 192.168.1.1;
}

systemctl restart dhcpd.service
systemctl enable dhcpd.service
systemctl stop firewalld ----关闭防火墙
setenforce 0 --关闭selinux防火墙
netstat -anpu | grep dhcp 查看端口
systemctl status dhcpd查看状态
systemctl restart network //重启网卡
客户端
route -n | grep UG

子夜不哭
最后更新于 2021-12-28