pxe&全自动化安装

首先,先实现全自动化安装

system-config-kickstart 自动应答脚本制作工具

yum install system-config-kickstart -y
1.执行system-config-kickstart命令

basic configuration ———— 基本信息设定

//设置时间,root密码

2.设置安装源

installation method ———— 安装模式选择

3.设置磁盘分区

partition information ———— 分区划分策略

//清空原有磁盘

## /boot 200M ;swap 500M ; / 剩余所有

4.添加网卡,配置网络,这里为dhcp

5.设置火墙为不自启

firewall configuration ———— 火墙配置信息

剩下的默认设置就可以

– boot loader options ———— 引导程序选项
– authentication ———— 认证加密方式
– display configuration ———— 图形界面选择 选择Disabled,不安装图形
– package selection ———— 软件包选择
– pre-installation ————安装前执行脚本
– post-installation ———— 安装后执行脚本

扫描二维码关注公众号,回复: 9717374 查看本文章

*设置好后,将配置信息文件保存到/var/www/html/下

  • 注意: 要实现全自动挂载,一定以网络配置镜像
    man virt-install

    //这是文件里面说明的。

打开文件,在之前的都是以文字命令保存的之前的配置,在36行之后可以添加新的配置,但是有固定的格式

//在这里,选择安装时默认把yum源与vim,base软件组配置、安装好。

保存退出后,用命令检测语法,但不会检测你写的配置的合理性,即相当于c的编译过程

//没有提示表示没有语法错误
在网站应该可以看到你的文件

*此时,可以称的上全自动安装脚本:

#!/bin/bash
virt-install \
--name $* \
--vcpus 1 \
--ram 1024 \
--file /var/lib/libvirt/images/$*.qcow2 \
--file-size 8 \
--location http://172.25.254.77/rhel7.2 \            ##一定以网络共享方式配置安装源
--extra-args "ks=http://172.25.254.77/ks.cfg"  &   ##默认后台运行



可是,想一想,在工作环境中,真的要给每一台安装时都运行一次的话,工作量该有多么庞大,所以,要用到网卡方式安装,真的实现全自动化安装!!

以虚拟机为例 :

将网卡选项打勾,然后顶置,以网卡方式安装,然后打开虚拟机

//其中文字是在连接共享服务,所以要用dhcp分配的ip,接下来tftp连接上之后开始读pxelinux.cfg文件

//这就是要配置的地方,如果配置好,就会直接进入安装

pxe环境搭建

除了kickstar还需要配置的服务有:

yum install :

syslinux ————-获得pxelinux.0文件安装包
dhcp ——————分配ip给客户机的服务
tftp-server ———提供tftp协议的服务
httpd —————–安装源共享服务,这个应该已经配置过了

文件服务的配置

1.修改dhcp配置文件 /etc/dhcp/dhcpd.conf


其他与之前的配置一样,但是添加了两行:

  filename "pxelinux.0";                //##pxe启动程序
  next-server 192.168.0.79;             ##tftp主机地址

配置后,重启服务,关闭火墙
systemctl restart dhcpd
systemctl stop firewalld

2 修改 TFTP 服务配置文件 /etc/xinetd.d/tftp


//14行中的disable后面设置为no,这个表示开启是否不自启
执行后: systemctl restart xinetd 生效

3 搭建pxe工作环境

这里默认http服务yum源按上文所说已经配置好

开启tftp服务,并查看端口开启状态

查看syslinux需要的文件,发现pxelinux.txt

less /usr/share/doc/syslinux-4.05/pxelinux.txt 进入这个文件


//通过文件可以发现需要一些文件的配置支持

cd /var/lib/tftpboot/
mkdir pxelinux.cfg
cp /var/www/html/rhtl7.2/isolinux/*      /var/lib/tftpboot
cp /var/lib/tftpboot/isolinux.cfg      /var/lib/tftpboot/pxelinux.cfg/default
cp /usr/share/syslinux/pxelinux.0      /var/lib/tftpboot/

=====================================================================

下面配置 /var/lib/tftpboot/pxelinux.cfg/default 文件

这里面的配置都是可以自己修改的,这里也体现了linux的可定制性非常的高

default vesamenu.c32
timeout 30                      //等待时间"
//这里时间单位是0.1秒,即600是60秒
display boot.msg

# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.

menu clear
menu background splash.png                              //背景图片
//如果想修改,只需要将png后缀的文件添加到/var/lib/tftpboot下,然后直接将这里的名字修改就可以
menu title yuanxudong  install      //大标题
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13

# Border Area                            //包括下面的,都是颜色的配置信息
menu color border * #00000000 #00000000 none

# Selected item
menu color sel 0 #ffffffff #00000000 none

# Title bar
menu color title 0 #ff7ba3d0 #00000000 none

# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none

# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none

# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none

# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none

# Help text
menu color help 0 #ffffffff #00000000 none

# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none

# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none

# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none

# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.

menu tabmsg Press Tab for full configuration options on menu items.

menu separator # insert an empty line
menu separator # insert an empty line

label linux
  menu label ^Install Red Hat Enterprise Linux 7.0          //小标题
   menu default                             //默认标题设定
   //因为我们选择的是直接安装,所以要将下面的默认设定放到这里来,这样在读完秒之后,就进行这项操作,为了更快,也可以将之前的timeout设置为0,直接就进入这里安装了,更加快捷
  kernel vmlinuz
  append initrd=initrd.img repo=http://172.25.254.77/soucre ks=http://172.25.254.77/ks.cfg      //安装源和ks

label check
  menu label Test this ^media & install Red Hat Enterprise Linux 7.0
  "menu default"             //删除,这里的放在上面
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 rd.live.check quiet

menu separator # insert an empty line

# utilities submenu
menu begin ^Troubleshooting
  menu title Troubleshooting

label vesa
  menu indent count 5
  menu label Install Red Hat Enterprise Linux 7.0 in ^basic graphics mode
  text help
    Try this option out if you are having trouble installing
    Red Hat Enterprise Linux 7.0.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 xdriver=vesa nomodeset quiet

label rescue
  menu indent count 5
  menu label ^Rescue a Red Hat Enterprise Linux system
  text help
    If the system will not boot, this lets you access files
    and edit config files to try to get it booting again.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 rescue quiet

label memtest
  menu label Run a ^memory test
  text help
    If your system is having issues, a problem with your
    system memory may be the cause. Use this utility to
    see if the memory is working correctly.
  endtext
  kernel memtest

menu separator # insert an empty line

label local
  menu label Boot from ^local drive
  localboot 0xffff

menu separator # insert an empty line
menu separator # insert an empty line

label returntomain
  menu label Return to ^main menu
  menu exit

menu end

设置以网卡启动之后,直接打开虚拟机,可以直接进入系统的安装

然后静静等待,虚拟机就安装成功了!

发布了55 篇原创文章 · 获赞 38 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/mon_star/article/details/76390343