pxe自动化批量安装系统(Centos7)

简介: PXE:preboot execute environment 环境实现:主服务器ip:10.0.10.1 1 tfpt trivial简单文件共享服务,基于udp协议工作; 加载系统安装程序; 69/udp [root@t2 ~]# yum list *tftp* [root@t2...

PXEpreboot execute environment

环境实现:主服务器ip10.0.10.1

tfpt

trivial简单文件共享服务,基于udp协议工作;

加载系统安装程序;

69/udp

[root@t2 ~]# yum list *tftp*

[root@t2 ~]# yum install tftp tftp-server

[root@t2 ~]# rpm -ql tftp-server

 1 /etc/xinetd.d/tftp
 2 /usr/lib/systemd/system/tftp.service
 3 /usr/lib/systemd/system/tftp.socket
 4 /usr/sbin/in.tftpd
 5 /usr/share/doc/tftp-server-5.2
 6 /usr/share/doc/tftp-server-5.2/CHANGES
 7 /usr/share/doc/tftp-server-5.2/README
 8 /usr/share/doc/tftp-server-5.2/README.security
 9 /usr/share/man/man8/in.tftpd.8.gz
10 /usr/share/man/man8/tftpd.8.gz
11 /var/lib/tftpboot           # 默认共享路径
View Code

[root@t2 ~]# systemctl start tftp.service

dhcp

dynamic host configuration protocol

提供地址池(租约);不能跨路由器;

能提供的信息包括:ip, netmask,  gateway,  dns server, dns search domain, nis server, lease time

C/S

Client 68/udp

Server67/udp

    C           S           C          S

dhcpdiscover-->dhcppoffer-->dhcprequest-->dhcpack

VM虚拟机提供dhcp服务功能,故测试不能使用自带的三种用户模式,应自建虚拟网络。

ifconfig eth1 10.0.10.1/24 up

[root@t2 ~]# yum -y install dhcp

[root@t2 ~]# rpm -ql dhcp

cp -p /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

[root@t2 ~]# cat /etc/dhcp/dhcpd.conf

dhcpd.conf    

[root@t2 ~]# systemctl start dhcpd.service

通过另外一台服务器配置dhcp设置网卡后,在dhcp服务器上存在租赁记录:

[root@t2 /etc/dhcp]# tail /var/lib/dhcpd/dhcpd.leases

dhcpd.leases    
 1 lease 10.0.10.11 {
 2   starts 6 2017/08/19 14:46:16;
 3   ends 6 2017/08/19 14:56:16;
 4   cltt 6 2017/08/19 14:46:16;
 5   binding state active;
 6   next binding state free;
 7   rewind binding state free;
 8   hardware ethernet 00:0c:29:e3:ea:af;
 9   client-hostname "t3";
10 }

http

[root@t2 ~]# yum -y install httpd

[root@t2 ~]# cat /etc/httpd/conf/httpd.conf|grep IncludeOptional

#IncludeOptional conf.d/*.conf

[root@t2 ~]# systemctl start httpd.service

mount /dev/sr0 /var/www/html/Centos7

准备系统文件:

[root@t2 ~]# yum -y install syslinux

