CentOS7 安裝cobbler自動部署ubuntu

CentOS7 安裝cobbler自動部署ubuntu

 

一、簡介

二、安裝CentOS 7 調整配置及安裝相關軟件

1、調整配置

2、安裝 epel

3、安裝cobblercobbler-web 以及相關依賴軟件

4、設置開機啓動

三、Cobblertftpdhcprsync配置

1TFTP配置

2、配置rsync

3、配置/etc/cobbler/settings

4、修改/etc/cobbler/modules.conf

5、修改/etc/cobbler/dhcp.template

6、重啓cobbler httpd服務

四、檢查cobbler配置

五、導入鏡像並查看導入情況

1、導入鏡像

2、查看

六、編輯seed文件

1、普通分區配置

2lvm分區配置

七、注意事項

八、截圖



 

一、簡介

Cobbler是紅帽開發的批量部署系統的工具,對RHELCentOS支持完美

對其他發行版的linux部分支持,也不是很完美

本文介紹的是基於CentOS 7上安裝cobbler 2.6的文檔

參照了網上的一些教程和官方文檔,加上自己的實踐,特別是分區部分,調試了數十次纔算完美了。

二、安裝CentOS 7 調整配置及安裝相關軟件

1、調整配置

安裝完成後關閉selinux或參照cobbler官方文檔設置selinuxhttp://cobbler.github.io/manuals/2.6.0/4/2_-_SELinux.html

[root@cobbler-server ~]# sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config  

重啓服務器

關閉iptables以及取消開機啓動,centos7 minimal沒有安裝ipables

關閉firewall或放行80 67 68 69 443 端口

80 443cobbler web管理界面端口

67 68 DHCP端口

69TFTP端口

[root@cobbler-server ~]# systemctl stop firewalld

[root@cobbler-server ~]# systemctl disable firewalld

2、安裝 epel

[root@cobbler-server ~]# yum install epel-release

[root@cobbler-server ~]# yum makecache

3、安裝cobblercobbler-web 以及相關依賴軟件

[root@cobbler-server ~]# yum install cobbler cobbler-web xinetd pykickstart cman dhcp -y

4、設置開機啓動

[root@cobbler-server ~]# systemctl enable httpd

[root@cobbler-server ~]# systemctl enable dhcpd  

[root@cobbler-server ~]# systemctl enable cobblerd

三、Cobblertftpdhcprsync配置

1TFTP配置

配置tftp綠色着色爲修改後的值

[root@cobbler-server ~]# vim /etc/xinetd.d/tftp

# default: off

# description: The tftp server serves files using the trivial file transfer \

#       protocol.  The tftp protocol is often used to boot diskless \

#       workstations, download configuration files to network-aware printers, \

#       and to start the installation process for some operating systems.

service tftp

{

        socket_type             = dgram

        protocol                = udp

        wait                    = yes

        user                    = root

        server                  = /usr/sbin/in.tftpd

        server_args             = -s /var/lib/tftpboot

        disable                 = no

        per_source              = 11

        cps                     = 100 2

        flags                   = IPv4

}

2、配置rsync

[root@cobbler-server ~]# systemctl enable rsyncd

CentOS7上安裝cobbler 對於rsync無需額外配置

3、配置/etc/cobbler/settings

[root@cobbler-server ~]# cat /etc/cobbler/settings |grep '^[^#]'

---

allow_duplicate_hostnames: 0

allow_duplicate_ips: 0

allow_duplicate_macs: 0

allow_dynamic_settings: 0

anamon_enabled: 0

authn_pam_service: "login"

auth_token_expiration: 3600

build_reporting_enabled: 0

build_reporting_sender: ""

build_reporting_email: [ 'root@localhost' ]

build_reporting_smtp_server: "localhost"

build_reporting_subject: ""

build_reporting_ignorelist: [ "" ]

cheetah_import_whitelist:

 - "random"

 - "re"

 - "time"

createrepo_flags: "-c cache -s sha"

default_kickstart: /var/lib/cobbler/kickstarts/default.ks

default_name_servers: []

default_ownership:

 - "admin"

default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."

default_template_type: "cheetah"

default_virt_bridge: xenbr0

default_virt_file_size: 5

