Cobbler安装和配置
1.yum国内源的安装与更新
1.1 备份原repo文件
cd /etc/yum.repo.d/
mkdir repo_bak
mv *.repo repo_bak
1.2 在centos中配置网易和阿里的开源镜像
wget http://mirrors.aliyun.com/repo/Centos-7.repo
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
1.3 清除系统缓存并生成新的yum缓存
yum clean all
yum makecache
1.4 安装epel源
yum -y install epel-release
1.5 下载安装阿里开源镜像提供的epel
wget http://mirrors.aliyun.com/repo/epel-7.repo
1.6 再次清除系统缓存并生成新的yum缓存
yum clean all
yum makecache
1.7 查看系统可用的yum源和所有yum源
yum repolist enable
yum repolist all
2.搭建前操作
2.1 升级系统到最新
yum update -y
2.2 关闭selinux
vi /etc/selinux/config
将SELINUX=enforcing改为disabled
getenforce
#检测selinux是否关闭
2.3 关闭防火墙
firewall-cmd --state
#查看防火墙状态
systemctl stop firewalld.service
#临时关闭防火墙
systemctl disable firewalld.service
#禁止firewall开机启动
2.4 支撑环境安装
yum -y install cobbler httpd rsync tftp-server xinetd dhcp pykickstart fence-agents cobbler-web
3.配置Tftp,Http
vim /etc/xinetd.d/tftp
service tftp
{
disable = no #原为yes
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
}
vim /etc/httpd/conf/httpd.conf
ServerName 192.168.4.88:80
4.配置Cobbler
4.1 生成系统装机默认密码
如在kiskstart文件内设置密码则系统安装后root密码为kickstart文件内设置的密码)
openssl passwd -1 -salt 'testabc' '123456'
$1$random-p$mzxQ/Sx848sXgvfwJCoZM0
#生成root密码
4.2 修改settings文件
vim /etc/cobbler/settings
manage_dhcp: 1 ## 原为 0
manage_tftpd: 1
manage_rsync: 1 ## 原为 0
next_server: 192.168.4.88 ## 本机 IP
server: 192.168.4.88 ## 本机 IP
default_password_crypted: "$1$random-p$mzxQ/Sx848sXgvfwJCoZM0" ## 生成的 root 密码
4.3 cobbler-web用户及密码修改
cobbler-web登陆默认使用cobbler/cobbler登陆,用户及密码存放的位置在/etc/cobbler/users.conf和/etc/cobbler/users.digest 两个文件内
如想修改可以使用如下命令:
htdigest /etc/cobbler/users.digest "Cobbler" cobbler
Changing password for user cobbler in realm Cobbler
New password:
Re-type new password:
4.4 配置DHCP
只修改这个区域的IP地址即可
vim /etc/cobbler/dhcp.template
subnet 172.16.31.0 netmask 255.255.255.0 {
option routers 172.16.31.88;
#option domain-name-servers 192.168.1.1;
option subnet-mask 255.255.255.0;
range dynamic-bootp 172.16.31.100 172.16.31.120;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
5.启动相关服务
5.1 启动服务
systemctl start httpd
systemctl start xinetd
systemctl start cobblerd
systemctl start rsyncd
5.2 将服务加入启动项
systemctl enable httpd
systemctl enable xinetd
systemctl enable cobblerd
systemctl enable rsyncd
6.检查配置
cobbler check
依照检查配置的要求完成每一步
执行cobbler get-loaders自动下载引导文件
cobbler get-loaders
注意 debmirror检查这一步可以忽略
7.同步操作
cobbler sync
8.重启cobbler服务
systemctl restart cobblerd
systemctl status cobblerd
9.注意事项
cobbler-web使用的python Django1.8.9实现,如果通过页面https://192.168.4.88/cobbler_web 登陆报“Internal Server Error”错误可以通过以下方式修复
#下载pip.py
wget https://bootstrap.pypa.io/get-pip.py
#调用本地python运行pip.py脚本
python get-pip.py
#安装pip
pip install Django==1.8.9
#查看pip版本号
python -c "import django; print(django.get_version())"
#重启httpd
systemctl restart httpd
10.cobbler使用
10.1 下载安装镜像文件
wget http://mirrors.163.com/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-DVD-1810.iso
10.2导入安装源 #以下步骤均可在web页面完成
mkdir /mnt/CentOS-7-x86_64
mount -r CentOS-7-x86_64-DVD-1810.iso /mnt/CentOS-7-x86_64/
cobbler import --path=/mnt/CentOS-7-x86_64 --name=Centos-7-x86_64
输出信息略(Cobbler 将镜像拷贝一份放在 /var/www/cobbler/ks_mirror/Centos-7-x86_64 目录下)
(同时会创建一个名为 Centos-7-x86_64 的发布版本及 profile 文件)
[root@localhost ~]# cobbler list
distros:
CenOS-7-xx86_64-Minimal-x86_64
Centos-7-x86_64
profiles:
CenOS-7-xx86_64-Minimal-x86_64
Centos-7-x86_64
systems:
CHN-JS-1-IRON-07
repos:
images:
mgmtclasses:
packages:
files:
10.3 创建ks文件
vim /var/lib/cobbler/kickstarts/Centos7-base-install.cfg
#platform=x86, AMD64, or Intel EM64T
# System language
lang en_US
# System keyboard
keyboard us
# System timezone
timezone Asia/Shanghai
# Root password
rootpw --plaintext ezsvs@123
#Use text mode install
text
# Install OS instead of upgrade
install
#Use NFS installation Media
url --url=$tree
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr
#version=DEVEL
#Firewall configuration
firewall --disabled
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
text
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# Network information
$SNIPPET('network_config')
# Network information
#network --bootproto=dhcp --device=eth0 --onboot=on
# Partition clearing information
#clearpart --all --initlabel
clearpart --drives=sda --all
# Disk partitioning information
#part /boot --asprimary --fstype="ext4" --ondisk=sda --size=200
#part swap --asprimary --fstype="swap" --ondisk=sda --size=4096
#part / --asprimary --fstype="xfs" --grow --ondisk=sda --size=1
part / --fstype="xfs" --ondisk=sda --size=20480
part swap --fstype="swap" --ondisk=sda --size=4096
part /boot --fstype="xfs" --ondisk=sda --size=500
part /data --fstype="xfs" --ondisk=sda --grow --asprimary --size=1
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
%post
$SNIPPET('post_install_network_config')
%end
%packages
@base
@core
%end
目前已有编写好的文件供安装系统调用,注意ks文件中不能有中文,注释也不能有中文。
注意磁盘分区字段
clearpart --all --initlabel
#系统初装删除所有分区
clearpart --drives=sda --all
#系统重装只删除系统分区sda保留数据盘
10.4 关联ks文件
[root@localhost kickstarts]# cobbler distro list
CenOS-7-xx86_64-Minimal-x86_64
Centos-7-x86_64
这里有2个镜像,其中Centos-7-x86_64是我刚上传制作的
[root@localhost kickstarts]# cobbler profile report --name Centos-7-x86_64
Name : Centos-7-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : Centos-7-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
这个镜像默认使用的ks文件为/var/lib/cobbler/kickstarts/sample_end.ks
cobbler profile add --name=Cenos-7-x86_64 --distro=Centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/Centos7-base-install.cfg
再次查看关联成功
Kickstart : /var/lib/cobbler/kickstarts/Centos7-base-install.cfg
10.5 修改内核参数
[root@localhost ~]# cobbler profile edit --name=Centos-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
[root@localhost ~]# cobbler profile report --name=Centos-7-x86_64
Name : Centos-7-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : Centos-7-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/Centos7-base-install.cfg
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
10.6 同步配置完成操作
cobbler sync
至此,cobbler的安装和配置已经完成,连接待安装的服务器,将服务器启动引导PXE启动,即可开始安装系统。
11.附录
11.1 cobbler 常用命令列表
[root@localhost kickstarts]# cobbler --help
usage
=====
cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ...
[add|edit|copy|getks*|list|remove|rename|report] [options|--help]
cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help]
[root@localhost kickstarts]# cobbler profile --help
usage
=====
cobbler profile add
cobbler profile copy
cobbler profile dumpvars
cobbler profile edit
cobbler profile find
cobbler profile getks
cobbler profile list
cobbler profile remove
cobbler profile rename
cobbler profile report
cobbler distro add --name=string --kernel=path --initrd=path [--kopts=string] [--kopts-post=string] [--ksmeta=string] [--arch=x86|x86_64|ia64] [--breed=redhat|debian|suse] [--template-files=string]
cobbler profile add --name=string --distro=string [--kickstart=path] [--kopts=string] [--ksmeta=string] [--virt-file-size=gigabytes] [--virt-ram=megabytes] [--virt-type=string] [--virt-cpus=integer] [--virt-path=string] [--virt-bridge=string] [--server] [--parent=profile]
cobbler system add --name=string --profile=string [--mac=macaddress] [--ip-address=ipaddress] [--hostname=hostname] [--kopts=string] [--ksmeta=string] [--kickstart=path] [--netboot-enabled=Y/N] [--server=string] [--gateway=string] [--dns-name=string] [--static-routes=string] [--power-address=string] [--power-type=string] [--power-user=string] [--power-pass=string] [--power-id=string]
11.2 基本命令说明
命令名称 | 命令用途 |
---|---|
cobbler check | 核对当前设置是否有问题 |
cobbler list | 列出所有的cobbler元素 |
cobbler distro/profile/system/repo/image/mgmtclass/package/file list | 列出每种元素的列表 |
cobbler report | 详细的列出每个元素 |
cobbler distro/profile/system/repo/image/mgmtclass/package/file report --name=[object-name] | 列出每个元素的报告 |
cobbler sync | 同步配置 |
cobbler reposync | 同步yum仓库 |
11.3 配置文件说明
cobbler配置文件存放在/etc/cobbler/下
配置文件名称 | 用途 |
---|---|
/etc/cobbler/settings | cobbler主配置文件 |
/etc/cobbler/dhcp.template | dhcp的模板配置文件 |
/etc/cobbler/tftpd.template | tftp的模板配置文件 |
/etc/cobbler/named.template | dns的模板配置文件 |
/etc/cobbler/users.digest | 用于web访问的用户名密码配置文件 |
/etc/cobbler/modules.conf | 模块配置文件 |
/etc/cobbler/users.conf | cobbler webUI/web service授权配置文件 |
repo数据目录/var/www/cobbler
导入的发行版,repos镜像和kickstarts文件都放置在/var/www/cobbler目录下。确保/var目录有足够的空间来存储这些文件
目录名称 | 用途 |
---|---|
images/ | 存储所有导入发行版的kernel和initrd镜像用于远程网路启动 |
ks_mirrors | 存储导入的发行版 |
repo_mirror | yum repos存储目录 |
/var/log/cobbler | 存放日志文件/var/log/cobbler/cobbler.log |
cobbler数据目录/var/lib/cobbler,此目录存储和cobbler profiles,systems,distros相关的配置。
目录名称 | 用途 |
---|---|
configs/ | 存储distros,repos,systems和profiles相关信息 |
backup/ | 备份目录 |
snippets | 放置一些可以在kickstarts导入的脚本小片段 |
triggers/ | 放置一些可执行脚本 |
kickstarts/ | 放置kickstarts模板文件 |