s32 kickstart 批量自动安装系统

1. 自动安装操作系统

http://blog.oldboyedu.com/autoinstall-kickstart/
 
自动安装操作系统的解决方案:kickstart、cobbler(披着web外皮的kickstart)
                       inotify sersync

2.kickstart自动安装操作系统的原理

 
anaconda自动安装系统程序从一个文件中读取安装过程所需的所有操作,然后可以自动的安装操作系统。这个文件就叫自动应答文件(ks文件)
 

3.kickstart的架构

cobbler(kickstart)服务组成:dhcp,tftp,http
 

4.安装kickstart

4.0 环境

[root@m01 ~]# cat /etc/redhat-release 
CentOS release 6.9 (Final)
[root@m01 ~]# uname -r
2.6.32-696.el6.x86_64
[root@m01 ~]# getenforce 
Disabled
[root@m01 ~]# /etc/init.d/iptables status
iptables: Firewall is not running.
[root@m01 ~]# hostname -I
10.0.0.21 172.16.1.21 

4.1 安装DHCP

yum -y install dhcp 
cat >>/etc/dhcp/dhcpd.conf<<EOF
subnet 172.16.1.0 netmask 255.255.255.0 {
range 172.16.1.100 172.16.1.200;
option subnet-mask 255.255.255.0;
default-lease-time 21600;
max-lease-time 43200;
next-server 172.16.1.21;
filename "/pxelinux.0";
}
EOF
 
 
100个IP同时安装50台  --> 初始化了两次网络 【第一次dhcp,第五次应答文件】 
 
 
range 172.16.1.100 172.16.1.200;      # 可分配的起始IP-结束IP
option subnet-mask 255.255.255.0;      # 设定netmask
default-lease-time 21600;              # 设置默认的IP租用期限
max-lease-time 43200;                   # 设置最大的IP租用期限
next-server 172.16.1.21;               # 告知客户端TFTP服务器的ip
filename "/pxelinux.0";              # 告知客户端从TFTP根目录下载pxelinux.0文件
 
 
一千台机器装系统    一次装23台【24口交换机性价比最高】  一台安装服务器
查看日志
  • tailf /var/log/messages
启动
  • /etc/init.d/dhcpd start

4.2 安装TFTP

yum -y install tftp-server
 
# 配置
sed -i.ori '14s#yes#no#' /etc/xinetd.d/tftp
 
# 启动
/etc/init.d/xinetd start
 
# 寻找pxelinux.0启动文件
yum -y install syslinux
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
 
