一:Cobbler的安装

安装epel源:

[root@kaibin ~]# rpm  -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
Retrieving http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
warning: /var/tmp/rpm-tmp.HDIstu: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing...                ########################################### [100%]
   1:epel-release           ########################################### [100%]

安装cobbler及其他服务

yum-y install cobbler httpd rsync tftp-server xinetd dhcp python-ctypes cman pykickstart

2.配置cobbler

2.1配置cobbler主配置文件

vim /etc/cobbler/settings                                        #cobbler主配置文件
manage_dhcp: 1                                                   #启用cobbler dhcp功能
manage_rsync: 1                                                  #启用cobbler rsync功能
next_server: 192.168.40.145                                      #dhcp服务地址
server: 192.168.40.145                                           #cobbler 服务地址
default_kickstart:/var/lib/cobbler/kickstarts/default.ks         #默认ks文件

2.1 检查,关闭selinuxiptable

/etc/init.d/iptables stop
chkconfig iptables off
setenforce 0

2.2 配置tftp ,rsync

vim /etc/xinetd.d/tftp
vim /etc/xinetd.d/rsync
disable= no

2.3 启用wsgi模块

vim /etc/httpd/conf.d/wsgi.conf
LoadModulewsgi_module modules/mod_wsgi.so

2.4   生成Cobbler安装系统初始密码

openssl passwd  -1  -salt  'zuoliao'  'mima'
$1$zuoliao$ucZsjnNnYeC1ddo9O19ei0
加入Cobbler设置
vim /etc/cobbler/settings
default_password_crypted:"$1$zuoliao$ucZsjnNnYeC1ddo9O19ei0"

2.5 配置HDCP

vim /etc/cobbler/dhcp.template
subnet 192.168.40.0 netmask 255.255.255.0{
     option routers             192.168.40.145;
     option domain-name-servers 219.141.136.10;           
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.40.100 192.168.40.150;     #分配的IP地址
     default-lease-time           600;                            #默认租约时间
     max-lease-time             1200;                             #最大租约时间
     next-server                $next_server;
     class "pxeclients" {
          match if substring (optionvendor-class-identifier, 0, 9) = "PXEClient";
          if option pxe-system-type = 00:02 {
                  filename"ia64/elilo.efi";
          } else if option pxe-system-type =00:06 {
                  filename"grub/grub-x86.efi";
          } else if option pxe-system-type =00:07 {
                  filename"grub/grub-x86_64.efi";
          } else {
                  filename"pxelinux.0";
          }
     }
 
}

2.6 设置相关服务启动及开机自启动

/etc/init.d/httpd start
/etc/init.d/xinetd start
/etc/init.d/cobblerd start
chkconfig httpd on
chkconfig xinetd on
chkconfig cobblerd on

2.7  下载引导操作系统软件

[root@kaibin ~]# /etc/init.d/cobblerd restart
[root@kaibin ~]# cobbler get-loaders

2.8   配置debmirror

yum -y install debmirror
vim /etc/debmirror.conf
#@dists="sid";
#@arches="i386";

2.9   检查Cobbler  配置

cobbler   check

wKioL1S0-vPTfz5rAACSAhhslsw992.jpg

根据提示解决错误

2.91同步设置

cobbler sync

3.导入系统镜像

mkdir /var/os/Linux/Centos/x86_64/Centos6.4/dvd
mount -o loop /media/rhel-server-6.4-x86_64-dvd.iso /var/os/Linux/Centos/x86_64/Centos6.4/dvd
cobbler import --path=/var/os/Linux/Centos/x86_64/Centos6.4/dvd 
--name=centos6.5 --arch=x86_64

删除导入的系统镜像:

[root@kaibin ~]# cobbler profile find --distro=centos6.5-x86_64    #查看配置文件是否存在
centos6.5-x86_64
[root@kaibin ~]# cobbler profile remove --name=centos6.5-x86_64    #删除配置文件
[root@kaibin ~]# cobbler distro remove --name=centos6.5-x86_64     #删除distro
[root@kaibin ~]# cobbler profile find --distro=centos6.5-x86_64    #再查看配置已无

列出导入后的配置

cobblerlist

wKiom1S0_EOhzV9BAAC5VBwo6-4358.jpg


列出详细信息

cobbler report

wKioL1S0_OrB2UHuAAEQrs2bnCQ684.jpg


4.创建PXE菜单密码

openssl passwd -1 -salt 111 kaibin.com
$1$111$NguSK02gcD9XFcrcw4Hww.
vim /etc/cobbler/pxe/pxedefault.template
MENU TITLE co-mall | Auto Install System                   #设置装系统标题
MENU MASTER PASSWD $1$111$NguSK02gcD9XFcrcw4Hww.           #设置密码
[root@kaibin ~]# vim /etc/cobbler/pxe/pxeprofile.template
LABEL   $profile_name
        MENU PASSWD
        kernel $kernel_path
        $menu_label
        $append_line
        ipappend 2
