Cobbler是一个快速安装Linux系统的网络安装服务套件,集成了PXE、DHCP、DNS/Kickstart服务管理和yum仓库管理工具,通过PXE网络引导安装,配置简单。

说明:

前面一篇介绍了使用Kickstart批量部署RedHat
Linux 见
http://www.linuxidc.com/Linux/2012-05/60606.htm,但是这种方法配置起来比较麻烦。现在,我们有了更好的选择。那就是:Cobbler。在看以下内容时最好先看下:Kickstart批量部署redhat。

Cobbler简介

运维自动化包括标准化、工具化、Web化、服务化、智能化等几个不同的层级,在一家规模稍大、拥有服务器上千台甚至是几万台的生产环境中,想要真正实现运维自动化,工具化系统安装流程、统一系统安装规范,是其中最不能忽略的重要环节。普通的自动化部署可以采用pxe+dhcp+tftp配合kickstart实现,但是面对多版本、多部署需求的情况下,这种普通的部署方式可能达不到我们的要求;这时候就需要借助cobbler开源自动化部署工具来实现。

Cobbler是一款快速的网络系统部署工具,其最大的特点是集合了所有系统部署所需服务,如DHCP、DNS、TFTP,这样你在部署一台操作系统的时候不需要在各个服务之前协调切换,Cobbler都可以替你来管理,Cobbler内部集成了一个镜像版本仓库,你可以自定义相关配置文件,实现不同系统不同安装需求的选择;当然,Cobbler还提供了包括yum源管理、Web界面管理、API接口、电源管理等功能,方便你自定义开发管理。

部署准备:
关闭防火墙:service iptablesstop
关闭selinux:setenforce 0
安装epel源:rpm -ivh

VMware 虚拟机

系统环境:CentOS 5

Cobbler设计方式

发行版:表示一个操作系统。它承载了内核和 initrd
的信息,以及内核参数等其他数据

配置文件:包含一个发行版、一个 kickstart
文件以及可能的存储库,还包含更多特定的内核参数等其他数据

系统:表示要配给的机器。它包含一个配置文件或一个镜像,还包含 IP 和 MAC
地址、电源管理(地址、凭据、类型)以及更为专业的数据等信息

存储库:保存一个 yum 或 rsync 存储库的镜像信息

镜像:可替换一个包含不属于此类别的文件的发行版对象(例如,无法分为内核和
initrd 的对象)

1、安装相关软件
[[email protected]
~]# yum install -y cobbler tftp dhcp httpdcman pykickstart

Cobbler服务器系统:CentOS 6.8 64位

IP地址:192.168.1.200

CentOS5.4默认的Repository里找不到Cobbler,先安装rpmforce这个Repository。很全很强大,近10000个软件包。

Cobbler部署

实验环境(网段172.16.2.0/24)

[root@linux-node1 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@linux-node1 ~]# uname -r
3.10.0-327.el7.x86_64

2、配置tftp-server和rsync
[[email protected]
~]# vi /etc/xinetd.d/tftp
disable    = no    #开启
[[email protected]
~]# vi /etc/xinetd.d/rsync
disable    = no
[[email protected]
~]# /etc/init.d/xinetd restart

需要安装部署的Linux系统:

eth0(第一块网卡,用于外网)IP地址: 192.168.1.200

eth1(第二块网卡,用于内网)IP地址: 192.168.111.2
eth1(第二块网卡,用于内网)IP地址段:192.168.111.160-192.168.111.200

子网掩码:255.255.255.0

网关:192.168.111.2

DNS:8.8.8.8  8.8.4.4

所有服务器均支持PXE网络启动
  1. #32位:   
  2. wget 
      
  3. rpm -ivh rpmforge-release-0.5.1-1.el5.rf.i386.rpm   
  4. #64位:   
  5. wget 
      
  6. rpm -ivh rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm  

  7. 安装相关软件:

1)安装epel源
[root@linux-node1 ~]# rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

3、配置DHCP
[[email protected]
~]# vi /etc/dhcp/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
subnet 192.168.0.0 netmask 255.255.255.0 {
  range dynamic-bootp192.168.0.200 192.168.0.210;
  optionbroadcast-address 192.168.0.254;
  option routers192.168.0.1;
  optiondomain-name-servers 192.168.0.1;
  default-lease-time600;
  max-lease-time 7200;
  filename “pxelinux.0”;
  next-server192.168.0.202;
}

实现目的:通过配置Cobbler服务器,全自动批量安装部署Linux系统

yum -y install cobbler dhcp httpd xinetd tftp-server  

