pxe+kickstart实现Linux无人值守自动安装

                        Linux系统无人值守全自动安装

1 针对类型

centos or redhat 7及以上

2 用到的软件

dhcp:给需要安装的系统分配及规划地址段,同时指定tftp地址以及pxelinux.0路径

tftp、tftp-server:提供引导文件与系统安装所必须的文件

httpd or vsftpd: 提供网络安装的系统镜像

syslinux: 提供引导文件

system-config-kickstart: 制作系统自动安装的文件

 

3 安装前期条件

所有需要安装的机器网卡支持pxe

主板支持网络启动引导

二层网络已打通

 

4 图示原理

pxe安装图示过程:

https://images2017.cnblogs.com/blog/1121174/201712/1121174-20171229124933475-502830744.jpg

pxe+kicakstart实现图示过程:

    https://images2017.cnblogs.com/blog/1121174/201712/1121174-20171229124950991-1342863154.jpg

5 制作安装

5.1 pxe+kickstart测试环境

我这采用VMware和virt-manager软件来实现,VMware貌似有bug,创建选择系统类型时得选择windows(virtualbox一样)

系统:centos7.2

网卡:我设置了两张,一张采用nat连接外网配置环境,网段192.168.192.0/24

      另外一张采用自定义虚拟网络,内部pxe安装使用,网段192.168.70/24

5.2禁用selinux以及firewall

setenforce 0  #临时使用

sed –I 's/SELINUX=enforcing/SELINUX=disabled/g'  #永久

systemctl stop firewalld

systemctl disable firewalld

5.3软件安装

yum  -y install dhcp tftp tftp-server vsftp syslinux system-config-kickstart

5.4配置

5.4.1 dhcp

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

# DHCP Server Configuration file.

#   see /usr/share/doc/dhcp*/dhcpd.conf.example

#   see dhcpd.conf(5) man page

allow booting;

allow bootp;

dns-update-style interim;

ignore client-updates;

subnet 192.168.70.0 netmask 255.255.255.0

{

range 192.168.70.10 192.168.70.100;

option domain-name-servers 192.168.70.128;

option routers 192.168.70.128;

default-lease-time 21600;

max-lease-time 43200;

 

#指定TFTP server地址

next-server 192.168.70.128;

#指定pxelinux启动文件位置,和TFTP一起

filename "pxelinux.0";

}

5.4.2 tftp

需要安装的系统ISO挂载

tftp默认由守护进程xinetd管控,如果没有的话可以安装

yum –y install xinetd

[root@localhost tftpboot]# cat /etc/xinetd.d/tftp

# default: off

# description: The tftp server serves files using the trivial file transfer \

#       protocol.  The tftp protocol is often used to boot diskless \

#       workstations, download configuration files to network-aware printers, \

#       and to start the installation process for some operating systems.

service tftp

{

        socket_type             = dgram

        protocol                = udp

        wait                    = yes

        user                    = root

        server                  = /usr/sbin/in.tftpd

        server_args             = -s /var/lib/tftpboot  #指定数据目录

        disable                 = no    #yes改成no

        per_source              = 11

        cps                     = 100 2

        flags                   = IPv4

}

 

拷贝系统文件至tftp下

包括:

内核文件:vmlinuz initrd.img

引导菜单配置文件: isolinux.cfg

系统自带的两种窗口模块之一:vesamenu.c32

窗口提示信息文件:boot.msg

窗口背景图片:splash.png

