cobbler补鞋匠

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

yum install cobbler cobbler-web pykickstart httpd dhcp tftp xinetd fence-agents 
debmirror  -y
如果有装不上情况就分开一个一个装 

终端图形管理界面:https://192.168.110.3/cobbler_web(没有研究过,学的是下面命令)

3. Cobbler 配置文件概述
# 配置⽂文件目录 /etc/cobbler
/etc/cobbler/settings # cobbler主配置文件
/etc/cobbler/dhcp.template # DHCP服务的配置模板
/etc/cobbler/tftpd.template # tftp服务的配置模板
/etc/cobbler/rsync.template # rsync服务的配置模板
/etc/cobbler/iso # iso模板配置文件目录

/etc/cobbler/pxe # pxe模板文件目录
/etc/cobbler/power # 电源的配置文件目录
/etc/cobbler/users.conf # Web服务授权配置⽂文件
/etc/cobbler/users.digest # web访问的⽤用户名密码配置⽂文件
/etc/cobbler/dnsmasq.template # DNS服务的配置模板
/etc/cobbler/modules.conf # Cobbler模块配置文件

#Cobbler数据目录 /var/lib/cobbler
/var/lib/cobbler/config # 配置⽂文件
/var/lib/cobbler/kickstarts # 默认存放kickstart⽂文件
/var/lib/cobbler/loaders # 存放的各种引导程序
/var/www/cobbler # 系统安装镜像目录
/var/www/cobbler/ks_mirror # 导入的系统镜像列列表
/var/www/cobbler/images # 导入的系统镜像启动⽂文件
/var/www/cobbler/repo_mirror # yum源存储目录

#日志目录/var/log/cobbler
/var/log/cobbler/install.log # 客户端系统安装⽇日志
/var/log/cobbler/cobbler.log # cobbler⽇日志

启动 httpd 以及 CobblerServer
[root@cobbler ~]# systemctl start httpd
[root@cobbler ~]# systemctl start cobblerd
cobbler check 检查一下有什么问题,全部解决掉 

改配置文件:
vi   /etc/cobbler/settings
server=192.168.10.3
next_server=192.168.10.3

//启用cobbler动态配置,如不不启动则可以通过手动或sed命令替换配置
sed -ri '/allow_dynamic_settings:/c \allow_dynamic_settings: 1' /etc/cobbler/settings
systemctl restart cobblerd

vi /etc/xinetd.d/tftp
disable   no
[root@cobbler ~]# systemctl enable xinetd
[root@cobbler ~]# systemctl restart xinetd

//4.启动rsync
[root@cobbler ~]# systemctl start rsyncd
[root@cobbler ~]# systemctl enable rsyncd

//5.下载网络安装需要执行的文件
[root@cobbler ~]# cobbler get-loaders
//6.安装debmirror, 修改/etc/debmirror.conf
[root@cobbler ~]# yum –y install debmirror
vim /etc/debmirror.conf注释掉下面两行
#@dists="sid";
#@arches="i386";

//7.配置系统登录密码
openssl passwd -1 -salt 'cobbler' 'Bgx123.com'
cobbler setting edit --name=default_password_crypted --value='$1$cobbler$RTWR1S/XXjsj9af1IZGi/.'

//8.电源控制模块安装[可选]
[root@cobbler ~]# yum –y install cman fence-agents

//9.开启dhcp地址分配
[root@cobbler ~]# cobbler setting edit --name=manage_dhcp --value=1

6.执⾏行行 cobbler check 检查
[root@cobbler ~]# systemctl restart cobblerd
[root@cobbler ~]# cobbler check
No configuration problems found. All systems go. 有这行就对了

7.配置 cobbler 的 dhcp 模板不代表给主机分配一定是如下地址]
先开启cobbler支持dhcp
vim /etc/cobbler/settings
manage_dhcp: 1

