cobbler自动化安装centos-7.2

一、cobbler:

1.cobbler介绍

Cobbler是一个Linux服务器快速网络安装的服务,由python开发,小巧轻便(15k行python代码),可以通过PXE的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS,TFTP、RSYNC以及yum仓库、构造系统ISO镜像。
Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。

2.cobbler工作原理

cobbler自动化安装centos-7.2_第1张图片


1.client裸机配置了从网络启动后,开机后会广播包请求DHCP服务器 (cobbler server)发送其分配好的一个IP

2.DHCP服务器(cobbler server)收到请求后发送responese,包括其ip地址
3.client裸机拿到ip后再向cobbler server发送请求IOS引导文件的请求
4.cobbler server告诉裸机OS引导文件的名字和TFTP server的ip和 port
5.client裸机通过上面告知的TFTP server地址通信,下载引导文件
6.client裸机执行执行该引导文件,确定加载信息,选择要安装的ios, 期间会再向cobbler server请求kickstart文件和ios image
7.cobbler server发送请求的kickstart和os iamge
8.client裸机加载kickstart文件
9.client裸机接收os image,安装该ios image

二、系统环境:

1.版本,ip

[root@liang ~]# cat /etc/redhat-release 

CentOS Linux release 7.2.1511 (Core)

 

[root@liang ~]# uname -r

3.10.0-327.el7.x86_64


[root@liang ~]# ifconfig eno16777736
eno16777736: flags=4163  mtu 1500

        inet 10.0.0.134  netmask 255.255.255.0  broadcast 10.0.0.255

2.关闭selinux,防火墙