cp /mnt/cdrom/isolinux/* /var/lib/tftpboot/

mkdir /var/lib/tftpboot/pxelinux.cfg

拷贝引导菜单文件至此目录下

mv /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

拷贝引导文件至tftp默认目录下

cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot

 

修改引导菜单文件

vim  /var/lib/tftpboot/pxelinux.cfg/default

主要修改如下信息

timeout 600  #引导界面等到时间,默认60s

可以修改为 timeout 100   默认等待10s

 

引导界面的显示项

label linux

  menu label ^Install CentOS Linux 7

  kernel vmlinuz

  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet

 

label check

  menu label Test this ^media & install CentOS Linux 7

  menu default

  kernel vmlinuz

  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet

 

menu separator # insert an empty line

 

# utilities submenu

menu begin ^Troubleshooting

  menu title Troubleshooting

        .

        .

        .

menu end

 

上述东西其实都可以删掉,如果你确定安装内容的话,留下第一段label即可

如下:

label linux

  menu label ^Install CentOS Linux 7

  kernel vmlinuz

  menu default    #默认以此启动项启动,否则不会自动进入

  append initrd=initrd.img ks=ftp://192.168.70.128/pub/dvd/ks.cfg quiet

#指定无人值守安装启动的文件ks.cfg,此文件指定了系统以怎样的方式安装

此文件必要的东西必须得全部设定好,否则会导致无法自动安装

 

完成上述东西,已经可以拿到地址,通过pxe进入系统安装界面,但是以怎么样的方式安装以及安装文件还没有准备

5.4.3 ftp

ftp存放系统镜像文件,当然也可以用http或者nfs都可以

ftp默认目录/var/ftp/pub/

mkdir  /var/ftp/pub/dvd

cp /mnt/cdrom/*  /var/ftp/pub/dvd

此ftp没有没有做任何权限控制,所以这样就可以了

 

5.4.4 system-config-kickstart

生成无人值守安装文件(这个制作过程得具备图形界面才行)

执行system-config-kickstart

过程不在赘述,有两个注意事项

 

这个地方要想选择到指定安装的包,yum仓库文件的第一个名字必须为development

[root@localhost pxelinux.cfg]# cat /etc/yum.repos.d/local.repo

[development]

name=local

baseurl=file:///mnt/cdrom

弄完之后记得保存,本身是没有保存按钮的,保存到指定目录即可

查看ks.cfg文件

cp /root/ks.cfg /var/ftp/pub/dvd

最小化安装文件如下:

[root@localhost dvd]# cat ks.cfg-bak20190505

#platform=x86, AMD64, or Intel EM64T

#version=DEVEL

# Install OS instead of upgrade

install

text

# Keyboard layouts

keyboard 'us'

# Root password

rootpw --iscrypted $1$Aa.OZSX8$eOmsbrStc.BKV4FmtpyuQ.

# Use network installation

url --url="ftp://192.168.70.128/pub/dvd"

# System language

lang en_US

# System authorization information

auth  --useshadow  --passalgo=sha512

# Use text mode install

text

# SELinux configuration

selinux --disabled

# Do not configure the X Window System

skipx

 

# Firewall configuration

firewall --disabled

# Network information

network  --bootproto=dhcp --device=eth0

# 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

# Disk partitioning information

part /boot --fstype="xfs" --size=800

part / --fstype="xfs" --size=7100

part swap --fstype="swap" --size=2048

 

%packages

@core

 

%end

 

图形化界面安装以及指定一些其他服务

[root@localhost dvd]# cat ks.cfg

#platform=x86, AMD64, or Intel EM64T

#version=DEVEL

# Install OS instead of upgrade

install

# Keyboard layouts

keyboard 'us'

# Root password

rootpw --iscrypted $1$yrN7JsmC$mHFf1GnWpdspcxBFzabsd0

# Use network installation

##指定安装文件的位置

url --url="ftp://192.168.70.128/pub/dvd"

# System language

lang en_US

# System authorization information

auth  --useshadow  --passalgo=sha512

# Use graphical install

#图形化界面安装

graphical

firstboot --disable

# SELinux configuration

selinux –disabled

#指定主机名字

network --hostname=Centos7.contoso.com

#创建指定永不

user --groups=wheel --name=tony --gecos="tony"

# Firewall configuration

firewall --disabled

# Network information

#创建网卡名字

network  --bootproto=dhcp --device=eth0

# 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=800

part / --fstype="xfs" --size=8196

part swap --fstype="swap" --size=2048

#安装的包,%packages开始,%end结束,@代表组安装,-单个服务安装

%packages

@base

@gnome-desktop

@virtualization-client

@virtualization-hypervisor

@virtualization-platform

@virtualization-tools

-abrt-addon-ccpp

-abrt-addon-python

-abrt-cli

-abrt-console-notification

-bash-completion

-blktrace

-bridge-utils

-bzip2

-chrony

-cryptsetup

-dmraid

-dosfstools

-ethtool

-fprintd-pam

-gnupg2

-hunspell

-hunspell-en

-kpatch

-ledmon

-libaio

-libreport-plugin-mailx

-libstoragemgmt

-lvm2

-man-pages

-man-pages-overrides

-mdadm

-mlocate

-mtr

-nano

-ntpdate

-pinfo

-plymouth

-pm-utils

-rdate

-rfkill

-rng-tools

-rsync

-scl-utils

-setuptool

-smartmontools

-sos

-sssd-client

-strace

-sysstat

-systemtap-runtime

-tcpdump

-tcsh

-teamd

-time

-unzip

-usbutils

-vim-enhanced

-virt-what

-wget

-which

-words

-xfsdump

-xz

-yum-langpacks

-yum-utils

-zip

 

%end

 

 

6测试

    只做简单的部分截图

    客户端进入DHCP获取阶段

    

DHCP获取成功,进入引导菜单界面

启动基本的内核,开始传送安装文件

进入自动安装界面

 

利用cobbler实现,见别人文档:https://www.cnblogs.com/zhangxingeng/p/9702625.html

cobbler+dhcp or dnsmasq+tftp+http+rsync

 

转载于:https://my.oschina.net/u/2343310/blog/3045501

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值