linux中实现虚拟机安装的全自动化

一、搭建dhcp服务器

yum install dhcp -y ##安装dhcp软件

在这里插入图片描述
rpm -qc dhcp ##查看dhcp安装路径
在这里插入图片描述
cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf ##复制模版到dhcpd.conf
在这里插入图片描述

im /etc/dhcp/dhcpd.conf ##更改其中部分配置,以下文为准,有注释的行可自行更改
1 # dhcpd.conf
2 #
3 # Sample configuration file for ISC dhcpd
4 #
5
6 # option definitions common to all supported networks…
7 option domain-name “dhcpserver.com”; ##设置域名
8 option domain-name-servers 114.114.114.114; ##dns解析地址
9
10 default-lease-time 600;
11 max-lease-time 7200;
12
13 # Use this to enble / disable dynamic dns updates globally.
14#ddns-update-style none;
15
16 # If this DHCP server is the official DHCP server for the local 17 # network, the authoritative directive should be uncommented. 18 #authoritative;
19
20 # Use this to send dhcp log messages to a different log file (you also
21 # have to hack syslog.conf to complete the redirection).
22 log-facility local7;
23
24 # No service will be given on this subnet, but declaring it helps the
25 # DHCP server to understand the network topology.
26
27
28 # This is a very basic subnet declaration.
29
30 subnet 172.25.254.0 netmask 255.255.255.0 {
31 range 172.25.254.60 172.25.254.99; ##分配的ip段
32 option routers 172.25.254.10; ##分配的网关
33 }

在这里插入图片描述
systemctl start dhcpd ##打开dhcpd服务

二、自动安装虚拟机

1.建立自动安装系统脚本
注:该脚本可在虚拟机上建立也可在真机上建立,以下是在虚拟机中建立过程。
yum install system-config-kickstart -y ##安装生成自动安装系统脚本的软件
system-config-kickstart ##打开该软件的图形界面,开始设置

完成以上步骤后会生成ks.cfg文件,打开该文件,在文章的最后添加以下内容
%packages
@base
lftp
%end

在这里插入图片描述
ksvalidator ks.cfg ##检验ks.cfg是否有语法错误

yum install httpd -y ##安装
httpd systemctl stop firewalld ##关闭防火墙
systemctl disable firewalld ##设置开机自动关闭防火墙
systemctl start httpd ##开启
httpd systemctl enable httpd ##设置开机自动开启
httpd cp ks.cfg /var/www/html/ ##发布ks.cfg到网络上
在这里插入图片描述
以下步骤必须在真机中操作
vim vm_install ##创建安装虚拟机脚本
#!/bin/bash
virt-install \ ##新建虚拟机命令
–name $1 \ ##设置名字,并在调用时命名
–memory 1000 \ ##设置内存
–vcpus 1 \ ##设置cpu内核数
–disk /var/lib/libvirt/images/$1.qcow2,size=8,bus=virtio \ ##设置硬盘
–network bridge=br0,model=virtio \ ##设置网卡
–location http://172.25.254.10/yum-b \ ##选择镜像路径 --extra-args “ks=http://172.25.254.109/ks.cfg” &> /dev/null & ##选择自动安装系统脚本

sh vm_install lan ##调用自动安装虚拟机脚本
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值