Centos7使用pxe安装KVM虚拟机

一、安装服务所需的软件

[root@localhost ~]yum install nginx  dhcp  vsftpd  syslinux -y
[root@localhost ~]mount -p loop -t iso9660 images/CentOS-7-x86_64-DVD-1804.iso /mnt #提前上传镜像
[root@localhost ~]systemctl start vsftpd
[root@localhost ~]systemctl enable vsftpd    

二、安装DHCP服务器

[root@localhost ~]cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example  /etc/dhcp/  #复制示例配置文件
[root@localhost ~]cd /etc/dhcp/
[root@localhost dhcp]#rm -f dhcpd.conf
[root@localhost dhcp]#mv dhcpd.conf.example dhcpd.conf
[root@localhost dhcp]# egrep -v "^#|^$" dhcpd.conf
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 172.16.150.0 netmask 255.255.255.0 { #网段
range 172.16.150.230 172.16.150.232 ; #地址池
option routers 172.16.150.254; #网关
option domain-name-servers 172.16.160.20,172.16.160.21; #dns服务器
}
[root@localhost ~]cp /usr/lib/systemd/system/dhcpd.service /etc/systemd/system/
[root@localhost ~]vi /etc/systemd/system/dhcpd.service
ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid <your_interface_name(s)>
[root@localhost ~]systemctl --system daemon-reload
[root@localhost ~]systemctl restart dhcpd.service #启动服务 

三、创建tftp相关目录和拷贝内核镜像及文件

[root@localhost ~]mkdir /var/tftp
[root@localhost ~]cp /mnt/images/pxeboot/initrd.img /var/tftp/
[root@localhost ~]cp /mnt/images/pxeboot/vmlinuz /var/tftp/
[root@localhost ~]rpm -ql syslinux | grep "pxelinux.0"
[root@localhost ~]cp /usr/share/syslinux/pxelinux.0 /var/tftp/
[root@localhost ~]mkdir /var/tftp/pxelinux.cfg/ 

四、创建菜单配置文件

[root@localhost ~]# vim /var/tftp/pxelinux.cfg/default
default linux
prompt 1
timeout 60
display boot.msg
label linux
kernel vmlinuz
append initrd=initrd.img text ks=http://172.16.150.32/ks.cfg net.ifnames=0 biosdevname=0 ksdevice=eth0
#172.16.150.32是http服务器地址,我们使用http的方式下载ks.cfg及软件包,因为7的网卡名称不在是eth0,1,2而改成enoxx的格式,新的方式不但长,而且难记。ksdevice=eth0表示所有网卡名称从eth0开始,如果有多快,依次增加

五、配置nginx下载、安装配置

[root@localhost ~]#cd /usr/share/nginx/html/
[root@localhost html]#mkdir Centos7_4 #创建软件包下载目录
[root@localhost html]#umont /mnt
[root@localhost html]#mount -p loop -t iso9660 /root/images/CentOS-7-x86_64-DVD-1804.iso /usr/share/nginx/html/Centos7_4/ [root@localhost html]# vim /usr/share/nginx/html/ks.cfg #具体自定义,文章结尾有份示例文件,也可以使用system-config-kickstart命令生成,命令可以通过yum安装
.....
url --url="http://172.16.150.32/Centos7_4" #在ks文件中指定下载的地址
.....