default_virt_ram: 512

default_virt_type: xenpv

enable_gpxe: 0

enable_menu: 1

func_auto_setup: 0

func_master: overlord.example.org

http_port: 80

kernel_options:

 ksdevice: bootif

 lang: ' '

 text: ~

kernel_options_s390x:

 RUNKS: 1

 ramdisk_size: 40000

 root: /dev/ram0

 ro: ~

 ip: off

 vnc: ~

ldap_server: "ldap.example.com"

ldap_base_dn: "DC=example,DC=com"

ldap_port: 389

ldap_tls: 1

ldap_anonymous_bind: 1

ldap_search_bind_dn: ''

ldap_search_passwd: ''

ldap_search_prefix: 'uid='

ldap_tls_cacertfile: ''

ldap_tls_keyfile: ''

ldap_tls_certfile: ''

mgmt_classes: []

mgmt_parameters:

 from_cobbler: 1

puppet_auto_setup: 0

sign_puppet_certs_automatically: 0

puppetca_path: "/usr/bin/puppet"

remove_old_puppet_certs_automatically: 0

manage_dhcp: 1

#cobbler接管DHCP,默認爲0,此處修改以後需要修改對應/etc/cobbler/dhcp.template模板

manage_dns: 0

bind_chroot_path: ""

bind_master: 127.0.0.1

manage_tftpd: 1

manage_rsync: 1 #接管rsync,無需額外配置rsync

manage_forward_zones: []

manage_reverse_zones: []

next_server: 192.168.11.252 #本機ip地址

power_management_default_type: 'ipmitool'

power_template_dir: "/etc/cobbler/power"

pxe_just_once: 0

pxe_template_dir: "/etc/cobbler/pxe"

consoles: "/var/consoles"

redhat_management_type: "off"

redhat_management_server: "xmlrpc.rhn.redhat.com"

redhat_management_key: ""

redhat_management_permissive: 0

register_new_installs: 0

reposync_flags: "-l -n -d"

restart_dns: 1

restart_dhcp: 1

run_install_triggers: 1

scm_track_enabled: 0

scm_track_mode: "git"

server: 192.168.11.252 #本機ip地址

client_use_localhost: 0

client_use_https: 0

snippetsdir: /var/lib/cobbler/snippets

template_remote_kickstarts: 0

virt_auto_boot: 1

webdir: /var/www/cobbler

xmlrpc_port: 25151

yum_post_install_mirror: 1

yum_distro_priority: 1

yumdownloader_flags: "--resolve"

serializer_pretty_json: 0

replicate_rsync_options: "-avzH"

replicate_repo_rsync_options: "-avzH"

always_write_dhcp_entries: 0

proxy_url_ext: ""

proxy_url_int: ""

 

4、修改/etc/cobbler/modules.conf

[root@cobbler-server ~]# cat /etc/cobbler/modules.conf |grep '^[^#]'

 

[authentication]

module = authn_configfile

[authorization]

module = authz_allowall

[dns]

module = manage_bind

[dhcp]

module = manage_isc #如果是dnsmasq就應該爲manage_dnsmasq

[tftpd]

module = manage_in_tftpd

 

5、修改/etc/cobbler/dhcp.template

[root@localhost cobbler]# cat /etc/cobbler/dhcp.template |grep '^[^#]'

ddns-update-style interim;

allow booting;

allow bootp;

ignore client-updates;

set vendorclass = option vendor-class-identifier;

option pxe-system-type code 93 = unsigned integer 16;

subnet 192.168.11.0 netmask 255.255.255.0 {

     option routers             192.168.11.252;

     option domain-name-servers 192.168.11.252;

     option subnet-mask         255.255.255.0;

     range dynamic-bootp        192.168.11.100 192.168.11.200;

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

          }

     }

}

    ## group could be subnet if your dhcp tags line up with your subnets

    ## or really any valid dhcpd.conf construct ... if you only use the

    ## default dhcp tag in cobbler, the group block can be deleted for a

    ## flat configuration

