定制CentOS 6.0精简的自动安装版

字体大小: 中小 标准 ->行高大小: 标准

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包脚本

  1. #!/bin/bash   DEBUG=0 
  2. CentOS_DVD=/mnt/cdrom   ALL_RPMS_DIR=/mnt/cdrom/Packages #源光盘RPM包存放的目录  
  3. KOS_RPMS_DIR=/data/OS/Packages    #精简后RPM包存放的目录   packages_list=/root/packages.list  #精简后的RPM包列表  
  4. number_of_packages=`cat $packages_list | wc -l`   i=1 
  5.     while [ $i -le $number_of_packages ] ; do           line=`head -n $i $packages_list | tail -n -1`  
  6.         name=`echo $line | awk '{print $1}'`           version=`echo $line | awk '{print $3}' | cut -f 2 -d :`  
  7.     if [ $DEBUG -eq "1" ] ; then           echo $i: $line  
  8.         echo $name            echo $version  
  9.     fi       if [ $DEBUG -eq "1" ] ; then  
  10.         ls $ALL_RPMS_DIR/$name-$version*           if [ $? -ne 0 ] ; then  
  11.             echo "cp $ALL_RPMS_DIR/$name-$version* "           fi  
  12.         else               echo "cp $ALL_RPMS_DIR/$name-$version* $KOS_RPMS_DIR/"  
  13.             cp $ALL_RPMS_DIR/$name-$version* $KOS_RPMS_DIR/           # in case the copy failed  
  14.         if [ $? -ne 0 ] ; then               echo "cp $ALL_RPMS_DIR/$name-$version* "  
  15.             cp $ALL_RPMS_DIR/$name* $KOS_RPMS_DIR/           fi  
  16.     fi   i=`expr $i + 1`  
  17. done 

chmod +x cprpm.sh
./cprpm.sh