2)安装相关服务组件
[root@linux-node1 ~]# yum install -y httpd dhcp tftp cobbler cobbler-web pykickstart xinetd
#httpd dhcp tftp cobbler程序包 cobbler-web服务包 pykickstart KS文件检查 xinetd 守护进程
[root@linux-node1 ~]# systemctl start cobblerd
[root@linux-node1 ~]# systemctl start httpd
[root@linux-node1 ~]# systemctl start xinetd

安装完成后启动服务,我们先来看看cobbler的一些重要文件目录

/etc/cobbler             # 配置文件目录
/etc/cobbler/settings       # cobbler主配置文件
/etc/cobbler/dhcp.template    # DHCP服务的配置模板
/etc/cobbler/tftpd.template  # tftp服务的配置模板
/etc/cobbler/rsync.template # rsync服务的配置模板
/etc/cobbler/iso           # iso模板配置文件目录
/etc/cobbler/pxe           # pxe模板文件目录
/etc/cobbler/power          # 电源的配置文件目录
/etc/cobbler/users.conf       # Web服务授权配置文件
/etc/cobbler/users.digest     # web访问的用户名密码配置文件
/etc/cobbler/dnsmasq.template # DNS服务的配置模板
/etc/cobbler/modules.conf     # Cobbler模块配置文件
/var/lib/cobbler           # Cobbler数据目录
/var/lib/cobbler/config      # 配置文件
/var/lib/cobbler/kickstarts  # 默认存放kickstart文件
/var/lib/cobbler/loaders    # 存放的各种引导程序
/var/www/cobbler          # 系统安装镜像目录
/var/www/cobbler/ks_mirror    # 导入的系统镜像列表
/var/www/cobbler/images      # 导入的系统镜像启动文件
/var/www/cobbler/repo_mirror  # yum源存储目录
/var/log/cobbler          # 日志目录
/var/log/cobbler/install.log  # 客户端系统安装日志
/var/log/cobbler/cobbler.log  # cobbler日志

/etc/cobbler/settings中几个比较重要的参数设置
manage_dhcp:1
manage_dns:1
manage_tftpd:1
restart_dhcp:1
restart_dns:1
pxe_just_once:1
next_server:<服务器的 IP 地址>
server:<服务器的 IP 地址>
选项 next_server 用在 DHCP 配置文件中,向机器告知提供引导文件的服务器地址。选项 server 在机器安装期间用于引用 Cobbler 服务器地址。最后,选项 pxe_just_once 预防将机器中的安装循环配置为始终从网络引导。激活此选项时,机器告诉 Cobbler 安装已完成。Cobbler 将系统对象的 netboot 标志更改为 false,这会强制机器从本地磁盘引导

[[email protected]
~]# /etc/init.d/dhcpd restart

具体操作:

#
cobbler的配置文件在/var/lib/cobbler/和/etc/cobbler下(不同版本可能不同)
# xinetd tftp-server用来做tftp服务器,pxe启动需要。
# httpd服务器主要存放ks文件和安装光盘。注意 /var/www/cobbler
目录必须具有足够容纳 Linux 安装文件的空间(移动,建软链接)

3)初始化cobbler
[root@linux-node1 ~]# cobbler check
The following are potential configuration items that you may want to fix:
 1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

上面是告诉我们要对cobbler做的一些初始化设置,接下来一步步设置即可

①修改/etc/cobbler/settings配置文件
272 next_server: 172.16.2.150
#如果配置过kickstart知道,这里是告诉启动文件服务器下载地址

②修改/etc/cobbler/settings cobbler主机地址
384 server: 172.16.2.150 #cobbler主机服务器地址

③开启TFTP服务
[root@linux-node1 ~]# vim /etc/xinetd.d/tftp
disable = no

④运行cobbler get-loaders下载一些网络引导文件

[root@linux-node1 ~]# cobbler get-loaders

⑤开启rsyncd服务

[root@linux-node1 ~]# systemctl start rsyncd

⑥debian库服务,这里我们可以忽略

⑦创建系统初始化后的root密码

[root@linux-node1 ~]# openssl passwd -1 -salt 'cobbler' 'coblbber'
$1$cobler$XJnisBweZJlhL651HxAM00
[root@linux-node1 ~]# vim /etc/cobbler/settings
101 default_password_crypted: "$1$cobler$XJnisBweZJlhL651HxAM00"

⑧电源模块支持,我们暂时不需要,忽略

再次执行检查结果

[root@linux-node1 ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : enable and start rsyncd.service with systemctl
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
3 : 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.

4、执行检查,修改提示问题

第一部分:在Cobbler服务器上操作

  1. 检查 cobbler 配置:

  2. cobbler check  

4)让cobbler管理DHCP

如果我们需要让cobbler替我们管理DHCP服务器,需要修改以下配置

