一、coobler部署
1.安装服务相关软件以及环境
[root@cobbler ~]# yum install httpd dhcp tftp cobbler cobbler-web pykickstart xinetd
cobbler #cobbler 程序包
cobbler-web #cobbler的web 服务包
pykickstart #cobbler 检查 kickstart 语法错误
httpd #Apache web服务
2.启动服务
[root@cobbler ~]# systemctl start httpd xinetd cobblerd
[root@cobbler ~]# systemctl enable httpd xinetd cobblerd
3.通过cobbler check 核对当前设置
[root@cobbler ~]# cobbler check
The following are potential configuration items that you may want to fix:
##将/etc/cobbler/settings中的"server"字段设置为本机IP
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.
##/etc/cobbler/settings中的'next_server'字段设置为本机IP
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.
##/etc/xinetd.d/tftp中的"disable"更改为"no"
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
##缺少一些网络引导加载程序,下载命令:"cobbler get-loaders"来下载
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.
##启动rsync服务,并且开机自启动
5 : enable and start rsyncd.service with systemctl
##debian 相关,可以忽略
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
##设置新安装机器的示例模板使用的默认密码
7 : 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
##电源管理功能,忽略
8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
##重启cobblerd,然后运行"cobbler sync"应用。
Restart cobblerd and then run 'cobbler sync' to apply changes.
04.解决问题
#问题1、2
[root@cobbler ~]# sed -i 's/server: 127.0.0.1/server: 10.0.0.105/' /etc/cobbler/settings
[root@cobbler ~]# sed -i 's/next_server: 127.0.0.1/next_server: 10.0.0.105/' /etc/cobbler/settings
#问题3
[root@cobbler ~]# vim /etc/xinetd.d/tftp
service tftp
{
disable = no
socket_type = dgram
protocol = udp
}
#问题4
[root@cobbler ~]# cobbler get-loaders
#问题5
[root@cobbler ~]# systemctl start rsyncd
[root@cobbler ~]# systemctl enable rsyncd
#问题7
[root@cobbler ~]# openssl passwd -1 -salt '123456' '123456'
$1$123456$wOSEtcyiP2N/IfIl15W6Z0
[root@cobbler ~]# sed -i '/^default_password_crypted:/c default_password_crypted: "$1$123456$wOSEtcyiP2N/IfIl15W6Z0"' /etc/cobbler/settings
05.在cobbler中开启dhcp功能
[root@cobbler ~]# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings
06.配置dhcp文件
[root@default cobbler]# vim /etc/cobbler/dhcp.template
subnet 10.0.0.0 netmask 255.255.255.0 { #设置网段
option routers 10.0.0.254; #设置网关
option domain-name-servers 10.0.0.254; #设置dns服务器地址
option subnet-mask 255.255.255.0; #网段
range dynamic-bootp 10.0.0.2 10.0.0.254; #设置dhcp服务器IP地址租用的范围
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
}
07.导入CentOS镜像
挂载光盘镜像
[root@cobbler ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
cobbler 导入镜像
[root@cobbler ~]# cobbler import --path=/mnt/ --name=CentOS-7.6-x86_64 --arch=x86_64
查看下cobble 列表
[root@cobbler ~]# cobbler list
查看cobbler配置信息
[root@cobbler ~]# cobbler profile report
08.自定义kickstart系统安装信息文件,指定ks文件
[root@cobbler /]# cobbler profile edit --name=CentOS-7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.6-x86_64.cfg
配置的ks文件(简单配置、具体按照业务需要来配置)
[root@cobbler ~]# cat /var/lib/cobbler/kickstarts/CentOS-7.6-x86_64.cfg
# Kickstart Configurator for cobbler by lpc
# platform=x86, AMD64, or Intel EM64T
# System language
lang en_US
# System keyboard
keyboard us
# System timezone
timezone Asia/Shanghai
#Root password
rootpw --iscrypted $default_password_crypted
# Use text mode install
text
# Install OS instead of upgrade
install
# Use network installation media
url --url=$tree
# 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 --ondisk sda
part swap --size 1024 --ondisk sda
part / --fstype xfs --size 1 --grow --ondisk sda
# System authorization information
auth --useshadow --enablemd5
# Network information
$SNIPPET('network_config')
# network --bootproto=dhcp --device=eml --onboot=on
# Reboot after installation
reboot
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
#Package install information
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
%packages
@ base
@ core
lrzsz
wget
ntp
rsync
unzip
iotop
sysstat
net-tools
tree
vim
bash-completion
nc
nmap
telnet
bc
lsof
ncurses-devel
openssl-devel
zlib-devel
OpenIPMI-tools
screen
iptraf
python-devel
%end
%post
systemctl disable postfix.service
%end
09.修改默认网卡名称为eth0(CetnOS7需要更改)
[root@cobbler ~]# cobbler profile edit --name=CentOS-7.6-x86_64 --kopts='net.ifnames=0 biosdevname=0'
10.重启同步cobbler
[root@cobbler ~]# systemctl restart cobblerd.service
[root@cobbler ~]# cobbler sync
11.测试cobbler是否搭建成功
新建一台虚拟机,内存一定要大于2G以上,否则会报错
二、cobbler扩展功能
编辑pxe模板实现完全自动部署(不需手动选着我们要安装的版本)
[root@cobbler ~]# vim /etc/cobbler/pxe/pxedefault.template
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT CentOS-7.6-x86_64 ##修改默认安装的profile也就是说当你没有选择,超时操作后自动安装此profile
LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT -1
$pxe_menu_items
MENU end
cobbler服务web管理界面
安装环境依赖
web页面需要下载: cobbler-web;
Django版本需要较高,这里安装Django==1.8.9,使用python的pip进行安装;
配置阿里源,安装python-pip和python-devel软件,升级pip,安装Django-1.8.9
[root@cobbler ~]# mkdir -p /root/.pip
[root@cobbler ~]# cat >~/.pip/pip.conf <
通过浏览器访问
https://IP/cobbler_web注意这里使用的是HTTPS
默认用户名:cobbler
默认密码:cobbler
03.通过mac地址绑定IP地址安装
#定制一个system,收集mac地址
cobbler system add --name=cobbler-one --mac=00:50:56:3A:11:FF --ip-address=10.0.0.122 --subnet=255.255.255.0 --gateway=10.0.0.254 --interface=eth0 --static=1 --profile=CentOS-7.6-x86_64 --hostname=cobbler-test --netboot-enabled=true --name-servers="202.106.0.20"
cobbler system edit --name=cobbler-one --mac=00:50:56:3F:5C:97 --ip-address=172.16.1.122 --subnet=255.255.255.0 --interface=eth1 --static=1
#参数说明
#--name : system 实例的名称
#--mac : 与实例对应的mac地址
#--ip-address : 实例所使用的网络接口的ip地址
#-subnet : 对应的网络掩码
#--gateway : 网关地址
#--interface : 网络接口的名称
#--static=1 : 使用静态ip也就是我们之前设置ip地址
#--hostname : 定义主机名
#--name-servers : 定义dns
# --netboot-enabled=true : cobbler 可以设置成一个新服务器的安装过后,第二次PXE启动的时候 能自动选择跳过(避免重复安装)