6、配置kickstart脚本
vi /data/OS/isolinux/kerry.cfg

  1. # Kickstart file automatically generated by anaconda.   #Install OS instead of upgrade  
  2. install   #Use text mode install   
  3. text   #Use CDROM installation media   
  4. cdrom   lang en_US.UTF-8  
  5. keyboard us    
  6. #Skip the X Configuration   skipx  
  7. #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  
  8. network --bootproto dhcp --noipv6 --onboot=yes --hostname kerry-web-001   #root -- 1q2w3e  
  9. rootpw  --iscrypted $6$ZVQx8trb4JB693IS$tdwYvbnrNLgAv9xyQTMm2/0IV5pmZWwa0dD.GWh69/LK0Ls4aUXUl3xJiPRyzVuRZDUdEzw0h26zRS5KOdbBl1   firewall --disabled  
  10. #System authorization information   authconfig --enableshadow --enablemd5  
  11. selinux --disabled   timezone --utc Asia/Shanghai  
  12. #System bootloader configuration    bootloader --location=mbr 
  13. #Clear the Master Boot Record   zerombr yes  
  14.   # The following is the partition information you requested  
  15. # Note that any partitions you deleted are not expressed   # here so unless you clear all partitions first, this is  
  16. # not guaranteed to work    
  17. #Partition clearing information   clearpart --all --initlabel  
  18. part /boot --fstype ext4 --size=200 --asprimary   part / --fstype ext4 --size=10000 
  19. part swap --size=4096  part /data --fstype ext4 --size=1 --grow  
  20.    
  21. #--- Reboot the host after installation is done   reboot  
  22.   %packages  
  23. @base   @core  
  24. @development   @server-policy  
  25. sgpio   nmap  
  26. iptraf   ntp  
  27.   %post --nochroot  
  28. # Mount CDROM   mkdir -p /mnt/cdrom  
  29. mount -r -t iso9660 /tmp/cdrom /mnt/cdrom   cp /mnt/cdrom/ipmod.tar.gz /mnt/sysimage/tmp/ipmod.tar.gz > /dev/null  
  30. cd /mnt/sysimage/tmp/   tar -zxvf ipmod.tar.gz > /dev/null  
  31. cp -R /mnt/sysimage/tmp/ipmod/* /mnt/sysimage/root/ > /dev/null 2>/dev/null    
  32. 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  
  33. 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  
  34. cp -R /mnt/sysimage/tmp/sbin/* /mnt/sysimage/sbin/ > /dev/null 2>/dev/null    
  35. umount /mnt/cdrom    
  36. %post   #vim syntax on  
  37. sed -i "8 s/^/alias vi='vim'/" /root/.bashrc 2>/dev/null   echo 'syntax on' > /root/.vimrc 2>/dev/null  
  38.   #init_ssh  
  39. ssh_cf="/etc/ssh/sshd_config"  sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' $ssh_cf  
  40. sed -i "s/#UseDNS yes/UseDNS no/" $ssh_cf    
  41. #client   sed -i -e '44 s/^/#/' -i -e '48 s/^/#/' $ssh_cf  
  42.   # Remove the ISO File translation files  
  43. find / -name TRANS.TBL -exec rm {} \; /dev/null 2>/dev/null    
  44. # Remove some unneeded services   #--------------------------------------------------------------------------------  
  45. cat << EOF  +--------------------------------------------------------------+  
  46. | === Welcome to Tunoff services === |   +--------------------------------------------------------------+  
  47. EOF   #---------------------------------------------------------------------------------  
  48. for i in `ls /etc/rc3.d/S*`   do  
  49.     CURSRV=`echo $i|cut -c 15-`   echo $CURSRV  
  50. case $CURSRV in           crond | irqbalance | microcode_ctl | network | random | sshd | syslog | local )  
  51.     echo "Base services, Skip!"       ;;  
  52.     *)           echo "change $CURSRV to off"  
  53.         chkconfig --level 235 $CURSRV off           service $CURSRV stop  
  54.     ;;   esac  
  55. done    
  56. # file descriptors   ulimit -HSn 65535  
  57.   echo -ne "  
  58. * soft nofile 65536   * hard nofile 65536  
  59. " >>/etc/security/limits.conf    
  60. #set sysctl   true > /etc/sysctl.conf  
  61. cat >> /etc/sysctl.conf << EOF  net.ipv4.ip_forward = 0 
  62. net.ipv4.conf.default.rp_filter = 1  net.ipv4.conf.default.accept_source_route = 0 
  63. kernel.sysrq = 0  kernel.core_uses_pid = 1 
  64. net.ipv4.tcp_syncookies = 1  kernel.msgmnb = 65536 
  65. kernel.msgmax = 65536  kernel.shmmax = 68719476736 
  66. kernel.shmall = 4294967296  net.ipv4.tcp_max_tw_buckets = 6000 
  67. net.ipv4.tcp_sack = 1  net.ipv4.tcp_window_scaling = 1 
  68. net.ipv4.tcp_rmem = 4096 87380 4194304   net.ipv4.tcp_wmem = 4096 16384 4194304  
  69. net.core.wmem_default = 8388608  net.core.rmem_default = 8388608 
  70. net.core.rmem_max = 16777216  net.core.wmem_max = 16777216 
  71. net.core.netdev_max_backlog = 262144  net.core.somaxconn = 262144 
  72. net.ipv4.tcp_max_orphans = 3276800  net.ipv4.tcp_max_syn_backlog = 262144 
  73. net.ipv4.tcp_timestamps = 0  net.ipv4.tcp_synack_retries = 1 
  74. net.ipv4.tcp_syn_retries = 1  net.ipv4.tcp_tw_recycle = 1 
  75. net.ipv4.tcp_tw_reuse = 1  net.ipv4.tcp_mem = 94500000 915000000 927000000  
  76. net.ipv4.tcp_fin_timeout = 1  net.ipv4.tcp_keepalive_time = 1200 
  77. net.ipv4.ip_local_port_range = 1024 65535   EOF  
  78.   /sbin/sysctl -p  
  79.   #close ctrl+alt+del  
  80. sed -i "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/" /etc/inittab    
  81. #set purview    chmod 600 /etc/passwd  
  82. chmod 600 /etc/shadow   chmod 600 /etc/group  
  83. chmod 600 /etc/gshadow  

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/59136.html