cobbler+PXE+DHCP全自动无人値守网络安装系统

简述:通过配置cobbler自动部署DHCP、TFTP、HTTP,在安装过程中加载kiskstart无人值守安装应答文件实现无人值守。从客户端使用PXE引导启动安装。

1. 安装相关软件:

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm  
rpm -ivh rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm 
yum -y install cobbler tftp-server dhcp httpd xinetd 

注意 /var/www/cobbler 目录必须具有足够容纳 Linux 安装文件的空间(移动,建软链接)
#ln -s /cobbler /var/www

2. 检查 cobbler 配置:

cobbler check 

按提示解决相关问题,把 /var/lib/cobbler/settings 中的 server 和 next_server 设为本服务器的 IP 地址,manage_dhcp 设为 1,以便管理 DHCP
 将 /etc/xinetd.d/tftp 中 disable = no

3. 导入CentOS 安装 DVD ISO 中的文件:

mount -o loop /home/dtm/CentOS-5.5-x86_64-bin-DVD.iso /mnt/iso       # 将ISO文件挂载到 /mnt/iso 目录
cobbler import --mirror=/mnt/iso --name=centos5.5                              # 从 /mnt/iso目录导入所有安装文件,命名为 centos5.5
cobbler distro list                                                                                      # 查看导入结果

[root@elain www]# cobbler distro list
  centos5.5-x86_64
  centos5.5-xen-x86_64

-------------------------------
cobbler目录及文件

cobbler相关配置文件: /etc/cobbler
cobbler数据存储目录: /var/www/cobbler
dhcp配置文件: /etc/dhcpd.conf
dhcp租期缓存文件: /var/lib/dhcpd/dhcpd.leases
pxe配置文件: /tftpboot/pxelinux.cfg/default
ks模板文件: /var/lib/cobbler/kickstarts
--------------------------------
4. 修改 DHCP 和 Kickstart 配置模板:

vi /etc/cobbler/dhcp.template                                                                 # DHCP 配置模板,根据提示修改下面模板
vi /etc/dhcpd.conf
################################
ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;

subnet 192.168.8.0 netmask 255.255.255.0 {
     option routers          192.168.8.92;
     option subnet-mask      255.255.255.0;
     range dynamic-bootp     192.168.8.10 192.168.8.254;
     filename                "/pxelinux.0";
     default-lease-time      21600;
     max-lease-time          43200;
     next-server             192.168.8.92;
}
###############################
vi /etc/cobbler/kickstart_fc6.ks                                                       # Kickstart 配置模板
#####################
#platform=x86, AMD64, 或 Intel EM64T
#created by elain
#date:2010.06.27

# System authorization information
auth  --useshadow  --enablemd5

# System bootloader configuration
bootloader --location=mbr

# Partition clearing information
clearpart --all --initlabel

# Use text mode install
text

# Firewall configuration
firewall --disabled

# Run the Setup Agent on first boot
firstboot --disable

# System keyboard
keyboard us

# System language
lang zh_CN

# Installation logging level
logging --level=info

# Use network installation
url --url=http://192.168.8.92/cobbler/ks_mirror/centos5.5

# Network information
network --bootproto=bootp --device=eth0 --onboot=on

# Reboot after installation
reboot

#Root password
rootpw   elain

# SELinux configuration
selinux --disabled

# Do not configure the X Window System
skipx 

# System timezone
timezone  Asia/Chongqing

# Install OS instead of upgrade
install

# Disk partitioning information(根据不同服务需求更改分区大小)
part /boot --asprimary --bytes-per-inode=4096 --fstype="ext3" --grow --maxsize=512 --size=1
part / --asprimary --bytes-per-inode=4096 --fstype="ext3" --grow --maxsize=81920 --size=1
part swap --bytes-per-inode=4096 --fstype="swap" --grow --maxsize=81920 --size=1
part /elain --bytes-per-inode=4096 --fstype="ext3" --grow --size=1 

%packages
@ development-libs
@ development-tools
@ admin-tools
@ system-tools
@ x-software-development
@ base
@ chinese-support
@ editors
%post

