[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
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口交換機性價比最高】 一臺安裝服務器
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
yum -y install httpd /etc/init.d/httpd start
---- curl http://172.16.1.21/CentOS6.9/ http://172.16.1.21/CentOS6.9/
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
1./root/anaconda-ks.cfg 這是安裝程序自動生成的, 做用1:告訴咱們系統安裝的信息; 做用2:能夠直接用(模仿)這個文件再次裝系統 2.Centos提供了一個圖形化的kickstart配置工具。 3.根據ks文件語法編輯一個ks文件 ks文件分爲3段 命令段 包組段 腳本段
# 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
[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