mynote/linux/cobbler.md
2021-12-22 17:10:35 +08:00

378 lines
11 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# centos7 Cobbler
https://blog.csdn.net/qq_36441659/article/details/104965639
https://askubuntu.com/questions/476508/why-ubuntu-server-asks-to-insert-a-cd-rom-when-installed-from-pxe
[TOC]
## 安装
```bash
# cobbler 在epel源中
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install cobbler xinetd dhcp bind cobbler-web debmirror pykickstart fence-agents
systemctl enable cobblerd httpd xinetd dhcpd
systemctl start cobblerd httpd xinetd dhcpd
# 需要关闭seliux和防火墙
vim /etc/selinux/config
systemctl stop firewalld.service
systemctl disable firewalld.service
reboot
```
## 配置
```bash
# 配置文件 /etc/cobbler/settings
# 自动化部署系统的密码的哈希, 用下行命令生成
# openssl passwd -1
# $1$j9.kasLF$4v5dJWXMDUmxYTXO9qPiG.
# 密文第一项 1 指hash方式 第二项 j9.kasLF 指的salt这样子用以系统判断密码是否正确但是又不存储密码密码和salt都相同时才能计算出唯一的密文
default_password_crypted: "$1$j9.kasLF$4v5dJWXMDUmxYTXO9qPiG."
# 设置cobbler的ip 不要设置0.0.0.0设置一个不隔离广播域的内网ip
server: 192.168.1.2
# 设置的tftp ip用于下载镜像通常与上一个一样
next_server: 192.168.1.2
# 是否开启DHCP0不开启 1开启
# 为了启动 pxe 需要开启dhcp分发地址 并引导系统 到tftp server下载网络启动文件
manage_dhcp: 1
```
```bash
# 配置DHCP /etc/cobbler/dhcp.template
# 不要修改 next-server 项,该配置会自动从上面拉取变量
# 不要修改 #for dhcp_tag in $dhcp_tags.keys(): 这一行之后的内容
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option domain-name-servers 114.114.114.114,8.8.8.8;
option subnet-mask 255.255.255.0;
filename "/pxelinux.0";
default-lease-time 2.8.0;
max-lease-time 43200;
next-server $next_server;
}
```
```bash
# 检测 会提示一些操作, 根据需要去做
cobbler check
# 返回下面7条
The following are potential configuration items that you may want to fix:
1 : ISC DHCP server (dhcp/dhcpd) is not installed
2 : change 'disable' to 'no' in /etc/xinetd.d/tftp
3 : 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.
4 : enable and start rsyncd.service with systemctl
5 : debmirror package is not installed, it will be required to manage debian deployments and repositories
6 : ksvalidator was not found, install pykickstart
7 : 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
yum install dhcp
# 2
# 3
cobbler get-loaders
# 4
systemctl enable rsyncd
systemctl start rsyncd
# 5
yum install debmirror
# 6
yum -y install pykickstart
# 7
yum -y install fence-agents
# 一切正常
cobbler sync
```
## 导入镜像
```bash
# http://mirrors.aliyun.com/centos 下载镜像, 下载minimal版方便测试
mkdir /mnt/centos7
mount -t iso9660 -o loop,ro ~/CentOS-7-x86_64-Minimal-2003.iso /mnt/centos7
# 导入
cobbler import --name=centos7 --path=/mnt/centos7
cobbler import --name=u20 --bread=ubuntu --os-version=focal --path=/mnt/u20
cobbler signature update
## profile url http://192.168.10.60/cblr/svc/op/ks/profile/centos7-x86_64
## 访问这个链接可以查看完整版的ks文件 也可以验证ks是否正确
# 检测
cobbler distro list
centos7-x86_64
cobbler profile list
centos7-x86_64
➜ ~ cobbler distro report --name=centos7-x86_64
Name : centos7-x86_64
Architecture : x86_64
TFTP Boot Files : {}
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/ks_mirror/centos7/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/ks_mirror/centos7/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/centos7-x86_64'}
Management Classes : []
OS Version : rhel7
Owners : ['admin']
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Template Files : {}
➜ ~ cobbler profile report --name=centos7-x86_64
Name : centos7-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : centos7-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
```
修改centos用的kickstart文件
```bash
cd /var/lib/cobbler/kickstarts/
cp sample_end.ks centos8.ks
cobbler profile edit --name=centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.ks# 验证
cobbler profile report --name=centos7-x86_64 | grep kickstart
# 同步
cobbler sync
```
## Centos7.ks
```bash
#platform=x86, AMD64, or Intel EM64T
#os=centos7
# Install OS instead of upgrade
install
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# System timezone
timezone Asia/ShangHai
# System authorization information
auth --useshadow --enablemd5
# Root password
rootpw --iscrypted $default_password_crypted
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled
# Use network installation
url --url=$tree
# Clear the Master Boot Record
zerombr
# System bootloader configuration
# bootloader --location=mbr
# interface can be named as eth*
bootloader --location=mbr --append="net.ifnames=0 biosdevname=0 rhgb quiet"
# Partition clearing information
clearpart --all --initlabel
# Allow anaconda to partition the system as needed
autopart
# or
# # create 1MB biosboot type partition, centos7 and centos8 .
# part biosboot --fstype=biosboot --size=1
# # Disk partitioning information
# part /boot --fstype=xfs --size=300
# part pv.122 --fstype="lvmpv" --grow
# volgroup VolGroup00 --pesize=16384 pv.122
# logvol / --fstype="xfs" --size=10000 --name=LogVol00 --vgname=VolGroup00
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# add repo manually
# repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream
# Network information
$SNIPPET('network_config')
# Do not configure the X Window System
skipx
# Run the Setup Agent on first boot
firstboot --disable
# Reboot after installation
reboot
%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')
# if you need puppet to install pkgs, just uncomment it
# $SNIPPET('puppet_install_if_enabled')
@core
@base
tree
nmap
wget
telnet
%end
%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end
%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('puppet_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
%post --nochroot
$SNIPPET('log_ks_post_nochroot')
# 关闭这两项可以避免ssh连接设备时卡顿
sed -ri "/^#UseDNS/c\UseDNS no" /etc/ssh/sshd_config
sed -ri "/^GSSAPIAuthentication/c\GSSAPIAuthentication no" /etc/ssh/sshd_config
# 根据ip地址设计host
id=compute_$(ip addr | grep "192" -m 1 | awk -F'[/.]+' '{print $4;}')
hostnamectl set-hostname --static $id
%end
```
## 验证
## 配置 centos7 本地源
```bash
# 添加
cobbler repo add --name=Centos7-Base --mirror=http://mirrors.aliyun.com/centos/7.8.2003/os/x86_64/ --arch=x86_64 --breed=yum
cobbler repo add --name=Centos7-Updates --mirror=http://mirrors.aliyun.com/centos/7.8.2003/updates/x86_64/ --arch=x86_64 --breed=yum
cobbler repo add --name=Centos7-extras --mirror=http://mirrors.aliyun.com/centos/7.8.2003/extras/x86_64/ --arch=x86_64 --breed=yum
cobbler repo add --name=Centos7-Epel --mirror=http://mirrors.aliyun.com/epel/7/x86_64/ --arch=x86_64 --breed=yum
cobbler repo add --name=Centos7-Openstack-train --mirror=http://mirrors.aliyun.com/centos/7/cloud/x86_64/openstack-train/ --arch=x86_64 --breed=yum
# 查看
cobbler repo list
# 同步
# 需要 sudo apt install yum-utils, 安装完后重启cobbler
# 存储在 /var/lib/cobbler/www/cobbler/repo_mirror/
cobbler reposync
cobbler profile edit --name=centos7-x86_64 --repos='Centos7-Base Centos7-Updates Centos7-extras Centos7-Epel'
cobbler profile report --name=centos7-x86_64
# 或者手动在ks文件里添加
# repo --name="BaseOS" --baseurl=http://192.168.10.50/cblr/repo_mirror/Centos8-BaseOS/
```
#### ubuntu20-server
```bash
# 需要将该文件作为initrd文件 否则会出现cd
/install/netboot/ubuntu-installer/amd64/initrd.gz
/var/lib/tftpboot/images/u20
```
---------------
[1]: http://cobbler.github.io
[2]: https://cobbler.readthedocs.io/en/latest/
[3]: https://www.golinuxcloud.com/rhel-centos-8-kickstart-example-generator/