[root@linux-node1 ~]# vim /etc/cobbler/settings
242 manage_dhcp: 1 #改为数字1
[root@linux-node1 ~]# vim /etc/cobbler/dhcp.template #重启cobbler后,cobbler会生成一个模板文件
subnet 172.16.2.0 netmask 255.255.255.0 {
     option routers             172.16.2.150; #路由地址
     option domain-name-servers 172.16.2.150; #DHCP服务器地址
     option subnet-mask         255.255.255.0; #掩码
     range dynamic-bootp        172.168.2.200 172.12.2.250; #DHCP地址池
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;

图片 1

一、关闭SELINUX

vi /etc/selinux/config

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq!  #保存退出

setenforce 0 #使配置立即生效

#0: The ‘server’ field in /var/lib/cobbler/settings must be set to
something other than localhost, or kickstarting features will not work. 
This should be a resolvable hostname or IP for the boot server as
reachable by all machines that will use it.
#1: For PXE to be functional, the ‘next_server’ field in
/var/lib/cobbler/settings must be set to something other than 127.0.0.1,
and should match the IP of the boot server on the PXE network.
#2: change ‘disable’ to ‘no’ in /etc/xinetd.d/tftp

5)重启cobbler,并sync生成各种新的配置文件
[root@linux-node1 ~]# systemctl restart cobblerd
[root@linux-node1 ~]# cobbler sync
task started: 2016-08-25_114015_sync
task started (id=Sync, time=Thu Aug 25 11:40:15 2016)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders #拷贝自身引导文件
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying images
generating PXE configuration files #启动PXE程序
generating PXE menu structure
rendering DHCP files #配置DHCP服务
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files #配置TFTP服务
generating /etc/xinetd.d/tftp
cleaning link caches 
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout:
received on stderr:
running: service dhcpd restart #重启DHCP
received on stdout:
received on stderr: Redirecting to /bin/systemctl restart  dhcpd.service

running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE *** #完成

1>.修改/etc/cobbler/settings里cobbler server地址
2>.修改/etc/cobbler/settings里next_server地址
3>.执行cobbler get-loaders,下载loader程序
4>.提示没有安装debmirror,如果不是debian类的系统可忽略
5>.修改cobbler用户默认密码,然后替换/etc/cobbler/settings中的密码
生成密码:openssl passwd -1-salt ‘1234.com’ ‘123.com’ 
#1234.com是干扰码,用于加在密文中。123.com是安装新系统root密码
替换密文:default_password_crypted:”$1$1234.com$P8CiR10xiKXSQKJwofdsh0″
6>.执行cobbler sync命令,让cobbler接管服务,应用配置
[[email protected]
~]# /etc/init.d/cobblerd restart

二、配置防火墙,开启TCP:80端口、TCP:25151端口、UDP:69端口

直接关闭防火墙
/etc/init.d/iptables stop && chkconfig iptables off
/etc/init.d/ip6tables stop && chkconfig ip6tables off

或者

vi /etc/sysconfig/iptables  #编辑

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT  #http服务需要此端口

-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 69 -j ACCEPT  #tftp服务需要此端口

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 25151 -j ACCEPT  #cobbler需要此端口

:wq!  #保存退出

/etc/init.d/iptables restart #最后重启防火墙使配置生效

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

6)接下来,我们就可以在cobbler中加入一个完成的系统安装镜像
[root@linux-node1 ~]# mount /dev/cdrom /mnt #在光驱中加载一个完成的centos7 ISO文件
mount: /dev/sr0 is write-protected, mounting read-only
[root@linux-node1 ~]# cobbler import --path=/mnt/ --name=/CentOS-7-x86_64 --arch=x86_64 #使用import导入

[root@linux-node1 ~]# cobbler profile list #查看镜像目录
   CentOS-7-x86_64

[root@linux-node1 ~]# cobbler profile report #查看cobbler系统仓库中的版本信息
Name                           : CentOS-7-x86_64
TFTP Boot Files                : {}
Comment                        :
DHCP Tag                       : default
Distribution                   : CentOS-7-x86_64 #版本名称
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {} #自定义内核参数
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks #这里显示此系统版本使用的是系统自带的kickstart文件

5、修改cobbler配置文件让cobbler来管理相关服务
[[email protected]
~]# vi /etc/cobbler/settings
manage_dhcp: 1
manage_tftpd: 1
manage_rsync: 1
pxe_just_once: 1

三、安装Cobbler

使用阿里云源
http://mirrors.aliyun.com
Centos.repo 和 EPEL 都要装
或者

cd /usr/local/src

wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm  #CentOS 5.x 64位

rpm -ivh  epel-release-5-4.noarch.rpm

备注:

wget http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm  #CentOS 5.x 32位

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm  #CentOS6.x 64位

wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm  #CentOS6.x 32位

yum  install cobbler tftp tftp-server xinetd  dhcp  httpd  rsync  #安装cobbler

