Cobbler是一个开源项目,用来部署和安装系统。Cobbler不仅仅是一个pxe服务器,他还可以管理dns和dhcp。一般数据中心里或者生产环境,是不允许dhcp, 但是pxe需要使用dhcp,所以我们这里根据mac地址来分配IP,这样dhcp就不会影响现有网络了。

 

1、首先关闭selinux

   [root@server04 ~]#sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config 

    #重新启动linux系统使配置生效;

2、关闭防火墙iptables

       [root@server04 ~]# service iptables stop


3、安装 epel 包

[root@server04 ~]#yum install http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm

4、安装 Cobbler 和它需要的第三方工具包

    [root@server04 ~]#yum install cobbler cobbler-web xinetd pykickstart cman dhcp tftp-server bind


    安装完成后需要设置几个服务自动启动

    [root@server04 ~]# chkconfig httpd on

    [root@server04 ~]# chkconfig dhcpd on

    [root@server04 ~]# chkconfig cobblerd on

    [root@server04 ~]# service httpd start    #启动http服务

    [root@server04 ~]# service cobblerd start  #启动cobbler服务

    注:此时dhcpd应该启动失败,因为还没有对dhcp做配置。




5、配置

5.1 修改/etc/xinetd.d/tftp   

disable = yes  

    =>   

    disable = no

    

5.2 修改/etc/xinetd.d/rsync

disable = yes 

    =>

    disable = no

    


 

5.3 编辑 /etc/cobbler/settings 文件,设置以下各项,其中 172.16.1.2 是当前机器IP。

    server: 172.16.1.2  

    next_server: 172.16.1.2

        pxe_just_once: 1 

        manage_rsync: 1  

        manage_dhcp: 1




 

5.4 设置默认(通过cobbler安装的系统) root 用户的密码

    [root@server04 ~]# openssl passwd -1 -salt 'random-phrase-here' 'dragon'    #密码加密

        $1$random-p$KIfNQzryOfZx/kAa0cjXv/

然后将结果替换 /etc/cobbler/settings 文件中的:default_password_crypted:

 

5.5  设置 Cobbler Web访问的密码

    [root@server04 ~]#htdigest /etc/cobbler/users.digest "Cobbler" cobbler


 

5.6 编辑 /etc/cobbler/dhcp.template 文件,下面是我改动部分的配置信息;

    option domain-name "172.16.1.2";

    option domain-name-servers 172.16.1.2;

    default-lease-time 43200;

    max-lease-time 86400;

    log-facility local7;

    subnet 172.16.0.0  netmask 255.255.0.0 {

         range 172.16.1.100 172.16.1.254; 

         option routers 172.16.1.1;

    }

    next-server 172.16.1.2;

    filename="pxelinux.0";


 

注意:如果在现有网段内已经有DHCP服务器,需要把 range dynamic-bootp 注释掉,否则会有冲突。这个地方需要特别注意,要根据自己的网络情况来设置。

 

5.7 重启服务,暂时先不启动DHCP,配置还没有同步到/etc/dhcp/dhcpd.conf

    [root@server04 ~]#service xinetd restart 

    [root@server04 ~]#service httpd restart  

    [root@server04 ~]#service cobblerd restart


 

5.8启动和检测 cobbler

[root@server04 ~]#cobbler sync   #任何关于cobbler的修改都需要使用cobbler sync命令来使其生效

    [root@server04 ~]#cobbler get-loaders    #执行 cobbler get-loaders,系统将自动下载loader程序

    [root@server04 ~]#cobbler check  #此时如果有错误,cobbler会提示,可以根据提示来修复。但是对参数的任何修改都需要使用下面的命令来使其生效

常见的错误见文章末尾;

 

5.9 Web 测试

浏览器访问 http://172.16.1.2/cobbler_web  #这里输入自己的IP

用户名/密码:cobbler/dragon   #在步骤5.5时设置

 

6.0 导入系统镜像,这里假定使用CentOS-6.6-x86_64来测试,虚拟机需要先挂载镜像;

       

    [root@server04 ~]#mount /dev/cdrom /mnt

    [root@server04 ~]#cobbler import --path=/mnt --name=CentOS-6.6 --arch=x86_64  

