利用CentOS快速構建本身的發行版(1)

 編者按:對於不少我的站長來講,每次業務擴容裝Linux系統都是件很麻煩的事情。有的IDC技術不會裝Linux系統,或者有的就是裝一次系統收取必定的費用。爲此製做一個精簡的CentOS發行版是很重要的。下面就一塊兒來看下具體制做過程吧。mysql

1、製做LTOS具體過程linux

光盤結構介紹sql

* isolinux 目錄存放光盤啓動時的安裝界面信息express

* p_w_picpaths 目錄包括了必要的啓動映像文件vim

* CentOS 目錄存放安裝軟件包及信息centos

* .discinfo 文件是安裝價質的識別信息sass

* lemp.tar.gz 文件存放系統初始化及其相關程序安裝腳本.bash

》》環境說明:CentOS 5.3-i386 Vmware Workstation上完成製做工做.app

1.安裝製做發行版所需的基本軟件包less

# yum -y install anaconda-runtime createrepo yum-utils anaconda anaconda-help busybox-anaconda mkisofs

2.製做ltos源文件夾

# mkdir /ltos
# mkdir /mnt/cdrom
# mount -t iso9660 -o loop /dev/cdrom /mnt/cdrom/ 掛載光盤鏡像
或者掛載ISO文件到/mnt/cdrom
# mount -t iso9660 -o loop centos.xxx.iso /mnt/cdrom 將CentOS的ISO文件掛載到/mnt/cdrom目錄
# cd /mnt/cdrom
# tar -cf - . | ( cd /ltos ; tar -xvpf - ) //將/mnt/cdrom裏的文件利用tar所有拷貝到/ltsos這個目錄下.
#cd /ltos //進入此目錄刪除一些無關的文件,仍後進入後面的工做.
[root@server ltos]# ls -al
total 88
drwxr-xr-x 6 root root 4096 Apr 11 21:00 .
drwxr-xr-x 27 root root 4096 Apr 12 05:26 ..
drwxr-xr-x 2 root root 36864 Apr 8 16:06 CentOS
-rw-r--r-- 1 root root 97 Apr 8 16:43 .discinfo
drwxr-xr-x 4 root root 4096 Mar 21 23:04 p_w_picpaths
drwxr-xr-x 2 root root 4096 Apr 12 00:00 isolinux
-rw-r--r-- 1 root root 14371 Apr 11 23:16 lemp.tar.gz //這個軟件包是咱們後面要創建的,讀者能夠分析一下後面的ks.cfg腳本就能夠明白他的用途.
drwxr-xr-x 2 root root 4096 Apr 11 21:00 repodata
-r--r--r-- 1 root root 7048 Mar 21 23:05 TRANS.TBL

3.定製package.list軟件包清單

如安裝一個CentOS5.3的系統,根據本身的需求選擇軟件包;若是想你的系統很小,建議選擇最少的包。安裝完成之後,在系統裏會產生日誌。日文文件存放在/root/install.log。

# cat install.log | grep Installing | sed 's/Installing //g'|sed 's/^[0-9]\+://g' > packages.list
#mkdir /ltos/CentOS 創建存放rpm包的目錄.

建立自動提取相關rpm腳本:

#vi cprpms.sh
#!/bin/bash
DEBUG=0
LT_CD=/mnt/cdrom
ALL_RPMS_DIR=/mnt/cdrom/CentOS #掛載光盤存放的目錄
LT_RPMS_DIR=/ltos/CentOS #存放RPM包的目錄
packages_list=/root/packages.list
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* $LT_RPMS_DIR/"
cp $ALL_RPMS_DIR/$name-$version* $LT_RPMS_DIR/
# in case the copy failed
if [ $? -ne 0 ] ; then
echo "cp $ALL_RPMS_DIR/$name-$version* "
cp $ALL_RPMS_DIR/$name* $LT_RPMS_DIR/
fi
fi
i=`expr $i + 1`
done

執行以上腳本將定製ltos必要的rpm複製到/ltos/CentOS目錄

返回到/ltos目錄下,執行createrepo程序生成repodata下的comps.xml文件

#cd /ltos
#createrepo -g repodata/comps.xml .

4.配置kickstart腳本

經過CentOS5.3定製安裝系統之後,會在系統裏產生一個kickstart安裝腳本(/root/anaconda-ks.cfg)

# cp anaconda-ks.cfg /ltos/isolinux/ks.cfg
# vi /ltos/isolinux/ks.cfg 並修改腳本以下:
# Kickstart file automatically generated by anaconda.
# Install CentOS instead of Upgrade
install
text
#install from cd-rom
cdrom
lang en_US.UTF-8
keyboard us
# Skip the X Configuration
skipx
network --device eth0 --bootproto dhcp --hostname ltos.linuxtone.org
rootpw --iscrypted $1$jPZf0P0r$JRe7pd.5wq9k.VZEMOgdq/
# Setup the firewall with SSH, HTTP/S, Syslog, Webmin, and Netflow enabled
firewall --enabled --port=22:tcp --port=69:udp --port=80:tcp --port=443:tcp
authconfig --enableshadow --enablemd5
# Disable SELinux
selinux --disabled
timezone --utc Asia/Shanghai
# Clear the Bootloader and load it to the Master Boot Record
bootloader --location=mbr
zerombr yes
# Set the Mouse
mouse generic3ps/2
# 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
clearpart --all --initlabel
part /boot --fstype ext3 --size=100 --asprimary
part / --fstype ext3 --size=25000
part swap --size=4096
part /data --fstype ext3 --size=1 --grow
#--- Reboot the host after installation is done
reboot
%packages
@development-libs
@editors
@system-tools
@text-internet
@legacy-network-server
@dialup
@core
@base
@mail-server
@development-tools
audit
net-snmp-utils
sysstat
iptraf
dstat
tftp
lynx
device-mapper-multipath
imake
-zsh
-vnc
-zisofs-tools
-xdelta
-openldap-clients
-samba-client
-fetchmail
-dovecot
-spamassassin
#
# ------- Begin LEMP Install ---------
#
%post --nochroot
# Mount CDROM
mkdir -p /mnt/cdrom
mount -r -t iso9660 /tmp/cdrom /mnt/cdrom
# Copy our tar file and extract it
cp /mnt/cdrom/lemp.tar.gz /mnt/sysp_w_picpath/tmp/lemp.tar.gz > /dev/null
cd /mnt/sysp_w_picpath/tmp/
tar -zxvf lemp.tar.gz > /dev/null
# Move the contents of the tar into their new locations
cp -R /mnt/sysp_w_picpath/tmp/boot/* /mnt/sysp_w_picpath/boot/ > /dev/null 2>/dev/null
cp -R /mnt/sysp_w_picpath/tmp/etc/* /mnt/sysp_w_picpath/etc/ > /dev/null 2>/dev/null
# Unmount CDROM
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
# Disable IPv6 until Cacti at least supports it
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
/sbin/chkconfig --level 35 ip6tables off
#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 | sendmail | sshd | syslog | local | mysqld )
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

5.讓系統從kickstart配置啓動

# vi /ltos/ isolinux/ isolinux.cfg
default auto
prompt 1
timeout 600
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
kernel vmlinuz
append initrd=initrd.img
label text
kernel vmlinuz
append initrd=initrd.img text
label auto
kernel vmlinuz
append ks=cdrom:/isolinux/ks.cfg initrd=initrd.img
label ks
kernel vmlinuz
append ks initrd=initrd.img
label local
localboot 1
label memtest86
kernel memtest
append -
相關文章
相關標籤/搜索