重新加载配置文件
[root@kaibin ~]# cobbler check
[root@kaibin ~]# cobbler sync


wKioL1S0_Kagkp2NAACrABuQeJ0647.jpg

5.   Cobbler web管理

5.1  yum安装cobbler_web

yum -y install cobbler-web 
htdigest /etc/cobbler/users.digest "yuanbinbin" cobbler          #创建新用户

5.2   重启cobblerhttp

cobbler-web默认管理 cobbler:cobbler

URL: http://192.168.3.110/cobbler_web

wKioL1TAVFTBSOlUAAFIwNNSlHo600.jpg

6.  添加指定客户机系统配置到Cobbler

1. 指定一个网段使用特定的装机配置

cobbler system add --name=test_000 --ip=192.168.1.0/24 --profile=Centos-5.9-x86_64

2. 添加一个指定服务器的装机配置

指定服务器的mac地址,并设置好主机名、IP地址等信息,需要提示知道服务器MAC地址,根据MAC应用到具体机器上。 

还可以指定ks参数。--kickstart=/var/lib/cobbler/kickstarts/webserver.ks

[root@kaibin ~]# cobbler system add --name=test_001 --profile=centos6.5-system-x86_64 --mac=00:0C:29:44:C0:96 --interface=eth0 \
--ip-address=192.168.3.140 --gateway=192.168.3.1 --dns-name=8.8.8.8 --hostname=kaibin.test3.com  \
--netboot-enabled=Y --subnet=255.255.255.0 --static=1 --kickstart=/var/lib/cobbler/kickstarts/sample_end.ks

3. 修改system配置

机器IP地址变更为192.168.10.110  

cobbler system add --name=test_001 --ip=192.168.1.110

变更system配置名称

cobbler system rename --name=test001 --newname=abc

4. 删除system配置 

需要删除的profile名称为test_001   

cobbler system remove --name=test_001

5. 查看定义的系统列表

cobbler system list

test_001

6.cobbler客户端装机anaconda文件

# Kickstart file automatically generated by anaconda.

#version=DEVEL
install
url --url=http://192.168.3.110/cblr/links/centos6.5-system-x86_64
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto static --ip 192.168.3.140 --netmask 255.255.255.0 --gateway 192.168.3.1 --hostname kaibin.test3.com
rootpw  --iscrypted $1$zuoliao$ucZsjnNnYeC1ddo9O19ei0
# Reboot after installation
reboot
firewall --service=ssh
authconfig --useshadow  --enablemd5
selinux --disabled
timezone America/New_York
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# 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=ext4 --size=500
#part pv.008002 --grow --size=1

#volgroup vg_kaibin --pesize=4096 pv.008002
#logvol / --fstype=ext4 --name=lv_root --vgname=vg_kaibin --grow --size=1024 --maxsize=51200
#logvol swap --name=lv_swap --vgname=vg_kaibin --grow --size=1984 --maxsize=1984

repo --name="CentOS"  --baseurl=http://192.168.3.110/cblr/links/centos6.5-system-x86_64 --cost=100
repo --name="source-1"  --baseurl=http://192.168.3.110/cobbler/ks_mirror/centos6.5-system-x86_64 --cost=1000

%packages
@Base
@Core

%end

%pre
set -x -v
exec 1>/tmp/ks-pre.log 2>&1

# Once root's homedir is there, copy over the log.
while : ; do
    sleep 10
    if [ -d /mnt/sysp_w_picpath/root ]; then
        cp /tmp/ks-pre.log /mnt/sysp_w_picpath/root/
        logger "Copied %pre section log to system"
        break
    fi
done &


wget "http://192.168.3.110/cblr/svc/op/trig/mode/pre/system/test_001" -O /dev/null
# Start pre_install_network_config generated code
# generic functions to be used later for discovering NICs
mac_exists() {
  [ -z "$1" ] && return 1

  if which ip 2>/dev/null >/dev/null; then
    ip -o link | grep -i "$1" 2>/dev/null >/dev/null
    return $?
  elif which esxcfg-nics 2>/dev/null >/dev/null; then
    esxcfg-nics -l | grep -i "$1" 2>/dev/null >/dev/null
    return $?
  else
    ifconfig -a | grep -i "$1" 2>/dev/null >/dev/null
    return $?
  fi
}
get_ifname() {
  if which ip 2>/dev/null >/dev/null; then
    IFNAME=$(ip -o link | grep -i "$1" | sed -e 's/^[0-9]*: //' -e 's/:.*//')
  elif which esxcfg-nics 2>/dev/null >/dev/null; then
    IFNAME=$(esxcfg-nics -l | grep -i "$1" | cut -d " " -f 1)
  else
    IFNAME=$(ifconfig -a | grep -i "$1" | cut -d " " -f 1)
    if [ -z $IFNAME ]; then
      IFNAME=$(ifconfig -a | grep -i -B 2 "$1" | sed -n '/flags/s/:.*$//p')
    fi
  fi
}

