JavaEE鸿蒙应用开发HTML&JS+前端Python+大数据开发人工智能开发AI+设计软件测试新媒体+短视频直播运营产品经理集成电路应用开发(含嵌入式)Linux云计算+运维开发C/C++拍摄剪辑+短视频制作PMP项目管理认证电商运营Go语言与区块链大数据PHP工程师Android+物联网iOS.NET

Cobbler自动化批量部署系统操作指南

来源:黑马程序员

浏览18843人

2020.02.05

1. 基本环境

1.1硬件环境

项目

详情

型号

华硕

CPU

Intel i5-7200U

内存

8GB

硬盘

256GB

网卡

千兆网卡*1

1.2 软件环境

项目

名称

操作系统

Red Hat Enterprise Linux 6.5

 

2. 环境配置

关闭iptables,selinux

#service iptables stop

#chkconfig iptables off

#sed –i ‘/^SELINUX=/cSELINUX=disabled’ /etc/selinux/config

配置静态ip

#vim /etc/sysconfig/network-scripts/ifcfg-INTERFACE_NAME

DEVICE=INTERFACE_NAME     

TYPE=Ethernet

BOOTPROTO=static

ONBOOT=yes

IPADDR=172.16.15.101

GATEWAY=172.16.15.254

DNS1=114.114.114.114

NETMASK=255.255.255.0

 

#service network restart   --重启网络试静态IP生效

设置主机名

#hostname cobbler

配置yum源(本地源和外网源二选一即可)

本地源

#mkdir /yum  --创建挂载镜像的目录

#mount rhel-server-6.5-x86_64-dvd.iso /yum  --找到自己的镜像并挂载

#vim /etc/yum.repos.d/local.repo

[local]

name=local yum

baseurl=file:///iso

enabled=1

gpgcheck=0

#yum clean all

#yum makecache

外网源

此处使用163(也可以使用rhel源) 

#vim /etc/yum.repos.d/aliyun.repo

[aliyun]

name=aliyun yum

baseurl=http://mirrors.163.com/centos/6/os/x86_64/

enabled=1

gpgcheck=0

#yum clean all

#yum makecache

NTP时间同步服务器

#yum install –y ntp ntpdate

#vim /etc/ntp.conf

server 0.rhel.pool.ntp.org iburst

server 1.rhel.pool.ntp.org iburst

server 2.rhel.pool.ntp.org iburst

server 3.rhel.pool.ntp.org iburst

#service start ntpd

#chkconfig ntpd on

#date   --确认时间已同步

3. 安装cobbler

需要的安装包:

cobbler-2.6.3-1.el6.noarch.rpm

koan-2.6.9-1.el6.noarch.rpm

cobbler-web-2.6.3-1.el6.noarch.rpm

libyaml-0.1.4-2.3.x86_64.rpm

django14-1.4.20-1.el6.noarch.rpm

pyYAML-3.10-3.1.el6.x86_64.rpm

 

将以上安装包放入同一个目录,如:/cobbler_soft

#yum install y createrepo

#createrepo /cobbler_soft/    --创建依赖关系

#vim /etc/yum.repos.d/cobbler.repo

[cobbler]

name=cobbler yum

baseurl=file:///cobbler_soft

enabled=1

gpgcheck=0

#yum clean all

#yum makecache

#yum install –y cobbler cobbler-web tftp* rsync xinetd http* syslinux dhcp* pykickstart  --安装cobbler及其相关包


4. Cobbler配置

#cobbler check  --检测cobbler需要修改的选项

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 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
https://github.com/cobbler/cobbler/wiki/Selinux
4 : 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.
5 : change 'disable' to 'no' in /etc/xinetd.d/rsync
6 : since iptables may be running, ensure 69, 80/443, and 25151 are unblocked
7 : debmirror package is not installed, it will be required to manage debian deployments and repositories
8 : 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
9 : 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.   –
以上问题由于系统环境等各方面原因,可能有所不同

需求1、2、8

# openssl passwd –l –salt ‘sdasdsfsdlhfskd’ ‘123456’   --123456为密码,sdasdsfsdlhfskd为随机字节干扰码,可随意编写

$1$werwqerw$.prcfrYFbwuvkD8XspayN.  –生成密码随机字符串 

 

#vim /etc/cobbler/settings

384 server: 172.16.15.1 --换成cobbler服务器端的IP
272 next_server: 172.16.15.1  --同上
101 default_password_crypted: "$1$werwqerw$.prcfrYFbwuvkD8XspayN."  
--将密码字符串换成上面生成的随机密码字符串

修改完配置文件以后再重启cobbler服务

#/etc/init.d/cobblerd restart

需求3

之前环境配置已将selinux设置为disabled,但需要重启系统才生效,所以此处临时关闭selinux

#setenforce 0

需求5

#vim /etc/xinetd.d/rsync

service rsync

