• kickstart半自动安装centos系统与pxe自动安装centos系统


    一、kickstart半自动安装centos系统

    关闭防火墙,关闭selinux使用system-config-kickstart生成kickstart配置文件,启动xmanger-Passive

    [root@centos7 ~]#export DISPLAY=10.0.0.1:0.0

    [root@centos7 ~]#system-config-kickstart

    即可进入kickstart配置文件图形终端,使用system-config-kickstart生成kickstart配置文件

    步骤:

    1、Basic Configuration

    #在kickstart应答文件中会生成以下格式
    #platform=x86, AMD64, or Intel EM64T                     #Default Language默认语言                                 lang en_US                                               # Keyboard 键盘 keyboard 'us' # timezone 时区(勾选了"Use UTC clock" 会追加[--isUtc]) timezone Asia/Shanghai # Root password rootpw --iscrypted $1$DBk7xfJp$Agxd303XUAfRKIf7gB8DG/ ==================================================== #Advanced Configuration       #勾选就有,不勾没有 ====================================================
    # Reboot after installation reboot # Use text mode install text

    2、Installation Method

    #在kickstart应答文件中会生成以下格式
    # Install OS instead of upgrade
    install
    # Upgrade existing installation
    upgrade
    # Use network installation #如果是光盘就会生成cdrom
    url --url="http://(服务器ip)/Centos/7/os/x86_64"

    3、Boot Loader Options

    #在kickstart应答文件中会生成以下格式
    # System bootloader configuration
     bootloader --append="ker" --location=mbr --password="123"
    #append是内核参数,location是bootloader安装位置,password是GRUB密码

    4、Partition Information

    #在kickstart应答文件中会生成以下格式
    # Clear the Master Boot Record
    zerombr
    # Partition clearing information
    clearpart --linux --initlabel
    # Disk partitioning information
    part / --fstype="xfs" --size=10240
    part /boot --fstype="ext4" --size=1024
    part swap --fstype="swap" --size=2048

    5、 Network Configuration

    #在kickstart应答文件中会生成以下格式
    # Network information
    network  --bootproto=dhcp --device=ens33

    6、Authentication

    #在kickstart应答文件中会生成以下格式
    # System authorization information
    auth  --useshadow  --passalgo=md5

    7、Firewall Configuration

    #在kickstart应答文件中会生成以下格式
    # SELinux configuration
    selinux  --disabled
    # Firewall configuration
    firewall  --disabled

    8、Display Configuration

    #在kickstart应答文件中会生成以下格式
    # Do not configure the X Window System (如果选了安图形则没有这个界面)
    skipx  
    # Run the Setup Agent on first boot
    firstboot --enable

    9、Package Selection

    如果包安装的界面不出现可选的包信息,那么需要修改yum仓库配置文件
    [root@centos ~]#vim /etc/yum.repos.d/***.repo
    [development]
    #把原来"[]"内的内容改成development,其它不变
    #选了什么包就会生成对应的文件信息
    #在kickstart应答文件中会生成以下格式
    %packages
    @development
    -byacc
    -indent
    -intltool
    -patchutils
    -rcs
    -subversion-swig
    -systemtap
    %end #(必须以%end结尾)

    10、Pre-Installation Script

    #在kickstart应答文件中会生成以下格式
    %pre    #(安装前脚本我一般都不写)
    echo i am pre 
    %end

    11、Post-Installation Script

    #在kickstart应答文件中会生成以下格式
    %post --nochroot
    #可以再安装后脚本中创建用户或创建yum源等等等等
    useradd zxc
    echo 123456 |passwd --stdin zxc &> /dev/null
    mkdir /etc/yum.repos.d/bak
    mv /etc/yum.repos.d/* /etc/yum.repos.d/bak
    cat > /etc/yum.repos.d/base.repo <<EOF
    [base]
    name=base
    baseurl=file:///misc/cd
    gpgcheck=0
    EOF
    
    %end

    最后生成的应答文件如下(例如文件名ks7.cfg)

    [root@centos7 ~]#vim  ks7.cfg
    #platform=x86, AMD64, or Intel EM64T
    #version=DEVEL
    # Install OS instead of upgrade
    install
    # Keyboard layouts
    keyboard 'us'
    # Root password
    rootpw --iscrypted ...................(加密的密码)................
    # System language
    lang en_US
    # System authorization information
    auth  --useshadow  --passalgo=sha512
    # Use text mode install
    text
    firstboot --disable
    # SELinux configuration
    selinux --disabled
     # Firewall configuration
    firewall --disabled
    # Network information
    network  --bootproto=dhcp --device=ens33
    #network  --hostname=centos7  #(此项为指定主机名可加可不加)
    # Reboot after installation
    reboot
    # System timezone
    timezone Asia/Shanghai
    # Use network installation
    url --url="http://(服务器ip)/centos/7/os/x86_64/"
    # Clear the Master Boot Record
    zerombr
    # Partition clearing information
    clearpart --all --initlabel
    ignoredisk --only-use=sda
    # Disk partitioning information
    part / --fstype="xfs" --size=10240
    part /boot --fstype="ext4" --size=1024
    part swap --fstype="swap" --size=2048
     %post
    useradd zxc
    e
    cho 123456|passwd --stdin zxc
    %end
    之后把该文件放到服务器上如:/var/www/html/k/下
    可以将定制安装光盘,并结合kickstart实现基于光盘启动的半自动化安装        #(嫌麻烦也可以去阿里源下载centos7的netinstall光盘 )

    步骤

    [root@centos7 ~]#mkdir –pv /data/myiso
    [root@centos7 ~]#cp -r /mnt/isolinux/ /data/myiso/
    [root@centos7 ~]#vim /data/myiso/isolinux/isolinux.cfg
    label linux
     menu label ^Auto Install CentOS Linux 7
     kernel vmlinuz
     append initrd=initrd.img quiet ks=http://10.0.0.18/k/ks7.cfg
    label rescue
     menu label ^Rescue a CentOS Linux system
     kernel vmlinuz
     append initrd=initrd.img inst.repo=http://10.0.0.18/centos/7/os/x86_64/ rescue 
    quiet
    label local
     menu default
     menu label Boot from ^local drive
     localboot 0xffff
    [root@centos7 ~]#cp /root/myks.cfg /data/myiso/
    [root@centos7 ~]#dnf -y install mkisofs
    [root@centos7 ~]#mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --bootinfo-table -V "CentOS 8.0 x86_64 boot" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /root/boot.iso /data/myiso/
    #从而生成boot.iso光盘

    把生成的光盘boot.iso镜像刻录到U盘,插到一台新机器上

    在启动菜单界面,任意选中一项安装方法,按ESC键进入boot:界面

     输入linux   ks=http://服务器ip/k/ks7.cfg   ip=dhcp  然后回车

     然后您可以出去抽个烟,溜达溜达回来后应该就已经安装好了

    二、pxe自动安装centos系统

    关闭防火墙和SELINUX,DHCP服务器静态IP

    (温馨提示:如果同时安装数量太多可能会发生意想不到的事情呦!)

    1、安装相关软件包并启动

    [root@centos8 ~]#dnf -y install dhcp-server tftp-server httpd syslinux-nonlinux 
    [root@centos8 ~]#systemctl enable --now httpd tftp dhcpd
    

     2、配置DHCP服务

    [root@centos8 ~]#cp /usr/share/doc/dhcp-server/dhcpd.conf.example 
    /etc/dhcp/dhcpd.conf
    [root@centos8 ~]#vim /etc/dhcp/dhcpd.conf 
    option domain-name "example.com";
    option domain-name-servers 180.76.76.76,223.6.6.6;
    default-lease-time 600;
    max-lease-time 7200;
    log-facility local7;
    subnet 10.0.0.0 netmask 255.255.255.0 {
     range 10.0.0.1 10.0.0.200;
     option routers 10.0.0.1;
     next-server 10.0.0.100;
     filename "pxelinux.0"; }
    [root@centos8 ~]#systemctl start dhcpd

    3、准备yum 源和相关目录

    [root@centos8 ~]#mkdir -pv /var/www/html/centos/{6,7,8}/os/x86_64/ 
    [root@centos8 ~]#mount /dev/sr0 /var/www/html/centos/6/os/x86_64/
    [root@centos8 ~]#mount /dev/sr1 /var/www/html/centos/7/os/x86_64/
    [root@centos8 ~]#mount /dev/sr2 /var/www/html/centos/8/os/x86_64/

    4、准备kickstart文件

    [root@centos8 ~]#mkdir /var/www/html/k/         #应答文件可根据需求可自行更改,也可参考“一”生成的文件
    [root@centos8 ~]#vim /var/www/html/k/ks6.cfg  
    install
    text
    reboot
    url --url=http://10.0.0.18/centos/6/iso/x86_64/
    lang en_US.UTF-8
    keyboard us
    network --onboot yes --device eth0 --bootproto dhcp  --noipv6
    rootpw --iscrypted $6$loeMb/DwOAMWO9MT$lvxCJFWGgvkfhk4u3mez23BCzNS4bv.yAMcObpH/zzzwoJ.kJriKpyh1YG7gBQYDfFXr8UOV9dco2lS54ag/50
    firewall --disabled
    authconfig --enableshadow --passalgo=sha512
    selinux --disabled
    timezone Asia/Shanghai
    bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
    zerombr
    clearpart --all --initlabel
    part /boot --fstype=ext4 --size=1024
    part / --fstype=ext4 --size=50000
    part /data --fstype=ext4 --size=30000
    part swap --size=2048
    %packages
    @core
    @server-policy
    @workstation-policy
    autofs
    vim-enhanced
    %end
    %post
    useradd zxc
    echo asd9420 | passwd --stdin zxc &> /dev/null
    mkdir /etc/yum.repos.d/bak
    mv /etc/yum.repos.d/* /etc/yum.repos.d/bak
    cat > /etc/yum.repos.d/base.repo <<EOF
    [base]
    name=base
    baseurl=file:///misc/cd
    gpgcheck=0
    EOF
    %end
    ================================================================================ [root@centos8 ~]#vim /var/www/html/k/ks7.cfg install xconfig --startxonboot keyboard --vckeymap=us --xlayouts='us' rootpw --iscrypted $6$xI3rPwQBFxqTNl1M$Imk2HHxf3jTIy1qVzBn/DAYX6RJLbc2amakegO/fQgmQ.6NJBEOBufkHx2B10ZXfScr/SExe.j5j1BDfqM4J21 url --url="
    http://10.0.0.18/centos/7/iso/x86_64" lang en_US.UTF-8 auth --useshadow --passalgo=sha512 text firstboot --enable selinux --disabled skipx services --disabled="chronyd" ignoredisk --only-use=sda firewall --disabled network --bootproto=dhcp --device=ens33 reboot timezone Asia/Shanghai --nontp autopart --type=lvm zerombr clearpart --all --initlabel %post useradd zxc echo asd9420 | passwd --stdin zxc & >/dev/null %end %packages @^minimal vim-enhanced %end
    ======================================================================================
    [root@centos8 ~]#vim /var/www/html/k/ks8.cfg ignoredisk --only-use=sda zerombr clearpart --all --initlabel text url --url=
    http://10.0.0.18/centos/8/iso/x86_64 keyboard --vckeymap=cn --xlayouts='cn' lang zh_CN.UTF-8 firewall --disabled network --bootproto=dhcp --device=ens160 --ipv6=auto --activate network --hostname=CentOS8 rootpw --iscrypted $6$loeMb/DwOAMWO9MT$lvxCJFWGgvkfhk4u3mez23BCzNS4bv.yAMcObpH/zzzwoJ.kJriKpyh1YG7gBQYDfFXr8UOV9dco2lS54ag/50 firstboot --enable skipx services --disabled="chronyd" timezone Asia/Shanghai --isUtc --nontp user --name=zxc --password=$6$L/YFB8zwDbSjnHQK$vkKhMNIKIqZKHsvPzUaud.BuKYKwnaHUl.4lbA9Nkesbjbpdec6eNi5j3msQ285LUx7.3kgM5AirHz/4Fvjut. --iscrypted --gecos="zxc" selinux --disabled reboot autopart --type=lvm %packages @^minimal-environment @container-management @legacy-unix @network-server @rpm-development-tools @security-tools @system-tools kexec-tools %end %addon com_redhat_kdump --enable --reserve-mb='auto' %end %anaconda pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty %end %post useradd zxc echo asd9420 | passwd --stdin zxc & >/dev/null %end

    5、准备PXE启动相关文件

    [root@centos8 ~]#mkdir /var/lib/tftpboot/centos{6,7,8}
    #准备CentOS6,7,8各自的内核相关文件
    [root@centos8 ~]#cp /var/www/html/centos/6/os/x86_64/isolinux/{vmlinuz,initrd.img}  /var/lib/tftpboot/centos6
    [root@centos8 ~]#cp /var/www/html/centos/7/os/x86_64/isolinux/{vmlinuz,initrd.img}  /var/lib/tftpboot/centos7
    [root@centos8 ~]#cp /var/www/html/centos/8/os/x86_64/isolinux/{vmlinuz,initrd.img}  /var/lib/tftpboot/centos8
    [root@centos8 ~]#cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/ 
    #以下三个文件是CentOS8安装所必须文件,CentOS6,7则不需要 [root@centos8
    ~]#cp /var/www/html/centos/8/os/x86_64/isolinux/{ldlinux.c32,libcom32.c32,libutil.c32} /var/lib/tftpboot/ #生成安装菜单文件 [root@centos8 ~]#mkdir /var/lib/tftpboot/pxelinux.cfg/ [root@centos8 ~]#vim /var/lib/tftpboot/pxelinux.cfg/default
    default menu.c32
    timeout 60

    menu title CentOS Linux 678

    label linux8
      menu label Auto Install CentOS Linux ^8
      kernel centos8/vmlinuz
      append initrd=centos8/initrd.img quiet ks=http://10.0.0.18/k/ks8.cfg

    label linux7
      menu label Auto Install CentOS Linux ^7
      kernel centos7/vmlinuz
      append initrd=centos7/initrd.img quiet ks=http://10.0.0.18/k/ks7.cfg

    label linux6
      menu label Auto Install CentOS Linux ^6
      kernel centos6/vmlinuz
      append initrd=centos6/initrd.img quiet ks=http://10.0.0.18/k/ks6.cfg


    label rescue #参考这个也可以生成6,7的救援菜单,不生成也不影响启动
      menu label ^Rescue a CentOS Linux system
      kernel centos8/vmlinuz
      append initrd=centos8/initrd.img inst.repo=http://10.0.0.18/centos/8/iso/x86_64/ rescue   quiet
          
    label local
      menu default
      menu label Boot from ^local drive
      localboot 0xffff

    6、测试客户端基于PXE实现自动安装

    准备一台新主机,v>

    设置网卡引导,可看到看启动菜单,并实现自动安装centos(或6、7、8),

     之后选择对应的对应的版本回车就行

     

  • 相关阅读:
    Self Numbers
    【acdream】小晴天老师系列——竖式乘法
    全错位排列
    2 ^ x mod n = 1问题
    基于cocos2dx的横版动作游戏制作(二)
    基于cocos2dx的横版动作游戏制作(一)
    横版游戏制作之英雄技能CD遮罩,人物头像血条属性
    cocos2d横版游戏之摇杆控制
    C++ delete []p 数组指针,如何知道该数组大小的
    do { ....} while(0) 在宏里冗余的意义
  • 原文地址:https://www.cnblogs.com/langgeniubi/p/13657397.html
Copyright © 2020-2023  润新知