group {

        #for mac in $dhcp_tags[$dhcp_tag].keys():

            #set iface = $dhcp_tags[$dhcp_tag][$mac]

    host $iface.name {

        hardware ethernet $mac;

        #if $iface.ip_address:

        fixed-address $iface.ip_address;

        #end if

        #if $iface.hostname:

        option host-name "$iface.hostname";

        #end if

        #if $iface.netmask:

        option subnet-mask $iface.netmask;

        #end if

        #if $iface.gateway:

        option routers $iface.gateway;

        #end if

        #if $iface.enable_gpxe:

        if exists user-class and option user-class = "gPXE" {

            filename "http://$cobbler_server/cblr/svc/op/gpxe/system/$iface.owner";

        } else if exists user-class and option user-class = "iPXE" {

            filename "http://$cobbler_server/cblr/svc/op/gpxe/system/$iface.owner";

        } else {

            filename "undionly.kpxe";

        }

        #else

        filename "$iface.filename";

        #end if

        ## Cobbler defaults to $next_server, but some users

        ## may like to use $iface.system.server for proxied setups

        next-server $next_server;

        ## next-server $iface.next_server;

    }

        #end for

}

6、重啓cobbler httpd服務

[root@cobbler-server ~]# systemctl restart cobblerd

[root@cobbler-server ~]# systemctl restart httpd

 

四、檢查cobbler配置

[root@cobbler-server ~]# cobbler check

The following are potential configuration items that you may want to fix:

 

1 : debmirror package is not installed, it will be required to manage debian deployments and repositories

2 : 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

 

Restart cobblerd and then run 'cobbler sync' to apply changes.

以上兩點都可以忽略

第二點是修改部署系統默認的root密碼

若提示enabled rsyncd or use systemctl to start rsyncd.service

是叫你把rsync加到開機啓動

[root@cobbler-server ~]# systemctl enable rsyncd

執行以上命令後就不會出現這個提示了

五、導入鏡像並查看導入情況

1、導入鏡像

[root@cobbler-server ~]# mount /dev/cdrom /mnt/cdrom/

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

[root@cobbler-server ~]#cobbler import --path=/mnt/cdrom/ --name=ubuntu-12.04.5 --arch=x86_64

task started: 2016-10-07_221950_import

task started (id=Media import, time=Fri Oct  7 22:19:50 2016)

Found a candidate signature: breed=freebsd, version=10.1

Found a candidate signature: breed=freebsd, version=10.0

Found a candidate signature: breed=freebsd, version=8.3

Found a candidate signature: breed=freebsd, version=8.2

Found a candidate signature: breed=freebsd, version=8.4

Found a candidate signature: breed=freebsd, version=10.2

Found a candidate signature: breed=freebsd, version=9.0

Found a candidate signature: breed=freebsd, version=9.1

Found a candidate signature: breed=freebsd, version=9.2

Found a candidate signature: breed=freebsd, version=9.3

Found a candidate signature: breed=ubuntu, version=precise

running: /usr/bin/file /var/www/cobbler/ks_mirror/ubuntu-12.04.5-x86_64/dists/precise/Release

received on stdout: /var/www/cobbler/ks_mirror/ubuntu-12.04.5-x86_64/dists/precise/Release: ASCII text

 

received on stderr:

Found a matching signature: breed=ubuntu, version=precise

Adding distros from path /var/www/cobbler/ks_mirror/ubuntu-12.04.5-x86_64:

creating new distro: ubuntu-12.04.5-x86_64

trying symlink: /var/www/cobbler/ks_mirror/ubuntu-12.04.5-x86_64 -> /var/www/cobbler/links/ubuntu-12.04.5-x86_64

creating new profile: ubuntu-12.04.5-x86_64

associating repos

checking for apt repo(s)

adding apt repo for ubuntu-12.04.5-x86_64

Added repos for ubuntu-12.04.5-x86_64

*** TASK COMPLETE ***

有些鏡像是不支持的,不支持就會導入錯誤

2、查看

查看導入的鏡像和使用到的kickstart文件信息

[root@cobbler-server ~]# cobbler distro list

   CentOS-7.2-x86_64

   ESXi-6.0.0-x86_64

   ubuntu-12.04.5-x86_64

[root@cobbler-server ~]# cobbler profile report

Name                           : ESXi-6.0.0-x86_64

TFTP Boot Files                : {}