yum  install  pykickstart  debmirror  python-ctypes   cman   #安装运行cobbler需要的软件包

图片 2

7)上传相关的kickstart文件,修改cobbler默认KS配置
[root@linux-node1 ~]# cd /var/lib/cobbler/kickstarts/
[root@linux-node1 kickstarts]# ll
total 60
-rw-r--r-- 1 root root 3701 Aug 25 21:55 CentOS-6-x86_64.cfg
-rw-r--r-- 1 root root 1467 Aug 26 02:07 CentOS-7-x86_64.cfg
[root@linux-node1 kickstarts]# cobbler profile edit --name=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg #上传完成后修改成我们自己的ks文件
[root@linux-node1 kickstarts]# cobbler profile edit --name=CentOS-6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6-x86_64.cfg
[root@linux-node1 ~]# cobbler profile edit --name=CentOS-7-x86_64 --kopts='net.ifnames=0 biosdevname=0' #这里我们顺便修改一下内核文件参数,让centos7初始化网卡名为“eth”

6、导入CentOS系统
先可以挂载iso镜像,从光驱中导入cobbler:
[[email protected]
~]# mount -o loop RHEL-server-6.0-i386-dvd.iso /media
[[email protected]
~]# cobbler import -path=/media –name=rhel6

四、配置Cobbler

8)修改配置文件记得重启cobbler并执行sync
[root@linux-node1 ~]# cobbler sync

7、通过cobbler
list查看现在的镜像,通过测试机开机设置网络启动,实现无人值守安装

1、设置http服务

vi /etc/httpd/conf.d/wsgi.conf

LoadModule wsgi_module modules/mod_wsgi.so  #取消前面的注释

:wq! #保存退出

chkconfig httpd on  #设置开机启动

service httpd start #启动
9)网络启动一台新主机,测试cobbler

图片 3

2、设置tftp服务开机启动

vi  /etc/cobbler/tftpd.template  #编辑

service tftp

{

disable                 = no #修改为no

socket_type             = dgram

protocol                = udp

wait                    = yes

user                    = root

server                  = /usr/sbin/in.tftpd

server_args             = -B 1380 -v -s /tftpboot

per_source              = 11

cps                     = 100 2

flags                   = IPv4

}

:wq! #保存退出

Cobbler自定义yum源

[root@linux-node1 ~]# cobbler repo add --name=openstack-mitaka --mirror=http://mirrors.aliyun.com/centos/7.2.1511/cloud/x86_64/openstack-mitaka/ --arch=x86_64 --breed=yum #在cobbler repo中增加openstack yum源
[root@linux-node1 ~]# cobbler reposync #同步网络yum源仓库数据
[root@linux-node1 ~]# cobbler profile edit --name=CentOS-7-x86_64 --repos="openstack-mitaka"
#加入到相应name的版本仓库中
[root@linux-node1 ~]# vim /etc/cobbler/settings #修改cobbler配置允许cobbler帮我们自定义yum
yum_post_install_mirror: 1
[root@linux-node1 ~]# vim /var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg
%post
systemctl disable postfix.service

$yum_config_stanza #在kickstart文件加入新yum
%end

[root@linux-node1 ~]# echo "1 3 * * * /usr/bin/cobbler reposync --tries=3 --no-fail" >> /var/spool/cron/root #定时任务同步yum数据
[root@linux-node1 ~]# cat /etc/yum.repos.d/cobbler-config.repo #安装成功,能在被部署的机器上看见yum源
cobbler指定MC地址定制安装


[root@linux-node1 yum.repos.d]# cobbler system add --name=linux-node2.lichengbing.cn --mac=00:0C:29:8E:A9:4F --profile=CentOS-7-x86_64 \
> --ip-address=172.16.2.151 --subnet=255.255.255.0 --gateway=172.16.2.151 --interface=eth0 \
> --static=1 --hostname=linux-node2.lichengbing.cn --name-servers="172.16.2.150" \
> --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg
#指定MAC地址的机器安装,配置IP地址、主机名等
[root@linux-node1 yum.repos.d]# cobbler system list #查看自定义主机列表
   linux-node2.lichengbing.cn

运维自动化之Cobbler安装配置

3、设置rsync服务开机启动

vi /etc/xinetd.d/rsync  #编辑配置文件,设置开机启动rsync

service rsync

{

disable = no   #修改为no

socket_type     = stream

wait            = no

user            = root

server          = /usr/bin/rsync

server_args     = --daemon

log_on_failure  += USERID

}

:wq! #保存退出

/etc/init.d/xinetd start  #启动(CentOS中是以xinetd 来管理Rsync和tftp服务的)

Web管理Cobbler