#优化
echo "NETWORKING=yes" >/etc/sysconfig/network
echo "HOSTNAME=elain" >>/etc/sysconfig/network
echo "nameserver  172.168.32.18" >/etc/resolv.conf
echo "nameserver  202.106.0.20" >>/etc/resolv.conf

cd /root/

rm -rf install.log anaconda-ks.cfg install.log.syslog
mkdir {tools,scripts,bak,conf_bak}
mkdir -p /elain/{apps,data,logs,backup}
touch "请保持服务器整洁,操作后无用的文件及时清理"

#添加用户
groupadd -g 600 elainadmin
useradd -g elainadmin elainadmin -u 600 -p 'elainadmin!@#'

#允许sodu
echo "elainadmin ALL=(ALL)   PASSWD: ALL"  >>/etc/sudoers

#连接超时1小时
echo "TMOUT=3600" >>/etc/profile
source /etc/profile

#禁止提示接收邮件
echo "unset MAILCHECK" >> /etc/profile
source /etc/profile

#禁止按CTRL+ALT+DEL重启
sed -i s/^ca/\#ca/g /etc/inittab

#解决SSH登录慢的问题
echo "UseDNS no" >>/etc/ssh/sshd_config
/etc/init.d/sshd restart

#默认VI为VIM
echo "alias vi='vim'" >>/root/.bashrc
echo "alias vi='vim'" >>/home/elainadmin/.bashrc
. /root/.bashrc
. /home/elainadmin/.bashrc
#关闭不必要的服务
for service in `chkconfig --list|awk '{print $1}'|egrep -v "^$"|awk -F ":" '{print $1}'`; do chkconfig $service off;done
for service in crond  sshd syslog network; do chkconfig $service on;done
#################################
5. 生成并同步所有配置:

cobbler sync

注:每次更改Kickstart 配置文件,都需要使用cobbler sync重新同步所有配置

6. 启动相关服务:

/etc/init.d/httpd start
/etc/init.d/xinetd start 
/etc/init.d/dhcpd start
/etc/init.d/cobblerd start

7.客户端启动PXE 安装

启动另一台新服务器,通过 PXE 启动进入,提示"boot:"时输入"menu"即可进入蓝色的 Cobbler 安装界面,选择安装项,自动完成系统安装。 

http方式安装:服务器:192.168.9.101 目录:/cobbler/ks_mirror/centos/

8.重装系统: 

在要重装的机器安装koan  
yum install koan  
查看cobbler服务器有哪些安装盘  
koan --list-profiles --server=192.168.9.101 
选择要重装的系统并重启  
koan --replace-self --server=192.168.9.101 --profile=centos5.5
reboot  


附上服务控制脚本:
[root@elain ~]# cat cobbler.sh
#!/bin/sh
# created by dingtm
# date: 2010.12.31

case $1 in
        start)
               /etc/init.d/httpd start
               /etc/init.d/xinetd start 
               /etc/init.d/dhcpd start
               /etc/init.d/cobblerd start
                ;;
        stop)
               /etc/init.d/httpd stop
               /etc/init.d/xinetd stop 
               /etc/init.d/dhcpd stop
               /etc/init.d/cobblerd stop
                ;;
        status)
                /etc/init.d/httpd status
                /etc/init.d/xinetd status 
                /etc/init.d/dhcpd status
                /etc/init.d/cobblerd status
                ;;     
         sync)
                cobbler sync
                ;;                          
        *)
                echo "Input error,please in put 'start|stop|status|sync'!"; 
                exit 2>&1 >/dev/null &
                ;; 
        esac

参考文档:

http://oss.org.cn/ossdocs/gnu_linux/redhat/rhl-cg-zh_CN-9/s1-kickstart2-options.html

另附上kickstarts配置文件,附件可下载

附件:http://down.51cto.com/data/2358575



本文转自 elain2012 51CTO博客,原文链接:http://blog.51cto.com/elain/613745


上一篇:Apache Spark机器学习.1.9 小结


下一篇:Orcale(一)----WIN7 X64下安装ORACLE 10g(检查操作系统版本: 6.1a等问题)