cobbler

1.cobbler简介

Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。

Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。

Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。

Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
cobbler集成的服务

  • PXE服务支持
  • DHCP服务管理
  • DNS服务管理(可选bind,dnsmasq)
  • 电源管理
  • Kickstart服务支持
  • YUM仓库管理
  • TFTP(PXE启动时需要)
  • Apache(提供kickstart的安装源,并提供定制化的kickstart配置)

2.cobbler服务端部署

//配置yum源
[root@chenwanting ~]# curl -o /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@chenwanting ~]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@chenwanting ~]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@chenwanting ~]# yum -y install epel-release

//安装cobbler以及相关的软件
[root@chenwanting ~]# yum -y install httpd dhcp tftp python-ctypes cobbler  xinetd cobbler-web pykickstart

//启动服务并设置开机自启
[root@chenwanting ~]# systemctl start httpd
[root@chenwanting ~]# systemctl start cobblerd
[root@chenwanting ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@chenwanting ~]# systemctl enable cobblerd
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.

//修改server的ip地址为本机ip
[root@chenwanting ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.40.139/' /etc/cobbler/settings

//设置tftp的ip地址为本机ip
[root@chenwanting ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.40.139/' /etc/cobbler/settings

//开启tftp
[root@chenwanting ~]# sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp

//下载缺失文件
[root@chenwanting ~]# cobbler get-loaders
#  出现这个就是正确的 *** TASK COMPLETE ***

//启动rsync并设置开机自启
[root@chenwanting ~]# systemctl start rsyncd
[root@chenwanting ~]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.

//生成加密的密码
[root@chenwanting ~]# openssl passwd -1 -salt "$RANDOM" 'chen123'
$1$30687$Eqc4fqs2EtmNFykGQLNZp/     //这是密码加密后的形式

//将生成的加密密码加入到配置文件
[root@chenwanting ~]# vim /etc/cobbler/settings 
....  //此处省略内容
default_password_crypted: "$1$30687$Eqc4fqs2EtmNFykGQLNZp/"
....  //此处省略内容

//重启cobbler
[root@chenwanting ~]# systemctl restart cobblerd
[root@chenwanting ~]# ss -antl
State      Recv-Q Send-Q     Local Address:Port                    Peer Address:Port              
LISTEN     0      128                    *:22                                 *:*                  
LISTEN     0      100            127.0.0.1:25                                 *:*                  
LISTEN     0      5              127.0.0.1:25151                              *:*                  
LISTEN     0      5                      *:873                                *:*                  
LISTEN     0      128                   :::80                                :::*                  
LISTEN     0      128                   :::22                                :::*                  
LISTEN     0      100                  ::1:25                                :::*                  
LISTEN     0      128                   :::443                               :::*                  
LISTEN     0      5                     :::873                               :::*  

//通过cobbler check 核对当前设置是否有问题
[root@chenwanting ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : debmirror package is not installed, it will be required to manage debian deployments and repositories
2 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

Restart cobblerd and then run 'cobbler sync' to apply changes.
//以上两个是关于debian系统的错误,请忽略

//配置cobbler dhcp
//修改cobbler配置文件,让cobbler控制dhcp
[root@chenwanting ~]# sed -i '/^manage_dhcp/s/0/1/g' /etc/cobbler/settings
[root@chenwanting ~]# sed -n '/^manage_dhcp/p' /etc/cobbler/settings
manage_dhcp: 1

//配置dhcp
[root@chenwanting ~]# vim /etc/cobbler/dhcp.template
....    //此处为省略内容
subnet 192.168.40.0 netmask 255.255.255.0 {
     option routers             192.168.40.139;
     option domain-name-servers 192.168.40.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.40.100 192.168.40.254;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
....    //此处为省略内容

//重启服务并同步配置,改完dhcp必须要sync同步配置
[root@chenwanting ~]# systemctl restart cobblerd
[root@chenwanting ~]# cobbler sync

//检查dhcp是否正常
[root@chenwanting ~]# netstat -anulp|grep dhcp
udp        0      0 0.0.0.0:67              0.0.0.0:*                           1631/dhcpd      

//导入redhat7镜像
[root@chenwanting ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@chenwanting ~]# cobbler import --path=/mnt --name=rhel-7 --arch=x86_64

//说明:
    --path      //镜像路径
    --name      //为安装源定义一个名字
    --arch      //指定安装源平台

//安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-7-x86_64,如果重复,系统会提示导入失败

//查看cobbler镜像列表
[root@chenwanting ~]# cobbler list
distros:
   rhel-7-x86_64

profiles:
   rhel-7-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

//创建kickstarts自动安装脚本
[root@chenwanting ~]#  vim /var/lib/cobbler/kickstarts/rhel-7-x86_64.ks 
auth --enableshadow --passalgo=sha512
bootloader --location=mbr
clearpart --all --initlabel
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=4096
part / --fstype="ext4" --grow --size=15000
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
url --url=http://192.168.40.139/cobbler/ks_mirror/rhel-7-x86_64
$yum_repo_stanza
reboot

rootpw --iscrypted $6$h0iKLaAsAbSUi1qo$oD5fFRmt4h5JVPCS0EymdTJFpsKJ36HACi3bminl0dt9K7i8zxQRvvIkOOGsTGUe/fL3/H8LRbHrOLI4ykyIJ.

selinux --disabled
skipx
timezone Asia/Shanghai --isUtc --nontp
install
zerombr

%packages
@^minimal
@core
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
#   rootpw在root下的anaconda-ks.cfg文件中

//检查ks文件语法是否有误
[root@chenwanting ~]# cobbler validateks

//查看当前cobbler有哪些配置文件
[root@chenwanting ~]# cobbler profile list
   rhel-7-x86_64

//修改profile,将我们新建的ks文件设为默认的kickstarts安装文件
[root@chenwanting ~]# obbler profile edit --name rhel-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/rhel-7-x86_64.ks

//配置网卡名称为传统网卡名称eth0
[root@chenwanting ~]# cobbler profile edit --name rhel-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'

//检查当前系统cobbler配置文件信息
[root@chenwanting ~]# cobbler profile report
Name                           : rhel-7-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : rhel-7-x86_64          //仓库名字
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {'biosdevname': '0', 'net.ifnames': '0'}        //网卡设为传统命名方式
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/rhel-7-x86_64.ks      //使用的kickstarts配置文件的路径,必须为我们新建的ks文件的路径
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <<inherit>>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 : 
Internal proxy                 : 
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      : 
Virt RAM (MB)                  : 512
Virt Type                      : kvm

//同步cobbler
[root@chenwanting ~]# cobbler sync

//为避免发生未知问题,先把服务端所有服务重启
[root@chenwanting ~]# systemctl restart xinetd
[root@chenwanting ~]# systemctl restart cobblerd
[root@chenwanting ~]# systemctl restart httpd
[root@chenwanting ~]# ss -antl
State      Recv-Q Send-Q     Local Address:Port                    Peer Address:Port              
LISTEN     0      128                    *:22                                 *:*                  
LISTEN     0      100            127.0.0.1:25                                 *:*                  
LISTEN     0      5              127.0.0.1:25151                              *:*                  
LISTEN     0      5                      *:873                                *:*                  
LISTEN     0      128                   :::80                                :::*                  
LISTEN     0      128                   :::22                                :::*                  
LISTEN     0      100                  ::1:25                                :::*                  
LISTEN     0      128                   :::443                               :::*                  
LISTEN     0      5                     :::873                               :::*     

3.客户端安装

新建虚拟机从pxe启动,若出现以下界面则表示成功:
在这里插入图片描述

4.定制安装

定制安装步骤:

  • 统计服务器mac地址
  • 配置cobbler
  • 安装
    统计mac地址此处就不赘述了,直接最重要的配置
    在 cobbler 的web界面上配置:
    在服务端安装
[root@chenwanting ~]# yum -y install python2-pip
[root@chenwanting ~]# pip install --upgrade pip
[root@chenwanting ~]# pip install Django==1.9.13

//重启httpd服务
[root@chenwanting ~]# systemctl restart httpd

#默认账户cobbler;密码cobbler
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
同步配置并重启相关服务:

[root@chenwanting ~]# cobbler sync
[root@chenwanting ~]# systemctl restart httpd
[root@chenwanting ~]# systemctl restart cobblerd
[root@chenwanting ~]# systemctl restart xinetd

最后开机自动会安装系统

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值