[root@linux-node1 cobbler]# cat users.conf
配置web界面用户文件,生成密码
[root@linux-node1 cobbler]# htdigest /etc/cobbler/users.digest "Cobbler" cobbler
Changing password for user cobbler in realm Cobbler
New password:
Re-type new password:

[root@linux-node1 ~]# cat /etc/cobbler/pxe/pxedefault.template #自定义cobbler安装界面
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT $pxe_timeout_profile

LABEL local
        MENU LABEL (local)
        MENU DEFAULT
        LOCALBOOT -1

$pxe_menu_items

MENU end

[root@linux-node1 ~]# cobbler sync

查看Distros信息

RHEL5.5下Cobbler的配置

4、配置cobbler相关参数

vi /etc/debmirror.conf  #注释掉 @dists 和 @arches 两行

#@dists="sid";

#@arches="i386";

:wq! #保存退出

openssl passwd -1 -salt 'osyunwei' '123456'  #生成默认模板下系统安装完成之后root账号登录密码

$1$osyunwei$sEV8iwXXuR4CqzLXyLnzm0  #记录下这行,下面会用到

vi /etc/cobbler/settings  #编辑,修改

default_password_crypted: "$1$osyunwei$sEV8iwXXuR4CqzLXyLnzm0"

next_server: 192.168.111.2

server: 192.168.111.2

manage_dhcp: 1

default_kickstart: /var/lib/cobbler/kickstarts/default.ks

:wq! #保存退出

Cobbler自定义重装

[root@localhost ~]# rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
[root@localhost ~]# yum install koan -y #安装koan服务
[root@localhost ~]# koan --replace-self --server=172.16.2.150 --profile=CentOS-6-x86_64

#指定这台主机需要被重装,指定cobbler服务器地址和profile文件
[root@localhost ~]# reboot #重启后就会自动重新安装
cobbler同样有API接口,有Python基础的可以试试...

运维自动化部署Cobbler之服务安装篇

5、配置dhcp服务器

vi /etc/cobbler/dhcp.template #编辑,修改

subnet 192.168.111.0 netmask 255.255.255.0 { #设置网段

option routers             192.168.111.2; #设置网关

option domain-name-servers 8.8.8.8,8.8.4.4; #设置dns服务器地址

option subnet-mask         255.255.255.0; #设置子网掩码

range dynamic-bootp        192.168.111.160 192.168.111.200;  #设置dhcp服务器IP地址租用的范围

default-lease-time         21600;  #默认租约时间

max-lease-time             43200;  #最大租约时间

next-server                $next_server;

class "pxeclients" {

match if substring (option vendor-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";

}

}

}

:wq! #保存退出

vi /etc/sysconfig/dhcpd   #指定DHCP服务的网络接口

DHCPDARGS=eth1

:wq!  #保存退出

dhcpd  #测试dhcp服务器配置是否正确

chkconfig dhcpd on   #设置开机启动

chkconfig cobblerd on   #设置开机启动

cobbler get-loaders  #安装cobbler相关工具包,否则检查cobbler配置会报错

service cobblerd start  #启动cobbler

cobbler sync  #同步配置文件到dhcp服务器

service dhcpd start    #启动dhcp服务



安装cobbler错误集锦:

xmlrpclib.Fault: <Fault 1: "cobbler.cexceptions.CX:'login failed'">

查看导入列表,如果报如下内容,需要重启cobbler,并执行cobbler get-loaders.
[root@master src]# service cobblerd restart 

[root@master src]# cobbler get-loaders

利用Cobbler批量快速网络安装CentOS

6、设置cobbler相关服务启动脚本

vi /etc/rc.d/init.d/cobbler #编辑,添加以下代码

#!/bin/sh

# chkconfig: - 80 90

# description:cobbler

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

;;

restart)

/etc/init.d/httpd restart

/etc/init.d/xinetd restart

/etc/init.d/dhcpd restart

/etc/init.d/cobblerd restart

;;

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|restart|status|sync'!";

exit 2>&1 >/dev/null &

;;

esac

:wq! #保存退出

chmod +x /etc/rc.d/init.d/cobbler  #添加脚本执行权限

chkconfig cobbler on  #添加开机启动

service cobbler  restart  #重启cobbler

cobbler  check  #检查cobbler配置,出现下面的提示,SELinux和防火墙前面已经设置过了,不用理会



=====================================================================================

The following are potential configuration items that you may want to fix:

1 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:

https://github.com/cobbler/cobbler/wiki/Selinux

2 : since iptables may be running, ensure 69, 80/443, and 25151 are unblocked

Restart cobblerd and then run 'cobbler sync' to apply changes

=====================================================================================

CentOS 6.3上安装部署 Cobbler

五、挂载系统安装镜像到http服务器站点目录

