歡迎您光臨本站 註冊首頁

kickstart實現全自動網路安裝RHEL5

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

【原創】kickstart實現全自動網路安裝RHEL5

參考了許多文檔,有官方的,也有他人的安裝文檔,同時也有自己的安裝心得。本文沒有太多的理論介紹,所以想了解其中各種原理可以Google相關資料。
介紹了http和NFS兩種網路安裝方式,配置文件中的區別主要有兩處,下文都有提到。本人實驗時為HTTP方式。
本人測試環境:RHEL5U2
步驟:
1. 安裝http服務:
我安裝的是RHEL5U2自帶apache rpm安裝包。httpd服務安裝后,假設web根目錄為WEB_HOME=/var/www/html,我的RHEL5U2放在/databackup/rhel5u2,可以創建一個鏈接文件到web根目錄里:

ln -s /databackup/rhel5u2 $WEB_HOME/

如果能在瀏覽器里瀏覽到rhel5u2的目錄,即在瀏覽器里輸入http://192.168.3.252/rhel5u2能列出安裝文件樹,接著:

2. 創建kickstart配置文件:
可以使用system-config-kickstart創建一個配置文件,另外可以使用/root/anaconda-ks.cfg作為原始文件,再根據你的需求加以修改。

# vi $WEB_HOME/ks5u2.cfg

以下為一個ks文件的範本,可根據自己需求定製。關鍵是要弄清楚每個命令的作用。對於每個命令的作用可參考redhat官方文檔:
http://www.redhat.com/docs/manua ... ced-deployment.html

# Kickstart file automatically generated by anaconda.

install
url --url http://192.168.3.252/rhel5u2
#nfs --server=192.168.3.252 --dir=/databackup/rhel5u2
key --skip
#key <your_install_number>
lang en_US.UTF-8
langsupport --default=en_US.UTF-8 zh_CN.UTF-8 en_US.UTF-8
keyboard us
rootpw --iscrypted $1$KkOV/KBQ$.MjH2HBd6kxGPxa6ebng20
firewall --disabled
authconfig --enableshadow --enablemd5
selinux --disabled
timezone Asia/Shanghai
reboot
text
#network --bootproto=dhcp --device=eth0
#network --device=eth0 --bootproto=static --ip=192.168.3.29 --netmask=255.255.255.0 --gateway=192.168.3.1 \
--nameserver=202.96.209.5 --hostname=test06
bootloader --location=mbr
# 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 --linux
part /boot --fstype ext3 --size=100
part / --fstype ext3 --size=15000
part /databackup --fstype ext3 --size=10240
part swap --size=1024

%packages
@mysql
@development-libs
@development-tools
@editors
@system-tools
@text-internet
@core
@base
@legacy-software-support
@base-x
@chinese-support
@web-server
@server-cfg
@admin-tools
@graphical-internet
emacs
sysstat
iptraf
lynx
mesa-libGLU-devel
device-mapper-multipath
gtk+
xorg-x11-utils
xorg-x11-server-Xvfb
system-config-kickstart
imake
-bluez-hcidump
-zsh
-ksh
-words
-apmd
-fbset
-finger
-mlocate
-dhcpv6-client
-mozldap
-rsh
-zsh
-sysreport
-rp-pppoe
-unix2dos
-svrcore
-amtu
-nc
-bluez-utils
-bluez-gnome
-nss_ldap
-krb5-workstation
-stunnel
-dosfstools
-pcmciautils
-pam_ccreds
-pam_smb
-mtools
-microcode_ctl
-mlocate
-mdadm
-talk
-system-config-httpd
-sabayon
-system-config-lvm
-setroubleshoot
-system-config-netboot
-system-config-kdump
-system-config-rootpassword
-sendmail
-symlinks
-vnc
-xdelta
-openldap-clients
-ypbind
-eject
-setarch
-nc
-irda-utils
-tux
-webalize
-squid
%post
echo 12345678 | passwd root --stdin
useradd nianzong
echo 12345678 | passwd test01 --stdin
chkconfig --level 345 sshd on
for i in autofs bluetooth cups firstboot ip6tables iptables rhnsd xfs yum-updatesd sendmail \
atd portmap pcmcia irqbalance ; do chkconfig $i off ; done
##To see more info about kickstart option:
#http://www.redhat.com/docs/manua ... ced-deployment.html
#上面這個配置可以實現雙系統安裝,即如果你的硬碟原有一個系統如Windows2003,並且有足夠的未分配空間,
#這個例子可以自動將Linux系統安裝在未分配空間里;如果是新硬碟或者你不想硬碟保留有其他系統,啟用
#clearpart --all命令即可。兩種安裝方式我都測試通過。

到這裡如果沒什麼意外的話,則可以實現半自動安裝了。你可以使用一張RHEL5安裝光碟進入引導畫面后,輸入:
linux ks=http://192.168.3.252/ks5u2.cfg
如果你安裝的發行版自帶的驅動能夠找到你的網卡,接下來就能自動安裝系統了,如果認不到你的網卡,那這種方式就行不通了,呵呵。所以謂之曰
半自動,因為前提是要能夠支持你的網卡驅動。要想實現全自動安裝,還得繼續配置DHCP,PEX,TFTP.

