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. js过滤输入的emoji表情

    因为emoji表情是Unicode编码, 在某些流浪器上会显示乱码, 有的数据库字节不够也无法存储, 网上有很多解决此类问题的办法, 最简单的莫过于将emoji表情替换成文本, 比如 [表情][表情] ...

  2. es query_string 和 match 的区别

    默认使用 空格拆分成 多个 子项,并且 每个子项 都会去分词 查询.可以通过 default_operator 指定  子项之间的关系.默认是 或 . 然后 每个 子项前面可以使用 -+ 指定必须有 ...

  3. es中级部分知识点总结

    --------------------------------------------------------------- 搜索开始-------------------------------- ...

  4. C#中四种常用集合的运用(非常重要)【转】

    1.ArrayList ArrayList类似于数组,有人也称它为数组列表.ArrayList可以动态维护,而数组的容量是固定的. 它的索引会根据程序的扩展而重新进行分配和调整.和数组类似,它所存储的 ...

  5. Linux CentOS6升级glibc库过程

    CentOS6升级glibc库过程 hadoop无法加载native库,可能原因是 glibc库版本过低,需要升级. 第一:安装以下软件 yum -y install zlib zlib-devel ...

  6. Visual Studio搭建Python开发环境

    一.搭建开发环境 1.创建工程: 2.下载环境: 创建好工作以后,点击运行,就会出现下面这个界面,然后点击下载,并安装 http://jingyan.baidu.com/article/fec4bce ...

  7. mysql 1267 error

    CREATE TABLE a (id VARCHAR(32)) DEFAULT CHARSET = utf8 COLLATE utf8_general_ci:INSERT INTO a(id) VAL ...

  8. delphi absolute 应用实例

    procedure TForm1.Button1Click(Sender: TObject); var i1,i2:Integer; b:..] of Byte absolute i1; // b 在 ...

  9. html多个水平并列组件自适应等高的做法

    做一个div盒子,设置over-flow:hidden,设置高度为auto.然后再盒子里排列若干inline-block,inline元素. 自适应的话常用做法是用line-height,font-s ...

  10. 【mysql】linux查看mysql配置文件my.conf

    mysql --help|grep 'my.cnf' /etc/my.cnf, /etc/mysql/my.cnf, /usr/local/etc/my.cnf, ~/.my.cnf 这些就是mysq ...