上传系统安装镜像文件CentOS-5.10-x86_64-bin-DVD-1of2.iso到/usr/local/src/目录

mkdir -p /var/www/html/os/CentOS-5.10-x86_64  #创建挂载目录

mount -t iso9660 -o loop /usr/local/src/CentOS-5.10-x86_64-bin-DVD-1of2.iso  /var/www/html/os/CentOS-5.10-x86_64 #挂载系统镜像

vi /etc/fstab   #添加以下代码。实现开机自动挂载

/usr/local/src/CentOS-5.10-x86_64-bin-DVD-1of2.iso   /var/www/html/os/CentOS-5.10-x86_64   iso9660    defaults,ro,loop  0 0

:wq! #保存退出

备注:iso9660使用df  -T 查看设备  卸载:umount  /var/www/html/os/CentOS-5.10-x86_64

重复上面的操作,把自己需要安装的CentOS系统镜像文件都挂载到/var/www/html/os/目录下

例如:

CentOS-5.10-x86_64-bin-DVD-1of2.iso

CentOS-6.5-x86_64-bin-DVD1.iso

六、创建kickstarts自动安装脚本

cd /var/lib/cobbler/kickstarts  #进入默认Kickstart模板目录

vi /var/lib/cobbler/kickstarts/CentOS-5.10-x86_64.ks  #创建CentOS-5.10-x86_64安装脚本

# Kickstart file automatically generated by anaconda.

install

url --url=http://192.168.111.2/cobbler/ks_mirror/CentOS-5.10-x86_64-x86_64/

lang en_US.UTF-8

zerombr  yes

key --skip

keyboard us

network --device eth0 --bootproto dhcp  --onboot on

#network --device eth0 --bootproto static --ip 192.168.111.250 --netmask 255.255.255.0 --gateway 192.168.111.2 --nameserver 8.8.8.8 --hostname CentOS5.10

rootpw --iscrypted $1$QqobZZ1g$rYnrawi9kYlEeUuq1vcRS/

firewall --enabled --port=22:tcp

authconfig --enableshadow --enablemd5

selinux --disabled

timezone Asia/Shanghai

bootloader --location=mbr --driveorder=sda

# 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 --linux

clearpart --all --initlabel

part / --bytes-per-inode=4096 --fstype="ext3" --size=2048

part /boot --bytes-per-inode=4096 --fstype="ext3" --size=128

part swap --bytes-per-inode=4096 --fstype="swap" --size=500

part /data --bytes-per-inode=4096 --fstype="ext3" --grow --size=1

reboot

%packages

ntp

@base

@core

@dialup

@editors

@text-internet

keyutils

trousers

fipscheck

device-mapper-multipath

%post

#同步系统时间

ntpdate cn.pool.ntp.org

hwclock --systohc

echo -e "0 1 * * * root /usr/sbin/ntpdate cn.pool.ntp.org > /dev/null"  >> /etc/crontab

service crond restart

#添加用户组

groupadd maintain

groupadd develop

mkdir -p /home/maintain

mkdir -p /home/develop

#添加用户

useradd -g maintain  user01  -d /home/maintain/user01 -m

echo "123456"|passwd user01 --stdin

useradd -g maintain user02  -d /home/maintain/user02 -m

echo "123456"|passwd user02 --stdin

useradd -g maintain user03  -d /home/maintain/user03 -m

echo "123456"|passwd user03 --stdin

useradd -g maintain user04  -d /home/maintain/user04 -m

echo "123456"|passwd user04 --stdin

#禁止root用户直接登录系统

sed -i "s/#PermitRootLogin yes/PermitRootLogin no/g" '/etc/ssh/sshd_config'

service sshd restart

#禁止开机启动的服务

chkconfig acpid off

chkconfig atd off

chkconfig autofs off

chkconfig bluetooth off

chkconfig cpuspeed off

chkconfig firstboot off

chkconfig gpm off

chkconfig haldaemon off

chkconfig hidd off

chkconfig ip6tables off

chkconfig isdn off

chkconfig messagebus off

chkconfig nfslock off

chkconfig pcscd off

chkconfig portmap off

chkconfig rpcgssd off

chkconfig rpcidmapd off

chkconfig yum-updatesd off

chkconfig sendmail off

#允许开机启动的服务

chkconfig crond on

chkconfig kudzu on

chkconfig network on

chkconfig readahead_early on

chkconfig sshd on

chkconfig syslog on

#禁止使用Ctrl+Alt+Del快捷键重启服务器

sed -i "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/g" '/etc/inittab'

telinit q

#优化系统内核

echo -e "ulimit -c unlimited"  >> /etc/profile

echo -e "ulimit -s unlimited"  >> /etc/profile

echo -e "ulimit -SHn 65535"  >> /etc/profile

source  /etc/profile