{

        disable    = no   --yes改为no,即可打开

        flags             = IPv6

        socket_type      = stream

        wait              = no

        user              = root

        server            = /usr/bin/rsync

        server_args       = --daemon

        log_on_failure   += USERID

}

需求6

#/etc/init.d/iptables stop

# chkconfig iptables off

# vim /etc/xinetd.d/tftp

service tftp

{

        disable                 = no  --yes改为no,即可打开

        socket_type             = dgram

        protocol                = udp

        wait                    = yes

        user                    = root

        server                  = /usr/sbin/in.tftpd

        server_args             = -B 1380 -v -s /var/lib/tftpboot

        per_source              = 11

        cps                     = 100 2

        flags                   = IPv4

}

需求9

#yum install y fence-agents

解决以上需求后:

#cobbler check

The following are potential configuration items that you may want to fix:
1 : 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.
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
Restart cobblerd and then run 'cobbler sync' to apply changes.

以上两个问题可以忽略

5. 导入镜像

方案rhel6.5

# cobbler import --path=/yum/ --name=rhel6.5

*** TASK COMPLETE ***  --此提示说明导入镜像成功

# ls /var/www/cobbler/ks_mirror/  --在这里可以查看导入的镜像目录
config rhel6.5

#cobbler distro list  --查看导入的镜像

rhel6.5  

#cobbler profile list –-查看自动安装方案列表

rhel6.5

方案rhel7.3

#mkdir /rhel7.3

#mount CentOS-7-x86_64-DVD-1611 /centos7.3  --导入之前必须要先挂载镜像文件到目录里才可以导入

# ls /var/www/cobbler/ks_mirror/
config rhel6.5

# cobbler import --path=/centos7.3/ --name=centos7.3

*** TASK COMPLETE ***  

# ls /var/www/cobbler/ks_mirror/
config rhel6.5 cnetos7.3

#cobbler distro list

rhel6.5  cnetos7.3

#cobbler profile list

rhel6.5  centos7.3

6. 设置dhcp

#vim /etc/cobbler/dhcpd.template

subnet 172.16.15.0 netmask 255.255.255.0 {  --网段,掩码

     option routers             172.16.15.101; --网关

     option domain-name-servers172.16.15.101; -- DNS指向

     option subnet-mask         255.255.255.0; -- IP的掩码

     range dynamic-bootp        172.16.15.140 172.16.15.150; -- IP的范围

     default-lease-time         21600;

     max-lease-time             43200;

     next-server                $next_server;

     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";

          }

     }

} 

# vim /etc/cobbler/settings

242 manage_dhcp: 1  --使用cobbler来管理dhcp 

#/etc/init.d/cobblerd restart

#cobbler sync  --同步cobbler配置并初始化 

#/etc/xinetd.d/xinetd restart


7. 按需定义ks配置文件

# cobbler distro list

   centos7.3-x86_64

   rhel6.5-x86_64

 

# cobbler profile report --name=centos7.3-x86_64 |grep Kickstart  
Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks   --
查看默认安装方案ks文件路径(不同系统的默认安装方案ks文件都是这个,下面我们可以自己做一个ks文件,然后再重新指定默认ks文件即可)

ks文件模板:/root/anaconda-ks.cfg

  

自定义安装服务器时所使用的ks配置文件:

vim /var/lib/cobbler/kickstarts/centos7.3.ks   --centos7.3为例

# 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

# 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=http://172.16.15.101/cobbler/ks_mirror/centos7.3/

# 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 --isUtc

# Install OS instead of upgrade

install

# Clear the Master Boot Record

zerombr

# Disk partitioning information

part /boot --fstype="xfs" --size=500

part swap --fstype="swap" --size=4096

part pv.01 --size=102400

volgroup vg_uplooking pv.01

logvol  /  --vgname=vg_uplooking  --size=102300  --name=lv_root

%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')

@Development tools

@Compatibility libraries

%end

%post --nochroot

$SNIPPET('log_ks_post_nochroot')

%end 

f 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 --isUtc

# Install OS instead of upgrade

Install

# Clear the Master Boot Record

zerombr

# Disk partitioning information

part /boot --fstype="xfs" --size=500

part swap --fstype="swap" --size=4096

%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

注意:在配置文件中写入的lvs size大小必须要比创建的pvs size的大小小一点才行,否则会装机失败!!!

把自定义的ks文件指定成默认的安装方案:

#cobbler profile edit --name=CentOS7.3-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.3.ks

 8. 安装系统

注意:安装系统的物理机等设备必须与服务器在同一局域网内,才能获取到由cobbler服务器分配的ip然后进行安装

步骤:

1、 进入需要装机的物理设备的BIOS界面

2、 更改默认启动方式为网络启动后保存离开重启机器

3、 进入选择方案的界面后选择自己想要安装的方案后等待自动完成装机即可


相关阅读