运行这两条命令后,可以使用下面的命令来查看已经装载的包

    [root@server04 ~]#cobbler distro list 

    [root@server04 ~]#cobbler profile list  

也可以通过 Web 界面的 Distros 和 Profiles 来查看。

7. 自动安装系统
    使用VirtualBox创建一个虚拟机,网络设置使用和上面同样的桥接模式。但是在 "虚拟机设置-> 系统 -> 启动顺序" 里把网络勾上并上移到第一位,然后启动虚拟机。此时就可以进入 Cobbler 的网络安装界面,选择上面创建的 CentOS-6.6-x86_64 然后就可以自动安装了。装完后,记得把虚拟机启动顺序改回到硬盘启动优先,然后就可以启动新安装的虚拟机了。


二、配置Kickstart 配置模板,带注释版本(下面有无注释版本)

1,可以把配置文件放在这个目录:/var/lib/cobbler/kickstarts

2,登录cobbler的web管理界面,点左侧的profiles--点镜像文件后面的edit--选择Kickstart文件

[root@localhost ~]# cat kickstart_fc6.ks  

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Upgrade existing installation
upgrade
# Use network installation
#修改成自己的IP
url --url="http://172.168.12/cobbler/ks_mirror/CentOS-6.6-x86_64/"
# Root password 
rootpw dragon
# System authorization information
auth  --useshadow  --passalgo=sha512
#关闭防火墙
firewall --disabled
#选择时区
timezone Asia/Shanghai
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language选择语言,如果想要使用中文填写:lang zh_CN
lang en_US
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System bootloader configuration
#--initlabel,根据不同体系结构把磁盘标签初始化为缺省设置(例如,msdos用于x86而gpt用于Itanium).当安装到一个崭新的硬 盘时,这很有用,安装程序不会询问是否应该初始化磁盘标签.
#--grow,告诉分区使用所有可用空间(若有),或使用设置的最大值.
#--size=,以MB为单位的分区最小值.在此处指定一个整数值,如500.不要在数字后面加MB.
#--fstype=,为分区设置文件系统类型.有效的类型为ext2,ext3,swap和vfat.
#--asprimary,强迫把分区分配为主分区,否则提示分区失败.
#--ondisk=或--ondrive=,强迫分区在指定磁盘上创建.
bootloader --location=mbr
clearpart --all --drives=sda --initlabel
part /boot --fstype ext3 --size=100 --ondisk=sda   
part swap --size=4096
part / --fstype ext3 --size=100 --grow --asprimary
#%packages部分,这部分选择需要安装的软件包.
%packages
@core
@server-policy
@workstation-policy
%end


无注释版本,可以直接复制,修改地址路径即可:

[root@localhost ~]# kickstart.ks

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Upgrade existing installation
upgrade
# Use network installation
#修改成自己的IP
url --url="http://172.168.12/cobbler/ks_mirror/CentOS-6.6-x86_64/"
# Root password
rootpw --iscrypted $1$CgIgFiPo$rqNvZR480Z5A2dnbxdd7C0
# System authorization information
auth  --useshadow  --passalgo=sha512
firewall --disabled
timezone Asia/Shanghai
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System bootloader configuration
bootloader --location=mbr
clearpart --all --drives=sda --initlabel
part /boot --fstype ext3 --size=100 --ondisk=sda
part swap --size=4096
part / --fstype ext3 --size=100 --grow --asprimary
%packages
@core
@server-policy
@workstation-policy
%end




常见的cobbler check错误


1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This shou
ld be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : file /etc/xinetd.d/rsync does not exist
3 : debmirror package is not installed, it will be required to manage debian deployments and repositories
4 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still s
et to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one

解决方法:

1,把/etc/cobbler/settings文件的server参数改为自己的IP地址
2,这个提示一致存在,不用管
3,和debian系统相关,不需要管
4,系统提示,/etc/cobbler/settings文件中的default_password_crypted:参数,
需要使用命令openssl passwd -1 -salt 'random-phrase-here' 'your-password-here' 来加密生成