如何使用cobbler实现批量自动部署Linux

2024-05-13

1. 如何使用cobbler实现批量自动部署Linux

Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows。该工具使用python开发,小巧轻便,使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP,DNS,以及yum包镜像。下面一步步来实现吧.
  实验平台:rhel 6.3 x86_64
  cobbler.laoguang.me     192.168.1.23
   一.环境准备
  1.1 安装dhcp
  yum -y install dhcp 1.2 安装其它所需服务如:tftp xinetd httpd   ##靠tftp传输文件,tftp依赖xinetd,httpd这个我暂时不清楚
  yum -y install tftp xinetd httpd 1.3 关闭selinux iptables
  setenforce 0 service iptables stop
  二.安装cobbler
  2.1 下载安装cobbler与依赖的包python-yaml
  下载地址:http://www.kuaipan.cn/file/id_33139203151758501.html ,其它平台的可以去 http://rpm.pbone.net/找,这个网站你一定不能忘记
  yum -y --nogpgcheck localinstall cobbler-2.2.2-1.el6.rf.noarch.rpm \python-yaml-3.09-3.el6.rf.x86_64.rpm
  2.2 启动cobbler
  service cobblerd start
  2.3 启动httpd
  service httpd start
  2.4 启用xinetd
  service xinetd start
  2.4 cobbler 检查配置
  cobbler check



  2.5 重启cobbler
  service cobblerd restart
  三.cobbler的配置
  3.1 导入欲安装的系统的镜像文件
  将redhat 6.3 x86_64 的ISO挂载/cdrom
  mount /dev/cdrom /cdrom
  导入需要的安装文件到cobbler的/var/www/cobbler/ks_mirrors下,并生成一profile,此过程需要一段时间,耐心等待
  cobbler import --path=/cdrom --name=RedHat-6.3-x86_64 3.2
  配置dhcp服务,让cobbler来管理
  vi /etc/cobbler/settings
  manage_dhcp: 1
  3.3 修改/etc/cobbler/dhcp.template模板文件中的配置,其它的默认即可

  3.4  同步cobbler配置
  cobbler sync cobbler会自动进行初始化工作,移除已经存在的启动项,然后根据模板拷贝loader文件。之后再生成pxe的配置文件,生成dhcp的配置文件,最后再重启dhcp服务。关键查看dhcp,tftp有没有启动成功。
  四.测试安装系统
  4.1  新建个虚拟机,网络记的是brige哦,新建的虚拟机网络默认是nat的,我就因为这个怎么都安装不上,启动虚拟机,调整启动顺序从网络启动(我用的是vmware,如果你没有挂cd的iso,也虚拟机是新建的直接启动应该是可以的)


  五.定制自己的kickstart文件
  定制自己的kickstart文件而不是使用默认的,kickstart文件cobbler放在了/var/lib/cobbler/kickstarts/中,查看cobbler默认使用的哪个
  vi /etc/cobbler/settings
   default_kickstart: /var/lib/cobbler/kickstarts/default.ks   ##看到了吧,用的是default.ks
  5.1 自定义kickstart文件。
  如果你对kickstart文件理解透彻,直接修改或新建即可,如果还是很精通就用gui工具吧
  yum -y install system-config-kickstart
  安装完毕后打开软件。
  system-config-kickstart
  根据自己的需要修改即可,修改完毕后保存,修改settings中的设置,重启cobbler即可
原文出处:http://laoguang.blog.51cto.com/6013350/1097874/

如何使用cobbler实现批量自动部署Linux

2. 如何建立cobbler

1、安装epel
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -Uvh epel-release-6*.rpm

2、服务安装
yum -y install cobbler httpd rsync tftp xinetd dhcp cman pykickstart

3、修改cobbler配置文件 /etc/cobbler/settings
sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings    #开启dhcp功能
sed -i 's/manage_rsync: 0/manage_rsync: 1/' /etc/cobbler/settings  #开启rsync功能
sed -i 's/next_server: 127.0.0.1/next_server: 192.168.1.100/' /etc/cobbler/settings  #设置你的 tftp server 地址
sed -i 's/server: 127.0.0.1/server: 192.168.1.100/' /etc/cobbler/settings   
#cobbler_server 地址

4、开启cobbler服务前需要做 
service iptables stop #关闭防火墙
setenforce 0 #关闭selinux
/etc/xinetd.d/tftp
disable                 = no #开启tftp服务
/etc/xinetd.d/rsync
disable                 = no #开启 rsync 服务
openssl passwd -1 -salt 'cocosoa' '00001234'  生成系统安装后的 root 密码,cocosoa是干扰密码,00001234是系统登录密码
vim /etc/cobbler/settings 编辑配置文件,将默认的密码替换为新生成的
default_password_crypted: "$1$cocosoa$oAeSzE7VLKwhMPiBEOJD81"