[root@cobbler ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.56.0 netmask 255.255.255.0 {
option routers 192.168.56.2;
option domain-name-servers 192.168.56.2;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.56.100 192.168.56.200;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;

8.同步 CobblerServer 所有配置信息
//重启并同步cobblerServer
[root@cobbler ~]# systemctl restart xinetd
[root@cobbler ~]# systemctl restart cobblerd
[root@cobbler ~]# cobbler sync

2.Cobbler基础应⽤用
1. cobbler 使⽤用第一步需要定义 distro 如果已经有 OS 镜像安装⽂文件, 使⽤用 improt 导入方式。

//1.挂载CentOS7系统ISO光盘
[root@cobbler ~]# mount /dev/cdrom /mnt/
//2.import导入系统镜像,以及镜像树
[root@cobbler ~]# cobbler import --path=/mnt/ --name=centos7 --arch=x86_64
会创建在:
/var/www/cobbler/ks_mirror/centos7-x86_64
/var/www/cobbler/images/centos7-x86_64

yum仓库位置:
/var/www/cobbler/repo_mirror

//3.查看cobbler distro
[root@cobbler ~]# cobbler distro list
centos7-x86_64

2. cobbler 默认 profile 无法满足运维需求, 需在 distro 基础上指定 kickstart
自定义配置文件(配置文件在文档末尾自行复制创建)2. Cobbler 的 Ks 文件以及脚本文件中指定硬盘分区时
注意:KVM虚拟机是vda和vdb,如果使⽤用vmware请注意磁盘名称为sda、sdb

注意:每安装好一台Centos机器,Centos安装程序都会创建一个kickstart配置文件,
记录你的真实安装配置。如果你希望实现和某系统类似的安装,
可以基于该系统的kickstart配置文件来生成你自己的kickstart配置文件。
(生成的文件名字叫anaconda-ks.cfg位于/root/anaconda-ks.cfg)

vim /var/lib/cobbler/kickstarts/centos7.cfg

#CentOS7
#Kickstart Configurator by xuliangwei
#platform=x86, AMD64, or Intel EM64T
#System language
lang en_US
#System keyboard
keyboard us
#Sytem timezone
timezone Asia/Shanghai
#Root password
rootpw --iscrypted $default_password_crypted
#Use text mode install
text
#Install OS instead of upgrade
install
#Use NFS installation Media
url --url=$tree
#System bootloader configuration
bootloader --location=mbr --append="net.ifnames=0 biosdevname=0"
#Clear the Master Boot Record
zerombr
#Partition clearing information
clearpart --all --initlabel
#Disk partitioning information
part /boot --fstype xfs --size 1024 --ondisk sda
part swap --size 2048 --ondisk sda
part / --fstype xfs --size 1 --grow --ondisk sda
#System authorization infomation
auth --useshadow --enablemd5
#Network information
$SNIPPET('network_config')
#network --bootproto=dhcp --device=eth0 --onboot=on
# Reboot after installation
reboot
#Firewall configuration
firewall --disabled
#SELinux configuration
selinux --disabled
#Do not configure XWindows
skipx

%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end

#Package install information
%packages
@base
@core
sysstat
iptraf
ntp
lrzsz
ncurses-devel
openssl-devel
zlib-devel
OpenIPMI-tools
tree
nmap
screen
wget
%end

%post
systemctl disable postfix.service
(这里可以加客户机安装的软件命令、执行的脚本等..例:yum install httpd,
systemctl stop firewalld,还可以直接改配置文件用sed -i)
%end

以下是6的配置文件:
新建:vim /var/lib/cobbler/kickstarts/centos6.cfg配置文件


auth --useshadow --enablemd5
bootloader --location=mbr

clearpart --all --initlabel

part /boot --fstype ext4 --size 1024 --ondisk sda
part swap --size=1500
part / --fstype ext4 --size 1 --grow --ondisk sda


text

firewall --disable

firstboot --disable

keyboard us

lang en_US

url --url=$tree

$yum_repo_stanza

$SNIPPET('network_config')

reboot

rootpw --iscrypted $default_password_crypted

selinux --disabled

skipx

timezone Asia/Shanghai

install

zerombr

%packages
@base
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet

%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
$SNIPPET('pre_anamon')
%post
%end

查看配置
cobbler profile list
cobbler profile report

修改kickstart文件位置(改原有的位置,name不能改,只能改指定配置文件,但可以删除)
[root@cobbler ~]# cobbler profile edit --name=centos7-x86_64 \
--distro=centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7-1.cfg

删除默认的profile配置
[root@cobbler ~]# cobbler profile remove --name="centos7-x86_64"

添加新的profile配置, 并指定kickstart应答文件位置
[root@cobbler ~]# cobbler profile add --name=centos7 \
--distro=centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg



//3.验证kickstart配置文件有效性,所有ok才行
cobbler validateks


3.由于 CentOS7 系统网卡名是 eno... ,为了统一标准, 修改为常用 eth0 管理
注意是 CentOS7 才需要下面的步骤 CentOS6 不需要。

//1.修改centos7系统profile安装时的内核(name要和上面对应不能有错)
cobbler profile edit --name=centos7 --kopts='net.ifnames=0 biosdevname=0'

//2.在kickstart配置文件中添加内核参数[推荐,可不设置这项]
bootloader --location=mbr --append="net.ifnames=0 biosdevname=0"

4.客户端网卡启动就行了,装完系统登陆root  密码Bgx123.com(上面设置的密码一样)
如果客户机出现:
/sbin/dmsquash-live-root/sbin/dmsquash-live-root: line 286: printf: write error:
 No space left on device因为内存不足2G的原因
 ----------------------客户机重装系统:-------------------------------

 1.客户端安装 koan
//下载当前系统对应的epel源(Centos7,阿里云)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

//安装koan
yum install -y koan

2.指定对应 profile 重装操作系统
//客户端列列出`Cobbler Server`端存在的`profile`
[root@localhost ~]# koan --server=192.168.56.11 --list=profiles

//选择对应配置即可
koan --replace-self --server=192.168.56.11 --profile=centos7-x86_64

4、重启客户端, 客户端⾃自动进入重装
reboot
----------客户端在装完系统时自动装上yum仓库----------
5.Cobbler自定义仓库(在cobbler服务器上先把网上的阿里云下载下来本地,然后客户机从
cobbler服务器下载)

先看查cobbler profile report看下repos对应行是空的

1.添加 repo
cobbler repo add --name=openstack-n-centos7 \
--mirror=https://mirrors.aliyun.com/centos/7.4.1708/cloud/x86_64/  \
--arch=x86_64 --breed=yum

查看:上面添加的:cobbler repo list

删除: cobbler repo remove --name=openstack-n-centos7
改名字:cobbler repo rename --name=openstack-n-centos7  --newname=zabbix-centos7

cobbler repo回车可以看到很多选项

//或者同步本地仓库
[root@cobbler ~]# cobbler repo add --name=local-ftp-base \
--mirror=ftp://192.168.56.11/centos7/base/

2.同步 repo把上面定义的阿里yum源下载到本地:/var/www/cobbler/repo_mirror/下面
[root@cobbler ~]# cobbler reposync

3.添加 repo 到对应的 profile
//http协议
[root@cobbler ~]# cobbler profile edit --name=centos7 --repos=zabbix-centos7

//本地ftp
[root@cobbler ~]# cobbler profile edit --name=centos7-x86_64 --repos=local-ftp-base

4.修改 kickstart 文件:/var/lib/cobbler/kickstarts/centos7.cfg (添加到 %post %end 中间)
%post
systemctl disable postfix.service
$yum_config_stanza
%end

cobbler reposync

cobbler sync

查看本地yum源:http://192.168.110.3/cobbler/repo_mirror/ 打开就能看到

5.添加定时任务, 定期同步 repo
echo "00 3 * * * /usr/bin/cobbler reposync --tries=3 --no-fail" >> /var/spool/cron/root
------------------------自动安装系统不用开始选择回车------------------------
由于 kickstart 指定某台服务器使用某个具体的 ks 文件比较复杂,所以引用 Cobbler 就变得非
常的简单。通过物理MAC地址来区分。
Cobbler system 主要目的配置网络接口, 通过 system 指定服务器MAC 地址来固定机器的IP、掩
码、网关、DNS、主机名等实现基础环境的标准化

先得到客户机的MAC地址:
 
规划配置如下:
MAC:00:0C:29:6E:41:CB
IP地址:192.168.56.12
掩码:255.255.255.0
网关:192.168.56.2
DNS: 192.168.56.2
主机名:linux-node2.com

cobbler system回车看到好多指令

//Cobbler具体指令(name=这里最好用要安装系统的计算机名,\
因为每一个主机要执行下面一次命令)
[root@cobbler ~]# cobbler system add --name=linux-node2.com \
--mac=00:0C:29:6E:41:CB \
--profile=Centos-7-x86_64 \
--ip-address=192.168.56.12 \
--subnet=255.255.255.0 \
--gateway=192.168.56.2\
--interface=eth0 \
--static=1 \
--hostname=linux-node2.com \
--name-servers="192.168.56.2"

多台主机添加可以用脚本如下(提前准备好计算机名、ip地址、mac列表:cobbler_file.txt)
使用脚本⾃自动化添加 system
[root@Cobbler ~]# cat cobbler_auto.sh
#!/usr/bin/bash
master="centos7-salt-zabbix-master"
minion="centos7-salt-zabbix-minion"

netmask="255.255.255.0"
gateway="192.168.70.254"
interface=eth0
dns=211.161.122.200

while read line
do
	len1=$(echo $line|awk '{print $1}')
	len2=$(echo $line|awk '{print $2}')
	len3=$(echo $line|awk '{print $3}')
cobbler system add \
--name="$len1" \
--mac="$len3" \
--profile="$minion" \
--ip-address=$len2 \
--subnet=$net \
--gateway=$gate \
--interface=$interface \
--static=1 \
--hostname=$len1 \
--name-servers=$dns

done<cobbler_file.txt



//同步配置信息
[root@cobbler ~]# cobbler sync

查看
[root@cobbler ~]# cobbler system list
linux-node2.com

客户机的配置信息可以在服务器上看:
cat /etc/dchp/dhcpd.conf
----------------------------------------------------------------------

你可能感兴趣的:(linux,linux)