我的博客已迁移到xdoujiang.com请去那边和我交流
Cobbler is an
install
server; batteries are included
Cobbler is a Linux installation server that allows
for
rapid setup of network installation environments.
It glues together and automates many associated Linux tasks so you
do
not have to hop between lots of
various commands and applications when rolling out new systems, and,
in
some cases, changing existing ones.
With a simple series of commands, network installs can be configured
for
PXE, reinstallations,
media-based net-installs, and virtualized installs (supporting Xen, qemu, KVM, and some variants of VMware).
Cobbler uses a helper program called koan (
which
interacts with Cobbler)
for
reinstallation and virtualization support.
Cobbler is a small and lightweight application (about 15k lines of Python code). It tries to be extremely
simple to use both
for
very small and very large installations -- as well as easy to work on, extend, and hack.
It avoids being
"enterprisey"
(as
in
complicated) whenever possible, but is highly useful
in
all sorts of
enterprises by having a lot of advanced features and doing small things to save a large amount of
time
in
repeated tasks.
Cobbler can also optionally help with managing DHCP, DNS, and yum package mirroring infrastructure --
in
this regard,
it is a
more
generalized automation app, rather than just dealing specifically with installations.
There is also a lightweight built-
in
configuration management system, as well as support
for
integrating
with configuration management systems like Puppet. Cobbler has a
command
line interface, a web interface
and also several API access options. That sounds like a lot, but it is really pretty simple.
New
users
may like to start with the web app after doing the initial setup steps on the
command
line
(cobbler check; cobbler
import
) as it will give them a good idea of all of the features available.
Advanced features
do
not have to be understood all at once, they can be incorporated over
time
as the need
for
them arises.
一、基础环境
1、角色、ip、版本、内核
serverA 192.168.1.30 3.10.0-229.el7.x86_64 CentOS Linux release 7.1.1503 (Core) cobbler dnsmasq httpd tftp-server
cobbler-2.6.9-1
dnsmasq-2.66-14
httpd-2.4.6-31
tftp-server-5.2-11
CentOS-5.9-x86_64-bin-DVD-1of1.iso
CentOS-5.9-x86_64-bin-DVD-2of2.iso
CentOS-6.7-x86_64-bin-DVD1.iso
CentOS-6.7-x86_64-bin-DVD2.iso
CentOS-7-x86_64-Everything-1503-01.iso
2、关闭防火墙和selinux
1)查看到当前已经关闭防火墙了
systemctl status firewalld.service
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (
/usr/lib/systemd/system/firewalld
.service; disabled)
Active: inactive (dead)
2)查看到selinux还开着
getenforce
Enforcing
3)关闭selinux
sed
-i
's/SELINUX=.*/SELINUX=disabled/'
/etc/selinux/config
setenforce 0
二、安装cobbler(serverA)
1、安装所需要的包
yum -y
install
cobbler pykickstart openssl fence-agents dnsmasq syslinux
2、设置开机启动
1)设置http服务开机启动
systemctl
enable
httpd.service
ln
-s
'/usr/lib/systemd/system/httpd.service'
'/etc/systemd/system/multi-user.target.wants/httpd.service'
2)设置dnsmasq服务开机启动
systemctl
enable
dnsmasq.service
ln
-s
'/usr/lib/systemd/system/dnsmasq.service'
'/etc/systemd/system/multi-user.target.wants/dnsmasq.service'
3)设置cobblerd服务开机启动
systemctl
enable
cobblerd.service
ln
-s
'/usr/lib/systemd/system/cobblerd.service'
'/etc/systemd/system/multi-user.target.wants/cobblerd.service'
3、确认cobbler已经正常启动
1)查看cobbler端口
netstat
-tupnl |
grep
python
tcp 0 0 127.0.0.1:25151 0.0.0.0:* LISTEN 2033
/python2
2)查看cobbler进程
ps
-ef |
grep
cobbler
root 2033 1 0 10:37 ? 00:00:00
/usr/bin/python2
/usr/bin/cobblerd
-F
4、执行cobbler检查
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 :
file
/etc/xinetd
.d
/rsync
does not exist
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
Restart cobblerd and
then
run
'cobbler sync'
to apply changes.
5、解决以上问题
1)备份配置
cp
/etc/cobbler/settings
/etc/cobbler/settings
.bak
2)生成root密码为redhat
openssl
passwd
-1 -salt
'root'
'redhat'
$1$root$M1uN9dLHipbORRwJW
/xR3/
3)修改配置
sed
-i
's/^server:.*/server: 192.168.1.30/'
/etc/cobbler/settings
sed
-i
's/^next_server:.*/next_server: 192.168.1.30/'
/etc/cobbler/settings
sed
-i
'/default_password_crypted/c\default_password_crypted:\ "$1$root$M1uN9dLHipbORRwJW/xR3/"'
/etc/cobbler/settings
sed
-i
's/^manage_dhcp:.*/manage_dhcp: 1/'
/etc/cobbler/settings
sed
-i
's/^manage_dns:.*/manage_dns: 1/'
/etc/cobbler/settings
sed
-i
's/^manage_tftpd:.*/manage_tftpd: 1/'
/etc/cobbler/settings
sed
-i
's/^restart_dhcp:.*/restart_dhcp: 1/'
/etc/cobbler/settings
sed
-i
's/^restart_dns:.*/restart_dns: 1/'
/etc/cobbler/settings
sed
-i
's/^pxe_just_once:.*/pxe_just_once: 1/'
/etc/cobbler/settings
PS:debmirror包在源里已经去除 第6条可以无视
4)下载pxelinux.0和menu.c32等文件
cobbler get-loaders
task started: 2015-10-10_111702_get_loaders
task started (
id
=Download Bootloader Content,
time
=Sat Oct 10 11:17:02 2015)
downloading http:
//cobbler
.github.com
/loaders/README
to
/var/lib/cobbler/loaders/README
downloading http:
//cobbler
.github.com
/loaders/COPYING
.elilo to
/var/lib/cobbler/loaders/COPYING
.elilo
downloading http:
//cobbler
.github.com
/loaders/COPYING
.yaboot to
/var/lib/cobbler/loaders/COPYING
.yaboot
downloading http:
//cobbler
.github.com
/loaders/COPYING
.syslinux to
/var/lib/cobbler/loaders/COPYING
.syslinux
downloading http:
//cobbler
.github.com
/loaders/elilo-3
.8-ia64.efi to
/var/lib/cobbler/loaders/elilo-ia64
.efi
downloading http:
//cobbler
.github.com
/loaders/yaboot-1
.3.17 to
/var/lib/cobbler/loaders/yaboot
downloading http:
//cobbler
.github.com
/loaders/pxelinux
.0-3.86 to
/var/lib/cobbler/loaders/pxelinux
.0
downloading http:
//cobbler
.github.com
/loaders/menu
.c32-3.86 to
/var/lib/cobbler/loaders/menu
.c32
downloading http:
//cobbler
.github.com
/loaders/grub-0
.97-x86.efi to
/var/lib/cobbler/loaders/grub-x86
.efi
downloading http:
//cobbler
.github.com
/loaders/grub-0
.97-x86_64.efi to
/var/lib/cobbler/loaders/grub-x86_64
.efi
*** TASK COMPLETE ***
5)创建
rsync
文件
touch
/etc/xinetd
.d
/rsync
6)修改
/etc/cobbler/modules
.conf配置文件
1)先备份下配置
cp
/etc/cobbler/modules
.conf
/etc/cobbler/modules
.conf.bak
2)开始修改
diff
/etc/cobbler/modules
.conf
/etc/cobbler/modules
.conf.bak
56c56
< module = manage_dnsmasq
---
> module = manage_bind
69c69
< module = manage_dnsmasq
---
> module = manage_isc
7)修改
/etc/cobbler/dnsmasq
.template配置文件
1)先备份下配置
cp
/etc/cobbler/dnsmasq
.template
/etc/cobbler/dnsmasq
.template.bak
2)开始修改
diff
/etc/cobbler/dnsmasq
.template
/etc/cobbler/dnsmasq
.template.bak
11c11
< dhcp-range=192.168.1.31,192.168.1.40
---
> dhcp-range=192.168.1.5,192.168.1.200
8)重启服务cobbler
systemctl restart cobblerd.service
9)使配置生效
cobbler
sync
task started: 2015-10-10_113739_sync
task started (
id
=Sync,
time
=Sat Oct 10 11:37:39 2015)
running pre-
sync
triggers
cleaning trees
removing:
/var/lib/tftpboot/pxelinux
.cfg
/default
removing:
/var/lib/tftpboot/grub/grub-x86_64
.efi
removing:
/var/lib/tftpboot/grub/grub-x86
.efi
removing:
/var/lib/tftpboot/grub/images
removing:
/var/lib/tftpboot/grub/efidefault
removing:
/var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink
/var/lib/cobbler/loaders/grub-x86_64
.efi ->
/var/lib/tftpboot/grub/grub-x86_64
.efi
trying hardlink
/var/lib/cobbler/loaders/grub-x86
.efi ->
/var/lib/tftpboot/grub/grub-x86
.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering TFTPD files
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 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 ***
10)再次检查
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
Restart cobblerd and
then
run
'cobbler sync'
to apply changes.
6、查看下default文件
cat
/var/lib/tftpboot/pxelinux
.cfg
/default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http:
//cobbler
.github.com
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT
local
LABEL
local
MENU LABEL (
local
)
MENU DEFAULT
LOCALBOOT -1
MENU end
7、挂载并导入dvd iso
1)挂载第1张dvd
cd
/opt
&&
mount
-o loop
/opt/CentOS-6
.7-x86_64-bin-DVD1.iso
/mnt
mount
:
/dev/loop0
is write-protected, mounting
read
-only
2)导入
cobbler
import
--arch=x86_64 --path=
/mnt
--name=centos6.7
task started: 2015-10-10_124327_import
task started (
id
=Media
import
,
time
=Sat Oct 10 12:43:27 2015)
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path
/var/www/cobbler/ks_mirror/centos6
.7-x86_64:
creating new distro: centos6.7-x86_64
trying
symlink
:
/var/www/cobbler/ks_mirror/centos6
.7-x86_64 ->
/var/www/cobbler/links/centos6
.7-x86_64
creating new profile: centos6.7-x86_64
associating repos
checking
for
rsync
repo(s)
checking
for
rhn repo(s)
checking
for
yum repo(s)
starting descent into
/var/www/cobbler/ks_mirror/centos6
.7-x86_64
for
centos6.7-x86_64
processing repo at :
/var/www/cobbler/ks_mirror/centos6
.7-x86_64
need to process repo
/comps
:
/var/www/cobbler/ks_mirror/centos6
.7-x86_64
looking
for
/var/www/cobbler/ks_mirror/centos6
.7-x86_64
/repodata/
*comps*.xml
Keeping repodata as-is :
/var/www/cobbler/ks_mirror/centos6
.7-x86_64
/repodata
*** TASK COMPLETE ***
3)卸载
umount
/mnt
4)挂载第2张dvd
cd
/opt
&&
mount
-o loop
/opt/CentOS-6
.7-x86_64-bin-DVD2.iso
/mnt
mount
:
/dev/loop0
is write-protected, mounting
read
-only
5)将第2张光盘继续复制到镜像里
cp
-rf
/mnt/Packages/
/var/www/cobbler/ks_mirror/centos6
.7-x86_64/
cp
: overwrite ?.var
/www/cobbler/ks_mirror/centos6
.7-x86_64
/Packages/TRANS
.TBL?. y
6)卸载
umount
/mnt
8、查看到已经导入了
cobbler list
distros:
centos6.7-x86_64
profiles:
centos6.7-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
9、再次查看default文件
cat
/var/lib/tftpboot/pxelinux
.cfg
/default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http:
//cobbler
.github.com
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT
local
LABEL
local
MENU LABEL (
local
)
MENU DEFAULT
LOCALBOOT -1
LABEL centos6.7-x86_64
kernel
/images/centos6
.7-x86_64
/vmlinuz
MENU LABEL centos6.7-x86_64
append initrd=
/images/centos6
.7-x86_64
/initrd
.img ksdevice=bootif lang= kssendmac text ks=http:
//192
.168.1.30
/cblr/svc/op/ks/profile/centos6
.7-x86_64
ipappend 2
MENU end
10、修改kickstart配置文件
1)复制模板
cp
/var/lib/cobbler/kickstarts/sample_end
.ks
/var/lib/cobbler/kickstarts/centos6
.7x86_64.cfg
2)具体配置
cat
/var/lib/cobbler/kickstarts/centos6
.7x86_64.cfg
auth --useshadow --enablemd5
bootloader --location=mbr
clearpart --all --initlabel
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
url --url=$tree
$yum_repo_stanza
$SNIPPET(
'network_config'
)
reboot
rootpw --iscrypted $default_password_crypted
selinux --disabled
skipx
timezone Asia
/shanghai
install
zerombr
part
/boot
--fstype=ext4 --size=200
part swap --fstype=swap --size=2048
part / --fstype=ext4 --size=10000
part
/opt
--fstype=ext4 --grow --size=1
%pre
$SNIPPET(
'log_ks_pre'
)
$SNIPPET(
'kickstart_start'
)
$SNIPPET(
'pre_install_network_config'
)
$SNIPPET(
'pre_anamon'
)
%end
%packages --nobase
wget
vim
openssh-server
$SNIPPET(
'func_install_if_enabled'
)
%end
%post --nochroot
$SNIPPET(
'log_ks_post_nochroot'
)
%end
%post
$SNIPPET(
'log_ks_post'
)
$yum_config_stanza
$SNIPPET(
'post_install_kernel_options'
)
$SNIPPET(
'post_install_network_config'
)
$SNIPPET(
'func_register_if_enabled'
)
$SNIPPET(
'download_config_files'
)
$SNIPPET(
'koan_environment'
)
$SNIPPET(
'redhat_register'
)
$SNIPPET(
'cobbler_register'
)
$SNIPPET(
'post_anamon'
)
$SNIPPET(
'kickstart_done'
)
%end
3)修改默认的模板为centos模板
cobbler profile edit --name=CentOS6.7-x86_64 --kickstart=
/var/lib/cobbler/kickstarts/centos6
.7x86_64.cfg
4)查看到现在已经在使用centos6.7x86_64.cfg配置文件了
cobbler profile report
Name : CentOS6.7-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : centos6.7-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart :
/var/lib/cobbler/kickstarts/centos6
.7x86_64.cfg
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
11、重启全部服务
systemctl restart cobblerd.service
systemctl restart dnsmasq.service
systemctl restart httpd.service
systemctl restart xinetd.service
12、查看进程
root 11120 1.1 6.2 363472 30216 ? Ss 13:07 0:00
/usr/bin/python2
/usr/bin/cobblerd
-F
nobody 11130 0.0 0.2 15524 1296 ? Ss 13:08 0:00
/usr/sbin/dnsmasq
-k
root 11137 0.2 1.1 223420 5608 ? Ss 13:08 0:00
/usr/sbin/httpd
-DFOREGROUND
apache 11138 0.0 1.2 225508 6216 ? S 13:08 0:00
/usr/sbin/httpd
-DFOREGROUND
apache 11139 0.0 1.2 225508 6216 ? S 13:08 0:00
/usr/sbin/httpd
-DFOREGROUND
apache 11140 0.0 1.2 225508 6216 ? S 13:08 0:00
/usr/sbin/httpd
-DFOREGROUND
apache 11141 0.0 1.2 225508 6216 ? S 13:08 0:00
/usr/sbin/httpd
-DFOREGROUND
apache 11142 0.0 1.2 225508 6216 ? S 13:08 0:00
/usr/sbin/httpd
-DFOREGROUND
root 11146 0.0 0.2 29272 1056 ? Ss 13:08 0:00
/usr/sbin/xinetd
-stayalive -pidfile
/var/run/xinetd
.pid
13、查看端口是否都开放了(53 67 69 80)
netstat
-tupnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID
/Program
name
tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN 11130
/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2443
/sshd
tcp 0 0 127.0.0.1:25151 0.0.0.0:* LISTEN 11120
/python2
tcp6 0 0 :::80 :::* LISTEN 11137
/httpd
tcp6 0 0 :::53 :::* LISTEN 11130
/dnsmasq
tcp6 0 0 :::22 :::* LISTEN 2443
/sshd
udp 0 0 0.0.0.0:53 0.0.0.0:* 11130
/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 11130
/dnsmasq
udp 0 0 0.0.0.0:69 0.0.0.0:* 11146
/xinetd
udp6 0 0 :::53 :::* 11130
/dnsmasq
三、测试
1、客户端安装的时候按F12网络引导就OK了,这里选择centos6安装