centos 7 下 cobbler 安装

一、cobbler 介绍;

 

Cobbler 是一个系统启动服务(boot server),可以通过网络启动(PXE)的方式用来快速安装、重装物理服务器和虚拟机,支持安装不同的 Linux 发行版和 Windows。该工具使用python开发,小巧轻便(才15k行代码),使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理 DHCP,DNS,以及yum包镜像。

Linux学习,http:// linux.it.net.cn

 

Cobbler 使用命令行方式管理,也提供了基于 Web 的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。 IT网,http://www.it.net.cn

Cobbler提供以下服务集成:
PXE服务支持
DHCP服务管理
DNS服务管理(可选bind,dnsmasq)
电源管理
Kickstart服务支持
yum仓库管理
TFTP (PXE启动时需要) Linux学习,http:// linux.it.net.cn
Apache(提供kickstart 的安装源,并提供定制化的kickstart配置) IT网,http://www.it.net.cn

同时,它和apache做了深度整合。通过 cobbler,可以实现对RedHat/Centos/Fedora系统的快速部署,同时也支持Suse 和Debian(Ubuntu)系统。 Linux学习,http:// linux.it.net.cn

cobbler装机系统是较早前kickstart的升级版,优点比较容易配置,还自带web界面比较易于管理,不足在于中文资料较少。和 Kickstart不同的是,使用cobbler不会因为在局域网中启动了dhcp而导致有些机器因为默认从pxe启动在重启服务器后加载tftp内容导 致启动终止。 IT网,http://www.it.net.cn

通过配置cobbler自动部署DHCP、TFTP、HTTP,在安装过程中加载kiskstart无人值守安装应答文件实现无人值守。从客户端使用PXE引导启动安装。 

二、新系统初始化:

  1、修改主机名:

    # vi /etc/hostname

  2、关闭防火墙,selinxu:

    #systemctl stop firewalld    (centos 7 默认防火墙 firewall)

    #systemctl disable firewalld

  3、安装常用工具:

     #yum -y install wget vim lrzsz

  4、更新yum 源,  在本地源中没有cobbler 

     #yum -y install epel-release

 三、安装配置cobbler:

   1、安装cobbler 依赖包和相关服务

    #yum -y install cobbler    

    #yum -y install cobbler-web

    #yum -y install fence-agents        (实现电源管理)

    #yum -y install dhcp        

    #yum -y install pykickstart           (kickstart 软件,系统无人值守安装

    #yum -y install xinetd        (tftp 服务 使用)

    #yum -y install tftp-server

    #yum -y install system-config-kickstart     (如果不通过图形化界面 创建ks 文件,可以不用安装)

   2、开启服务:

    # systemctl start httpd

    # systemctl start cobblerd

    # systemctl enable httpd

    # systemctl enable cobblerd

   3、配置cobbler ,检查配置:

    # cobbler check

      

    按提示依次解决相关报错:

    1-2:编辑cobbler配置文件/etc/cobbler/settings 修改一下几项 

    # vim /etc/cobbler/settings 

      bind_master: 可用的dns服务器IP 

      next_server: cobbler服务器IP  (选项 next_server 用在 DHCP 配置文件中,向机器告知提供引导文件的服务器地址。选项 server 在机器安装期间用于引用 Cobbler 服务器地址)

      server: cobbler服务器IP  

        manage_dhcp: 1     (0:表示有独立的*服务器, 1:表示服务由cobbler 托管)

        manage_dns: 0

      manage_tftpd: 1 

      restart_dns: 1 

      restart_dhcp: 1 

      pxe_just_once:1    (选项 pxe_just_once 预防将机器中的安装循环配置为始终从网络引导。激活此选项时,机器告诉 Cobbler 安装已完成。Cobbler 将系统对象的 netboot 标志更改为 false,这会强制机器从本地磁盘引导。)

    3:上述dhcp 服务器和 tftp 服务器均由cobbler 托管,需要配置cobbler的dhcp服务配置和tftp服务配置,配置完成后服务由cobbler sync 托管启动。

      3-1、编辑tftp配置文件:

        # vim /etc/cobbler/tftpd.template

          disable  = no    “yes改为no”

      3-2、编辑dhcp配置文件

        # vim /etc/cobbler/dhcp.template

      

    4:执行cobbler get-loaders 下载部分缺失的网络boot-loaders 引导文件 

      # cobbler get-loaders

    5:启动rsyncd 

      # systemctl start rsyncd

      # systemctl enable rsyncd

     6:debian安装用,不需要可以不管

     7:"openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'"   其中random-phrase-here  为任意字符、your-password-here  是cobbler 服务器的密码

      # openssl passwd -1 -salt '123456789' '111111'   生成的密码替换/etc/cobbler/settings文件里面default_password_crypted:的密码

 

  4、http 配置:

    由于默认distro文件存放目录为/var/www/cobbler/ks_mirrors 而http默认站点根目录为/var/www/html,所以安装系统的时候会报错找不到/var/www/cobbler/ks_mirror/centos7.2-x86_64/LiveOS/squashfs.img 所以在这里需要更改http服务默认站点根目录然后重启服务

     # vim /etc/http/conf/httpd.conf

       DocumentRoot “/var/www/html”   ––> DocumentRoot “/var/www” 

     # systemctl restart httpd

     # systemctl restart cobblerd

     # cobbler sync     (cobbler 配置刷新,检查有没有配置或依赖服务有问题)

   5、定义distro

    挂在iso镜像:

      # mkdir /mnt/iso

      # mount -o loop /date/CentOS-7-x86_64-DVD-1611.iso /mnt/iso      (iso 文件已下载至 /data 目录下)

    导入distro:

      # cobbler import --arch=x86_64 --path=/mnt/iso --name=Centos-7-x86_64    (需要一段时间)

    命令格式:cobbler import --path=镜像路径 -- name=安装引导名 --arch=32位或64位

    参数说明:
      --name :为安装源定义一个名字
      --arch :指定安装源是32位还是64位、ia64, 目前支持的选项有: x86│x86_64│ia64
      注意:这个安装源的唯一标示 就是根据这两个参数来定义

    导入成功后,安装源的唯一标示就是:centos-7-x86_64,如果重复,系统会提示导入失败,其它命令可通过cobbler -help来进行查看.如果需要更多的参数定制,也可以查看官方文档:man cobbler,然后查找 import 的配置,可以使用另外一个命令:cobbler distro. cobbler会将镜像中的所有安装文件拷贝到本地一份,放在/var/www/cobbler/ks_mirrors/下的centos-7-x86_64目录下,同时会创建一个名字为centos-7--x86_64的一个发布版本,以及一个名字为centos-7-x86_64的profile文件,此profile文件指定/var/lib/cobbler/kickstarts/simple_end.ks为默认ks文件

  6、制作ks文件 (无人值守脚本) 

