cobbler+kickstart安装笔记

时间:2020-12-06 16:59:14

cobbler+kickstart安装笔记

本文参考老男孩配置:https://blog.oldboyedu.com/autoinstall-cobbler/

centos7:开机如果不启动网卡,需要修改/etc/sysconfig/network-scripts/本地的网卡(一般为ens-xxx)将onboot改为yes

1.安装epel rpm源(这里使用的阿里云源)

yum clean all

rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

2.安装前置安装环境

关闭防火墙,和selinux(不愿意关的话可以开放相应端口25151 69 22 80)

    systemctl stop firewalld  #停止防火墙

    systemctl disable firewalld  #禁止开机启动防火墙

    vi /etc/sysconfig/selinux  #修改selinux

     SELINUX=disabled

    reboot #重启 

下面安装基础环境

yum -y install cobbler cobbler-web pykickstart debmirror httpd dhcp xinetd xftp rsyncd

#这里我们启动服务,并设置开机启动

systemctl start httpd

systemctl enable httpd

systemctl start cobblerd

systemctl enable cobblerd

systemctl start xftp

systemctl enable xftp

systemctl start rsyncd

systemctl enable rsyncd
ksvalidator /var/lib/cobbler/kickstarts/CentOS7-7-x86_64.cfg #安装的pykickstart里面的工具,用来检查简单的语法错误登,但是有时候会误判,发现有朋友ks文件出问题,当初写的时候忘了补充下

配置cobbler:

cobbler check

会有以下提示:

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 : change 'disable' to 'no' in /etc/xinetd.d/tftp
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 : enable and start rsyncd.service with systemctl
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 Restart cobblerd and then run 'cobbler sync' to apply changes.

按照步骤设置

修改cobbler配置文件

vim /etc/cobbler/settings

#第一项 server 将server设置为提供cobbler服务的服务器ip(我这里是单虚拟机模拟所以就设置的为本机)

#server = 127.0.0.1
server = 192.168.184.130
#可以使用sed直接修改,第一次推荐还是先手动改改,多看看配置,后面就直接改了就行了
#sed -i 's/server: 127.0.0.1/server: 192.168.184.130/' /etc/cobbler/settings

#第一项 next_server 将提供pxe服务的ip

#next_server = 127.0.0.1
next_server = 192.168.184.130 #sed -i 's/next_server: 127.0.0.1/next_server:192.168.184.130/' /etc/cobbler/settings

#第三项 将tftp的disable 值从yes修改为no

vi /etc/xinetd.d/tftp
disable=no
#sed -i 's/disable=yes/disable=no/' /etc/xinetd.d/tftp

#第四项 下载网络安装所需文件

cobbler get-loaders   #注意,在上面步骤中,如果你不小心输错了你配置的server的ip地址的话,会报错,请先检查自己输入的ip是否正确。

#第五项 启动rsync(/etc/xinetd.d/rsync有些人分享的步骤中会有这个文件,但是实际上不用xinetd托管rsync也不影响,所以只要启动了服务就问题不大)

systemct start rsyncd

systemct  enable rsyncd

ps:如果在前面你像我一样启动了,这一步可以省略,这里只是为了对照cobbler的提示

#第六项 配置密码

#(执行下面命令后之后会出现加密后的密码,现在的版本随机值最好不要设置为random-phrase)

openssl passwd - -salt 'random-phrase-here' 'your-password-here' 

#将密码添加到/etc/cobbler/settings中的default_password值
#default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."

重启cobbler

systemctl restart httpd
systemctl restart cobbler

再次检查配置,若没有问题则提交同步

cobbler check

cobbler rsync 

#通过cobbler管理dhcp

#修改/etc/cobbler/settings值manage_dhcp: 1
#sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings

#查看cobbler的配置例子

vim /etc/cobbler/dhcp.template

