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


批量部署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

相关内容