歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 批量部署Linux機器(RedHat5.4/CentOS5.3)

批量部署Linux機器(RedHat5.4/CentOS5.3)

日期:2017/2/28 16:05:54   编辑:Linux教程

批量部署Linux機器(RedHat5.4/CentOS5.3):
系統:centos5/redhat5
軟件包:
wget http://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-3.86.tar.gz或
wget http://ftp.ntu.edu.tw/linux/boot/syslinux/3.xx/syslinux-3.86.tar.gz
1、syslinux編譯安裝,pxe啟動目錄和文件創建
tar zxvf syslinux-3.86.tar.gz
cd syslinux-3.86
make
mkdir /tftpboot/pxelinux.cfg -p
mkdir /tftpboot/ks -p
mkdir /tftpboot/centos5.3
mkdir /tftpboot/redhat5.4
chmod 755 /tftpboot
#cd gpx/gpxelinux.0 /tftpboot
#cp gpx/pxelinux.gpxe /tftpboot
#cp com32/menu/*.c32 /tftpboot/pxelinux.cfg
#cp com32/modules/reboot.c32 /tftpboot/pxelinux.cfg
#cp com32/modules/chain.c32 /tftpboot/pxelinux.cfg
復制安裝盤isolinux目錄下的兩個重要文件vmlinuz和initrd.img到TFTP根目錄/tftpboot下
cp /data/centos5.3/isolinux/vmlinuz /tftpboot/centos5.3
cp /data/centos5.3/isolinux/initrd.img /tftpboot/centos5.3
cp /data/redhat5.4/isolinux/vmlinuz /tftpboot/redhat5.4
cp /data/redhat5.4/isolinux/initrd.img /tftpboot/redhat5.4

復制安裝盤isolinux目錄下的所有.msg文件(boot.msg,initrd.msg,param.msg,general.msg,options.msg,rescue.msg)到TFTP根目錄/tftpboot下
命令:
cp /data/centos5.3/isolinux/*.msg /tftpboot/centos5.3/
cp /data/redhat5.4/isolinux/*msg /tftpboot/redhat5.4/
復制isolinux目錄下的isolinux.cfg文件為tftpboot/pxelinux.cfg下的default
cp /data/centos5.3/isolinux.cfg /tftpboot/pxelinux.cfg/default

2、dhcpd配置
yum -y install dhcp dhcp-devel
編輯DHCP配置文件/etc/dhcpd.conf,可以從/usr/share/doc/dhcp*/dhcpd.conf.sample將這個配置文件的樣例復制過來,這樣編輯起來會更快些
dhcpd.conf配置的有關說明:

parameters(參數):
ddns-update-style 配置DHCP-DNS互動更新模式
default-lease-time 指定缺省租賃時間的長度,單位是秒
max-lease-time 指定最大租賃時間長度,單位是秒
hardware 指定網卡接口類型和MAC地址
server-name 通知DHCP客戶服務器名稱
get-lease-hostnames flag 檢查客戶端使用的IP地址
fixed-address ip 分配給客戶端一個固定的地址
authritative 拒絕不正確的IP地址的要求

declarations(聲明):
shared-network 用來告知是否一些子網絡分享相同網絡
subnet 描述一個IP地址是否屬於該子網
range 起始IP 終止IP 提供動態分配IP 的范圍
host 主機名稱 參考特別的主機
group 為一組參數提供聲明
allow unknown-clients或deny unknown-client 是否動態分配IP給未知的使用者
allow bootp或deny bootp 是否響應激活查詢
allow booting或deny booting 是否響應使用者查詢
filename 開始啟動文件的名稱,應用於無盤工作站
next-server 設置服務器從引導文件中裝如主機名,應用於無盤工作站

option(選項):
subnet-mask 為客戶端設定子網掩碼
domain-name 為客戶端指明DNS名字
domain-name-servers 為客戶端指明DNS服務器IP地址
host-name 為客戶端指定主機名稱
routers 為客戶端設定默認網關
broadcast-address 為客戶端設定廣播地址
ntp-server 為客戶端設定網絡時間服務器IP地址
time-offset 為客戶端設定和格林威治時間的偏移時間,單位是秒。

命令:
cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcpd.conf
vim /etc/dhcpd.conf
#--------------global------------------------------------------
option domain-name-servers 192.168.1.199;
ddns-update-style none;
default-lease-time 14400;
max-lease-time 43200;
#----------tftp------------------------------------------
ignore client-updates;
allow booting;
allow bootp;
class "pxeclients"{
match if substring(option vendor-class-identifier,0,9) = "PXEClient";
filename "gpxelinux.0";
next-server 192.168.1.199;
}
#----------subnet---------------------------------------------
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.1.200 192.168.1.254;
}

檢查文件/var/lib/dhcpd/dhcpd.leases,文件存在即可

如果考慮到安全問題,在多網卡的機器上可以編輯/etc/sysconfig/dhcpd文件來制定DHCP服務在那個設備上啟動
命令:
vim /etc/sysconfig/dhcpd
編輯內容為:
# Command line options here
DHCPDARGS=eth0
重啟DHCP服務
service dhcpd restart或/etc/rc.d/ini.d/dhcpd restart