subnet 192.168.184.0 netmask 255.255.255.0 {
option routers 192.168.184.2;
option domain-name-servers 192.168.184.2;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.184.100 192.168.184.254;

#导入镜像 先将镜像挂在,再通过import导入 --path为挂在镜像的路径 --name为名字 --arch为架构

mount /dev/cdrom /mnt
#mount: /dev/sr0 写保护,将以只读方式挂载 如果是虚拟机的朋友,导入挂载没发先cdrom,在虚拟机里将cdrom启动再挂载即可,path为镜像挂载的目录,name为你这个镜像的名称,arch为系统架构 cobbler import --path=/mnt/ --name=CentOS7 --arch=x86_64 #文件镜像位置为/var/www/cobbler/ks_mirror 

#kickstart

#将写好的启动配置文件文件上传至/var/lib/cobbler/kickstarts/CentOS7-7-x86_64.cfg目录下,下面是我使用的配置文件,可以根据自身需求修改配置文件(这个中文注释只是方便理解,在使用中的时候配置文件中不能有中文,需要全部删除)

#System

#设置字符集格式
lang en_US.UTF-
#设置键盘类型
keyboard us
#设置时区
timezone --utc Asia/Shanghai
#Root密码
rootpw --iscrypted $default_password_crypted
#text模式安装
text
#告知安装程序,这是一次全新安装,而不是升级
install
#通过cobbler安装镜像
url --url=$tree
#bootloader安装在mbr扇区(磁盘的0磁道0柱面1扇区前512字节,后64字节为分区信息,每个分区占16个字节)
bootloader --location=mbr
#清除mbr引导(清空引导扇区)
zerombr
#清空分区
clearpart --all --initlabel
#/boot分区
part /boot --fstype xfs --size --ondisk sda
#swap分区
part /swap --size --ondisk sda
#根分区
part / --fstype xfs --size --grow --ondisk sda
#设置密码格式
authconfig --enableshadow --passalgo=sha512
#网络信息
$SNIPPET('network_config')
#重启
reboot
#关闭防火墙
firewall --disabled
#关闭selinux
selinux --disabled
#不配置Xwindows
skipx
#安装包信息
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
$SNIPPET('pre_anamon')
%end %packages
@ base
@ core
sysstat
iptraf
ntp
lrzsz
ncurses-devel
openssl=devel
zilb-devel
OpenIPMI-tools
mysql
nmap
screen
%end %post
systemctl disabled postfix.service
%end

上传了之后我们可以更新一下cobbler的默认配置文件(配置文件里面不能有中文,注释也不能有中文,否则会配置文件读取会出问题)

可以通过cobbler list命令查看

cobbler profile edit --name=CentOS7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS7-7-x86_64.cfg

设置网卡名,因为在CentOS7之后网卡名会被命名为ens-XXXX的格式

cobbler profile edit --name=CentOS7-x86_64 --kopts='net.ifnames=0 biosdevname=0'

确认更新情况

cobbler profile report CentOS7-x86_64

cobbler sync 再次提交更新

可以查看下CentOS的启动文件

cat /var/lib/tftpboot/pxelinux.cfg/default

cobbler(报错):

1.tftp TimeOut :端口未开放
解决方法:systemctl stop firewalld systemctl disable firewalld

2./dev/root does not exist :在安装CentOS7的过程中会遇见这个问题,经过我查资料是(除了注释里有中文或者配置文件中有中文)找不到镜像目录,指定目录即可安装

distro:主要用来定义某个发行版特有的或者特用的ramdisk和kernel的,该命令主要用于对distro进行增加,编辑,拷贝,查找,移除,重命名操作。

https://anaconda-installer.readthedocs.io/en/latest/boot-options.html?highlight=ksdevice我们在anaconda的官方文档中看到的选项使用inst.repo=[http,https,ftp]://<host>/<path>指定镜像目录

cobbler distro edit --name=CentOS7-x86_64 --kopts="ksdevice= inst.repo=http://192.168.184.131/cblr/ks_mirror/CentOS7-x86_64/" --ksmeta="tree=http