Cobbler全自动安装CentOS(整理)

环境:    
OEL6.3 x64 (CentOS6.3 x64)     
网络环境中无其它DHCP服务器 

本文出自:http://koumm.blog.51cto.com

一、 cobbler安装准备 

1. 关闭iptables与selinux 

1
2
3
# chkconfig iptables off
# vi /etc/selinux/config
SELINUX=disabled
1
# sestatus  重启后查看

2. 安装源准备并安装cobbler软件 

说明:基础源与epel源。 

1
2
rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum -y install cobbler cobbler-web httpd rsync tftp-server xinetd dhcp python-ctypes debmirror pykickstart fence-agents

二、 配置tftp-server与rsync 

开启tftp与rsync服务 

1
2
sed -i '/disable/c disable = no' /etc/xinetd.d/tftp
sed -i -e 's/= yes/= no/g' /etc/xinetd.d/rsync

三、配置cobbler 

1. 配置httpd配置文件 

1
2
# vi /etc/httpd/conf/httpd.conf
ServerName 127.0.0.1:80

2. 配置cobbler主配置文件 

1
2
3
4
sed -i 's/next_server: 127.0.0.1/next_server: 192.168.1.10/g' /etc/cobbler/settings
sed -i 's/server: 127.0.0.1/server: 192.168.1.10/g' /etc/cobbler/settings
sed -i 's/manage_dhcp: 0/manage_dhcp: 1/g' /etc/cobbler/settings
sed -i 's/manage_rsync: 0/manage_rsync: 1/g' /etc/cobbler/settings

 

3. 配置cobbler web登录认证配置文件 

(1) 修改认证文件

1
sed -i 's/module = authn_denyall/module = authn_configfile/g' /etc/cobbler/modules.conf

(2) 设置用户名密码:

 

1
htdigest /etc/cobbler/users.digest "Cobbler" cobbler

4. 生成Cobbler安装系统root初始密码 

(1)这里生成密钥和配置默认密钥,ks文件引用 

1
2
# openssl passwd -1 -salt 'random-phrase-here' '111111'
$1$random-p$WbZ3JxhRzCS/1Ne4S9g4Z.

(2) 将上面的加密串加入cobbler配置文件中。 

1
2
3
# vi /etc/cobbler/settings
# 修改为如下配置
default_password_crypted: "$1$random-p$WbZ3JxhRzCS/1Ne4S9g4Z."

四、配置DHCP与启动cobbler相关服务 

1. 配置dhcp配置文件 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# mv /etc/cobbler/dhcp.template /etc/cobbler/dhcp.template.bak
# vi /etc/cobbler/dhcp.template
ddns-update-style interim;
allow booting;
allow bootp;
ignore client-updates;
set vendorclass = option vendor-class-identifier;
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option domain-name-servers 202.100.192.68;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.1.120 192.168.1.254;
filename "/pxelinux.0";
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
}

2. 需要启动的服务 

1
2
3
4
5
6
7
8
chkconfig httpd on
chkconfig xinetd on
chkconfig dhcpd on
chkconfig cobblerd on
service httpd start
service xinetd start
service dhcpd start
service cobblerd start

五、效验cobbler安装条件 

1. 修复cobbler check时出现的第一条错误信息 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@pxe ~]# cobbler get-loaders
task started: 2013-12-15_191305_get_loaders
task started (id=Download Bootloader Content, time=Sun Dec 15 19:13:05 2013)
downloading http://www.cobblerd.org/loaders/README to /var/lib/cobbler/loaders/README
downloading http://www.cobblerd.org/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading http://www.cobblerd.org/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading http://www.cobblerd.org/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading http://www.cobblerd.org/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading http://www.cobblerd.org/loaders/yaboot-1.3.14-12 to /var/lib/cobbler/loaders/yaboot
downloading http://www.cobblerd.org/loaders/pxelinux.0-3.61 to /var/lib/cobbler/loaders/pxelinux.0
downloading http://www.cobblerd.org/loaders/menu.c32-3.61 to /var/lib/cobbler/loaders/menu.c32
downloading http://www.cobblerd.org/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading http://www.cobblerd.org/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***
[root@pxe ~]#

2. 修复debian/ubuntu系统安装选项支持包 

1
2
3
4
# vi /etc/debmirror.conf
说明:前提是安装debmirror pykickstart这两个包,注释掉如下两行。
#@dists="sid";
#@arches="i386";

3. cobbler check效验环境 