#如果想打开nginx目录浏览功能,可以添加如下配置:
[root@localhost html]# cat /etc/nginx/nginx.conf
.....
server {
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
.......

#如果想在线浏览ks文件,则添加如下配置
vim /etc/nginx/mime.types
text/plain cfg; #添加该行

六、注意事项

1.安装的系统内容不得小于2G,否则报如下错误:
dracut-initqueue[552]: /sbin/dmsquash-live-root: line 273: printf: write error: No space left on device
2.boot分区不得小于200M,否则或导致kickstart进程暂停,需要手动确认才会继续

 #示例文件

#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $$pTG9CQO9$MmB9KurbyQtyAeqJm7Hrbh.kl1IGUhQK35Ce027/lGYq6TkNYHyUd6WYqluhUVnEQoPzruTbqm7HFO8CyZB0r/ #root密码,加密方法参考http://clavinli.github.io/2014/11/14/linux-command-hash-root-password-in-kickstart/
user --groups=admin --name=admin
user --groups=log --name=log url --url="http://172.16.150.32/Centos7_4/" #软件包下载地址
# System language
lang zh_CN
# Firewall configuration
firewall --enabled --http --ftp --ssh --port=:tcp,:tcp,:tcp #可以禁用,或者开启需要放行的端口或者服务
# Use text mode install
text
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx # Network information
network --bootproto=dhcp --device=eth0 --gateway=172.16.150.254 --onboot=on
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size= #不得少于200M
part swap --fstype="swap" --size=
part / --fstype="xfs" --grow --size= #1代表使用所有的剩余磁盘空间
%packages #这段表示你要安装的软件包,@表示选择的包组,最前面使用横杠表示取反,即不选择的包或包组。@base和@core两个包组总是被默认选择,可以不在%packages中指定它们
@Base
curl
lrzsz
%end
%post --interpreter /bin/bash
/bin/curl http://172.16.150.32/System_initialize.sh -o /root/System_initialize.sh #安装后需要做的操作,也可以是命令或者打包到脚本中执行
/bin/bash /root/System_initialize.sh
%end

ks.cfg文件

virt-install --virt-type=kvm   --name "zest_machine"  --location=http://172.16.150.32/Centos7_4/  --memory=4096  --vcpus=1 --disk path=/var/lib/libvirt/images/zest_machine.img,size=60  --network bridge=br0  --os-type linux --os-variant rhel7 --extra-args="ks=http://172.16.150.32/ks.cfg --autostart  console=tty0 " --force &

kvm安装脚本

Centos7使用pxe安装KVM虚拟机的更多相关文章

  1. (亲测成功)在centos7.5上安装kvm,通过VNC远程连接并创建多台ubuntu虚拟机(ubuntu server版本)

    在centos7.5上安装kvm,通过VNC远程连接并创建多台ubuntu虚拟机 前提:服务器端安装桌面版的centos系统 CentOS Linux release 7.5.1804 (Core) ...

  2. (转)CentOS7安装KVM虚拟机详解

    原文:https://github.com/jaywcjlove/handbook/blob/master/CentOS/CentOS7%E5%AE%89%E8%A3%85KVM%E8%99%9A%E ...

  3. centos7安装kvm虚拟机

    一 centos7安装kvm虚拟机 1.验证CPU是否支持KVM 结果中有vmx(Intel)或svm(AMD)字样,就说明CPU的支持的. [root@centos ~]# egrep '(vmx| ...

  4. CentOS 7.5 安装KVM虚拟机(Windows)

    一.KVM环境搭建1.检测系统是否支持cat /proc/cpuinfo | egrep 'vmx|svm' KVM是基于x86虚拟化扩展(Intel VT 或者 AMD-V)技术的虚拟机软件,所以查 ...

  5. vmware安装kvm虚拟机

    1. 概述 本篇博客主要使用运行在win10专业版上的vmware workstation 15 pro虚拟化软件,安装centos7.7最小化系统,并在centos7上安装kvm虚拟机,实现快速创建 ...

  6. 6、安装kvm虚拟机

    6.1.虚拟机开启虚拟化: 6.2.检查linux虚拟机cpu是否开启了虚拟化: egrep -o 'vmx|svm' /proc/cpuinfo vmx 6.3.安装kvm管理和安装kvm虚拟机的软 ...

  7. 11.安装KVM虚拟机

    安装KVM虚拟机是一大难题,不按照虚拟机物理机128G内存和强劲的CPU无法充分利用.也不便于后面的jenkins自动部署.安装KVM虚拟机过程我是借鉴了网上下载的马哥linux   KVM那块的内容 ...

  8. 命令行安装kvm虚拟机、桥接网络、用virt-manager管理

    宿主机CentOS Linux release 7.2.1511 (Core),内核3.10.0-327.el7.x86_64 1.配置宿主机网络桥接 想让虚拟机有自己的ip且外网可访问,需要在安装虚 ...

  9. centos6.2安装kvm虚拟机

    http://www.wenzizone.com/2012/03/06/centos_6-2_install_kvm.html KVM虚拟机简介 kernel-based Virtual Machin ...

随机推荐

  1. EMC EMI 自行评估记录

    EMC EMI 自行评估记录 设备 频谱仪 网房 评估 设置频谱频率为 30M 1G. 给频谱仪接一个天线,将被测试的机器上电然后在不同的角度换,看频谱仪上的数值. 可以绕上去,但不要和 PCB接触.

  2. dev 域名与 Chrome

    前几天在相开发时使用什么的样域名比较好呢? 之前使用到 localhost,但只是本地开发,使用 test.com 感觉又不专业. 后来发现了一些指向 127.0.0.1 的域名,比如 localte ...

  3. 怎么用fiddler抓APP的包

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/liujingqiu/article/details/79387909Fiddler安装 此处略.我们 ...

  4. docker: Error response from daemon: driver failed programming external connectivity on endpoint jolly_shockley

    1. docker 启动image错误 docker: Error response from daemon: driver failed programming external connectiv ...

  5. split与re.split/捕获分组和非捕获分组/startswith和endswith和fnmatch/finditer 笔记

    split()对字符串进行划分: >>> a = 'a b c d' >>> a.split(' ') ['a', 'b', 'c', 'd'] 复杂一些可以使用r ...

  6. NET设计模式 第三部分 结构型模式(7):适配器模式(Adapter Pattern)

    适配器模式(Adapter Pattern) ——.NET设计模式系列之八 Terrylee,2006年2月 概述 在软件系统中,由于应用环境的变化,常常需要将“一些现存的对象”放在新的环境中应用,但 ...

  7. Spring Cloud Feign Ribbon 配置

    由于 Spring Cloud Feign 的客户端负载均衡是通过 Spring Cloud Ribbon 实现的,所以我们可以直接通过配置 Ribbon 的客户端的方式来自定义各个服务客户端调用的参 ...

  8. ML: 降维算法-LE

    PCA的降维原则是最小化投影损失,或者是最大化保留投影后数据的方差.LDA降维需要知道降维前数据分别属于哪一类,而且还要知道数据完整的高维信息.拉普拉斯特征映射 (Laplacian Eigenmap ...

  9. ML: 聚类算法R包 - 模型聚类

    模型聚类 mclust::Mclust RWeka::Cobweb mclust::Mclust EM算法也称为期望最大化算法,在是使用该算法聚类时,将数据集看作一个有隐形变量的概率模型,并实现模型最 ...

  10. C/C++程序CPU问题分析

    转载地址:http://www.10tiao.com/html/473/201606/2651473094/1.html   程序的CPU问题是另外一类典型的程序性能问题,很多开发人员都受到过程序CP ...