Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1154817
  • 博文数量: 150
  • 博客积分: 2739
  • 博客等级: 少校
  • 技术积分: 2392
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-07 12:28
文章分类

全部博文(150)

文章存档

2015年(2)

2014年(16)

2013年(10)

2012年(58)

2011年(64)

分类: Python/Ruby

2012-09-07 18:14:22

自己抽时间写了个批量安装linux操作系统的脚本,生产环境中使用过。只要将光盘或iso镜像安装好,运行脚本即可进行批量安装linux操作系统,系统centos 5.*版本都实际测试使用过,6.0以上的版本未测试,应该可以直接使用的。

#########################################################################
Kickstart配置内容详解:
Kickstartl图型化配置详解:


点击(此处)折叠或打开

  1. #!/bin/bash
  2. #install linux
  3. #date 2012-09-07
  4. #by gavin && 随风飘云
  5. #weblog: http://blog.chinaunix.net/uid/25046147.html

  6. ###############define network######################
  7. #IPADD=`ifconfig eth0 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "`
  8. IPADD=`ifconfig eth0 | sed -n "2,2p" | awk '{print $2}'|awk -F: '{print $2}'`
  9. NET=`ifconfig eth0 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "|awk -F. '{print $1"."$2"."$3}';`

  10. ##############yum install tftp dhcp################
  11. if [ ![ -f /usr/lib/syslinux/pxelinux.0 ] ];then
  12. # yum install syslinux*
  13.         wget ftp://ftp.uni-bayreuth.de/pub/redhat.com/fedora-archive/linux/releases/7/Fedora/i386/os/Fedora/syslinux-3.36-4.fc7.i386.
  14. rpm
  15.         rpm -ivh syslinux*
  16.   elif [ !-f /usr/lib/syslinux/pxelinux.0 ];then
  17.         echo "The syslinux not install!!!!"
  18.         exit 1;
  19.   fi

  20. yum -y install tftp* dhcp*
  21. sed -i 's/disable=no/disable=yes/g' /etc/xinetd.d/tftp
  22. ###
  23. if [ -d /mnt/cdrom ] ;then
  24.         mount /dev/cdrom /mnt/cdrom
  25. else
  26.         mkdir /mnt/cdrom
  27.         mount /dev/cdrom /mnt/cdrom
  28. fi
  29. ##
  30. mkdir -p /tftpboot
  31. cd /tftpboot
  32. cp /usr/lib/syslinux/pxelinux.0 ./
  33. cp /mnt/cdrom/images/pxeboot/{vmlinuz,initrd.img} ./
  34. mkdir -p pxelinux.cfg
  35. cp /mnt/cdrom/isolinux/isolinux.cfg pxelinux.cfg/default
  36. echo > pxelinux.cfg/default
  37. cat >/tftpboot/pxelinux.cfg/default<<EOF
  38. default linux
  39. prompt 1
  40. timeout 10
  41. display boot.msg
  42. F1 boot.msg
  43. F2 options.msg
  44. F3 general.msg
  45. F4 param.msg
  46. F5 rescue.msg
  47. label linux
  48. kernel vmlinuz
  49. append ks=nfs:$IPADD:/mnt/ks.cfg initrd=initrd.img
  50.  
  51. label text
  52. kernel vmlinuz
  53. append initrd=initrd.img text
  54. label ks
  55. kernel vmlinuz
  56. append ks initrd=initrd.img
  57. label local
  58. localboot 1
  59. label memtest86
  60. kernel memtest
  61. append -
  62. EOF
  63. ###
  64. if [ -d /var/lib/tftpboot ];then
  65.         rm -rf /var/lib/tftpboot
  66.         ln -sv /tftpboot /var/lib/tftpboot
  67. fi

  68. chkconfig tftp on
  69. service xinetd restart
  70. ###################define dhcp#####################
  71. cat >/etc/dhcpd.conf<<EOF
  72. ddns-update-style interim;
  73. ignore client-updates;
  74. allow booting;
  75. allow bootp;
  76. subnet $NET.0 netmask 255.255.255.0 {
  77. range dynamic-bootp $NET.100 $NET.240;
  78. }
  79. option subnet-mask 255.255.255.0;
  80. option broadcast-address $NET.255;
  81. default-lease-time 21600;
  82. max-lease-time 43200;
  83. Next-server $IPADD;
  84. Filename "/pxelinux.0";
  85. EOF
  86. ####
  87. if [ -f /etc/dhcp/dhcpd.conf ];then
  88.         mv /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak
  89.         ln -sv /etc/dhcpd.conf /etc/dhcp/dhcpd.conf
  90. fi

  91. service dhcpd restart
  92. ######################share nfs ###################
  93. cp /etc/exports /etc/exports.bak
  94. echo "/mnt *(rw,sync)" > /etc/exports
  95. echo "/mnt/cdrom *(rw,sync)" >> /etc/exports
  96. service nfs restart

  97. ###################make ks.cfg###########################
  98. cat>/mnt/ks.cfg<<EOF
  99. # Kickstart file automatically generated by anaconda.
  100. install
  101. text
  102. nfs --server=$IPADD --dir=/mnt/cdrom
  103. key --skip
  104. lang zh_CN.UTF-8
  105. keyboard us
  106. network --device eth0 --bootproto=dhcp --noipv6
  107. rootpw 123456
  108. firewall --disabled
  109. authconfig --enableshadow --enablemd5
  110. selinux --disabled
  111. timezone Asia/Shanghai
  112. reboot
  113. bootloader --location=mbr --driveorder=sda --append="rhgb quiet"
  114. # The following is the partition information you requested
  115. # Note that any partitions you deleted are not expressed
  116. # here so unless you clear all partitions first, this is
  117. # not guaranteed to work
  118. clearpart --all --initlabel
  119. part /boot --fstype ext3 --size=200
  120. part swap --size=2000
  121. part /root/software --fstype ext3 --size=10000
  122. part / --fstype ext3 --size=10000
  123. part /home --fstype ext3 --size=100
  124. part /opt --fstype ext3 --size=1 --grow
  125. %packages
  126. @development-libs
  127. @development-tools
  128. EOF
  129. ###################start server####################
  130. chkconfig tftp on
  131. service nfs start
  132. service dhcpd start
  133. service xinetd start
自定义自己的ks.cfg文件包,能让其自动编译安装需要的软件:
#########################################################################
上文中,ks.cfg已经是个完整的,这里补充一下如何能自动编译安装软件,加到ks.cfg后面就行了:

点击(此处)折叠或打开

  1. %post --nochroot
  2. wget ***.tar.gz
  3. tar xvf ***.tar.gz
  4. cd **
  5. make && make install
  6. echo "*/1 * * * * /usr/sbin/ntpdate 210.72.145.44" >>/tmp/cront.txt
  7. crontab /tmp/cront.txt
  8. rm -rf /tmp/cront.txt
  9. %end




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

随风飘云2012-11-02 17:59:19