[root@liang ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux 
[root@liang ~]# setenforce 0
[root@liang ~]# systemctl stop firewalld  
[root@liang ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service

三、安装步骤:
1.安装epel包

[root@liang ~]# yum install epel-release -y

[root@liang ~]# yum makecache

2.安装所需的服务

[root@liang ~]# yum install cobbler cobbler-web pykickstart dhcp xinetd tftp-server pykickstart httpd -y
3.启动httpd
[root@liang ~]# systemctl start httpd
[root@liang ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

4.启动cobbler
[root@liang ~]# systemctl start cobblerd
[root@liang ~]# systemctl enable cobblerd
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.

5.检查cobbler的配置(按提示将未配置的步骤配置完)
[root@liang ~]# 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 : 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 : change 'disable' to 'no' in /etc/xinetd.d/tftp
5 : 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.
6 : enable and start rsyncd.service with systemctl
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.



第一步+第二步:
[root@liang ~]# vim /etc/cobbler/settings
server: 10.0.0.134
next_server: 10.0.0.134

manage_dhcp: 1


第三步:
[root@liang ~]# vim /etc/sysconfig/selinux 
SELINUX=disabled

[root@liang ~]# setenforce 0
[root@liang ~]# getenforce 
Permissive


第四步:
[root@liang ~]# vim /etc/xinetd.d/tftp
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no(将yes修改为no)
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}
第五步:
下载缺少的文件
[root@liang ~]# cobbler get-loaders
task started: 2018-06-08_101543_get_loaders
task started (id=Download Bootloader Content, time=Fri Jun  8 10:15:43 2018)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***
第六步:
[root@liang ~]# systemctl start rsyncd.service  
[root@liang ~]# systemctl enable rsyncd.service  
第八步:
[root@liang ~]# openssl passwd -1 -salt 'cobbler' '000000'                     
$1$cobbler$yvUCMps1IlTa5ocamRXv1.
[root@liang ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$cobbler$yvUCMps1IlTa5ocamRXv1."

6.重启服务
[root@liang ~]# systemctl restart xinetd 
[root@liang ~]# systemctl restart cobblerd
7.剩下提示的步骤可以跳过
[root@liang ~]# cobbler check
The following are potential configuration items that you may want to fix:


1 : 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
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
3 : 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.配置dhcp(需要改dhcp服务的配置文件,只需要改cobbler的模板)
[root@liang ~]# vim /etc/cobbler/dhcp.template 


subnet 10.0.0.0 netmask 255.255.255.0 {
     option routers             10.0.0.2;
     option domain-name-servers 10.0.0.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        10.0.0.100 10.0.0.200;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;

9.同步配置
[root@liang ~]# cobbler sync

10.导入镜像

10.1挂载镜像

[root@liang ~]# mount /dev/cdrom /opt/centos/

mount: /dev/sr0 is write-protected, mounting read-only


10.2导入镜像

[root@liang ~]# cobbler import --path=/opt/centos --name=Centos-7.2 --arch=x86_64
task started: 2018-06-08_104159_import
task started (id=Media import, time=Fri Jun  8 10:41:59 2018)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/Centos-7.2-x86_64:
creating new distro: Centos-7.2-x86_64
trying symlink: /var/www/cobbler/ks_mirror/Centos-7.2-x86_64 -> /var/www/cobbler/links/Centos-7.2-x86_64
creating new profile: Centos-7.2-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/Centos-7.2-x86_64 for Centos-7.2-x86_64
processing repo at : /var/www/cobbler/ks_mirror/Centos-7.2-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/Centos-7.2-x86_64
looking for /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/Centos-7.2-x86_64/repodata

*** TASK COMPLETE ***


10.3镜像存放的路径
[root@liang ~]# ls /var/www/cobbler/ks_mirror/                      
Centos-7.2-x86_64  config


11.查看cobbler配置
[root@liang ~]# cobbler list
distros:
   Centos-7.2-x86_64(仓库)


profiles:
   Centos-7.2-x86_64(配置)


systems:


repos:


images:


mgmtclasses:


packages:


files:


查看具体配置
[root@liang ~]# cobbler profile report
Name                           : Centos-7.2-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : Centos-7.2-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks(ks文件路径)
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 : 
Internal proxy                 : 
Red Hat Management Key         : <>
Red Hat Management Server      : <>
Repos                          : []
Server Override                : <>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      : 
Virt RAM (MB)                  : 512
Virt Type                      : kvm

12.ks文件的配置与存放路径
12.1ks存放的目录(这里使用的上一篇博客的ks文件,本篇博客后面会将ks的内容贴出来)

[root@liang ~]# cp ks.cfg /var/lib/cobbler/kickstarts/


12.2修改ks文件内容(三个地方)
[root@liang ~]# vim /var/lib/cobbler/kickstarts/ks.cfg 
# Root password
#rootpw --iscrypted $1$eSOV7j.U$/8fVRwXLfG7WvjJ8hb1kU.
rootpw --iscrypted $default_password_crypted
# Use network installation
#url --url="http://10.0.0.134/Centos-7.2/"
url --url=$tree
# Network information
#network  --bootproto=dhcp --device=eth0
$SNIPPET('network_config')
13.修改cobbler配置
13.1修改ks路径为自定义的ks文件所在地
[root@liang ~]# cobbler profile edit --name=Centos-7.2-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks.cfg


13.2修改网卡名称为eth0
[root@liang ~]# cobbler profile edit --name=Centos-7.2-x86_64 --kopts='net.ifnames=0 biosdevname=0'

13.3查看详细配置
[root@liang ~]# cobbler profile report
Name                           : Centos-7.2-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : Centos-7.2-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {'biosdevname': '0', 'net.ifnames': '0'}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/ks.cfg
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 : 
Internal proxy                 : 
Red Hat Management Key         : <>
Red Hat Management Server      : <>
Repos                          : []
Server Override                : <>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      : 
Virt RAM (MB)                  : 512
Virt Type                      : kvm

14.同步cobbler配置
[root@liang ~]# cobbler sync 
15.新建虚拟机测试

cobbler自动化安装centos-7.2_第2张图片

15.1修改显示的模板(纯属装X用)

[root@liang pxe]# cat /etc/cobbler/pxe/pxedefault.template 
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/(修改为想要的,我这里修改成博客地址 https://blog.csdn.net/liang_operations/)
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT $pxe_timeout_profile


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


$pxe_menu_items


MENU end


[root@liang pxe]# cobbler sync

cobbler自动化安装centos-7.2_第3张图片

cobbler自动化安装centos-7.2_第4张图片

17.ks文件的内容

[root@liang ~]# cat /var/lib/cobbler/kickstarts/ks.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
#rootpw --iscrypted $1$eSOV7j.U$/8fVRwXLfG7WvjJ8hb1kU.
rootpw --iscrypted $default_password_crypted
# System timezone
timezone Asia/Shanghai
# Use network installation
#url --url="http://10.0.0.134/Centos-7.2/"
url --url=$tree
# System language
lang en_US
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled


# Network information
#network  --bootproto=dhcp --device=eth0
$SNIPPET('network_config')
# Reboot after installation
reboot
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=200
part swap --fstype="swap" --size=4096
part / --fstype="xfs" --grow --size=1


%packages --nobase 


@core 


%end




你可能感兴趣的:(自动化安装系统)