cobbler get-loaders    #下载引导操作系统文件
 yum install debmirror -y
vim /etc/debmirror.conf
#@dists="sid";    // 注销
#@arches="i386";    // 注销
配置dhcp服务,只需要修改cobbler的dhcp模板文件即可
vim /etc/cobbler/dhcp.template


subnet 192.168.1.0 netmask 255.255.255.0 {
     option routers             192.168.1.5;
     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;
     next-server                192.168.1.122;
     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";
          }
     }


}


注意修改之后,使用cobbler sync 同步下配置文件,不然dhcp无法启动,会报错



5、启动服务
service httpd start 在配置文件中加入ServerName localhost:80
service cobbler start
chkconfig httpd on
chkconfig cobblerd on
chkconfig dhcpd on
chkconfig xinetd on
chkconfig tftp on
chkconfig iptables off
6、导入镜像
cobbler import --path=/media --name=CentOS6.4 --arch=x86_64
touch /var/lib/cobbler/kickstarts/CentOS6.4.ks
cobbler profile add --name=centos6.4 --distro=CentOS6.4-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS6.4.ks
添加一个profile文件,并使用CentOS6.4-x86_64这个distro,并指定相应的ks文件,ks文件是事先准备好的
vim /etc/cobbler/pxe/pxedefault.template    #编辑pxe模板
ONTIMEOUT centos6.4         #修改默认安装的profile为centos6.4,也就是说当你没有选择,超时操作后自动安装此profile
7、编辑kickstarts文件     #可以自己写
vim /var/lib/cobbler/kickstarts/CentOS6.4.ks
install
auth --useshadow --enablemd5
key --skip
bootloader --location=mbr
clearpart --all --initlabel
text
firewall --disabled
keyboard us
lang en_US
url --url=$tree
reboot
rootpw --iscrypted $1$cocosoa$oAeSzE7VLKwhMPiBEOJD81
selinux --disabled
timezone --isUtc Asia/Shanghai
zerombr
autopart

%packages
$SNIPPET('package')

cat /var/lib/cobbler/snippets/package
此文件里写入需要安装的包

下面是扩展目录,可以自己添加单独的配置文件,方便管理
/var/lib/cobbler/snippets
$SNIPPET (文件名)  该文件要到/var/lib/cobbler/snippets下创建编辑。



# System authorization information 
auth --useshadow --enablemd #用户登录认证 
# System bootloader configuration 
bootloader --location=mbr #mbr引导 
# Partition clearing information 
clearpart --all --initlabel #默认清除所以分区 
# Use text mode install 
text #默认以文本模式安装 
# Firewall configuration 
firewall --enabled #防火墙默认开启 
# Run the Setup Agent on first boot 
firstboot --disable #禁用启动代理 
# System keyboard 
keyboard us #默认英文键盘 
# System language 
lang en_US #默认语言英文 
# Use network installation 
url --url=$tree #网络安装路径 
# If any cobbler repo definitions were referenced in the kickstart profile, include them here 
$yum_repo_stanza #默认的yum仓库 
# Network information 
$SNIPPET('network_config')  
# Reboot after installation 
reboot #安装完成后重启
#Root password 
rootpw --iscrypted $default_password_crypted #密码是我们/etc/cobbler/settings设置密码 
# SELinux configuration 
selinux --disabled #默认关闭selinux 
# Do not configure the X Window System 
skipx #默认没有安装图形界面  
# System timezone 
timezone America/New_York #默认时区是美国/纽约 
# Install OS instead of upgrade 
install #定义的是安装系统而不是升级系统 
# Clear the Master Boot Record 
zerombr #默认清空所有的mbr 
# Allow anaconda to partition the system as needed 
autopart #默认自动分区

3. cobbler web上怎么放东西

Cobbler的Web管理模块和命令行模块是可以分开工作的,没有依赖关系。
1 WebUI的功能
查看所有的对象和配置文件
添加或者删除system,distro, profile
执行“cobbler sync”
编辑kickstart文件
    目前WebUI还未实现的功能
自动导入media
执行"cobbler validateks"
 
2 安装Cobbler-web
  (1)安装WebUI需要以下模块
Django
cobbler-web
  (2)编辑文件/etc/cobbler/modules.conf

cobbler web上怎么放东西

4. 如何在 Cobbler 上导入和启动 Ubuntu

