写一个一键安作业

  1. 使用 kickstart 半自动化安装CentOS系统

    分两步:第一步制作kickstart文件,第二在安装时指定kickstart文件

    • 制作kickstart文件

      • centos7 kickstart文件

        #platform=x86, AMD64, or Intel EM64T
        #version=DEVEL
        # Install OS instead of upgrade
        ignoredisk --only-use=sda
        install
        # Keyboard layouts
        keyboard 'us'
        # Root password
        rootpw --iscrypted $1$soUjfIEK$vYPh2zadx6by9t2ingDyy.
        # 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
        # Reboot after installation
        reboot
        # System timezone
        timezone Asia/Shanghai
        # Use network installation
        url --url="<http://172.16.135.203/centos7/>"
        # System bootloader configuration
        bootloader --location=mbr
        # Clear the Master Boot Record
        zerombr
        # Partition clearing information
        clearpart --all --initlabel --drives=sda
        # Disk partitioning information
        part /boot --fstype="xfs" --ondisk=sda --size=1024
        part pv.159 --fstype="lvmpv" --ondisk=sda --size=18432
        volgroup centos --pesize=4096 pv.159
        logvol swap  --fstype="swap" --size=2048 --name=swap --vgname=centos
        logvol /  --fstype="xfs" --size=16000 --name=root --vgname=centos
        
        %packages
        @base
        @core
        bash-completion
        tree
        %end
        
        %post
        date > /root/install_time.txt
        %end
        

      kickstart可以使用 system-config-kickstart 工具生成(需要安装), 也可以使用系统安装时生成的/root/anaconda-ks.cfg文件

      应答文件制作好后,放到web服务器上(方便修改安装时的选项,如果是刻录到光盘文件中,修改将会非常麻烦)

      需要注意的是,如果是centos7,在使用 system-config-kickstart 工具制作kickstart文件时,可能会出现以下情况

      image-20200930111552916

      解决方法是:修改增加或修改一个yum源为development,如下

      image-20200930112029661

      手工修改的kickstart文件后,可以使用ksvaildator 应答文件来检查是否有语法错误

    • 安装时指定kickstart文件

      1. 进入安装界面后,按下esc键,进入boot命令模式

      2. 输入:linux ks=应答文件存放位置,比如:linux <http://172.168.135.201>:/ksidr/ks_7.cfg

        存放在网络上的话,因为要联网才能拿到应答文件,所以需要配置网络。配置网络可以boot命令模式中指定,linux ks=应答文件存放位置 ip=xxx netmask=xxx gateway=xxx。也可以不指定,系统会在安装时自动获取IP地址。

        指定kickstart文件也可以在进入安装界面按下tab键,直接输入kickstart文件位置。如:linux <http://172.168.135.201>:/ksidr/ks_7.cfg

      3. 指定完成后,直接回车等待安装完成即可

  2. 实现pxe安装双系统centos6、centos7

    安装前准备:

    关闭防火墙和SELINUX,为DHCP服务器静态IP(如果使用的虚拟机,网卡的连接方式选择NAT为佳。因为选择桥接的话,很可能物理网络中还有别的DHCP服务器,容易出现冲突)

    1. 安装软件包,并启动httpd tftp-server dhcp服务

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

      httpd:存放yum仓库和kickstart文件

      tftp-server:简化版的文件传输服务,之所以需要使用它,是因为网卡中一般都会继承tftp-client

      dhcp:用于为要安装的机器分配IP地址,和传输启动文件pxelinux.0

      syslinux:一些文件由这个包提供,pxelinux.0这个文件来自这个包

      system-config-kickstart:生成kickstart文件

    2. 配置dhcp服务,并启动httpd tftp-server dhcp服务

      dhcp服务配置如下:

      subnet 192.168.3.0 netmask 255.255.255.0 {
        range 192.168.3.10 192.168.3.20;
        option routers 192.168.3.1;
        next-server 192.168.3.2;
        filename "pxelinux.0";
      }
      

      systemctl start httpd tftp-server dhcpd

    3. 准备yum源,也就是将相应的系统安装包放到httpd的网页目录下

      mount /dev/sr0 /var/www/html/centos/7 sr0为centos7的光盘,sr1为centos6的光盘

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

    4. 准备kickstart应答文件,并放入httpd的网页目录下

      • ks6_min.cfg
      • ks7_min.cfg
      Centos7root@Wed Feb 19 html]# tree ksdir
      ksdir
      └── 6
      		└── ks6_min.cfg
      └── 7
          └── ks7_min.cfg
      
    5. 准备PXE相关文件

      • 需要切换到tftp-server的工作目录:/var/lib/tftpboot

      复制pxelinux.0文件:cp /usr/share/syslinux/pxelinux.0 .

      从系统光盘中拷贝内核文件(vmlinuz)和虚拟文件系统文件(initrd.img)

      拷贝菜单风格文件menu.c32:cp /usr/share/syslinux/menu.c32 .

      从光盘中拷贝启动菜单配置文件:cp /var/www/html/centos/7/isolinux/isolinux.cfg pxelinux.cfg/default,并修改defaul文件如下:

      default menu.c32
      timeout 600 
      
      menu title CentOS 7
      
      label desktop
        menu label Install min CentOS ^6
        kernel vmlinuz
        append initrd=initrd.img ks=http://192.168.3.2/ksdir/7/ks6_min.cfg
      
      label mini
        menu label  Install mini CentOS ^7
        kernel vmlinuz
        append initrd=initrd.img ks=http://192.168.3.2/ksdir/7/ks7_min.cfg
      
      label local
        menu default
        menu label Boot from ^local drive
        localboot 0xffff
      
      menu end
      
    6. 重启tftp服务:systemctl start tftpd

    7. 至此配置完成,只需要安装机器的时候选择从网络安装就能自动安装了(在BIOS界面中选择)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值