3、tftp配置
yum -y install xinetd tftp tftp-server
編輯TFTP的配置文件
vim /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -u nobody -s /tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
重啟TFTP服務需要重啟xinetd這個守護服務
service xinetd restart


4、nfs配置:
yum -y install nfs-utils nfs-utils-lib

編輯NFS的配置文件
命令:
vim /etc/exports
/tftpboot *(ro,sync)
/data/centos5.3 *(ro,sync)

重啟nfs服務:
service nfs restart
service portmap restart

或者可以不必重啟整個服務,用下面命令更新NFS服務
exportfs -arv

檢查目錄設置是否正確:
showmount -e localhost

只需要根據自己業務定義cfg文件:

/tftpboot/ks下的ceentos5.3.cfg和redhat5.4.cfg

#########/tftpboot/pxelinux.cfg/default#######

default ct53_32
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 local
localboot 1
label memtest86
kernel memtest
append -

label ct53_32
kernel centos5.3/vmlinuz
append initrd=centos5.3/initrd.img ks=nfs:192.168.1.199:/tftpboot/ks/ct53_32.cfg devfs=nomount ramdisk_size=4096 nofb text
label rh54_32
kernel redhat5.4/vmlinuz
append initrd=redhat5.4/initrd.img ks=nfs:192.168.1.199:/tftpboot/ks/rh54_32.cfg devfs=nomount ramdisk_size=4096 nofb text

############/tftpboot/ks/rh54_32.cfg#############

# Kickstart file automatically generated by anaconda.

install
nfs --server=192.168.1.199 --dir=/data/redhat5.4
lang en_US.UTF-8
langsupport --default=en_US.UTF-8 en_US.UTF-8
keyboard us
key --skip
network --bootproto=dhcp --device=eth0 --onboot=on
rootpw --iscrypted $1$XPr0sv0o$1.XsUW0h36ZdWetQOefR21
firewall --disabled
selinux --disabled
authconfig --enableshadow --enablemd5
timezone Asia/Shanghai
bootloader --location=mbr
#disk
clearpart --all --initlabel
part /boot --fstype ext3 --size=100
part / --fstype ext3 --size=12000
part swap --fstype swap --size=1024

%packages
@admin-tools
@editors
#@emacs
@base
@system-tools
@dialup
@server-cfg
@development-tools
@ruby
@text-internet
net-snmp

%post
/sbin/chkconfig --level 2345 anacron off
/sbin/chkconfig --level 2345 apmd off
/sbin/chkconfig --level 2345 atd off
/sbin/chkconfig --level 2345 gpm off
/sbin/chkconfig --level 2345 httpd off
/sbin/chkconfig --level 2345 identd off
/sbin/chkconfig --level 2345 ipchains off
/sbin/chkconfig --level 2345 isdn off
/sbin/chkconfig --level 2345 keytable off
/sbin/chkconfig --level 2345 kudzu off
/sbin/chkconfig --level 2345 linuxconf off
/sbin/chkconfig --level 2345 lpd off
/sbin/chkconfig --level 2345 netfs off
/sbin/chkconfig --level 2345 nfslock off
/sbin/chkconfig --level 2345 pcmcia off
/sbin/chkconfig --level 2345 portmap off
/sbin/chkconfig --level 2345 random off
/sbin/chkconfig --level 2345 rawdevices off
/sbin/chkconfig --level 2345 rhnsd off
/sbin/chkconfig --level 2345 sgi_fam off
/sbin/chkconfig --level 2345 sshd off
/sbin/chkconfig --level 2345 xfs off
/sbin/chkconfig --level 2345 xinetd off
/sbin/chkconfig --level 2345 cups off
/sbin/chkconfig --level 2345 hpoj off
/sbin/chkconfig --level 2345 mdmpd off
/sbin/chkconfig --level 2345 firstboot off
/sbin/chkconfig --level 2345 arptables_jf off
/sbin/chkconfig --level 2345 mdmonitor off
/sbin/chkconfig --level 2345 smartd off
/sbin/chkconfig --level 2345 messagebus off
/sbin/chkconfig --level 2345 acpid off
/sbin/chkconfig --level 2345 avahi-daemon off
/sbin/chkconfig --level 2345 rpcsvcgssd off
/sbin/chkconfig --level 2345 rpcgssd off
/sbin/chkconfig --level 2345 rpcidmapd off
/sbin/chkconfig --level 2345 irqbalance on
/sbin/chkconfig --level 2345 bluetooth off
/sbin/chkconfig --level 2345 psacct on
/sbin/chkconfig --level 2345 sshd on
/sbin/chkconfig --level 2345 snmpd on

echo "* */5 * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1" >> /etc/crontab
echo "nameserver 202.106.46.151">/etc/resolv.conf
echo "nameserver 202.106.196.115">>/etc/resolv.conf

Copyright © Linux教程網 All Rights Reserved