您的位置:首页 > 运维架构 > Apache

使用PXE+DHCP+Apache+Kickstart系统自动化安装

2017-07-29 12:19 701 查看
使用PXE+DHCP+Apache+Kickstart系统自动化安装

一:apache平台,共享镜像和Kickstart生成文件1:安装配置apache服务
yum install http
systemctl start httpd
systemctl enable httpd
systemctl stop firewalld
systemctl disable firewalld
/默认发布目录:/var/www/html
2:挂载镜像到默认发布目录
mount /home/kiosk/Desktop/ftp/镜像/iso/rhel-server-7.2-x86_64-dvd.iso /var/www/html/rh    el7.2/
二:安装配置dhcpdhcp主要为在l系统网卡启动时,分配dhcp的
yum install -y dhcp
vim /etc/dhcp/dhcpd.conf
cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
vim /etc/dhcp/dhcpd.conf
~~~~~~~~~~~
7 option domain-name "example.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 #subnet 10.152.187.0 netmask 255.255.255.0 {
28 #}
29
30 # This is a very basic subnet declaration.
31
32 subnet 172.25.254.0 netmask 255.255.255.0 {
33   range 172.25.254.120 172.25.254.130;  #地址池
34   option routers 172.25.254.20;          #网关
35 }
~~~~~~~~~~~
systemctl restart dhcp


三:配置pxePXE启动原理
当计算机引导时,BIOS把 PXE Client 调入内存中执行,然后由 PXE Client 将放置在远端的文件通过网络下载到本地运行。
1:安装tftp,
yum install -y tftp-server
默认发布目录:/var/lib/tftpboot
2:搭建pxe环境
cp /var/www/html/rhel7.2/isolinux/* /var/lib/tftpboot/
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
mkdir /var/lib/tftpboot/pxelinux.cfg
cp /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@server tftpboot]# ls
boot.cat  grub.conf   isolinux.bin  memtest     pxelinux.cfg  TRANS.TBL    vesamenu.c32
boot.msg  initrd.img  isolinux.cfg  pxelinux.0  splash.png    upgrade.img  vmlinuz
3:搭建好pxe环境后,分析一下网卡启动的过程,首先dhcp寻找ip ,这时候读dhcp文件/etc/dhcp/dhcpd.conf文件,接下来应该让他读pxe的default文件从而进行安装,所以将下来要干什么写到/etc/dhcp/dhcpd.conf 文件。
next-server 172.25.254.20;
filename "pxelinux.0";
4:启动服务
systemctl restart dhcpd
systemctl start tftp
四:kickstart将安装设置过程生成文件
在红帽中,安装系统设置过程是个特别麻烦耗费时间的事情,在安装过程中,机器会给大家询问许多安装配置问题,kickstart将所有的问题生成一个ks.cfg文件,在安装过程中,直接调用这个文件,很快完成安装1:安装kickstart
yum install -y system-config-kickstart.noarch

2:图形界面回答安装配置问题,生成ks.cfg 文件
system-config-kickstart     ##生成文件打开图形界面命令

3:图形界面回答问题,配置虚拟机服务basic configuiation ##主要设置语言,时区密码等reboot system after installation
##安装后重新启动系统perform installation in text mode (graphical is default)
##在文本模式进行安装(图形是默认的)
installation method ##安装模式,主要为了设置安装镜像的来源
perform new installation
执行新的安装upgrade an existing installation
升级现有安装安装根源 installation source -->http server 172.25.254.20 http directory /rhel7.2
boot loader options

install type
install new boot loader
##安装新的引导装载程序install options(装置选项)
install boot loader on master boot record

在主引导记录安装引导装载程序install boot loader on first sector of the boot partition
在引导分区的第一扇区上安装引导加载程序master boot record(主引导记录)
clear master boot record ###清除主引导记录
remove all existing partitions
##删除所有现有的分区
preserve existing partitions
##保留现有的分区disk label(磁盘标签)
initialize the disk label
##初始化磁盘标签add /boot 200

add swap 500
add / 剩余空间
network configuration

添加网卡和dhcp/ip
authentication认证;

post-installation script #最后安装的脚本

安装前脚本:以%pre开始,以%end结束;
安装后脚本:以%post开始,以%end/结束;

完成完设置后,左上角有个file,将生成的ks.cfg 文件保存,建议保存在apache的发布目录/var/www/html/里面,方便其他虚拟机或者真机的安装。
4:处理生成的ks.cfg文件
%packages
@base

%end
5:将ks.cfg文件运用到系统安装中
vim /var/lib/tftpboot/pxelinux.cfg/default
61 label linux
62   menu label ^Install Red Hat Enterprise Linux 7.2
63   kernel vmlinuz
64   append initrd=initrd.img repo=http://172.25.254.20/rhel7.2 ks=http://172.25.254.20/ks.cfg q    uiet
五:测试
设置系统启动从网卡启动,启动所有服务,
由于电脑一些问题,没法上传测试图片,后续有问题继续更
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息