# kickstart template for Fedora 8 and later.
# (includes %end blocks)
# do not use with earlier distros

#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --location=mbr
# 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
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot

#Root password
rootpw --iscrypted $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone  Asia/Shanghai
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
#autopart
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=1024
part swap --fstype="swap" --size=2048
part / --fstype="xfs" --grow --size=1

%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end

%packages
$SNIPPET('func_install_if_enabled')
%end

%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end

%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$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')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
%end
View Code

 

    也可以使用图形化工具生成ks文件

      # system-config-kickstart        #需要在图形化界面运行,需要安装桌面包,然后按提示一步一步生成ks.cfg文件)   VNC配置:http://www.cnblogs.com/weijie0717/p/6746508.html

  7、创建ks文件 ,保存到/var/lib/cobbler/kickstarts/目录内 ,导入系统distro时,系统指定的默认ks文件为/var/lib/cobbler/kickstarts/sample_end.ks,在这里我们需要重新指定ks文件

    # cobbler profile report --name Centos-7-x86_64     ( 查看profile 设置)

    # cobbler distro report --name Centos-7-x86_64  (查看安装镜像文件信息)

    # cobbler profile add --name=Centos-7-x86_64 --distro=Centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/Centos-7.ks    (绑定 profile 和 distro )

    # cobbler profile edit --name=Centos-7-x86_64 --distro=Centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/Centos-7.ks    (编辑 profile 和 distro )

  8、再次执行 cobbler check   看看之前的报错是否的一一解决。

  9、 如果没有任何问题,刷新cobbler 配置:

    # cobbler sync

  10、从起服务器,安装系统:

    

 

四、cobbler  web配置

 

posted @ 2017-04-22 00:33  语~默  阅读(968)  评论(0编辑  收藏  举报