CentOS 6.0 在大家翘首以盼中姗姗来迟,但官方发布的DVD太过于庞大,很多组件其实在日常的生产环境中并用不上,所以基于此种情况,在这里我们就来对官方发布的DVD进行瘦身,只安装我们需要的组件,并实现自动安装,安装完毕后再对系统做基本的初始化,这样在生产环境中需要批量布署服务器的时候,显的效率非常高
1、定制安装系统,选择常用的组件
2、安装制作发行版所需的基本软件包
yum –y install createrepo mkisofs
3、生成安装系统所需的rpm文件列表
awk '/Installing/{print $2}' install.log |sed 's/^[0-9]*://g' >/root/packages.list
4、创建定制工作目录
mkdir -p /mnt/cdrom
mkdir -p /data/OS
mount /dev/cdrom /mnt/cdrom
rsync –a --exclude=Packages /mnt/cdrom /data/OS
mkdir /data/OS/Packages
5、复制精简后的RPM包
vi /data/cprmps.sh #创建自动复制RPM包脚本
#!/bin/bash
DEBUG=0
CentOS_DVD=/mnt/cdrom
ALL_RPMS_DIR=/mnt/cdrom/Packages #源光盘RPM包存放的目录
KOS_RPMS_DIR=/data/OS/Packages#精简后RPM包存放的目录
packages_list=/root/packages.list #精简后的RPM包列表
number_of_packages=`cat $packages_list | wc -l`
i=1
while [ $i -le $number_of_packages ] ; do
line=`head -n $i $packages_list | tail -n -1`
name=`echo $line | awk '{print $1}'`
version=`echo $line | awk '{print $3}' | cut -f 2 -d :`
if [ $DEBUG -eq "1" ] ; then
echo $i: $line
echo $name
echo $version
fi
if [ $DEBUG -eq "1" ] ; then
ls $ALL_RPMS_DIR/$name-$version*
if [ $? -ne 0 ] ; then
echo "cp $ALL_RPMS_DIR/$name-$version* "
fi
else
echo "cp $ALL_RPMS_DIR/$name-$version* $KOS_RPMS_DIR/"
cp $ALL_RPMS_DIR/$name-$version* $KOS_RPMS_DIR/
# in case the copy failed
if [ $? -ne 0 ] ; then
echo "cp $ALL_RPMS_DIR/$name-$version* "
cp $ALL_RPMS_DIR/$name* $KOS_RPMS_DIR/
fi
fi
i=`expr $i + 1`
done
chmod +x cprpm.sh
./cprpm.sh
6、配置kickstart脚本
vi /data/OS/isolinux/kerry.cfg
# Kickstart file automatically generated by anaconda.
#Install OS instead of upgrade
install
#Use text mode install
text
#Use CDROM installation media
cdrom
lang en_US.UTF-8
keyboard us
#Skip the X Configuration
skipx
#Network information
#network --device eth0 --onboot yes --bootproto static --ip 192.168.9.226 --netmask 255.255.255.0 --gateway 192.168.9.1 --nameserver 192.168.9.1 --noipv6 --hostname kerry-web-001
network --bootproto dhcp --noipv6 --onboot=yes --hostname kerry-web-001
#root -- 1q2w3e
rootpw --iscrypted $6$ZVQx8trb4JB693IS$tdwYvbnrNLgAv9xyQTMm2/0IV5pmZWwa0dD.GWh69/LK0Ls4aUXUl3xJiPRyzVuRZDUdEzw0h26zRS5KOdbBl1
firewall --disabled
#System authorization information
authconfig --enableshadow --enablemd5
selinux --disabled
timezone --utc Asia/Shanghai
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr yes
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#Partition clearing information
clearpart --all --initlabel
part /boot --fstype ext4 --size=200 --asprimary
part / --fstype ext4 --size=10000
part swap --size=4096
part /data --fstype ext4 --size=1 --grow
#--- Reboot the host after installation is done
reboot
%packages
@base
@core
@development
@server-policy
sgpio
nmap
iptraf
ntp
%post --nochroot
# Mount CDROM
mkdir -p /mnt/cdrom
mount -r -t iso9660 /tmp/cdrom /mnt/cdrom
cp /mnt/cdrom/ipmod.tar.gz /mnt/sysimage/tmp/ipmod.tar.gz > /dev/null
cd /mnt/sysimage/tmp/
tar -zxvf ipmod.tar.gz > /dev/null
cp -R /mnt/sysimage/tmp/ipmod/* /mnt/sysimage/root/ > /dev/null 2>/dev/null
cp -R /mnt/sysimage/tmp/etc/* /mnt/sysimage/etc/ > /dev/null 2>/dev/null
cp -R /mnt/sysimage/tmp/usr/* /mnt/sysimage/usr/ > /dev/null 2>/dev/null
cp -R /mnt/sysimage/tmp/var/* /mnt/sysimage/var/ > /dev/null 2>/dev/null
cp -R /mnt/sysimage/tmp/boot/* /mnt/sysimage/boot/ > /dev/null 2>/dev/null
cp -R /mnt/sysimage/tmp/sbin/* /mnt/sysimage/sbin/ > /dev/null 2>/dev/null
umount /mnt/cdrom
%post
#vim syntax on
sed -i "8 s/^/alias vi='vim'/" /root/.bashrc 2>/dev/null
echo 'syntax on' > /root/.vimrc 2>/dev/null
#init_ssh
ssh_cf="/etc/ssh/sshd_config"
sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' $ssh_cf
sed -i "s/#UseDNS yes/UseDNS no/" $ssh_cf
#client
sed -i -e '44 s/^/#/' -i -e '48 s/^/#/' $ssh_cf
# Remove the ISO File translation files
find / -name TRANS.TBL -exec rm {} \; /dev/null 2>/dev/null
# Remove some unneeded services
#--------------------------------------------------------------------------------
cat << EOF
+--------------------------------------------------------------+
| === Welcome to Tunoff services === |
+--------------------------------------------------------------+
EOF
#---------------------------------------------------------------------------------
for i in `ls /etc/rc3.d/S*`
do
CURSRV=`echo $i|cut -c 15-`
echo $CURSRV
case $CURSRV in
crond | irqbalance | microcode_ctl | network | random | sshd | syslog | local )
echo "Base services, Skip!"
;;
*)
echo "change $CURSRV to off"
chkconfig --level 235 $CURSRV off
service $CURSRV stop
;;
esac
done
# file descriptors
ulimit -HSn 65535
echo -ne "
* soft nofile 65536
* hard nofile 65536
" >>/etc/security/limits.conf
#set sysctl
true > /etc/sysctl.conf
cat >> /etc/sysctl.conf << EOF
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 1024 65535
EOF
/sbin/sysctl -p
#close ctrl+alt+del
sed -i "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/" /etc/inittab
#set purview
chmod 600 /etc/passwd
chmod 600 /etc/shadow
chmod 600 /etc/group
chmod 600 /etc/gshadow
7、生成comps.xml
cd /data/OS
createrepo –g repodata/*-comps.xml /data/OS/
8、让系统从kickstart配置启动安装
vi /data/OS/isolinux/isolinux.cfg
default auto
label auto
kernel vmlinuz
append ks=cdrom:/isolinux/kerry.cfg initrd=initrd.img
9、生成ISO文件
cd /data/OS
declare -x discinfo=`head -1 .discinfo`
createrepo -u "media://$discinfo" -g repodata/*-comps.xml /data/OS/
mkisofs -R -J -T -r -l -d -joliet-long -allow-multidot -allow-leading-dots -no-bak -o /data/KerryOS-1.0-i386.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table /data/OS
10、生成MD5检验码
/usr/bin/implantisomd5 /data/KerryOS-1.0-i386.iso