Comment                        :

DHCP Tag                       : default

Distribution                   : ESXi-6.0.0-x86_64

Enable gPXE?                   : 0

Enable PXE Menu?               : 1

Fetchable Files                : {}

Kernel Options                 : {}

Kernel Options (Post Install)  : {}

Kickstart                      : /var/lib/cobbler/kickstarts/sample_esxi5.ks

Kickstart Metadata             : {}

Management Classes             : []

Management Parameters          : <<inherit>>

Name Servers                   : []

Name Servers Search Path       : []

Owners                         : ['admin']

Parent Profile                 :

Internal proxy                 :

Red Hat Management Key         : <<inherit>>

Red Hat Management Server      : <<inherit>>

Repos                          : []

Server Override                : <<inherit>>

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

 

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

Kickstart Metadata             : {}

Management Classes             : []

Management Parameters          : <<inherit>>

Name Servers                   : []

Name Servers Search Path       : []

Owners                         : ['admin']

Parent Profile                 :

Internal proxy                 :

Red Hat Management Key         : <<inherit>>

Red Hat Management Server      : <<inherit>>

Repos                          : []

Server Override                : <<inherit>>

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

 

Name                           : ubuntu-12.04.5-x86_64

TFTP Boot Files                : {}

Comment                        :

DHCP Tag                       : default

Distribution                   : ubuntu-12.04.5-x86_64

Enable gPXE?                   : 0

Enable PXE Menu?               : 1

Fetchable Files                : {}

Kernel Options                 : {}

Kernel Options (Post Install)  : {}

Kickstart                      : /var/lib/cobbler/kickstarts/sample.seed

Kickstart Metadata             : {}

Management Classes             : []

Management Parameters          : <<inherit>>

Name Servers                   : []

Name Servers Search Path       : []

Owners                         : ['admin']

Parent Profile                 :

Internal proxy                 :

Red Hat Management Key         : <<inherit>>

Red Hat Management Server      : <<inherit>>

Repos                          : []

Server Override                : <<inherit>>

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

六、編輯seed文件

1、普通分區配置

[root@cobbler-server ~]# grep "^[^#]" /var/lib/cobbler/kickstarts/sample.seed

d-i debian-installer/locale string en_US

d-i console-setup/ask_detect boolean false

d-i keyboard-configuration/layoutcode string us

d-i keyboard-configuration/variantcode string

d-i netcfg/choose_interface select auto

d-i netcfg/get_hostname string $myhostname

d-i time/zone string US/Eastern

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 mirror/country string manual

d-i mirror/http/hostname string $http_server

d-i mirror/http/directory string $install_source_directory

d-i mirror/http/proxy string

d-i live-installer/net-p_w_picpath string http://$http_server/cobbler/links/$distro_name/install/filesystem.squashfs

d-i partman-auto/disk string /dev/sda

d-i partman-auto/method string regular

d-i partman-auto/choose_recipe select fsm

d-i partman-lvm/device_remove_lvm boolean true

d-i partman-md/device_remove_md boolean true

d-i partman-auto/expert_recipe string \

fsm :: \

1024 100% 1024 linux-swap method{ swap } \

format{ } \

. \

2048 2048 2048 ext4 method{ format } \

mountpoint{ /home } \

format{ } use_filesystem{ } filesystem{ ext4 } \

. \

10240 10240 10240 ext4 method{ format } \

mountpoint{ / } \

format{ } use_filesystem{ } filesystem{ ext4 } \

options/relatime{ relatime } \

. \

768 1024 1024 ext4 method{ format } \

mountpoint{ /tmp } \

format{ } use_filesystem{ } filesystem{ ext4 } \

options/relatime{ relatime } \

. \

1 2048 1000000000 ext4 method{ format } \

mountpoint{ /www } \

format{ } use_filesystem{ } filesystem{ ext4 } \

options/relatime{ relatime } \

.

d-i partman-lvm/confirm_nooverwrite boolean true

d-i partman-lvm/confirm boolean true

d-i partman-partitioning/confirm_write_new_label boolean true

d-i partman/confirm_nooverwrite boolean true

d-i partman/confirm boolean true

d-i partman/choose_partition \