# Start of code to match cobbler system interfaces to physical interfaces by their mac addresses
#  Start eth0
# Configuring eth0 (00:0C:29:44:C0:96)
if mac_exists 00:0C:29:44:C0:96
then
  get_ifname 00:0C:29:44:C0:96
  echo "network --device=$IFNAME --bootproto=static --ip=192.168.3.140 --netmask=255.255.255.0 --gateway=192.168.3.1 --hostname=kaibin.test3.com" >> /tmp/pre_install_network_config
fi
# End pre_install_network_config generated code

# Enable installation monitoring

%end

%post --nochroot
set -x -v
exec 1>/mnt/sysp_w_picpath/root/ks-post-nochroot.log 2>&1

%end

%post
set -x -v
exec 1>/root/ks-post.log 2>&1

# Start yum configuration
wget "http://192.168.3.110/cblr/svc/op/yum/system/test_001" --output-document=/etc/yum.repos.d/cobbler-config.repo

# End yum configuration



# Start post_install_network_config generated code

# create a working directory for interface scripts
mkdir /etc/sysconfig/network-scripts/cobbler
cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/cobbler/

# set the gateway in the network configuration file
grep -v GATEWAY /etc/sysconfig/network > /etc/sysconfig/network.cobbler
echo "GATEWAY=192.168.3.1" >> /etc/sysconfig/network.cobbler
rm -f /etc/sysconfig/network
mv /etc/sysconfig/network.cobbler /etc/sysconfig/network

# set the hostname in the network configuration file
grep -v HOSTNAME /etc/sysconfig/network > /etc/sysconfig/network.cobbler
echo "HOSTNAME=kaibin.test3.com" >> /etc/sysconfig/network.cobbler
rm -f /etc/sysconfig/network
mv /etc/sysconfig/network.cobbler /etc/sysconfig/network

# Also set the hostname now, some applications require it
# (e.g.: if we're connecting to Puppet before a reboot).
/bin/hostname kaibin.test3.com

# Start configuration for eth0
echo "DEVICE=eth0" > /etc/sysconfig/network-scripts/cobbler/ifcfg-eth0
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eth0
echo "HWADDR=00:0C:29:44:C0:96" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eth0
IFNAME=$(ip -o link | grep -i '00:0C:29:44:C0:96' | sed -e 's/^[0-9]*: //' -e 's/:.*//')
if [ -f "/etc/modprobe.conf" ] && [ $IFNAME ]; then
    grep $IFNAME /etc/modprobe.conf | sed "s/$IFNAME/eth0/" >> /etc/modprobe.conf.cobbler
    grep -v $IFNAME /etc/modprobe.conf >> /etc/modprobe.conf.new
    rm -f /etc/modprobe.conf
    mv /etc/modprobe.conf.new /etc/modprobe.conf
fi
echo "TYPE=Ethernet" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eth0
echo "BOOTPROTO=none" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eth0
echo "IPADDR=192.168.3.140" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eth0
echo "NETMASK=255.255.255.0" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eth0
# End configuration for eth0

sed -i 's/ONBOOT=yes/ONBOOT=no/g' /etc/sysconfig/network-scripts/ifcfg-eth*

rm -f /etc/sysconfig/network-scripts/ifcfg-eth0
mv /etc/sysconfig/network-scripts/cobbler/* /etc/sysconfig/network-scripts/
rm -r /etc/sysconfig/network-scripts/cobbler
if [ -f "/etc/modprobe.conf" ]; then
cat /etc/modprobe.conf.cobbler >> /etc/modprobe.conf
rm -f /etc/modprobe.conf.cobbler
fi
# End post_install_network_config generated code




# Start download cobbler managed config files (if applicable)
# End download cobbler managed config files (if applicable)

# Start koan environment setup
echo "export COBBLER_SERVER=192.168.3.110" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.3.110" > /etc/profile.d/cobbler.csh
# End koan environment setup

# begin Red Hat management server registration
# not configured to register to any Red Hat management server (ok)
# end Red Hat management server registration

# Begin cobbler registration
# skipping for system-based installation
# End cobbler registration

# Enable post-install boot notification

# Start final steps

wget "http://192.168.3.110/cblr/svc/op/ks/system/test_001" -O /root/cobbler.ks
wget "http://192.168.3.110/cblr/svc/op/trig/mode/post/system/test_001" -O /dev/null
# End final steps
%end