Cobbler 在 CentOS/RHEL/Fedora 系的发行版上工作良好,在 CentOS/RHEL/Fedora 上安装 Cobbler以后可以直接导入 CentOS/RHEL/Fedora ISO 文件,很顺利,不过导入 Ubuntu/Debian ISO 就不是那么幸运了,直接导入 ubuntu-11.10-server-amd64.iso 的话会报错:
# cobbler import –path=/mnt/ –name=ubuntu-11.10-server-amd64
...
sent 710595315 bytes  received 36388 bytes  52639385.41 bytes/sec
total size is 710349452  speedup is 1.00
...
!!! TASK FAILED !!!


忽略上面的错误,会发现在 ks_mirror 下面已经导入了 ubuntu-11.10-server-amd64 整个 ubuntu 目录:
# ls /var/www/cobbler/ks_mirror/
config  ubuntu-11.10-server-amd64


如果对上面已经导入的 ubuntu 目录还不放心的话,可以删除这个目录后手动导入(直接 cp 就行):
# rm -rf /var/www/cobbler/ks_mirror/ubuntu-11.10-server-amd64

# mount -o loop -t iso9660 ubuntu-11.10-server-amd64.iso /mnt

# cp -r /mnt/ /var/www/cobbler/ks_mirror/ubuntu-11.10-server-amd64


完成导入(拷贝)后,做个链接:
# cd /var/www/cobbler/links/
# ln -s /var/www/cobbler/ks_mirror/ubuntu-11.10-server-amd64 ubuntu-11.10-server-amd64


然后加入 distro 和 profile:
# cobbler distro add \
--name=ubuntu-11.10-server-amd64 \
--kernel=/var/www/cobbler/ks_mirror/ubuntu-11.10-server-amd64/install/netboot/ubuntu-installer/amd64/linux \
--initrd=/var/www/cobbler/ks_mirror/ubuntu-11.10-server-amd64/install/netboot/ubuntu-installer/amd64/initrd.gz \
--arch=x86_64 \
--breed=ubuntu \
--ksmeta="directory=/cblr/links/ubuntu-11.10-server-amd64"

# cobbler profile add \
--name=ubuntu-11.10-server-amd64 \
--distro=ubuntu-11.10-server-amd64 \
--kickstart=/var/lib/cobbler/kickstarts/ubuntu-11.10-server-amd64.seed


最后我们需要 ubuntu 能完成自动安装,加入以下 kickstart 脚本 ubuntu-11.10-server-amd64.seed 到 /var/lib/cobbler/kickstarts/ :
# vi /var/lib/cobbler/kickstarts/ubuntu-11.10-server-amd64.seed
d-i     debian-installer/locale string en_US.UTF-8
d-i     debian-installer/splash boolean false
d-i     console-setup/ask_detect        boolean false
d-i     console-setup/layoutcode        string us
d-i     console-setup/variantcode       string
d-i     netcfg/get_nameservers  string
d-i     netcfg/get_ipaddress    string
d-i     netcfg/get_netmask      string 255.255.255.0
d-i     netcfg/get_gateway      string
d-i     netcfg/confirm_static   boolean true
d-i     clock-setup/utc boolean true
d-i     partman-auto/method string regular
d-i     partman-lvm/device_remove_lvm boolean true
d-i     partman-lvm/confirm boolean true
d-i     partman/confirm_write_new_label boolean true
d-i     partman/choose_partition        select Finish partitioning and write changes to disk
d-i     partman/confirm boolean true
d-i     partman/confirm_nooverwrite boolean true
d-i     partman/default_filesystem string ext3
d-i     clock-setup/utc boolean true
d-i     clock-setup/ntp boolean true
d-i     clock-setup/ntp-server  string ntp.ubuntu.com
d-i     base-installer/kernel/image     string linux-server
d-i     passwd/root-login       boolean false
d-i     passwd/make-user        boolean true
d-i     passwd/user-fullname    string ubuntu
d-i     passwd/username string ubuntu
d-i     passwd/user-password-crypted    password $default_password_crypted
d-i     passwd/user-uid string
d-i     user-setup/allow-password-weak  boolean false
d-i     user-setup/encrypt-home boolean false
d-i     passwd/user-default-groups      string adm cdrom dialout lpadmin plugdev sambashare
d-i     apt-setup/services-select       multiselect security
d-i     apt-setup/security_host string security.ubuntu.com
d-i     apt-setup/security_path string /ubuntu
d-i     debian-installer/allow_unauthenticated  string false
d-i     pkgsel/upgrade  select safe-upgrade
d-i     pkgsel/language-packs   multiselect
d-i     pkgsel/update-policy    select none
d-i     pkgsel/updatedb boolean true
d-i     grub-installer/skip     boolean false
d-i     lilo-installer/skip     boolean false
d-i     grub-installer/only_debian      boolean true
d-i     grub-installer/with_other_os    boolean true
d-i     finish-install/keep-consoles    boolean false
d-i     finish-install/reboot_in_progress       note
d-i     cdrom-detect/eject      boolean true
d-i     debian-installer/exit/halt      boolean false
d-i     debian-installer/exit/poweroff  boolean false
d-i     pkgsel/include string openssh-server