select Finish partitioning and write changes to disk

d-i passwd/root-login boolean true

d-i passwd/root-password-crypted password $default_password_crypted

d-i passwd/make-user boolean false

$SNIPPET('preseed_apt_repo_config')

d-i pkgsel/include string ntp ssh wget vim

d-i debian-installer/add-kernel-opts string $kernel_options_post

d-i finish-install/reboot_in_progress note

d-i preseed/early_command string wget -O- \

   http://$http_server/cblr/svc/op/script/$what/$name/?script=preseed_early_default | \

   /bin/sh -s

d-i preseed/late_command string wget -O- \

   http://$http_server/cblr/svc/op/script/$what/$name/?script=preseed_late_default | \

   chroot /target /bin/sh -s

2lvm分區配置

綠色標記部分是最重要的,定製分區的配置,以上是普通分區方式

如果是lvm分區方式,用以下配置

d-i partman-auto/disk string /dev/sda#指定磁盤

d-i partman-auto/method string lvm#分區格式lvm還是普通分區還是raid

d-i partman-auto/choose_recipe select fsm

d-i partman-lvm/device_remove_lvm boolean true

d-i partman-md/device_remove_md boolean true

d-i partman-auto-lvm/no_boot boolean true

d-i partman-auto-lvm/new_vg_name string vg0

d-i partman-auto/expert_recipe string \

fsm :: \

1024 100% 1024 linux-swap method{ swap } \

format{ } $lvmok{ } lv_name{ swap } \

. \

2048 2048 2048 ext4 method{ lvm } \

$lvmok{ } mountpoint{ /home } lv_name{ home } \

format{ } use_filesystem{ } filesystem{ ext4 } \

. \

10240 10240 10240 ext4 method{ lvm } \

$lvmok{ } mountpoint{ / } lv_name{ root } \

format{ } use_filesystem{ } filesystem{ ext4 } \

options/relatime{ relatime } \

. \

768 1024 1024 ext4 method{ lvm } \

$lvmok{ } mountpoint{ /tmp } lv_name{ tmp } \

format{ } use_filesystem{ } filesystem{ ext4 } \

options/relatime{ relatime } \

. \

1 2048 1000000000 ext4 method{ lvm } \

$lvmok{ } mountpoint{ /www } lv_name{ www } \

format{ } use_filesystem{ } filesystem{ ext4 } \

options/relatime{ relatime } \

.

d-i partman-lvm/confirm_nooverwrite boolean true

d-i partman-lvm/confirm boolean true

d-i partman-partitioning/confirm_write_new_label boolean true

d-i partman/confirm_nooverwrite boolean true

d-i partman/confirm boolean true

d-i partman/choose_partition \

    select Finish partitioning and write changes to disk    #保存分區

wKioL1f8WQ6DVUotAAATeo1GsDY481.png-wh_50 

 

注:

$lvmok{ }必須存在,不然安裝會報錯無法繼續

wKiom1f8WRjBxKtwAAA-7amg9wM880.png-wh_50 

不存在這個選項cobbler又會報錯

{'code': u'VFFSL(SL,"lvmok",True)',

  'exc_val': NotFound(u"cannot find 'lvmok'",),

  'lineCol': (60, 11),

  'rawCode': u'$lvmok',

  'time': 'Sun Oct  9 23:43:14 2016'}]

不知道是不是cobblerbug

 

七、注意事項

11 2048 1000000000 ext4 method{ lvm } \ 這三個數字分別代表最少1M ,權重,最多1000000000M

如果把剩餘的都分配就用三個-1,即-1 -1 -1 ext4 method{ lvm } \

2d-i partman-auto/choose_recipe select fsmfsm隨意命名,但必須和d-i partman-auto/expert_recipe string fsm :: 這個fsm對應

3seed文件中不能有中文哪怕是註釋,不然會報錯

4、每次修改/etc/cobbler/setting配置後需要執行cobbler sync進行同步

5、對於esxi的支持,默認不支持esxi6,但是可以用esxi5kickstart文件,部分不兼容,但仍能全自動安裝

 

八、截圖

 

wKioL1f8WSLTZLOKAAAoz9FwqC4993.png-wh_50 

 

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章