[root@t2 ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

[root@t2 ~]# cp /media/cdrom/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/

[root@t2 ~]# cp /usr/share/syslinux/{chain.c32,mboot.c32,menu.c32,memdisk} /var/lib/tftpboot/

[root@t2 ~]# mkdir -pv /var/lib/tftpboot/pxelinux.cfg

[root@t2 ~]# cat pxelinux.cfg/default

1 default menu.c32
2 prompt 5 
3 timeout 15
4 MENU TITLE Hello , luomr
5 
6 LABEL linux
7 MENU LABEL Install CentOS / x86_64
8 KERNEL vmlinuz
9 APPEND initrd=initrd.img inst.repo=http://10.0.10.1/Centos7 ks=http://10.0.10.1/ks.cfg
default

确认文件:

[root@t2 /var/lib/tftpboot]# ls

chain.c32   mboot.c32  menu.c32    pxelinux.cfg

initrd.img  memdisk    pxelinux.0  vmlinuz

ks.cfg

注:以下为ks.cfg内容,可直接复制粘贴使用

[root@t2 ~]# cp ks.cfg /var/www/html/

  1 #platform=x86, AMD64, 或 Intel EM64T
  2 #version=DEVEL
  3 # Install OS instead of upgrade
  4 install
  5 # Keyboard layouts
  6 keyboard 'us'
  7 # Root password
  8 rootpw --plaintext 000000
  9 # Use network installation
 10 url --url="http://10.0.10.1/Centos7"
 11 # System language
 12 lang zh_CN
 13 # Firewall configuration
 14 firewall --disabled
 15 # System authorization information
 16 auth  --useshadow  --passalgo=sha512
 17 # Use graphical install
 18 graphical
 19 # SELinux configuration
 20 selinux --disabled
 21 # Do not configure the X Window System
 22 skipx
 23 
 24 # Network information
 25 network  --bootproto=dhcp --device=eth0
 26 # Reboot after installation
 27 reboot
 28 # System timezone
 29 timezone Asia/Shanghai
 30 # System bootloader configuration
 31 bootloader --location=mbr
 32 # Partition clearing information
 33 clearpart --all --initlabel
 34 # Disk partitioning information
 35 part /boot --fstype="ext4" --ondisk=sda --size=200
 36 part /usr/local --fstype="ext4" --ondisk=sda --size=8000
 37 part swap --fstype="swap" --ondisk=sda --size=800
 38 part / --fstype="ext4" --grow --ondisk=sda --size=1
 39 
 40 %packages
 41 @development
 42 @remote-system-management
 43 ElectricFence
 44 ant
 45 babel
 46 bzr
 47 chrpath
 48 cmake
 49 cvs
 50 expect
 51 imake
 52 ksc
 53 lrzsz
 54 libstdc++-docs
 55 mercurial
 56 nasm
 57 net-tools
 58 perltidy
 59 rpmdevtools
 60 rpmlint
 61 vim
 62 systemtap-sdt-devel
 63 systemtap-server
 64 
 65 %end
 66 
 67 %post --interpreter=/bin/sh
 68 #!/bin/bash
 69 #by luomr
 70 
 71 #deploy yum 
 72 rm -rf /etc/yum.repos.d/*.repo
 73 cat>/etc/yum.repos.d/local.repo << EOF
 74 [Centos7]
 75 name=This is a local repo
 76 baseurl=http://10.0.10.1/Centos7
 77 enabled=1
 78 gpgcheck=0
 79 EOF
 80 yum clean all && yum list
 81 
 82 #network
 83 systemctl restart network.service
 84 
 85 ifconfig |grep inet|awk 'NR==1{print $2}' >/tmp/ip_local
 86 ip=`cat /tmp/ip_local`
 87 #nwn : network name
 88 nwn=`ifconfig |grep eno|awk -F: '{print $1}'`
 89 path_n=/etc/sysconfig/network-scripts/ifcfg-"$nwn"
 90 
 91 
 92 sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=static/g' $path_n
 93 cat>>$path_n <<EOF
 94 IPADDR=$ip
 95 NETMASK=255.255.255.0
 96 EOF
 97 
 98 ifdown $nwn && ifup $nwn
 99 
100 %end
ks.cfg

配置完毕,测试,本人实操成功!

 

-------------------------------------------------------------

作者: 罗穆瑞

转载请保留此段声明,且在文章页面明显位置给出原文链接,谢谢!

------------------------------------------------------------------------------

如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!

------------------------------------------------------------------------------

目录
相关文章
|
1天前
|
Unix Linux 开发工具
centos的官网下载和vm16虚拟机安装centos8【保姆级教程图解】
本文详细介绍了如何在官网下载CentOS 8以及在VMware Workstation Pro 16虚拟机上安装CentOS 8的步骤,包括可能出现的问题和解决方案,如vcpu-0错误的处理方法。
centos的官网下载和vm16虚拟机安装centos8【保姆级教程图解】
|
2天前
|
消息中间件 Linux
centos7安装rabbitmq
centos7安装rabbitmq
|
1天前
|
Linux 虚拟化 Windows
完美解决:重新安装VMware Tools灰色。以及共享文件夹的创建(centos8)
这篇文章提供了解决VMware Tools无法重新安装(显示为灰色)问题的步骤,并介绍了如何在CentOS 8上创建和配置VMware共享文件夹。
完美解决:重新安装VMware Tools灰色。以及共享文件夹的创建(centos8)
|
1天前
|
Linux
centos 安装etcd|待优化
centos 安装etcd|待优化
|
2天前
|
Docker 容器
centos7.3之安装docker
centos7.3之安装docker
|
3天前
|
Linux Python
Linux之centos安装clinkhouse以及python如何连接
Linux之centos安装clinkhouse以及python如何连接
|
3天前
|
Linux
linux之centos安装dataease数据报表工具
linux之centos安装dataease数据报表工具
|
22天前
|
运维 Ubuntu Devops
自动化运维工具的魅力:Ansible入门
【9月更文挑战第5天】在快速变化的IT世界里,自动化运维不再是可选项,而是必需品。Ansible,一款简单却强大的自动化工具,正成为众多DevOps工程师的首选。本文将带你了解Ansible的基本概念、安装步骤以及如何编写简单的Playbook,从而开启你的自动化之旅。
67 36
|
2天前
|
机器学习/深度学习 人工智能 运维
构建高效运维体系:从自动化到智能化的演进之路
在当今数字化时代,运维作为保障企业IT系统稳定运行的关键环节,正经历着前所未有的变革。本文将探讨如何通过实施自动化和引入智能化技术,构建一个更加高效、可靠的运维体系,以应对日益复杂的业务需求和技术挑战。
10 1
|
19天前
|
存储 弹性计算 运维
自动化监控和响应ECS系统事件
阿里云提供的ECS系统事件用于记录云资源信息,如实例启停、到期通知等。为实现自动化运维,如故障处理与动态调度,可使用云助手插件`ecs-tool-event`。该插件定时获取并转化ECS事件为日志存储,便于监控与响应,无需额外开发,适用于大规模集群管理。详情及示例可见链接文档。