打赏

星辰大海ゞ

That which does not kill us makes us stronger!

导航

cobbler全自动批量安装部署linux

Cobbler的设计方式:

  Cobbler的配置结构基于一组注册的对象。每个对象表示一个与另一个实体相关联的实体(该对象指向另一个对象,或者另一个对象指向该对象)。当一个对象指向另一个对象时,它就继承了被指向对象的数据,并可覆盖或添加更多特定信息。以下对象类型的定义

Distros(发行版):表示一个操作系统,它承载了内核和initrd的信息,以及内核参数等其他数据
Profile(配置文件):包含一个发行版、一个kickstart文件以及可能的存储库,还包含更多特定的内核参数等其他数据
Systems(系统):表示要配给的额机器。它包含一个配置文件或一个景象,还包含IP和MAC地址、电源管理(地址、凭据、类型)、(网卡绑定、设置valn等)
Repository(镜像):保存一个yum或rsync存储库的镜像信息
Image(存储库):可替换一个包含不属于此类比的额文件的发行版对象(例如,无法分为内核和initrd的对象)。

 基于注册的对象以及各个对象之间的关联,Cobbler知道如何更改文件系统以反应具体配置。因为系统配置的内部是抽象的,所以您可以仅关注想要执行的操作。

 

 

Cobbler流程图如下:

 

1、安装cobbler和所需组件

   cobbler可以手动编译安装,也可以基于yum源的安装,如果使用yum源安装,则需要配置epel源epel源可以通过下载官网的epel源的目录来实现。由于cobbler是由python而写,所以还要安装python环境。    

https://fedoraproject.org/wiki/EPEL/zh-cn

# yum -y install cobbler cobbler-web pykickstart debmirror cman createrepo httpd dhcp xinted tftp-server rsync python

 

2、配置cobbler依赖的服务,本次操作使用cobbler来管理这些依赖服务,即使用cobbler提供的模板配置文件。

cobbler可行管理这些服务中的部分甚至全部,但需要配置/etc/cobbler/settings文件中的“manager_dhcp”、 “manage_tftpd”、“manage_rsync”、“manage_dns”来定义,同时各种服务都有着不同的实现方式,如果进行自定义,需要通过修改/etc/cobbler/modules.conf配置文件中各个服务的模块参数的值来实现。

#在Cobbler主配置文件/etc/cobbler/settings设置开启自带的dhcp服务开关
# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/g' /etc/cobbler/settings
# sed -i 's/manage_tftpd: 0/manage_tftpd: 1/g' /etc/cobbler/settings
# sed -i 's/manage_rsync: 0/manage_rsync: 1/g' /etc/cobbler/settings
# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/g' /etc/cobbler/settings

 按环境需求编辑以下dhcp模板文件部分内容

