Chinaunix首页 | 论坛 | 博客
  • 博客访问: 213679
  • 博文数量: 70
  • 博客积分: 55
  • 博客等级: 民兵
  • 技术积分: 388
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-26 23:53
文章分类

全部博文(70)

文章存档

2014年(1)

2013年(5)

2012年(42)

2011年(22)

我的朋友

分类:

2012-04-25 12:55:40

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://blog.chinaunix.net/space.php?uid=9419692&do=blog&id=3184120

# BY kerry (聆听未来)
# BLOG:http://kerry.blog.51cto.com

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

chmod +x cprpm.sh
./cprpm.sh


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

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

本文出自 “聆听未来” 博客,请务必保留此出处http://blog.chinaunix.net/space.php?uid=9419692&do=blog&id=3184120

阅读(827) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~