3. DHCP:
# rpm -qa|grep dhcp
dhcp-3.0.5-13.el5
#To enable dhcp daemon after system start.
# chkconfig --level 345 dhcpd on

把客戶端機器的MAC地址寫入下列配置文件里,我的是vmware虛擬機作為客戶端,開機可以按F12從
網路啟動:

Here is my dhcpd.conf:

# cat /etc/dhcpd.conf
#---------------------------------/etc/dhcpd.conf------------------------------------#
ddns-update-style interim;
ignore client-updates;
deny unknown-clients;
#not authoritative;

subnet 192.168.3.0 netmask 255.255.255.0 {

# --- default gateway
        option routers                  192.168.3.1;
        option subnet-mask              255.255.255.0;
        option ip-forwarding            false;  # No IP forwarding
# --    option mask-supplier    false;  # Don't respond to ICMP Mask req
        option domain-name-servers      192.168.3.1;
        option time-offset              -18000; # Eastern Standard Time
        range dynamic-bootp 192.168.3.24 192.168.3.26;
        default-lease-time 21600;
        max-lease-time 43200;
group {
  next-server 192.168.3.252;          # name of your TFTP server
  filename "pxelinux.0";              # name of the bootloader program

  host node1 {
        hardware ethernet 00:0C:29:54:89:79;
        fixed-address 192.168.3.25;
  }
  host node2 {
        hardware ethernet 00:0C:29:54:89:80;
        fixed-address 192.168.3.26;
  }
}
}
#---------------------------------/etc/dhcpd.conf------------------------------------#

4. TFTP:
# rpm -qa|grep tftp
tftp-server-0.42-3.1

# chkconfig --level 345 tftp on
# cp /usr/lib/syslinux/pxelinux.0 /tftpboot/
# cp /databackup/rhel5u2/images/pxeboot/initrd.img /tftpboot/initrd-as5u2.img
# cp /databackup/rhel5u2/images/pxeboot/vmlinuz /tftpboot/vmlinuz-as5u2
# mkdir /tftpboot/pxelinux.cfg
# cp /databackup/rhel5u2/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
# cp /databackup/rhel5u2/isolinux/*.msg /tftpboot/


The TFTP server directory /tftpboot should look like this:

# ls -p
boot.msg     initrd-as5u2.img  param.msg   pxelinux.cfg/  snake.msg
general.msg  options.msg       pxelinux.0  rescue.msg     vmlinuz-as5u2

# ls -p pxelinux.cfg/
default
                  



5. PEXlinux:
PXE can load a program into the client's memory and start it. I found it the easiest to manage,
if I first load a bootloader into the clients. The bootloader then loads its configuration file
via TFTP from the next-server(tftpsrv in the dhcpd.conf file example above).
The bootloader configuration file determines whether a client boots from its local hard disk
or over the network.

Here are example configuration files for my case:

default local
prompt 1
timeout 30
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 ks
  kernel vmlinuz
  append ks initrd=initrd.img
label local
  localboot 0
label memtest86
  kernel memtest
  append -
label netinstall
  kernel vmlinuz-as5u2
  append ks=http://192.168.3.252/ks5u2.cfg initrd=initrd-as5u2.img

NFS方式安裝則為:
ks=nfs:192.168.3.252:/var/www/html/ks5u2.cfg

修改/tftp/boot.msg:
注意cat和vi的顯示是不一樣的,vi編輯的時候不要去修改那些特殊的字元,添加行時複製即可。

##---------------/tftpboot/boot.msg-------------------------------------------------#

splash.lss

-  To boot from local, press the 01<ENTER>07 key.

-  To install or upgrade in graphical mode, press the 01linux <ENTER>07 key.

-  To install or upgrade in text mode, type: 01linux text <ENTER>07.

-  To install RHEL AS5U2 automaticaly from network , type: 01netinstall <ENTER>07.

-  Use the function keys listed below for more information.

0f 07

##---------------/tftpboot/boot.msg--------------------------------------------------#



kickstart參考文檔:
http://www.redhat.com/docs/manua ... ced-deployment.html

能申請加個精華么,呵呵。

[ 本帖最後由 nianzong 於 2009-7-7 17:23 編輯 ]
《解決方案》

好,樓主辛苦了
《解決方案》

樓主有心,多謝!!
《解決方案》

早知如此,我也該發自己的>
《解決方案》

樓上哥們,不必後悔了,我發了不也沒加精么,本來還想加點東西完善一下,都沒有動力了,呵呵
或許技術含量低了吧
《解決方案》

樂於分享是一種美德。

呵呵。
《解決方案》

正好我剛接觸這個,感謝樓主分享
《解決方案》

sharing spirit...

[火星人 ] kickstart實現全自動網路安裝RHEL5已經有1149次圍觀

http://coctec.com/docs/service/show-post-3375.html