Linux高阶—自动化安装操作系统PXE+Kickstart(一)

Kickstart服务器

IP: 192.168.136.253   掩码:255.255.255.0   网关:192.168.136.2   DNS192.168.136.2

  • 安装部署HTTP服务器

# mkdir -p /content/pub/rhel7/x86_64/{isos,dvd}/

上传RedHat安装光盘镜像至 /content/pub/rhel7/x86_64/isos/rhel-server-7.2-x86_64-dvd.iso

安装HTTP服务器(Nginx

# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

# yum -y install nginx

修改默认网站配置文件

 # vi /etc/nginx/conf.d/default.conf

server {

    listen       80;

    server_name  localhost;

    root        /content;

    index       index.html index.htm;

    location ^~ /pub/ {

        autoindex             on;

        autoindex_exact_size  off;

        autoindex_localtime   on;

    }

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   /usr/share/nginx/html;

    }

}

启动Nginx服务并设置为开机启动

# systemctl start nginx

# systemctl enable nginx

修改网站目录SELinux类型

# chcon -t public_content_t -R /content/

设置开机自动挂载光盘镜像到/content/pub/rhel7/x86_64/dvd

# echo "/content/pub/rhel7/x86_64/isos/rhel-server-7.2-x86_64-dvd.iso   /content/pub/rhel7/x86_64/dvd   iso9660   loop,ro   0 0" >> /etc/fstab

# mount -a

  • 安装部署DHCP服务器

# yum -y install dhcp

修改配置文件

# vi /etc/dhcp/dhcpd.conf

log-facility local7;

option domain-name "example.com";

option domain-name-servers 192.168.136.2;

default-lease-time 600;

max-lease-time 7200;

subnet 192.168.136.0 netmask 255.255.255.0 {

  range 192.168.136.100 192.168.136.200;

  option routers 192.168.136.2;            #路由器IP,可以写网关IP

  next-server 192.168.136.253;             #TFTP Server IP地址

  filename "pxelinux.0";                   #pxelinux 启动文件位置

}

启动DHCP服务并设置为开机启动

# systemctl start dhcpd

# systemctl enable dhcpd

  • 安装部署TFTP服务器

# yum -y install tftp-server

修改配置文件

# vi /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                       #把这行改成no即可

        per_source              = 11

        cps                     = 100 2

        flags                   = IPv4

}

启动TFTP服务并设置为开机自启动

# systemctl start tftp

# systemctl enable tftp

将客户端所需启动文件复制到TFTP服务器

# yum -y install syslinux

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

复制启动镜像文件和启动配置文件至TFTP共享目录

# cp /content/pub/rhel7/x86_64/dvd/isolinux/{boot.msg,splash.png,vmlinuz,initrd.img} /var/lib/tftpboot/

# mkdir /var/lib/tftpboot/pxelinux.cfg/

# cp /content/pub/rhel7/x86_64/dvd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

# chmod 644 /var/lib/tftpboot/pxelinux.cfg/default

修改启动配置文件

# vi /var/lib/tftpboot/pxelinux.cfg/default

default linux
timeout 600

...

label linux

  menu label ^Install Red Hat Enterprise Linux 7.2
  kernel vmlinuz
  append initrd=initrd.img ks=http://192.168.136.253/ks-config/ks7.cfg

...

  • 创建Kickstart自动应答文件

#platform=x86, AMD64, or Intel EM64T

#version=DEVEL

# Install OS instead of upgrade

install

# Keyboard layouts

keyboard --vckeymap=us --xlayouts='us'

# Root password

rootpw --plaintext redhat

# System services

services --enabled="chronyd"

# System timezone

timezone Asia/Shanghai --isUtc

# Use network installation

url --url="http://192.168.10.120/pub/rhel7/x86_64/dvd"

# System language

lang en_US.UTF-8

# System authorization information

auth --enableshadow --passalgo=sha512

# Use graphical install

graphical

# Network information

network  --bootproto=dhcp --device=eth0

# Firewall configuration

firewall --disabled 

# SELinux configuration

selinux --disabled 

# Reboot after installation

reboot

# System bootloader configuration

bootloader --location=mbr

# Partition clearing information

clearpart --all --initlabel

# Disk partitioning information

part /boot --asprimary --fstype="ext4" --ondisk=sda --size=200

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

part / --fstype="ext4" --ondisk=sda --size=10240

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

#part /boot --fstype="xfs" --size=256

#part / --fstype="xfs" --grow --size=10240

  %packages

  @^minimal

  @core

  @Development Tools

  chrony

  net-tools

  lsof

  wget

  kexec-tools

  %end

%post

cat > /etc/yum.repos.d/rhel-dvd.repo << EOF

[rhel-dvd]

name=rhel dvd

baseurl=http://192.168.10.120/pub/rhel7/x86_64/dvd

gpgcheck=0

enabled=1

EOF

%end

或者在有图形界面的RedHat上安装kickstart图形化配置软件system-config-kickstart

# yum -y install system-config-kickstart

运行system-config-kickstart

# system-config-kickstart

  • 开通防火墙

# firewall-cmd --permanent --add-service={tftp,http}

# firewall-cmd --reload

  •  启动客户端,安装部署系统

在所有客户端主机的BIOS中,将第一启动方式设置为PXE网络启动。设置完成后,重启所有客户端计算机即可完成大规模集中安装部署操作系统。

上一篇:Linux中阶—域名解析服务DNS(十)

下一篇:​​​​​​​Linux高阶—磁盘性能分析iostat(二)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值