首页 > 代码库 > cobbler批量自动网络安装centos

cobbler批量自动网络安装centos

一、cobbler工作原理

cobbler 实现自动化安装OS,是依赖于:

网卡的PXE技术(dhcp client、tftp client ) + anaconda(linux上安装操作系统的程序) 

+ dhcp(为需要安装操作系统的主机分配IP) + tftp(提供基于网卡引导时所需要的启动文件) 

+ httpd(os install tree 的存放位置 ) 实现的。


二、安装和修改cobbler配置

1.Cobbler不在CentOS的基本源中,需要导入EPEL源升级软件包,

# rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rp

安装完运行yum报错:

Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

解决方法

vim /etc/yum.repos.d/epel.repo

编辑[epel]下的baseurl前的#号去掉,mirrorlist前添加#号。正确配置如下:

[epel]

name=Extra Packages for Enterprise Linux 6 - $basearch

baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch

#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch

failovermethod=priority

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

2. yum安装cobbler包

# yum -y install cobbler  httpd rsync tftp-server xinetd dhcp

3. 开启cobbler服务,重启Apache服务,设置各个服务开机自启动

# service httpd start

# service cobblerd start

# service xinetd start

# /sbin/chkconfig httpd on

# /sbin/chkconfig dhcpd on

# /sbin/chkconfig xinetd on

# /sbin/chkconfig tftp on

# /sbin/chkconfig cobblerd on

4. 关闭SELinux和防火墙

# vi /etc/sysconfig/selinux

SELINUX=enforcing更改为SELINUX=disabled

# reboot

5. 修改cobbler配置

# vi /etc/cobbler/setting

‘next_server: 127.0.0.1‘ 替换本机IP地址 (DHCP服务地址)

‘server: 127.0.0.1‘ 替换本机IP地址(cobbler服务地址)

‘manage_dhcp: 0‘ 替换为 1(cobbler管理dhcp,后面用于同步更新配置信息[cobbler sync])

‘manage_rsync: 0‘ 替换为 1 (cobbler管理rsync功能)

6. 加载部分缺失的网络boot-loaders

# cobbler get-loaders

7. 启动tftp和rsync服务

# vi /etc/xinetd.d/tftp

修改成:disable=no

# vi /etc/xinetd.d/rsync

修改成:disable=no

8. 修改DHCP模板,确保DHCP分配的地址和Cobbler在同一网段

# cat /etc/cobbler/dhcp.template

ddns-update-style interim;

allow booting;

allow bootp;

ignore client-updates;

set vendorclass = option vendor-class-identifier;

option pxe-system-type code 93 = unsigned integer 16;

subnet 192.168.1.0 netmask 255.255.255.0 {

option routers 192.168.1.1;

option domain-name-servers 192.168.1.1;

option subnet-mask 255.255.255.0;

range dynamic-bootp 192.168.1.100 192.168.1.254;

default-lease-time 21600;

max-lease-time 43200;

filename "/pxelinux.0";

next-server $next_server;

9. 修改cobbler的默认密码

用 openssl 生成一串密码后加入到 cobbler 的配置文件(/etc/cobbler/settings)里,替换 default_password_crypted 字段:

# openssl passwd -1 -salt ‘random-phrase-here‘ ‘1234567‘

$1$random-p$/pL7QZ2d5UVH9GzhJ2lYT1

# vi /etc/cobbler/settings

default_password_crypted: "$1$random-p$/pL7QZ2d5UVH9GzhJ2lYT1"

注意:这里保存的密码,将会用于批量部署机器中,root账户的登录密码。

10. 安装cman启动电源管理功能

# yum install cman

11. 检查cobbler安装环境

# cobbler check

# cobbler sync

三、导入ISO文件

1. 挂载ISO镜像到/meida 目录

#mount /dev/cdrom  /media/

2.从iso中导入客户端的OS。这将自动设置了“x86_64”,并将其命名为Centos6.2

#cobbler import --path=/media --name=centos6.2--arch=x86_64

这需要一点时间,不要急。可查看/var/www/cobbler/ks_mirror/centos6.2-x86_64/目录文件生成情况

# cobbler sync

# cobbler list

distros:

centos6.2-x86_64

profiles:

centos6.2-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

四、部署测试

创建一台虚拟机测试一下,把虚拟机设置成网络 PXE 启动

本文出自 “hanyun.fang” 博客,请务必保留此出处http://hanyun.blog.51cto.com/1060170/1588840

cobbler批量自动网络安装centos