1
2
3
4
[root@pxe ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : service dhcpd is not running
Restart cobblerd and then run 'cobbler sync' to apply changes.

4. 按上文校验提示操作修复 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[root@pxe ~]# cobbler sync
task started: 2013-12-15_192432_sync
task started (id=Sync, time=Sun Dec 15 19:24:32 2013)
running pre-sync triggers
cleaning trees
mkdir: /var/lib/tftpboot/pxelinux.cfg
mkdir: /var/lib/tftpboot/grub
mkdir: /var/lib/tftpboot/s390x
mkdir: /var/lib/tftpboot/ppc
mkdir: /var/lib/tftpboot/etc
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
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
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
rendering Rsync files
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
received on stdout: 正在启动 dhcpd:[确定]
received on stderr:
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 ***
[root@pxe ~]#

说明:本节在前面已经考虑过cobbler check的错误提示了,大部分处理了。 

5. 重启cobblerd 与xinetd服务 

1
2
3
4
5
6
[root@pxe ~]# service cobblerd restart
Stopping cobbler daemon:                                   [确定]
Starting cobbler daemon:                                   [确定]
[root@pxe ~]# service xinetd restart
停止 xinetd:                                              [确定]
正在启动 xinetd:                                          [确定]

六、导入linux ISO安装镜像 

1. 挂载ISO光盘镜像 

1
# mount /dev/cdrom /mnt

2. 开始导入光盘镜像 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# cobbler import --path=/mnt --arch=x86_64 --name=Centos-5.9
task started: 2013-12-15_193916_import
task started (id=Media import, time=Sun Dec 15 19:39:16 2013)
Found a candidate signature: breed=redhat, version=rhel5
Found a matching signature: breed=redhat, version=rhel5
Adding distros from path /var/www/cobbler/ks_mirror/Centos-5.9-x86_64:
creating new distro: Centos-5.9-x86_64
trying symlink: /var/www/cobbler/ks_mirror/Centos-5.9-x86_64 -> /var/www/cobbler/links/Centos-5.9-x86_64
creating new profile: Centos-5.9-x86_64
creating new distro: Centos-5.9-xen-x86_64
trying symlink: /var/www/cobbler/ks_mirror/Centos-5.9-x86_64 -> /var/www/cobbler/links/Centos-5.9-xen-x86_64
creating new profile: Centos-5.9-xen-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/Centos-5.9-x86_64 for Centos-5.9-x86_64
processing repo at : /var/www/cobbler/ks_mirror/Centos-5.9-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/Centos-5.9-x86_64
looking for /var/www/cobbler/ks_mirror/Centos-5.9-x86_64/repodata/*comps*.xml
running: createrepo -c cache -s sha --groupfile /var/www/cobbler/ks_mirror/Centos-5.9-x86_64/repodata/comps.xml
/var/www/cobbler/ks_mirror/Centos-5.9-x86_64
received on stdout: Spawning worker 0 with 3579 pkgs
Worker 0:
..........
... 略....
..........
Worker 0:
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
received on stderr:
starting descent into /var/www/cobbler/ks_mirror/Centos-5.9-x86_64 for Centos-5.9-xen-x86_64
processing repo at : /var/www/cobbler/ks_mirror/Centos-5.9-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/Centos-5.9-x86_64
looking for /var/www/cobbler/ks_mirror/Centos-5.9-x86_64/repodata/*comps*.xml
*** TASK COMPLETE ***

说明: cobbler将镜像拷贝一份放在/var/www/cobbler/ks_mirrors/CentOS-5.9-x86_64目录下。   
同时会创建一个名字为CentOS-5.9-x86_64的一个发布版本,以及一个名字为CentOS-5.9-x86_64的profile文件。 

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@pxe kickstarts]# cobbler list
distros:
Centos-5.9-x86_64
Centos-5.9-xen-x86_64
profiles:
Centos-5.9-x86_64
Centos-5.9-xen-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:

七、修改安装更改kickstart文件 

1. 相关知识内容 

说明:   
默认kickstart文件是/var/lib/cobbler/kickstarts/sample.ks,需要手动为每个发行版单独指定, 或单独修改。 

1
2
3
4
# cobbler distro list
Centos-5.9-x86_64
Centos-5.9-xen-x86_64
#

2. 手动创建自定义新的kickstart文件 

1
vi /var/lib/cobbler/kickstarts/centos-5.9.ks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
install
text
cdrom
lang zh_CN.UTF-8
keyboard us
reboot
url --url=http://192.168.1.10/cobbler/ks_mirror/Centos-5.9-x86_64
network --device eth0 --bootproto dhcp --noipv6 --hostname oa
rootpw --iscrypted $1$H0bnNoWM$HE1R/mWv6LqbhUGI8Xw/t.
firewall --disabled
authconfig --enableshadow --enablemd5
selinux --disabled
timezone Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="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 ext3 --size=200 --asprimary
part swap --size=2048
part / --fstype ext3 --size=200 --grow
%packages
@admin-tools
@base
@chinese-support
@core
@development-libs
@development-tools
@dialup
@editors
@gnome-desktop
@games
@graphical-internet
@graphics
@java
@legacy-software-development
@legacy-software-support
@office
@printing
@sound-and-video
@text-internet
@base-x
system-config-kickstart
kexec-tools
iscsi-initiator-utils
fipscheck
squashfs-tools
device-mapper-multipath
sgpio
imake
emacs
libsane-hpaio
xorg-x11-utils
xorg-x11-server-Xnest
xorg-x11-server-Xvfb
%post
service sendmail stop

 

3. 修改profile指定新的KS启动文件,按角色进行分类 

说明   
1. 选择Centos-5.9-x86_64,将采用Centos-5.9-x86_64安装源,并通过/var/lib/cobbler/kickstarts/centos-5.9.ks文件进行全自动安装。    
2. 如有其它发行版,导入完镜像后,可以通过以下方式进行修改,否则将采用默认KS进行安装系统。    
3. 也可以采用不同的ks文件来实现个性能自动安装,如下面第三条add命令,添加一个半自动的ks文件。    
4. 如果没有按下面内容修改指定ks文件的话,引导菜单只显示Centos-5.9-x86_64默认一项。指定ks文件后,会在启动菜单中显示。 

1
# cobbler profile edit --name=Centos-5.9-x86_64 --distro=Centos-5.9-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-5.9.ks

示例:   

1
2
# cobbler profile edit --name=Centos-5.9-xen-x86_64 --distro=Centos-5.9-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-5.9-xen.ks
# cobbler profile add --name=Centos-5.9-half-auto --distro=Centos-5.9-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-5.9-halfauto.ks

如图所示: 

Cobbler全自动安装CentOS(整理)

4. 更改profile名称

1
# cobbler profile rename --name=Centos-5.9-x86_64 --newname=CentOS-5U9-x64

5. 删除profile配置,需要删除的profile名称为Centos-5.9-x86_64,删除后,安装启动菜单相关项消失。

1
# cobbler profile remove --name=Centos-5.9-x86_64

 

八、添加指定客户机系统配置到Cobbler

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

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

 

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

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

1
2
还可以指定ks参数。--kickstart=/var/lib/cobbler/kickstarts/webserver.ks
cobbler system add --name=test_001 --hostname=test_001 --mac=00:0C:29:E3:81:32 --interface=eth0 --ip-address=192.168.1.123 --subnet=255.255.255.0 --gateway=192.168.1.1 --static=1 --profile=Centos-5.9-x86_64

3. 修改system配置 

机器IP地址变更为192.168.10.110    

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

变更system配置名称   

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

4. 删除system配置 

需要删除的profile名称为test_001   

1
cobbler system remove --name=test_001

5. 查看定义的系统列表

 

1
2
cobbler system list
test_001

九、安装客户端操作系统 

(1) 通过网卡pxe启动

(2) 自动完成安装 

 

十、重装客户端操作系统 

1
2
wget ftp://rpmfind.net/linux/epel/5/i386/koan-1.6.6-1.el5.noarch.rpm
rpm -ivh koan-1.6.6-1.el5.noarch.rpm

查看cobbler server上的配置文件,对于centos5.x 的系统koan不能采用yum安装,否则会因python版本过低而报错。

1
# koan --server=192.168.1.10 --list=profiles
1
2
3
4
5
6
7
8
9
10
11
- looking for Cobbler at http://192.168.1.10/cobbler_api
- reading URL: http://192.168.1.10/cblr/svc/op/ks/profile/Centos-5.9-x86_64
install_tree: http://192.168.1.10/cobbler/ks_mirror/Centos-5.9-x86_64
downloading initrd initrd.img to /boot/initrd.img
url=http://192.168.1.10/cobbler/images/Centos-5.9-x86_64/initrd.img
- reading URL: http://192.168.1.10/cobbler/images/Centos-5.9-x86_64/initrd.img
downloading kernel vmlinuz to /boot/vmlinuz
url=http://192.168.1.10/cobbler/images/Centos-5.9-x86_64/vmlinuz
- reading URL: http://192.168.1.10/cobbler/images/Centos-5.9-x86_64/vmlinuz
- ['/sbin/grubby''--add-kernel''/boot/vmlinuz''--initrd''/boot/initrd.img''--args''"ks=http://192.168.1.10/cblr/svc/op/ks/profile/Centos-5.9-x86_64 ksdevice=link kssendmac lang= text "''--copy-default''--make-default''--title=kick1387098833']
- reboot to apply changes
1
# reboot

reboot重启服务器后,客户端服务器会自动重新安装操作系统 

Cobbler全自动安装CentOS(整理)








本文转自 koumm 51CTO博客,原文链接:http://blog.51cto.com/koumm/1340852,如需转载请自行联系原作者

上一篇:C语言写的秒速计算四则混合运算项目


下一篇:《C语言课程设计》一2.4 表达式和基本语句