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. 查看加密的vba代码

    查看加密的vba代码,可以使用这个工具,excel文件里面的宏代码一览无余. https://files.cnblogs.com/files/laoxia/PVP.zip

  2. gulp 压缩 js 和 css 代码

    我们在写出来的代码都是非常规范的,改换行的时候就换行,改tab 的时候就有tab,还有这样做是为了后期维护方便,但是这也导致了内存占用量的增大,当把把代码发到线上,如果网速慢一点,可能很久都加载不出来 ...

  3. jp@gc - Stepping Thread Group配置解释描述

    测试环境 apache-jmeter-2.13   插件: https://jmeter-plugins.org/downloads/old/ http://pan.baidu.com/s/1gfC1 ...

  4. 2019.4.11 一题 XSY 1551 ——广义后缀数组(trie上后缀数组)

    参考:http://www.mamicode.com/info-detail-1949898.html (log2) https://blog.csdn.net/geotcbrl/article/de ...

  5. java-普通类文件@Autowired自动注入为null

    @Autowired注解在非Controller中注入为null 1.配置文件(类文件所在的包) <context:component-scan base-package="net.n ...

  6. Android 单元测试实践

    1. 在Android Studio创建工程 工程名称  AndroidUnitTest 2. 创建测试类CommonUtil 在类中加入sum和multiply方法 在CommonUtil类中右击 ...

  7. ubuntu如何为获得root权限

    在终端中输入:sudo passwd rootEnter new UNIX password: (在这输入你的密码)Retype new UNIX password: (确定你输入的密码)passwd ...

  8. 什么是词性标注(POS tagging)

    词性标注也叫词类标注,POS tagging是part-of-speech tagging的缩写. 维基百科对POS Tagging的定义: In corpus linguistics, part-o ...

  9. sql 语句收集

    SELECT type as 'plan cache store', buckets_count  FROM sys.dm_os_memory_cache_hash_tables WHERE type ...

  10. linux 简单笔记

    Linux查看端口使用状态.关闭端口方法    http://blog.csdn.net/wudiyi815/article/details/7473097