cobbler自动装机服务简介与配置

cobbler简介

Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。

Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。

Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。

Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。

Cobbler官网

cobbler集成的服务

  • PXE服务支持
  • DHCP服务管理
  • DNS服务管理(可选bind,dnsmasq)
  • 电源管理
  • Kickstart服务支持
  • YUM仓库管理
  • TFTP(PXE启动时需要)
  • Apache(提供kickstart的安装源,并提供定制化的kickstart配置)

cobbler配置文件详解
cobbler配置文件目录在/etc/cobbler

配置文件 作用
/etc/cobbler/settings cobbler 主配置文件
/etc/cobbler/iso/ iso模板配置文件
/etc/cobbler/pxe pxe模板配置文件
/etc/cobbler/power 电源配置文件
/etc/cobbler/user.conf web服务授权配置文件
/etc/cobbler/users.digest web访问的用户名密码配置文件
/etc/cobbler/dhcp.template dhcp服务器的的配置模板
/etc/cobbler/dnsmasq.template dns服务器的配置模板
/etc/cobbler/tftpd.template tftp服务的配置模板
/etc/cobbler/modules.conf 模块的配置文件

cobbler数据目录

目录 作用
/var/lib/cobbler/config/ 用于存放distros,system,profiles等信息配置文件
/var/lib/cobbler/triggers/ 用于存放用户定义的cobbler命令
/var/lib/cobbler/kickstart/ 默认存放kickstart文件
/var/lib/cobbler/loaders/ 存放各种引导程序以及镜像目录
/var/www/cobbler/ks_mirror/ 导入的发行版系统的所有数据
/var/www/cobbler/images/ 导入发行版的kernel和initrd镜像用于远程网络启动
/var/www/cobbler/repo_mirror/ yum仓库存储目录

cobbler日志文件

日志文件路径 说明
/var/log/cobbler/installing 客户端安装日志
/var/log/cobbler/cobbler.log cobbler日志

cobbler命令详解

cobbler check       #核对当前设置是否有问题
cobbler list        #列出所有的cobbler元素
cobbler report      #列出元素的详细信息
cobbler sync        #同步配置到数据目录,更改配置最好都要执行下
cobbler reposync    #同步yum仓库
cobbler distro      #查看导入的发行版系统信息
cobbler system      #查看添加的系统信息
cobbler profile     #查看配置信息

cobbler服务端部署

#配置yum源
[root@Lynk ~]# curl -o /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1572  100  1572    0     0  22258      0 --:--:-- --:--:-- --:--:-- 22457
[root@Lynk ~]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@Lynk ~]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@Lynk ~]# yum -y install epel-release

#安装cobbler及所需的环境
[root@Lynk ~]# yum -y install httpd dhcp tftp python-ctypes cobbler  xinetd cobbler-web pykickstart

#启动服务
[root@Lynk ~]# systemctl start httpd
[root@Lynk ~]# systemctl start cobblerd
[root@Lynk ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@Lynk ~]# systemctl enable cobblerd
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.

#修改配置文件
[root@Lynk ~]# vim /etc/cobbler/settings
#将serve项改成母机IP
server: 192.168.83.128
#设置tftp项为母机IP
next_server: 192.168.83.128
#开启ftp
[root@Lynk ~]# vim /etc/xinetd.d/tftp

        disable                 = no

#查看并修改Selinux状态为disable
[root@Lynk ~]# getenforce 
Enforcing
[root@Lynk ~]# vim /etc/sysconfig/selinux
SELINUX=disabled
#注意结尾的d不要忘了
#如果修改了配置文件,请重启服务器

#下载缺失文件
[root@Lynk ~]# cobbler get-loaders

#启动rsync
[root@Lynk ~]# systemctl start rsyncd
[root@Lynk ~]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.