sed -i "s/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g" '/etc/sysctl.conf'

echo -e "net.core.somaxconn = 262144"  >> /etc/sysctl.conf

echo -e "net.core.netdev_max_backlog = 262144"  >> /etc/sysctl.conf

echo -e "net.core.wmem_default = 8388608"  >> /etc/sysctl.conf

echo -e "net.core.rmem_default = 8388608"  >> /etc/sysctl.conf

echo -e "net.core.rmem_max = 16777216"  >> /etc/sysctl.conf

echo -e "net.core.wmem_max = 16777216"  >> /etc/sysctl.conf

echo -e "net.ipv4.netfilter.ip_conntrack_max = 131072"  >> /etc/sysctl.conf

echo -e "net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 180"  >> /etc/sysctl.conf

echo -e "net.ipv4.route.gc_timeout = 20"  >> /etc/sysctl.conf

echo -e "net.ipv4.ip_conntrack_max = 819200"  >> /etc/sysctl.conf

echo -e "net.ipv4.ip_local_port_range = 10024  65535"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_retries2 = 5"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_fin_timeout = 30"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_syn_retries = 1"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_synack_retries = 1"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_timestamps = 0"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_tw_recycle = 1"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_tw_len = 1"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_tw_reuse = 1"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_keepalive_time = 120"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_keepalive_probes = 3"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_keepalive_intvl = 15"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_max_tw_buckets = 36000"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_max_orphans = 3276800"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_max_syn_backlog = 262144"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_wmem = 8192 131072 16777216"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_rmem = 32768 131072 16777216"  >> /etc/sysctl.conf

echo -e "net.ipv4.tcp_mem = 94500000 915000000 927000000"  >> /etc/sysctl.conf

/sbin/sysctl -p

#执行外部脚本

cd /root

wget http://192.168.111.2/cobbler/ks_mirror/config/autoip.sh

sh /root/autoip.sh

:wq! #保存退出

vi /var/www/cobbler/ks_mirror/config/autoip.sh  #创建脚本,自动设置Linux系统静态IP地址、DNS、网关、计算机名称

#!/bin/sh

ROUTE=$(route -n|grep "^0.0.0.0"|awk '{print $2}')

BROADCAST=$(/sbin/ifconfig eth0|grep -i bcast|awk '{print $3}'|awk -F":" '{print $2}')

HWADDR=$(/sbin/ifconfig eth0|grep -i HWaddr|awk '{print $5}')

IPADDR=$(/sbin/ifconfig eth0|grep "inet addr"|awk '{print $2}'|awk -F":" '{print $2}')

NETMASK=$(/sbin/ifconfig eth0|grep "inet addr"|awk '{print $4}'|awk -F":" '{print $2}')

cat >/etc/sysconfig/network-scripts/ifcfg-eth0<<EOF

DEVICE=eth0

BOOTPROTO=static

BROADCAST=$BROADCAST

HWADDR=$HWADDR

IPADDR=$IPADDR

NETMASK=$NETMASK

GATEWAY=$ROUTE

ONBOOT=yes

EOF

IPADDR1=$(echo $IPADDR|awk -F"." '{print $4}')

cat >/etc/sysconfig/network-scripts/ifcfg-eth1<<EOF

DEVICE=eth1

BOOTPROTO=static

BROADCAST=10.0.0.255

HWADDR=$(/sbin/ifconfig eth1|grep -i HWaddr|awk '{print $5}')

IPADDR=10.0.0.$IPADDR1

NETMASK=255.255.255.0

ONBOOT=yes

EOF

HOSTNAME=OsYunWei_HZ_$(echo $IPADDR|awk -F"." '{print $4}')

cat >/etc/sysconfig/network<<EOF

NETWORKING=yes

NETWORKING_IPV6=no

HOSTNAME=$HOSTNAME

GATEWAY=$ROUTE

EOF

echo "127.0.0.1  $HOSTNAME" >> /etc/hosts

hostname=$HOSTNAME

echo "nameserver  8.8.8.8"  > /etc/resolv.conf

echo "nameserver  8.8.4.4" >> /etc/resolv.conf

:wq!  #保存退出

七、导入系统镜像到cobbler

cobbler import --path=/var/www/html/os/CentOS-5.10-x86_64  --name=CentOS-5.10-x86_64  --arch=x86_64  #导入系统镜像文件,需要一段时间

cd /var/www/cobbler/ks_mirror  #进入系统镜像导入目录

命令格式:cobbler import --path=镜像路径 -- name=安装引导名 --arch=32位或64位

重复上面的操作,把其他的系统镜像文件导入到cobbler

八、设置profile,按照操作系统版本分别关联系统镜像文件和kickstart自动安装文件

在第一次导入系统镜像时,cobbler会给安装镜像指定一个默认的kickstart自动安装文件

