Cobbler自動化批量部署系統操作指南

基本環境

1.1硬件環境

1.2 軟件環境

環境配置

關閉iptables,selinux

#service iptables stop

#chkconfig iptables off

#sed –i ‘/^SELINUX=/c\SELINUX=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 http://0.rhel.pool.ntp.org iburst

server http://1.rhel.pool.ntp.org iburst

server http://2.rhel.pool.ntp.org iburst

server http://3.rhel.pool.ntp.org iburst

 

#service start ntpd

#chkconfig ntpd on

 

#date --確認時間已同步

安裝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及其相關包

 

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.

以上兩個問題可以忽略

 

導入鏡像

方案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

設置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

 

按需定義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

安裝系統

注意:安裝系統的物理機等設備必須與服務器在同一局域網內,才能獲取到由cobbler服務器分配的ip然後進行安裝

步驟:

  1. 進入需要裝機的物理設備的BIOS界面
  2. 更改默認啓動方式爲網絡啓動後保存離開重啓機器
  3. 進入選擇方案的界面後選擇自己想要安裝的方案後等待自動完成裝機即可
發佈了643 篇原創文章 · 獲贊 1315 · 訪問量 163萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章