Cobbler自动装机

一、Cobbler概述

​ Cobbler是一个使用Python开发的开源项目,通过部署系统所涉及的所有服务集中在一起,来提供一个全自动批量快速建立Linux系统的网络安装环境,Cobbler最初支持Fedora、Redhat和衍生版(如centos和scientific Linux),现在还支持Debian、Ubuntu、SUSE以及FreeBSD、ESXI等。cobbler的诞生,使得Linux网络安装系统更加简单方便。

​ Cobbler提供了DHCP管理、YUM源管理、电源管理等功能,除此之外还支持命令行管理、WEB界面管理、并且提供了API接口,方便进行二次开发。

二、安装Cobbler环境

网络环境准备

1-把虚拟机网络编辑器里的dhcp关掉

2-手动配置IP 192.168.139.131 子网掩码 255.255.255.0 ;网关和DNS配置能正确上网的

1、搭建本地源和扩展源
#mount /dev/sr0 /mnt/cdrom
#vim /etc/yum.repos.d/local.repo
[local]
name=local
enabled=1
gpgcheck=0
baseurl=file:///mnt/cdrom

[epel]
name=epel
enabled=1
gpgcheck=0
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/


[centos]
name=centos base
enabled=1
gpgcheck=0
baseurl=http://mirrors.163.com/centos/7/os/x86_64/
2、安装Cobbler以及其相关服务软件包
#yum install cobbler dhcp tftp-server xinetd syslinux httpd -y
3、启动相关服务
#systemctl stop firewalld
#setenforce 0
#systemctl start cobblerd.service
#systemctl start xinetd
#systemctl start tftp
#systemctl start httpd
4、检查cobbler配置
# systemctl restart cobblerd
# systemctl restart xinetd
# systemctl start tftp
# systemctl start httpd
# cobbler check

三、配置cobbler服务

1、修改cobbler主配置文件
#vim /etc/cobbler/settings
//把next_server和server修改成主机ip
    server:192.168.75.131
    netxt_server:192.168.75.131
	manage_rsync:1   //允许rsync--允许同步
	manage_dhcp:1    //允许dhcp访问
2、配置TFTP和Rsync
#vim /etc/xinetd.d/tftp
	disable          no
3、设置cobbler用户初始密码
#yum -y install pykickstart 

# openssl passwd -1 "123" "123456"
    $1$JkWSEjeV$scLwoJfMTNTBoRsOMylCn.  ---123的加密
    $1$GqJ.LT3/$eSKbbzOfwL07BDTWfQ.7F0  ---123456的加密

# vim /etc/cobbler/settings
    dfault_password_crypted: "$1$JkWSEjeV$scLwoJfMTNTBoRsOMylCn."
4、安装cman启动电源管理功能
yum install fence-agent
5、检查cobbler配置:
#systemctl restart cobblerd.service
#systemctl restart xinetd
#systemctl restart tftp
#systemctl restart httpd
#cobbler sync 
#cobbler check
6、配置DHCP服务
vim /etc/dhcp/dhcpd.conf
subnet 192.168.75.0 netmask 255.255.255.0 {
    option routers       192.168.75.2;
    option domain-name-servers 192.168.75.2;
    option subnet-mask     255.255.255.0;
    range dynamic-bootp     192.168.75.10 192.168.75.100;
    default-lease-time     21600;
    max-lease-time       43200;
    next-server         192.168.75.131;
}

# systemctl start dhcpd

//检查/etc/cobbler/dhcp.template的IP和dhcpd.conf一致