例如:CentOS-5.10-x86_64版本的kickstart自动安装文件为:/var/lib/cobbler/kickstarts/sample.ks

cobbler profile report --name  CentOS-5.10-x86_64  #查看profile设置

cobbler distro report --name CentOS-5.10-x86_64 #查看安装镜像文件信息

cobbler profile remove --name=CentOS-5.10-x86_64  #移除profile

cobbler profile add --name=CentOS-5.10-x86_64 --distro=CentOS-5.10-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-5.10-x86_64.ks  #添加

cobbler profile edit --name=CentOS-5.10-x86_64 --distro=CentOS-5.10-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-5.10-x86_64.ks  #编辑

命令:cobbler profile add|edit|remove --name=安装引导名 --distro=系统镜像名 --kickstart=kickstart自动安装文件路径

--name:自定义的安装引导名,注意不能重复

--distro:系统安装镜像名,用cobbler distro list可以查看

--kickstart:与系统镜像文件相关联的kickstart自动安装文件

#查看Cobbler列表

cobbler list

cobbler report

cobbler profile report

cobbler distro list

#通过profile查找对应的kickstart自动安装文件文件

例如:

ksfile=$( cobbler profile report --name  CentOS-5.10-x86_64|grep -E '^Kickstart' |head -n 1|cut -d ':' -f 2 );cat $ksfile;

重复上面的操作,把其他的系统镜像文件和kickstart自动安装文件关联起来

注意:

1、kickstart自动安装文件需要预先配置好

2、每次修改完配置文件,需要执行一次同步操作:cobbler sync 配置才能生效

3、kickstart自动安装文件可以用工具生成(需要用到图形界面操作)

yum  install system-config-kickstart #安装

yum groupinstall "X Window System" #安装X Window图形界面

system-config-kickstart #运行kickstart配置

service  cobbler  sync  #与cobbler sync作用相同

service  cobbler  restart  #重启cobbler

第二部分:设置要安装的服务器从网络启动

重新安装系统:

在需要重装系统的服务器上安装koan

wget http://dl.fedoraproject.org/pub/epel/5/x86_64/koan-2.4.0-1.el5.noarch.rpm  #CentOS 5.X

rpm -ivh koan-2.4.0-1.el5.noarch.rpm  #安装koan

http://dl.fedoraproject.org/pub/epel/6/x86_64/koan-2.4.0-1.el6.noarch.rpm  #CentOS 6.X

yum  install  cobbler  debmirror  pykickstart  python-ctypes  cman   #安装koan运行依赖包(需要设置epel源)

koan --list=profiles  --server=192.168.111.2  #查看Cobbler服务器系统镜像列表

koan --replace-self --server=192.168.111.2 --profile=CentOS-5.10-x86_64  #选择要重装的系统

reboot #重新启动系统进行自动安装

扩展阅读:

Cobbler目录说明:

1、Cobbler配置文件目录:/etc/cobbler

/etc/cobbler/settings   #cobbler主配置文件

/etc/cobbler/dhcp.template   #DHCP服务的配置模板

/etc/cobbler/tftpd.template   #tftp服务的配置模板

/etc/cobbler/rsync.template   #rsync服务的配置模板

/etc/cobbler/iso   #iso模板配置文件

/etc/cobbler/pxe   #pxe模板文件

/etc/cobbler/power  #电源的配置文件

/etc/cobbler/users.conf   #Web服务授权配置文件

/etc/cobbler/users.digest   #用于web访问的用户名密码配置文件

/etc/cobbler/dnsmasq.template   #DNS服务的配置模板

/etc/cobbler/modules.conf   #Cobbler模块配置文件

2、Cobbler数据目录:/var/lib/cobbler

/var/lib/cobbler/config #配置文件

/var/lib/cobbler/triggers  #Cobbler命令

/var/lib/cobbler/kickstarts  #默认存放kickstart文件

/var/lib/cobbler/loaders  #存放的各种引导程序

3、系统安装镜像目录:/var/www/cobbler

/var/www/cobbler/ks_mirror #导入的系统镜像列表

/var/www/cobbler/images  #导入的系统镜像启动文件

/var/www/cobbler/repo_mirror #yum源存储目录

4、日志目录:/var/log/cobbler

/var/log/cobbler/install.log  #客户端系统安装日志

/var/log/cobbler/cobbler.log  #cobbler日志

至此,Cobbler全自动批量安装部署Linux系统完成。

FROM
http://www.osyunwei.com/archives/7606.html
FROMhttp://www.tuicool.com/articles/Z7BnamU
FROMhttp://blog.sina.com.cn/s/blog\_61c07ac50101d0b7.html
FROMhttp://www.linuxidc.com/Linux/2015-09/122945.htm

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图