5. cobbler 通过哪一个工具来实现系统的自动化部署

  一、概述
    服务最好安装在 Centos下,它需要Python支持。
    Cobbler服务是一个容器,它整合了以下几个开源软件:
    1 Dhcp
    2 Dns (可选bind,dnsmasq)
    3 Kickstart/PXE
    4 Apache(提供kickstart 的安装源,并提供定制化的kickstart配置)
    5 Tftp (PXE启动时需要)
    同时,它和apache做了深度整合。通过 cobbler,可以实现对RedHat/Centos/Fedora系统的快速部署,同时也支持Suse  和Debian(Ubuntu)系统。
    综上所述,一个理想的安装环境是:
      相关配置参数:
      官方文档 : https://github或mirrors
    相关配置文件: /etc/yum/fedora/epel/5/i386/epel-release-5-4/fedora/epel/5/x86_64/epel-release-5-4/fedora/epel/6/i386/epel-release-6-7/fedora/epel/6/x86_64/epel-release-6-7/fedora/epel/5Server/x86_64/debmirror-20090807-1/linux/rpm2html/search.php?query=debmirror
    4 : 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
    //解决办法 : 默认加密的密码,可以修改
    5 : fencing tools were not found, and are required to use the (optional)  power management features. install cman or fence-agents to use them
    //解决办法 : 关于电源管理(跟DELl 远程控制协议类似东西?),也暂时不管。
    10)重启 cobbler,并更新相关配置
    //重启服务
    /etc/init.d/cobblerd restart
    //同步最新cobbler配置,它会根据配置自动修改dhcp,bind 等服务,因此我称之为容器的原因。
    cobbler sync
    注:在 对cobbler进行研究的整个过程中,得到了前辈陈沙克老师(  )  的大力支持和解惑,在编写此文时,也借鉴了部分沙克老师的文章,特此感谢。

cobbler 通过哪一个工具来实现系统的自动化部署

6. 安装cobbler时报错.请问怎么回事

  Linux下使用cobbler可以快速建立Linux网络安装环境,大大降低了Linux网络安装的技术门槛,那么Linux系统要如何安装Cobbler呢?一起来学习下吧。
    cobbler的简介
    cobbler是Redhat支持的一个开源项目,用来部署和安装系统。所以对Redhat系列os支持是比较好的。不过对ubuntu支持是非常差  的。cobbler里不少设置,只针对redhat有效,同时也由于不同发行版的安装是有差异。cobbler感觉好像和ubuntu关系比较紧张。
    cobbler不仅仅是一个pxe服务器,他还可以管理dns(bind),dhcp。一般数据中心里或者生产环境,是不允许dhcp,但是pxe,必须需要dhcp,所以我们需要根据mac地址来分配IP,这样dhcp就不会影响到网络。
    1、安装cobbler
    提前配置好epel源mirrors/fedora/epel/6/i386/
    [root@60sec /]# yum -y install cobbler
    [root@60sec /]# service httpd start
    Starting httpd: [ OK ]
    [root@60sec /]# service cobblerd start
    Starting cobbler daemon: [ OK ]
    2、执行cobbler check命令检查存的问题,而后逐一按提示解决之
    [root@60sec /]# vim /etc/cobbler/settings
    next_server: 192.168.83.137
    server: 192.168.83.137
    manage_tftpd: 0
    [root@60sec /]# yum -y install syslinux
    [root@60sec /]# chkconfig rsync on
    [root@60sec /]# yum -y install pykickstart
    [root@60sec /]# openssl passwd -1 -salt ‘openssl rand -hex 4’
    Password:
    $1$openssl $.oduSwbhLj6jqAwVsLo/H1
    [root@60sec /]# vim /etc/cobbler/settings
    default_password_crypted: “penssl $.oduSwbhLj6jqAwVsLo/H1”
    [root@60sec /]# cd /usr/share/syslinux/
   
    [root@60sec syslinux]# cp -r 。/* /var/lib/cobbler/loaders/

7. 为什么自动安装过程中总是找不到ks.cfg,而手动却可以下载。

1,禁用selinux,我的系统版本是RHEL6.4,编辑文件 vi /etc/selinux/config ,将SELIINUX=disabled 2,重启机器;就可以了  查看原帖>>

为什么自动安装过程中总是找不到ks.cfg,而手动却可以下载。

8. 新架Cobbler会不会与原有DHCP冲突

我觉得应该是不行的
首先cobbler会去加载dhcp.template这里边的信息,而且还要定义     filename                "/pxelinux.0";

不是简简单单给PXE客户端分配一个IP就行的。