#生成加密的密码
[root@Lynk ~]# openssl passwd -1 -salt "$RANDOM" 'lynk123'
$1$28735$sQyE0UCiD2uexfkbZMmIN1
#将密码加入配置文件
[root@Lynk ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$28735$sQyE0UCiD2uexfkbZMmIN1"
[root@Lynk ~]# systemctl restart cobblerd

#检查配置有没有问题
[root@Lynk ~]# cobbler check
#以下两条可以忽略
1 : debmirror package is not installed, it will be required to manage debian deployments and repositories
2 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them


#让cobbler接管dhcp
[root@Lynk ~]# vim /etc/cobbler/settings
manage_dhcp: 1

#配置dhcp
[root@Lynk ~]# vim /etc/cobbler/dhcp.template
#我的是这样的,请根据自己的需求和情况修改
subnet 192.168.83.0 netmask 255.255.255.0 {
     option routers             192.168.83.128;
     option domain-name-servers 8.8.8.8;                         #安装完成后子机的DNS
     option subnet-mask         255.255.255.0;                   #子网掩码
     range dynamic-bootp        192.168.83.100 192.168.83.254;   #分配地址的范围
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;

#重启服务
[root@Lynk ~]# systemctl restart cobblerd

#同步配置
[root@Lynk ~]# cobbler sync

#检查DHCP服务状态
[root@Lynk ~]# netstat -anulp|grep dhcp
udp        0      0 0.0.0.0:67              0.0.0.0:*                           1241/dhcpd    

#导入CentOS7镜像
[root@Lynk ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@Lynk ~]# cobbler import --path=/mnt --name=centos-7 --arch=x86_64
#说明:
    --path      #镜像路径
    --name      #为安装源定义一个名字
    --arch      #指定安装源平台
[root@Lynk ~]# cobbler list
distros:
   centos-7-x86_64

profiles:
   centos-7-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

#编写kickstarts自动安装脚本
[root@Lynk ~]# cat > /var/lib/cobbler/kickstarts/centos-7-x86_64.ks <<EOF
auth --enableshadow --passalgo=sha512
bootloader --location=mbr
clearpart --all --initlabel
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=4096
part / --fstype="ext4" --grow --size=15000
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
url --url=http://192.168.83.128/cobbler/ks_mirror/centos-7-x86_64         #注意这里改成自己的IP和系统
$yum_repo_stanza
reboot

rootpw --iscrypted $6$TqHk0ra46PiN9O2$8WlC8wzl8HjlQ8XEbh45Y6Wm9ezqi1gipMLjHhhcSUEbmQvepmeQeMjTeSIxhX3bD7WaTJSQPHySP0eskFg831
       #这里的后面一串内容要改成自己当前系统的密码,可以在anaconda-ks.cfg中相应的部分找到

selinux --disabled
skipx
timezone Asia/Shanghai --isUtc --nontp
install
zerombr

%packages
@^minimal
@core
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
EOF

#检查ks脚本有没有错误
[root@Lynk ~]# cobbler validateks
*** all kickstarts seem to be ok ***
*** TASK COMPLETE ***
#看到以上内容代表没有问题

#查看cobbler配置文件列表
[root@Lynk ~]# cobbler profile list
   centos-7-x86_64

#将新建的ks设为默认的ks脚本
[root@Lynk ~]# cobbler profile edit --name centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-7-x86_64.ks
#配置网卡名称为传统名称(eth0)
[root@Lynk ~]# cobbler profile edit --name centos-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'

#查看当前系统cobbler配置文件信息
[root@Lynk ~]# cobbler profile report
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/centos-7-x86_64.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

#同步cobbler
[root@Lynk ~]# cobbler sync

#重启服务并关闭防火墙
[root@Lynk ~]# systemctl restart xinetd
[root@Lynk  ~]# systemctl restart cobblerd
[root@Lynk  ~]# systemctl restart httpd
[root@Lynk ~]# systemctl stop firewalld

验证配置

注意,如果安装虚拟机,请至少分配2G内存
新建一个没有任何系统的虚拟机
如果如图所示,代表cobbler配制成功

猜你喜欢

转载自www.cnblogs.com/lynk/p/10480685.html