# 找配置文件
mkdir -p /var/www/html/CentOS6.9
mount /dev/cdrom /var/www/html/CentOS6.9
cp -a /var/www/html/CentOS6.9/isolinux/* /var/lib/tftpboot/
 
mkdir -p /var/lib/tftpboot/pxelinux.cfg
 
# 配置文件default
cp /var/www/html/CentOS6.9/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
 

4.3 安装HTTP

yum -y install httpd
/etc/init.d/httpd start
 
---- curl http:
//172.16.1.21/CentOS6.9/ http://172.16.1.21/CentOS6.9/

4.4 配置自动化安装的default

cat>/var/lib/tftpboot/pxelinux.cfg/default<<EOF
default ks
prompt 0
 
label ks
  kernel vmlinuz
  append initrd=initrd.img ks=http://172.16.1.21/ks_config/CentOS-6.9-ks.cfg ksdevice=eth1
EOF

4.5 自动应答文件

/var/lib/tftpboot/pxelinux.cfg/default
/var/www/html/ks_config/CentOS-6.9-ks.cfg
/var/www/html/ks_config/optimization.sh
 
同一个局域网最好只有一个DHCP服务器
ks文件 自动应答文件 给系统安装程序提供它所需要的所有必要的安装信息
  生成ks文件的方法:
  
1./root/anaconda-ks.cfg 这是安装程序自动生成的,
  作用1:告诉我们系统安装的信息;
  作用2:可以直接用(模仿)这个文件再次装系统
2.Centos提供了一个图形化的kickstart配置工具。
3.根据ks文件语法编辑一个ks文件
    ks文件分为3段
    命令段
    包组段
    脚本段
 ks文件 
# Kickstart Configurator for CentOS 6.7 by lewen
install
url --url="http://172.16.1.21/CentOS6.9/"
text
lang en_US.UTF-8
keyboard us
zerombr
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
network --bootproto=dhcp --device=eth1 --onboot=yes --noipv6 --hostname=lewen-kick
network --bootproto=dhcp --device=eth0 --onboot=yes --noipv6 
timezone --utc Asia/Shanghai
authconfig --enableshadow --passalgo=sha512
rootpw --iscrypted $6$X20eRtuZhkHznTb4$dK0BJByOSAWSDD8jccLVFz0CscijS9ldMWwpoCw/ZEjYw2BTQYGWlgKsn945fFTjRC658UXjuocwJbAjVI5D6/
clearpart --all --initlabel
part /boot --fstype=ext4 --asprimary --size=200
part swap --size=1024
part / --fstype=ext4 --grow --asprimary --size=200
firstboot --disable
selinux --disabled
firewall --disabled
logging --level=info
reboot
​
%packages
@base
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet
​
%post
wget -O /tmp/optimization.sh http://172.16.1.21/ks_config/optimization.sh &>/dev/null
/bin/sh /tmp/optimization.sh
%end
vim /var/www/html/ks_config/optimization.sh
#!/bin/bash
​
. /etc/init.d/functions
Ip=172.16.1.21
Port=80
ConfigDir=ks_config
# Judge Http server is ok?
PortNum=`nmap $Ip  -p $Port 2>/dev/null|grep open|wc -l`
[ $PortNum -lt 1 ] && {
        echo "Http server is bad!"
        exit 1
}
# Defined result function
function Msg(){
        if [ $? -eq 0 ];then
          action "$1" /bin/true
        else
          action "$1" /bin/false
        fi
}
# Defined IP function
function ConfigIP(){
        Suffix=`ifconfig eth0|awk -F "[ .]+" 'NR==2 {print $6}'`
        cat >/etc/sysconfig/network-scripts/ifcfg-eth0 <<-END
        DEVICE=eth0
        TYPE=Ethernet
        ONBOOT=yes
        NM_CONTROLLED=yes
        BOOTPROTO=none
        IPADDR=10.0.0.$Suffix
        PREFIX=24
        GATEWAY=10.0.0.254
        DNS1=8.8.8.8
        DEFROUTE=yes
        IPV4_FAILURE_FATAL=yes
        IPV6INIT=no
        NAME="System eth0"
        END
        Msg "config eth0"
}
# Defined Yum source Functions
function yum(){
        YumDir=/etc/yum.repos.d
        [ -f "$YumDir/CentOS-Base.repo" ] && cp $YumDir/CentOS-Base.repo{,.ori} 
        wget -O $YumDir/CentOS-Base.repo http://$Ip:$Port/$ConfigDir/CentOS-Base.repo &>/dev/null &&
        wget -O $YumDir/epel.repo http://$Ip:$Port/$ConfigDir/epel.repo &>/dev/null &&
        Msg "YUM source"
}
# Defined Hide the system version number Functions
function HideVersion(){
        [ -f "/etc/issue" ] && >/etc/issue
        Msg "Hide issue" 
        [ -f "/etc/issue.net" ] && > /etc/issue.net
        Msg "Hide issue.net"
}
# Defined OPEN FILES Functions
function openfiles(){
        [ -f "/etc/security/limits.conf" ] && {
        echo '*  -  nofile  65535' >> /etc/security/limits.conf
        Msg "open files"
        }
}
# Defined Kernel parameters Functions
function kernel(){
        KernelDir=/etc
        [ -f "$KernelDir/sysctl.conf" ] && /bin/mv $KernelDir/sysctl.conf{,.ori}
        wget -O $KernelDir/sysctl.conf http://$Ip:$Port/$ConfigDir/sysctl.conf &>/dev/null
        Msg "Kernel config"
}
# Defined System Startup Services Functions
function boot(){
        for oldboy in `chkconfig --list|grep "3:on"|awk '{print $1}'|grep -vE "crond|network|rsyslog|sshd|sysstat"` 
          do 
           chkconfig $oldboy off
        done
        Msg "BOOT config"
}
# Defined Time Synchronization Functions
function Time(){
        echo "#time sync by zhangyao at $(date +%F)" >>/var/spool/cron/root
        echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov &>/dev/null' >>/var/spool/cron/root
        Msg "Time Synchronization"
}
# Defined main Functions
function main(){
        ConfigIP
        yum
        HideVersion
        openfiles
        kernel
        boot
        Time
}
main
# rz上传CentOS-Base.repo、epel.repo、sysctl.conf
optimization.sh 非必须

centos 7 安装完的ks文件模板

[root@cs7-model tmp]# cat anaconda-ks.cfg 
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
​
# Network information
network --bootproto=static --device=eth0 --gateway=10.0.0.254 --ip=10.0.0.210 --nameserver=223.5.5.5 --netmask=255.255.255.0 --ipv6=auto --activate
network --bootproto=static --device=eth1 --gateway=10.0.0.254 --ip=172.16.1.210 --netmask=255.255.255.0 --onboot=off --ipv6=auto --activate
network --hostname=cs7-model
​
# Root password
rootpw --iscrypted $6$fA8sNPkIWX1UZJfA$XuUxCvwPDHeTGKGBrE3Si5udHCEz/zaHctEd9ggRV4TtkJM.Vja4K.JyE5nylfhYZ0OC2BP8e9BxXoJKf5AAY1
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel
​
%packages
@^minimal
@compat-libraries
@core
@debugging
@development
​
%end
​
%addon com_redhat_kdump --disable --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
centos 7 ks 安装完模板
 
原文地址:https://www.cnblogs.com/wenyule/p/9770441.html