写好一个脚本, 让centos自己完全自动安装, 就这么干!

每次安装CentOS时候,都需要鼠标勾选配置.一台机器安装还可以接受,如果有多台,就不好了,下面就介绍下CentOS ftp形式无人值守安装

  • 测试环境

    • 2台机器

    • 机器1: ip 192.168.1.103/24 跑了vsftpd服务,并且共享了/var/ftp, 目录内容

      1. ks.cfg CentOS kickstart配置文件[就是安装的配置文件, 每次安装系统后,都会生成 /root/anaconda-ks.cfg]
      2. pub/CentOS/* CentOS光盘中所有内容的复制[理论是可以挂在的, 但实验挂在不行,读取不到文件]
    • 机器2 只需要放入CentOS的光盘, 启动后按键盘ESC, 输入命令 linux ks=ftp://192.168.1.103/ks.cfg 即可完成

  • ks.cfg配置文件详解

    # Kickstart file automatically generated by anaconda.
    
    

    #version=DEVEL
    install
    url
    –url=ftp://192.168.1.103/pub/CentOS # 配置安装树目录 本文已ftp方式
    lang en_US.UTF-8
    keyboard us
    network
    –onboot no –device eth0 –mtu=1500 –bootproto dhcp –noipv6 # dhcp方式获取ip
    rootpw
    –iscrypted $6$RyFEkouZJLufDNGf$POLwfvq2CHW2BY1qVGFzX6HoX1CsRGvaifo03Zec0uRQnupT.el3fg50b4I3pQRRMFZJqPdW8BypTe0shmZYi.

    Reboot after installation

    reboot
    firewall –service=ssh
    authconfig
    –enableshadow –passalgo=sha512
    selinux
    enforcing
    timezone
    –utc Asia/Shanghai # 默认时区
    bootloader
    –location=mbr –driveorder=sda –append=crashkernel=auto rhgb rhgb quiet 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 –all –drives=sda # 删除磁盘

    part /boot –fstype=ext4 –size=500 # 分boot分区
    part
    / –fstype=ext4 –size=5000 # 分根分区
    part swap
    –grow –maxsize=1024 –size=1024 # 分swap分区 可以使用 part swap --<span style="color: #000000;">recommended 推荐

    repo –name=CentOS –baseurl=ftp://192.168.1.103/pub/CentOS –cost=1000 # 镜像源,包含所有的软件包

    %packages –nobase
    @Core # 核心包, 可以自己添加多个

    %end

    %post
    yum install -y vim # 安装后自动执行脚本 可根据自己定义编写
    %end

配置参数很多,只列出了一点详细可参考官方网站centos kickstart 也可一用软件自动生成ks.cfg文件,搜索软件包 yum search kickstart 出来两个 pykickstart|system-config-kickstart 安装即可