4. Cobbler 基础配置
最后更新于:2022-04-02 07:42:43
#### 任何修改后,重新同步cobbler配置,配置生效
```shell
cobbler sync
```
#### 导入安装镜像
**挂载光盘**
```
mount -t iso9660 -o loop /tmp/CentOS-7-x86_64-DVD-1611.iso /mnt/
```
**挂载Centos 6.8光盘镜像到/mnt目录下,导入**
```shell
cobbler import --name=Centos-6.8 --path=/mnt/ --arch=x86_64
```
**挂载Centos 7.3光盘镜像到/mnt目录下,导入**
```shell
cobbler import --name=Centos-7.3 --path=/mnt/ --arch=x86_64
```
**挂载ESXI 5.5光盘镜像到/mnt目录下,导入**
```shell
cobbler import --path=/mnt/ --name=ESXI-5.5.0 --arch=x86_64
```
#### 查看distro配置
```shell
cobbler distro report
```
#### 定义自动安装的应答文件,文件放到/var/lib/cobbler/kickstarts/目录下
> Cobbler通过读取该文件,执行相关安装步骤
请查看1.5 Cobbler 配置文件
#### 为可用镜像配置默认ks文件
**Centos 6.8**
```shell
cobbler profile edit --name=Centos-6.8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/Centos-6.8-x86_64.cfg
```
**Centos 7.3**
```shell
cobbler profile edit --name=Centos-7.3-x86_64 --kickstart=/var/lib/cobbler/kickstarts/Centos-7.3-x86_64.cfg
```
**ESXI 5.5**
```shell
cobbler profile edit --name=ESXI-5.5.0-x86_64 --kickstart=/var/lib/cobbler/kickstarts/esxi5.5.cfg
```
#### 调整网卡内核参数(标准化,名称统一,关闭IPv6)
**Centos 7.3**
```shell
cobbler profile edit --name=Centos-7.3-x86_64 --kopts='net.ifnames=0 biosdevname=0 noipv6'
```
#### 查看profile配置
```shell
cobbler profile report
```
#### 建立本地yum源
**Centos 6.8**
```shell
cobbler repo add --name=Centos-6-x86_64 --mirror=https://mirrors.aliyun.com/centos/6.9/os/x86_64/ --arch=x86_64 --breed=yum --keep-update=Y
cobbler repo add --name=Centos-6-epel-x86_64 --mirror=https://mirrors.aliyun.com/epel/6Server/x86_64/ --arch=x86_64 --breed=yum --keep-update=Y
```
**Centos 7.x**
```shell
cobbler repo add --name=Centos-7-x86_64 --mirror=https://mirrors.aliyun.com/centos/7.4.1708/os/x86_64/ --arch=x86_64 --breed=yum --keep-update=Y
cobbler repo add --name=Centos-7-epel-x86_64 --mirror=https://mirrors.aliyun.com/epel/7Server/x86_64/ --arch=x86_64 --breed=yum --keep-update=Y
cobbler repo add --name=zabbix3.0-Centos7 --mirror=http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/ --arch=x86_64 --breed=yum --keep-update=Y
```
#### 查看repo配置
```shell
cobbler repo report
```
**执行同步任务**
```shell
cobbler reposync
```
错误一例:
Exception occured:
Exception value: 'cobbler reposync failed'
解决方法1: 把--breed=yum更换为rsync或wget
**建立任务计划,每周六同步一次**
```shell
echo "0 23 * * 6 /usr/bin/cobbler reposync >> /app/log/cobbler.log 2>&1" >> /var/spool/cron/root
```
**重启Cron**
**Centos 6.8**
```shell
/etc/init.d/crond restart
```
**Centos 7.3**
```shell
systemctl restart crond
```
#### 为镜像配置本队YUM源
**Centos 6.8**
```shell
cobbler profile edit --name=Centos-6.8-x86_64 --repos="Centos-6-epel-x86_64 Centos-6.8-x86_64-extras Centos-6.8-x86_64-os Centos-6.8-x86_64-updates Centos-6.8-x86_64-cr Centos-6.8-x86_64-gfs zabbix3.0-Centos6"
```
**Centos 7.3**
```shell
cobbler profile edit --name=Centos-7.3-x86_64 --repos="Centos-7.3-x86_64-os Centos-7.3-x86_64-updates Centos-7.3-x86_64-extras Centos-7-epel-x86_64 Centos-7.3-x86_64-cloud-l Centos-7.3-x86_64-gfs zabbix3.0-Centos7"
```
#### 根据MAC地址零交互安装
** 创建一个新的自定义安装**
```shell
cobbler system add --name=odb01.prod.ding --mac=00:0c:29:34:58:f1 --profile=Centos-6.8-x86_64 --ip-address=192.168.0.20 --subnet=255.255.255.0 --gateway=192.168.0.1 --interface=eth0 --static=1 --hostname=odb01.prod.ding --name-servers="114.114.114.114"
```
#### 修改自定义安装(name不可修改)
```shell
cobbler system edit --name=odb01.prod.ding --mac=00:0c:29:34:58:f1 --profile=Centos-6.8-x86_64 --ip-address=192.168.0.20 --subnet=255.255.255.0 --gateway=192.168.0.1 --interface=eth0 --static=1 --hostname=odb01.prod.ding --name-servers="114.114.114.114"
```
#### 查看system配置
```shell
cobbler system report
```
#### 修改展示页面内容
```shell
[root@Centos-souce kickstarts]# cat /etc/cobbler/pxe/pxedefault.template
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | 系统自动化部署
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT $pxe_timeout_profile
LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT -1
$pxe_menu_items
MENU end
```
#### 自动重装系统(注意:客户机配置)
问题:虽然可以重装系统,但是不能设置IP、DNS、主机名
解决:
- 重装时候,生成专门为这台机器使用的一次性系统profile,用完即删
- 将自定义操作交由saltstack或者ansible来做,但是IP地址怎么分配呢?
- 通过dell的IDRAC等远程管理卡的远程界面,手工PXE启动(个人推荐)
**安装epel源,安装koan**
```shell
yum install koan -y
```
**获取Cobbler服务器上的可用系统列表**
```shell
[root@openstack ~]# koan --server=192.168.0.232 --list=profiles
- looking for Cobbler at http://192.168.0.232:80/cobbler_api
Centos-7.3-x86_64
```
**选择要重装的系统,执行安装命令**
```shell
koan --replace-self --server=192.168.0.232 --profile=Centos-7.3-x886_64
```
#### 1.2.3 Cobbler WEB配置
```shell
https://192.168.0.232/cobbler_web
```
';