PXE基于网络自动化安装

时间:2021-01-03 06:56:18

    这周针对自动化安装我们讲述PXE自动化安装centos6和centos7

一、需要提前关闭防火墙和SELINUX,DHCP服务器使用静态IP

    用getenforce查看SELINUX是否关闭

    iptables -F 关闭防火墙

二、安装http、tftp-server、dhcp、syslinux包

    yum install http tftp-server dhcp syslinux

三、启动httpd服务

    设置httpd开启自启

    systemctl enable httpd

    启动httpd服务

    systemctl start httpd

    创建目录

    mkdir -p /var/www/html/centos/{6,7}

    挂载对应的光盘

    mount /dev/sr0 /var/www/html/centos/7

    mount /dev/sr1 /var/www/html/centos/6

    设置开启自动挂载

    vim /etc/fstab

    /dev/sr0 /var/www/html/centos/6 iso9660 defaults 0 0

    /dev/sr1 /var/www/html/centos/7 iso9660 defaults 0 0

四、修改DHCP配置文件

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

    vim /etc/dhcp/dhcpd.conf

    PXE基于网络自动化安装

    systemctl start dhcpd

    ss -nul查看DHCP67端口是否开启

    systemctl enable dhcpd

五、启动tftp服务

    PXE基于网络自动化安装

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

    cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot

    cp /var/www/html/centos/7/isolinux/isolinux.cfg pxelinux.cfg/

    vim default内容如下:

    PXE基于网络自动化安装

    设置开机启动

    systemctl enable tftp

    启动服务

    systemctl start tftp

六、准备应达文件

    mkdir /var/www/html/ks

    cp /root/{ks6.cfg,ks7.cfg} /var/www/html/ks/

vim ks6.cfg内容如下:

    # Kickstart file automatically generated by anaconda.

    #version=DEVEL

    install

    url --url="http://172.17.0.1/centos/6"

    lang en_US.UTF-8

    keyboard us

    network --onboot yes --device eth1 --bootproto dhcp --noipv6

    rootpw  --iscrypted $6$tXmSEQTX.96Oxlwf$CS6RX80cUp/M/ME7NudrGH8uMtQA32fq9qWHGpda

    VOyFExQGZtG3aBGcbHikxZ5Q69YR5pDJaF98C3MtCDU5b1

    firewall --service=ssh

    authconfig --enableshadow --passalgo=sha512

    selinux --disabled

    timezone Asia/Shanghai

    bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet

    "

    # The following is the partition information you requested

    # Note that any partitions you deleted are not expressed

    # here so unless you clear all partitions first, this is

    # not guaranteed to work

    #clearpart --none

     

    part /boot --fstype=ext4 --size=1024

    part / --fstype=ext4 --size=51200

    part /app --fstype=ext4 --size=51200

     

    part swap ―size=2048

    repo --name="CentOS"  --baseurl=cdrom:sr0 --cost=100

     

    %packages

    @core

    @server-policy

    @workstation-policy

    autofs

    @desktop

    %end

     

    %post

    rm -rf /etc/yum.repos.d/*

    cat > /etc/yum.repos.d/base.repo <<EOF

    [base]

    name=base

    baseurl=http://172.17.0.1/centos/6

    gpgcheck=0

    EOF

    useradd wang

    echo magedu |passwd --stdin wang

    %end

 

vim ks7.cfg内容如下:

    #version=DEVEL

    # System authorization information

    auth --enableshadow --passalgo=sha512

    # Use CDROM installation media

    url --url=http://192.168.153.146/centos/7/

    # Use graphical install

    text

    reboot

    # Run the Setup Agent on first boot

    firstboot --disable

    ignoredisk --only-use=sda

    # Keyboard layouts

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

    # System language

    lang en_US.UTF-8

     

    # Network information

    network  --bootproto=dhcp --device=ens33 --onboot=on --ipv6=auto --activate

    network  --hostname=centos7.magedu.com

     

    # Root password

    rootpw --iscrypted $6$JXYEkzjhvNHA9CO8$yIDZnl0jc5YRRSkzQZIVnGiBRTLv1eF/q1ubmmG0a

    Dpj20vTpvn56rCCQl9kfnBNENkxWxSiuzqo/qX9Un3nt0

    # System services

    services --disabled="chronyd"

    # System timezone

    timezone Asia/Shanghai --isUtc ―nontp

    user --name=magedu --password=$6$qhd7tuB6MGxRHCoB$EIsmRGtxp4J/hl2AnYjIBhJMYGUXRG

    KgD/zrPfL0yStVwvbCn60UqrSLQBtYWcJTjZXSwSMkuHldD7G2GTdgD/ --iscrypted --gecos="ma

    gedu"

    # X Window System configuration information

    xconfig  --startxonboot

    # System bootloader configuration

    bootloader --location=mbr --boot-drive=sda

    autopart --type=lvm

    # Partition clearing information

    clearpart --none --initlabel

     

    %packages

    @^graphical-server-environment

    @base

    @core

    @desktop-debugging

    @dial-up

    @fonts

    @gnome-desktop

    @guest-agents

    @guest-desktop-agents

    @hardware-monitoring

    @input-methods

    @internet-browser

    @multimedia

    @print-client

    @x11

     

    %end

     

    %addon com_redhat_kdump --disable --reserve-mb='auto'

     

    %end

     

    %anaconda

    pwpolicy root --minlen=6 --minquality=50 --notstrict --nochanges --notempty

    pwpolicy user --minlen=6 --minquality=50 --notstrict --nochanges --notempty

    pwpolicy luks --minlen=6 --minquality=50 --notstrict --nochanges --notempty

    %end

到此为止就可以基于网络自动化安装了。