# vim  /etc/cobbler/dhcp.template
subnet 172.16.65.0 netmask 255.255.255.0 {
     option routers             172.16.65.1;
     option domain-name-servers 8.8.8.8;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        172.16.65.100 172.16.65.200;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;

 

3、检查配置文件,需要在启动httpd服务的前提下检查

 
#service httpd start
#service cobblerd start
#cobbler sync #让cobbler接管所依赖的服务,应用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 : 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. 4 : change 'disable' to 'no' in /etc/xinetd.d/rsync 5 : comment out 'dists' on /etc/debmirror.conf for proper debian support 6 : comment out 'arches' on /etc/debmirror.conf for proper debian support 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 Restart cobblerd and then run 'cobbler sync' to apply changes. 

以上8个问题的解决方法

1.修改/etc/cobbler/settings文件中的server参数的值为提供cobbler服务的主机对应的ip地址

2.修改/etc/cobbler/settings文件的next_server参数的值为提供PXE服务的主机的ip

#sed -i 's/server: 127.0.0.1/server: 172.16.65.222/g' /etc/cobbler/settings

#sed -i 's/next_server: 127.0.0.1/next_server: 172.16.65.222/g' /etc/cobbler/settings

3.如果当前节点可以访问互联网,执行“cobbler get-loaders”命令下载pxelinux.0,menu.c32,elibo.efi,yaboot文件,否则则需要安装syslinux程序 包,复制/usr/share/syslinux/中的pxelinux.0,menu.c32等文件至/var/lib/cobbler /loaders目录中

4.将/etc/xinetd.d/rsync 中的disable改为no

#sed -i '/disable/s/yes/no/g' /etc/xinetd.d/rsync

#sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp

5.注释/etc/debmirror.conf文件中的@dists="sid";一行

6.注释/etc/debmirror.conf文件中的@arches="i386";一行

# sed -i 's/@dists=\"sid\";/#@dists=\"sid\";/g' /etc/debmirror.conf

# sed -i 's/@arches=\"i386\";/#@arches=\"i386\";/g' /etc/debmirror.conf

7.执行 openssl passwd -1 -salt 'haha' '123456' 生成密码 其中haha为随意给出的干扰码,并将密码串替换掉/etc/cobbler/settings中的default_password_crypted

default_password_crypted: "$1$haha$T7nt1ThchynsrEviA0KLT0"     #该密码即创建完成后新装系统的root密码

8.安装cam和fence-agents来实现电源管理 

 

4、同步数据,与此同时同步配置文件到dhcp服务器,并自动重新启动dhcp服务。

 # /etc/init.d/xinetd restart

 # service cobblerd restart

 # cobbler sync  #每次对各依赖服务的配置进行修改完毕后都需要执行此命令进行同步生效,尤其是dhcp服务被接管后,更改dhcp配置的话,应该配  置/etc/cobbler/dhcp.template文件,否则如果每次执行cobbler sync同步的话,/etc/dhcp/dhcpd.conf会被覆盖。

 5、导入系统镜像到cobbler

# mount /dev/cdrom /media

# cobbler import  --name=centos6.5-x86-64  --path=/media/

 

6、设置profile,使用自定义的ks文件进行全自动安装

# cobbler profile edit --name=centos-6.5-x86_64 --distro=centos-6.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos65.ks

    profile默认是采用 /var/lib/cobbler/kickstarts/sample_end.ks  模板文件作为ks文件,而不是default.ks

此至,cobbler全部安装完毕,可以进行客户端服务器系统PXE安装了。

 

以下为详细说明:

在第一次导入系统镜像时,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自动安装文件关联起来

 

7、配置cobbler_web

   cobbler_web支持多种认证方式,如authn_configfil、authn_ldap或 authn_pam等,默认为authn_denyall拒接所有。

   下面我们使用authn_pam模块认证cobbler_web用户

 
# vim  /etc/cobbler/modules.conf
[authentication]
module = authn_pam
# useradd wjoyxt
# passwd wjoyxt
# vim  /etc/cobbler/users.conf
 [admins]
 admin = "wjoyxt" 

访问:https://172.16.65.222/cobbler_web

此时我们可以手动的添加删除配置,更灵活的对distro 、profile等组件的管理!

 

参考资料:http://www.osyunwei.com/archives/7606.html

       http://www.cnblogs.com/xiaocen/p/3734767.html

 

---------------------------------------------------------------------------------------------

如果想要实现进入启动项时输入密码的话,需要在以下两个模板文件中添加红色项:

vim /etc/cobbler/pxe/pxedefault.template

DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.com
MENU MASTER PASSWD $1$haha$T7nt1ThchynsrEviA0KLT0
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT $pxe_timeout_profile

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

$pxe_menu_items

MENU end

vim /etc/cobbler/pxe/pxeprofile.template

LABEL $profile_name
        MENU PASSWD
        kernel $kernel_path
        $menu_label
        $append_line
        ipappend 2

 ------------------------------------------------------------------

当出现如上报错的话,修改 /var/lib/cobbler/kickstarts/centos65.ks 中的"url --url=...." 改完后cobbler sync同步一次配置,并且确保此url是可以被正常访问的。

此处是 url --url="http://172.16.65.222/cobbler/ks_mirror/CentOS-6.4-x86_64/"

 

posted on 2015-11-18 18:25  星辰大海ゞ  阅读(841)  评论(0编辑  收藏  举报