# vim /etc/cobbler/dhcp.template
//将里面的subnet替换成如下:
subnet 192.168.75.0 netmask 255.255.255.0 {
    option routers       192.168.75.2;
    option domain-name-servers 192.168.75.2;
    option subnet-mask     255.255.255.0;
    range dynamic-bootp     192.168.75.10 192.168.75.100;
    default-lease-time     21600;
    max-lease-time       43200;
    next-server         192.168.75.131;
    
#cobbler sync //同步
#systemctl restart cobblerd
#systemctl restart dhcpd
7、导入ISO镜像

使用cobbler的import命令从IOS安装镜像中导入安装所需要的程序包。

命令格式:

# cobbler import --path=镜像路径 --name=安装引导名 --arch=32位或64位
  参数说明:
   --path  表示镜像所挂载的目录
   --name  表示为安装源定义的名字
   --arch  表示指定安装源是32位、64位、ia64,目前支持的选项有:x86|x86_6|ia6
	Cobbler会将镜像中的所有安装文件拷贝到本地一份,放在/var/www/cobbler/ks_mirrors下的centos7-x86_64目录下。同时会创建一个名字为centos7-x86_64的发布版本,以及一个名字为centos7-x86_64的profile文件。
其中:
distro  表示一个发行版,标记一个发行版的最关键源是kernel和ramdisk
profile 表示kickstart配置文件

导入ISO镜像

# cobbler import --path=/mnt/cdrom --name=centos7 --arch=x86_64
8、cobbler管理distro和profile的相关命令
#cobbler list   查看镜像导入结果
#cobbler distro list 查看cobbler提供可安装的OS发行版
#cobbler profile find --distro=centos7-x86_64  查看配置是否存在
#cobbler distro remove --name=centos7-x86_64  删除distro
#cobbler profile remove --name=centos7-x86_64 删除配置文件

此时TFTP服务器的共享目录也了启动Linux所需文件,因为从OS安装光盘导入时,同时会把内核vmlinuz和initrd.img复制到tft pserver共享目录下。

9、测试安装
1-打开客户机,选择centos7-x86_64启动;
2-安装完成后在蓝色界面选择local启动;
3-输入之前配置的加密密码用root用户登录;
10、导入kickstart文件

安装OS时,会自动在/root目录下生成以.cfg结尾的文件,这就是kickstart自动应答文件。该文件保存了安装OS时配置的所有参数。cobbler引导文件会把默认的ks文件作为参数传递给内核。

cobbler默认的ks文件位置在/var/lib/cobbler/kickstarts/sample.ks。

cobbler还可以自定义ks文件,命令格式如下:

# cobbler profile add --name=list名 --distro=镜像 --kickstart=路径
参数说明:
--name  表示添加的ks的名字,用cobbler report可以看到这个名字。
--distro  是用哪个镜像,list的distros里面选择一个,需要版本相对应。
--kickstart  是具体的ks文件路径

需要注意:
(1)kickstart自动应答文件需要预先配置好
(2)每次修改完配置文件,需要执行一次同步操作:cobbler sync配置才能生效。
(3)自动应答文件可以使用kikstart图形工具生成(软件包:system-config-kickstart)
11、使用koan重装系统

​ koan是cobbler的一个辅助工具,安装在客户端的使用,为kickstart over a network的缩写,配合cobbler实现快速重装Linux系统。

koan的相关脚本在/usr/lib/python/2.6/site-packages/koan目录内。

通过epel源在重装机器上安装koan

#yum install koan

列出远程cobbler服务器上的系统版本对象

#koan --server=192.168.75.131 --list=proiles  

列出更多关于远程cobbler对象的信息

#koan --server=192.168.75.131 --display --profile=centos7-x86_64  

重新安装客户端系统

#koan -r -server=192.168.75.131 --profile=centos7-x86_64

输入以上命令重启后,不能再终止重装,重启后自动进行PXE装机界面。

#reboot
12、yum仓库管理

cobbler可以对yum仓库进行管理,在cobbler服务器上添加yum仓库信息,安装客户端系统之后会自动配置yum仓库,方便客户商系统直接使用。

在定义YUM仓库时,首先需要添加镜像源,比如,使用163的base、updates库以及epel源定义repo源。

# cobbler repo add --name=CentOS6.5-x86_64-Base --mirror=http://mirrors.163.com/centos/6/os/x86_64/ --arch=x86_64 --breed=yum

# cobbler repo add --name=CentOS6.5-x86_64-updates --mirror=http://mirrors.163.com/centos/6/updates/x86_64/ --arch=x86_64 --breed=yum

# cobbler repo add --name=epel6-x86_64 --mirror=http://mirrors.ustc.edu.cn/epel/6/x86_64/ --arch=x86_64 --breed=yum

还可以修改已经定义好的仓库库信息,如对定义的仓库名进行修改。

# cobbler repo edit --name=CentOS6.5-x86_64-base --mirror=http://mirrors.163.com/centos/6/os/x86_64 --arch=x86_64 --breed=yum

删除镜像源

# cobbler repo remove --name=CentOS6.5-x86_64-updates

同步YUM仓库内容到本地。需要注意的是同步时间较长,需有足够的磁盘空间。

# cobbler reposyn

将repo添加到profile安装系统时会自动添加仓库配置

# cobbler profile edit --name=centos6.5-x86_64 --repos=”CentOS6.5-x86_64-base epel-x86_64” --distro=centos6.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/sample.ks

添加更新仓库源的任务计划,如每周日更新一次。确保crond服务启动,并设置为开机自动启动。

# crontab -e
0 0 * 0 /usr/bin/cobbler reposync --tries=3 --no-fail &>/dev/null
# /etc/init.d/crond statu
# chkconfig crond on

如果想安装系统时自动配置YUM仓库,需要确保Cobbler主配置文件中有如下配置:

#vim /etc/cobbler/settings
	yum_post_install_mirror:1

在装机脚本ks文件加入以下内容:

%pos
t$yum_config_stanza  //PXE装机系统会引用添加的cobbler repo配置

客户端系统自动配置的YUM仓库文件为/etc/yum.repos.d/cobbler-config.repo

补充:Cobbler命令小结,如表所示:

命令名称命令用途
cobbler check检查Cobbler配置
cobbler list列出所有的Cobbler元素
cobbler report列出元素的详细信息
cobbler distro查看导入的发行版本系统信息
cobbler profile查看配置信息
cobbler sync同步 Cobbler 配置,更改配置后最好都执行下
cobbler reposync同步 YUM仓

四、PXE菜单管理

为了增强装机安全可以设置PXE菜单和密码

(1)生成hash密码
# openssl passwd -1 -salt cobbler 123456   #注 此处的-1 是123的1
 $1$cobble r$sqDD0BeLKJVmxTCZr52/ 1
(2)编辑配置文件pxedefault,添加密码信息
# vim /etc/cobbler/pxe/pxedefault.template
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
MENU MASTER PASSWD $1$cobble r$sqDD0BeLKJVmxTCZr52/11 #复制上面的密码信息
MENU TITLE Cobbler | Welcome Lying's com  自定义TITLE
TIMEOUT 200
TOTALTIMEUT 6000
(3)编辑配置文件pxeprofile,添加加密菜单和标题
# vim /etc/cobbler/pxe/pxeprofile.template 
LABEL $profile_name
    MENU PASSWD  添加密码菜单
    kernel $kernel_path
    $menu_label
    $append_line
    ipappend 2
(4)同步配置
#cobbler sync
#systemctl restart cobblerd
(5)客户端验证
在蓝色界面选择contos7-x86_64选项,输入密码,登录即可

五、Cobbler的WEB管理

Cobbler Web界面是一个非常友好的前端,用Web界面管理Cobbler是一个非常简便的方法,只需要安装cobbler_web软件包即可。

使用它可以添加/删除distro、profile,还可以查看与编辑distros、profiles、repos、kickstart文件。

# yum install cobbler-web  -y
# systemctl restart cobbled
1、设置cobbler web登录密码

Cobbler web支持多种认证方式:authn_confile、authn_ldap或authn_pam等。

(1)使用authn_confile模块认证方式
Cobbler web界面的身份验证和授权配置位于文件/etc/cobbler/modules.conf中。
[authentication]
module = authn_configfile    使用/etc/cobbler/users.digest文件
[authorization]
module = authz_allowall    默认,所有authentication认证用户完全访问

为cobbler用户设置密码,提示输入2次密码确认。

# htdigest -c /etc/cobbler/users.digest Cobbler webuser  #webuser为登录web的用户名

Adding user cobbler in realm webuser
New password: 123456
Re-type new password:123456 
(2)使用authn_pam模块认证方式
首先修改认证方式:
#vim /etc/cobbler/modules.conf
    [authentication]
    module = authn_pam    使用pam认证方式
    [authorization]
    module = authz_ownership    可在users.conf文件中指定认证能够访问web界面

然后添加系统用户:
#useradd webuser
#passwd webuser
之后在/etc/cobbler/users.conf中,将webuser用户添加到admins组,组具有完整访问权限。
(3)同步设置重启服务
同步设置: 
# cobbler sync

重启apache和cobbler服务:
# systemctl restart httpd
# systemctl restart cobblerd
(4)web默认网址存放地
/var/www/cobbler_webui_conten
2、访问
https:192.168.139.131/cobbler_web
当报错不安全连接的时候点击允许/继续访问
使用webuser和密码123456登录 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值