在咱們平常工做中不免會出現一些系統安裝的過程,可是有時候安裝任務會不少,好比幾十臺,幾百臺機器,人工手動安裝會有點難受,這裏給你們提供一個kick start,咱們能夠經過手動配置來自動安裝系統,這時對於部署大量機器,顯得尤其重要,下面來介紹下kick start,如何安裝,html
官方給的一些說明,你們能夠參考.
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/performing_an_advanced_rhel_installation/index
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/installation_guide/sect-kickstart-syntax
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/installation_guide/s1-kickstart2-optionslinux
kickstart文件主要包括三個部分:命令段,程序包段,腳本段git
這裏要注意:redis
CentOS 8,7,6 不一樣版本的kickstart文件格式不盡相同,不可混用
%addon, %packages, %onerror, %pre 、 %post 必須以%end結束,不然安裝失敗
如下爲centos 8.的最小安裝kiskstart文件配置vim
ignoredisk --only-use=sda #此行必須指定 zerombr #grub清空 text reboot clearpart --all --initlabel selinux --disabled #禁用SELinux firewall --disabled #禁用firewalld url --url=http://10.0.0.8/centos/8/os/x86_64/ keyboard --vckeymap=us --xlayouts='us' lang en_US.UTF-8 bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda #此行必須指定 network --bootproto=dhcp --device=eth0 --ipv6=auto --activate network --hostname=centos8.magedu.org rootpw --iscrypted $6$j9YhzDUnQVnxaAk8$qv7rkMcPAEbV5yvwsP666DXWYadd3jYjkA9fpxAo9qYotjGGBUclCGoP1TRv gHBpqgc5n0RypMsPTQnVDcpO01 firstboot --enable skipx services --disabled="chronyd" timezone Asia/Shanghai --isUtc --nontp user --name=wang -- password=6oUfb/02CWfLb5l8f$sgEZeR7c7DpqfpmFDH6huSmDbW1XQNR4qKl2EPns.gOXqlnAIgv9p TogtFVaDtEpMOC.SWXKYqxfVtd9MCwxb1 --iscrypted --gecos="wang" #autopart --type=lvm #自動按照邏輯卷分區 #part / --fstype xfs --size 1 --grow --ondisk sda 能夠實現根自動使用全部剩餘空間 part / --fstype="xfs" --ondisk=sda --size=102400 part /data --fstype="xfs" --ondisk=sda --size=51200 part swap --fstype="swap" --ondisk=sda --size=2048 part /boot --fstype="ext4" --ondisk=sda --size=1024 %packages @^minimal-environment kexec-tools vim curl wget tree %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 mage echo magedu | passwd --stdin mage &> /dev/null %end 1 ignoredisk --only-use=sda 2 zerombr 3 text 4 reboot 5 clearpart --all --initlabel 6 selinux --disabled 7 firewall --disabled 8 url --url=http://10.0.0.80/centos/8/os/x86_64/ 9 keyboard --vckeymap=us --xlayouts='us' 10 lang en_US.UTF-8 11 network --bootproto=dhcp --device=ens160 --ipv6=auto --activate 12 network --hostname=centos8.magedu.com 13 rootpw --iscrypted $6$j9YhzDUnQVnxaAk8$qv7rkMcPAEbV5yvwsP666DXWYadd3jYjkA9fpxAo9qYotjGGBUclCGoP1TRvgHBpqgc5n0Ry pMsPTQnVDcpO01 14 firstboot --enable 15 skipx 16 services --disabled="chronyd" 17 timezone Asia/Shanghai --isUtc --nontp 18 user --name=rzx --password=6oUfb/02CWfLb5l8f$sgEZeR7c7DpqfpmFDH6huSmDbW1XQNR4qKl2EPns.gOXqlnAIgv9pTogtFVaDtEpMO C.SWXKYqxfVtd9MCwxb1 --iscrypted --gecos="wang" 19 part / --fstype="xfs" --ondisk=sda --size=102400 20 part /data --fstype="xfs" --ondisk=sda --size=51200 21 part swap --fstype="swap" --ondisk=sda --size=2048 22 part /boot --fstype="ext4" --ondisk=sda --size=1024 23 %packages 24 @^minimal-environment 25 kexec-tools 26 %end 27 %addon com_redhat_kdump --enable --reserve-mb='auto' 28 %end 29 %anaconda 30 pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty 31 pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok 32 pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty 33 %end 34 35 %post 36 useradd mage 37 echo magedu | passwd --stdin mage &> /dev/null 38 %end
CentOS 7 的最小化安裝kickstart文件centos
install xconfig --startxonboot keyboard --vckeymap=us --xlayouts='us' rootpw --iscrypted $1$bpNEv8S5$lK.CjNkf.YCpFPHskSNiN0 url --url="http://10.0.0.8/centos/7/os/x86_64" lang en_US 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 bootloader --append="crashkernel=auto" --location=mbr --boot-drive=sda zerombr clearpart --all --initlabel part swap --fstype="swap" --ondisk=sda --size=3072 part / --fstype="xfs" --ondisk=sda --size=51200 part /boot --fstype="xfs" --ondisk=sda --size=1024 part /data --fstype="xfs" --ondisk=sda --size=30720 %post useradd wang %end %packages @^minimal vim-enhanced %end 1 #platform=x86, AMD64, or Intel EM64T 2 #version=DEVEL 3 # Install OS instead of upgrade 4 install 5 # Keyboard layouts 6 keyboard 'us' 7 # Root password 8 rootpw --plaintext magedu 9 # System language 10 lang en_US 11 # System authorization information 12 auth --useshadow --passalgo=sha512 13 # Use text mode install 14 text 15 firstboot --disable 16 # SELinux configuration 17 selinux --disabled 18 19 20 # Firewall configuration 21 firewall --disabled 22 # Network information 23 network --bootproto=static --device=eth0 --ip=10.0.0.123 --netmask=255.255.255.0 24 # Reboot after installation 25 reboot 26 # System timezone 27 timezone Asia/Shanghai 28 # Use network installation 29 url --url="http://10.0.0.8/centos/7/os/x86_64" 30 # System bootloader configuration 31 bootloader --append="net.ifnames=0" --location=mbr 32 # Partition clearing information 33 clearpart --all 34 # Disk partitioning information 35 part / --fstype="xfs" --size=100000 36 37 %post 38 useradd rzx 39 echo magedu |passwd --stdin 123456 40 mkdir /etc/yum.repos.d/backup 41 mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup 42 cat > /etc/yum.repos.d/base.repo <<EOF 43 [base] 44 baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ 45 http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/ 46 http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/ 47 gpgcheck=1 48 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 49 EOF 50 mkdir /root/.ssh -m 700 51 cat > /root/.ssh/authorized_keys <<EOF 52 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAsGcrlhZQUX07tc/F7OEcpUpSYFRP9M+jejHewX8C37aZxxMZLH8ULSrdH8YDbYhyl2/aN7QlxpJ BxFTEI5CmzLocwRRNVynL4jVRNRa+61Km2CaaqgIio6Kfp7qHqYxZjirY8fDsB8ygjQmF3D5CCCwGd+Y9KxOVNLMdyoQmmK8= 53 EOF 54 chmod 600 /root/.ssh/authorized_keys 55 %end 56 57 %packages
CentOS 6 的最小化安裝kickstart文件bash
install text reboot url --url=http://10.0.0.8/centos/6/os/x86_64/ lang en_US.UTF-8 keyboard us network --onboot yes --device eth0 --bootproto dhcp --noipv6 rootpw --iscrypted $6$b6C5mM/BwOMBoK8H$cYZFrHoNlOL0iDsxOTRhwnWJ3yfFmf7mRJBOxEqGoI56UMrT8J7qlrGwX7tS nOf7wKxYR2hAvAREILDgOgsFe1 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 wang echo magedu | passwd --stdin wang &> /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 1 install 2 text 3 reboot 4 url --url=http://10.0.0.80/centos/6/os/x86_64/ 5 lang en_US.UTF-8 6 keyboard us 7 network --onboot yes --device eth0 --bootproto dhcp --noipv6 8 rootpw --iscrypted $6$j9YhzDUnQVnxaAk8$qv7rkMcPAEbV5yvwsP666DXWYadd3jYjkA9fpxAo9qYotjGGBUclCGoP1TRvgHBpqgc5n0R ypMsPTQnVDcpO01 9 firewall --disabled 10 authconfig --enableshadow --passalgo=sha512 11 selinux --disabled 12 timezone Asia/Shanghai 13 bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" 14 zerombr 15 clearpart --all --initlabel 16 part /boot --fstype=ext4 --size=1024 17 part / --fstype=ext4 --size=50000 18 part /data --fstype=ext4 --size=30000 19 part swap --size=2048 20 %packages 21 @core 22 @server-policy 23 @workstation-policy 24 autofs 25 vim-enhanced 26 %end 27 %post 28 useradd wang 29 echo magedu | passwd --stdin wang &> /dev/null 30 mkdir /etc/yum.repos.d/bak 31 mv /etc/yum.repos.d/* /etc/yum.repos.d/bak 32 cat > /etc/yum.repos.d/base.repo <<EOF 33 [base] 34 name=base 35 baseurl=file:///misc/cd 36 gpgcheck=0 37 EOF 38 %end
建立kickstart文件的方式服務器
可以使用建立工具:system-config-kickstart ,注意:此方法 CentOS 8 再也不支持網絡
依據某模板修改並生成新配置,CentOS安裝完後,會自動參考當前系統的安裝過程,生成一個
kickstart文件 /root/anaconda-ks.cfgapp
檢查ks文件的語法錯誤:
使用 ksvalidator 工具能夠檢查kickstart的文件格式是否有語法錯誤,來自於 pykickstart 包
格式:
ksvalidator /PATH/TO/KICKSTART_FILE
使用以前須要安裝kickstart
root@centos7 ~]#yum -y install system-config-kickstart # 而後讓 Xmanager -Passive 運行起來 [21:59:04 root@centos7 ~]#export DISPLAY=10.0.0.1:0.0 [22:09:08 root@centos7 ~]#system-config-kickstart
如下爲詳細使用使用 system-config-kickstart 生成kickstart`配置文件;
配置文件以下
┌────────────────────────────────────────────────────────┐ │#Basic Configuration │======================================================== │#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 └────────────────────────────────────────────────────────┘
配置文件以下
┌────────────────────────────────────────────────────────┐ │#Installation Method │======================================================== │# Install OS instead of upgrade │install 3. Boot Loader Options 配置文件以下 │# Upgrade existing installation │upgrade └────────────────────────────────────────────────────────┘ ┌────────────────────────────────────────────────────────┐ │#Installation source │選了哪項就寫哪項 │======================================================== │# Use CDROM installation media │cdrom │# Use NFS installation media │nfs --server=服務器 --dir=目錄 │# Use network installation │url --url="ftp://用戶名:密碼@服務器/目錄" │# Use network installation │url --url="http://服務器/目錄" │# Use hard drive installation media │harddrive --dir=目錄 --partition=分區 └────────────────────────────────────────────────────────┘
配置文件以下
┌────────────────────────────────────────────────────────────────┐ │#Installation Method&GRUB options&Install Options │================================================================= │ ┌────────────────────────────────────┐ │ │ 選擇了Do not install a boot loader │ │ └────────────────────────────────────┘ │ # System bootloader configuration │ bootloader --location=none │ │ ┌────────────────────────────────────┐ │ │ 選擇了install new boot loader │ │ └────────────────────────────────────┘ │ bootloader --append="ker" --location=mbr --password="123" │#append是內核參數,location是bootloader安裝位置,password是GRUB密碼 └────────────────────────────────────────────────────────────────┘ net.ifnames=0
配置文件以下
┌─────────────────────────────────────────────────────┐ │# Master Boot Record │#Master Boot Record選擇了clear... 不然就沒有 │====================================================== │# Clear the Master Boot Record │zerombr └─────────────────────────────────────────────────────┘ ┌─────────────────────────────────────────────────────┐ │# Partitions&Disk Label │====================================================== │# Partition clearing information │clearpart --linux --initlabel └─────────────────────────────────────────────────────┘ ┌─────────────────────────────────────────────────────┐ │# Layout 分區 │part 掛載點 --fstype=文件系統 --size=大小(單位M) │====================================================== │# Disk partitioning information │part / --fstype="xfs" --size=10240 │part /boot --fstype="ext4" --size=1024 │part swap --fstype="swap" --size=2048 └─────────────────────────────────────────────────────┘
配置文件以下
eth0
Langqq123
┌─────────────────────────────────────────────────────┐ │# Network Configuration │Centos7若是要寫eth0,要加內核參數net.ifnames=0 │====================================================== │# Network information │network --bootproto=dhcp --device=eth0 └─────────────────────────────────────────────────────┘
配置文件以下
┌───────────────────────────────────────────────────────────────┐ │# Authentication │若是勾選Enable Fingerprint reader則追加參數 --enablefingerprint │=============================================================== │# System authorization information │auth --useshadow --passalgo=md5 └───────────────────────────────────────────────────────────────┘
配置文件以下
┌───────────────────────────────────────────────────────────────┐ │# Firewall Configuration │=============================================================== │# SELinux configuration │selinux --disabled或permissive或enforcing │ │# Firewall configuration │firewall --disabled或enabled │#若是是enable,能夠在追加:--http --ftp --telnet --smtp --ssh │#還能夠追加端口:--port=555:tcp,444:udp └───────────────────────────────────────────────────────────────┘
┌───────────────────────────────────────────────────────────────┐ │# Display Configuration │=============================================================== │若是選了安裝圖形界面,就沒有下面這句話 │# Do not configure the X Window System │skipx │# Run the Setup Agent on first boot │firstboot --enable或disable └───────────────────────────────────────────────────────────────┘
若是包安裝的界面不出現可選的包信息,那麼須要修改yum倉庫配置文件
[root@centos ~]#vim /etc/yum.repos.d/***.repo [development] #把原來"[]"內的內容改爲development,其它不變
配置文件以下
%packages @development -byacc -cscope -ctags -diffstat -doxygen -elfutils -gcc-gfortran -git -indent -intltool -patchutils -rcs -subversion -swig -systemtap %end
配置文件以下
%pre echo i am pre %end
配置文件以下
%post --nochroot echo i am post %end
12 以上system-config-kickstart 執行後最終生成的kickstart文件以下
#platform=x86, AMD64, or Intel EM64T #version=DEVEL # Install OS instead of upgrade install # Keyboard layouts keyboard 'us' # Root password rootpw --iscrypted $1$2TeoFGRN$EeykyMirEiMIya57QmbG71 # Use network installation url --url="http://192.168.100.7/Centos/7/os/x86_64" # System language lang zh_CN # System authorization information auth --useshadow --passalgo=sha512 # Use text mode install text # Run the Setup Agent on first boot firstboot --enable # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # Firewall configuration firewall --disabled # Network information network --bootproto=dhcp --device=eth0 # Reboot after installation reboot # System timezone timezone Asia/Shanghai # System bootloader configuration bootloader --append="net.ifnames=0" --location=mbr # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel # Disk partitioning information part /boot --fstype="ext4" --size=2048 part / --fstype="xfs" --size=10240 part swap --fstype="swap" --size=2048 %pre i am pre %end %post --nochroot i am post %end %packages @development -byacc -cscope -ctags -diffstat -doxygen -elfutils -gcc-gfortran -git -indent -intltool -patchutils -rcs -subversion -swig -systemtap %end
完成後 能夠進行語法檢查
root@centos7 ~]#vim kstest.cfg root@centos7 ~]#ksvalidator kstest.cfg #須要安裝pyksvalidator
PXE 自動化安裝系統部署見下篇,感謝閱讀.