回顾:
之前讲到了dhc服务,pxe的实现,cobbler的简单介绍
dhcp:是一种协议,监听在UDP67(服务端)68(客户端)端口
实现:dhcpd(isc维护,维护的还有bind),dnsmasq
dhcp包:dhcpd(ipv4,ipv6),dhcrelay(实现中继功能,通常不会同时使用)python
tftp server:tftp协议,监听在udp的69端口,通常只在本地网络中使用。
centos6和7的启动方式是不同的,6是守护进程
systemctl start tftp.socket(7)
使用xinetd来启动(6)
pxe:借助于dhcp,tftp,yum repository构建出基于网络引导的自动安装环境
通常只针对一种环境来自动安装linux
cobbler:pxe的二次封装,由python研发
distro(依赖repository)+kickstart--->profile+ip/mask--->system
使用cobbler check检测,有可能检测出不少问题,一个一个解决就能够了
问题:
关闭selinux
vim /etc/sysconfig/selinuxgit
#This file controls the state of SELinux on the system. #SELINUX= can take one of these three values; # enforcing - SELinux security policy is enfored. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=permissive---这里改成disabled,再重启服务才能生效,由于selinux是内核中的功能 #SELINUXTYPE= can take one of three two values; # targeted - Targeted processes are protected, # minimum - Modification of targeted policy.Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted distro:表示一个发行版,标记一个发行版的最关键资源是kernel:vmlinuz和ramdisk
总结:
cobbler安装完之后须要先启动cobbler服务,而后cobbler check,若是有问题,就一个一个的去修复
必需要作的是复制这两个文件
/usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/cobbler/loaders/
而后cobbler sync作一次同步,此时cobbler就可使用了
做用:
管理distro:
cobbler distro {list|add|remove|edit|rename}
管理profile:
cobbler profile {list|add|remove|edit|rename}
同步:
cobbler syncgithub
cobbler-web
Django
http://host/cobbler_web/web
执行"cobbler check"命令检查存在的 问题,然后逐一按提示解决之。常见的问题以下所示:
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 wille use it.
2:For PXE to be functional,the 'next_server' field in /etc/cobbler/settings must be set to someting other than 127.0.0.1,and should match the IP of the boot server on the PXE network.
3: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 an 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.
4:change 'disable' to 'no' in /etc/xinetd.d/rsync
5:comment 'dists' on /etc/debmirror.conf for proper debian support
6:comment 'arches' on /etc/debmirror.conf for proper debian support
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 themredis
Restart cobblerd and then run 'cobbler sync' to apply changes.django
如上各问题的解决方法以下所示:
一、修改/etc/cobbler/settings文件中的server参数的值为提供cobbler服务的主机相应的IP地址或主机名,如:172.16.100.15;
二、修改/etc/cobbler/settings文件中的next_server参数的值为提供PXE服务的主机相应的IP地址,如172.16.100.16;
三、若是当前节点能够访问互联网,执行"cobbler get-loaders"命令便可;不然,须要安装syslinux程序包,然后复制/usr/share/syslinux/{pxelinux.0,menu.c32}等文件至/var/lib/cobbler/loaders/目录中;---最好是复制全部的文件
四、执行"chkconfig rsync on"命令便可;br/>五、注释/etc/debmirror.conf文件中的"@dists="sid";"一行;---对于centos7而言,这个文件是不存在的,能够直接忽略
六、注释/etc/debmirror.conf文件中的"@arches="i386";"一行;
七、执行"openssl passwd -1 -salt $(openssl rand -hex 4)"生成密码,并用其替换/etc/cobbler/settings文件中default_password_crypted参数的值;
八、执行"yum install cman fence-agents"命令安装相应的程序包便可;---这是高可用集群中用到的组件vim
接着重启cobblerd,然后执行"cobbler sync"同步新的配置至cobbler。centos
2、配置及启动cobbler所依赖的各服务
cobbler的运行以来与dhcp、tftp、rsync及dns(并不是必须)服务。其中dhcp可由dhcpd(isc)提供,也可由dnsmasq提供;tftp可由tftp-server程序包提供,也可由cobbler自带的tftp功能提供;rsync由rsync程序包提供;dns可由bind提供,也可由dnsmasq提供。
cobbler可自行管理这些服务中部分甚至是所有,但须要配置/etc/cobbler/settings文件中的"manage_dhcp"、"manage_tftpd"、"manage_rsync"和"manage_dns"分别进行定义,另外,因为每种服务都有着不一样的实现方式,如若须要进行自定义,须要经过修改/etc/cobbler/modules.conf配置文件中各服务的模块参数的值来实现。
本文采用了独立管理的方式,即不经过cobbler来管理这些服务。
2.1配置dhcp服务
定义好所需的"subnet"及其它参数或选项,然后启动dhcpd守护进程便可。本示例中所用的dhcpd的配置以下所示:
option domain-name "magedu.com";
option domain-name-server 192.168.10.254,172.16.0.1;浏览器
default-lease-time 43200;
max-lease-time 86400;
log-facility local7;
subnet 172.16.0.0 netmask 255.255.0.0 {
range 172.16.100.121 172.16.100200;
option routers 172.16.100.7;
}
next-server 172.16.100.7;
filename="pxelinux.0";
接着使用"service dhcpd start"启动服务便可。
2.2配置tftp服务
#chkconfig tftp on
#service xinetd restart
3、配置cobbler
cobbler的各主要组件间的关系以下图所示。
3.1管理distro
使cobbler变得可用的第一步为定义distro,其能够经过为其指定外部的安装引导内核及ramdisk文件的方式实现。而若是已经有完整的系统安装树(如centos6的安装镜像)则推荐使用import直接导入的方式进行。
例如,对于已经挂载至/media/cdrom目录的Centos 6.5 x86_64的安装镜像,则可使用相似以下命令进行导入。
#cobbler import --name=centos-6.5-x86_64 --path=/meida/cdrom
可以使用"cobbler distro list"列出全部的distro。
若是有kickstart文件,也可使用"--kickstart=/path/to/kickstart_file"进行导入,所以import会自动为导入的distro生成一个profile。
3.2管理profile
cobbler使用profile来为特定的需求类别提供所须要安装配置,即在distro的基础上经过提供kickstart文件来生成一个特定的系统安装配置,distro的profile能够出如今PXE的引导菜单中做为安装的选择之一。
所以,若是须要为前面建立的centos-6.5-x86_64这个distro提供一个可引导安装条目,其用到的kickstart文件为/tmp/centos-6.5-x86_64.cfg(只提供了最基本的程序包),则可经过以下命令实现。
#cobbler profile add --name=centos-6.5-x86_64-basic --distro=centos-6.5-x86_64 --kickstart=/tmp/centos-6.5-x86_64.cfg
可以使用"cobbler profile list"查看已经建立的profile。
4、使用cobbler_web
4.1配置cobbler_web的认证功能
cobbler_web支持多种认证方式,如authn_configfile、anthn_ldap或authn_pam(基于操做系统用户)等,默认为authn_denyall,即拒绝全部用户登陆。下面说明两种能认证用户登陆cobbler_web的方式。
4.1.1使用authn_pam模块认证cobbler_web用户
首先修改modules中[authentication]段的module参数的值为authn_pam。
接着添加系统用户,用户名和密码按需设定便可,例以下面的命令所示。
#useradd cblradmin
#echo 'cblrpass' | passwd --stdim cblradmin
演示:
三、
ls /usr/share/syslinux/
cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/cobbler/loaders/
systemctl restart cobblerd.service
cobbler check---检查一下
cobbler sync---作一次同步操做
而后就应该没有什么问题了
vim /etc/cobbler/settings---去找到manage关键词,查看使用的是什么方式来管理dhcp、tftp、dns等服务
manage_dhcp:0---0表示不适用cobbler来管理
manage_dns:0
manage_tftpd:1
manage_rsync:0---只要确保rsync服务是启动就能够systemctl status rsyncd.socket
演示:讲解cobbler import命令
已经挂载光盘,导入操做会把光盘上全部文件所有复制到当前文件系统中,因此要确保磁盘空间够用。会复制到/var/www/下,会在这里自动建立一个cobbler目录以及cobbler/ks_mirror/
ls /media/cdrom
df -lh---查看磁盘空间
cobbler import --name="CentOS-7_x86_64-1503" --path=/media/cdrom---这样就会开始导入
cobbler distro list---列出全部的distro
cobbler profile list---导入之后会自动建立一个distro,而且还会建立一个同名的profile,只不过这个profile没有kickstart文件,因此没办法实现自动安装。
cobbler sync---若是要肯定使用,就同步一下。
systemctl restart cobblerd.service---为了万无一失,重启下服务
而后要确保这台主机的dhcp服务开启
systemctl start dhcpd.service
而后网段中的其余主机就会自动获取到一个安装菜单,第一项local(表示从本地硬盘启动),第二项CentOS-7-1503-x86_64(本身定义的,此时没有kickstart文件,可是cobbler会自动提供默认的kickstart文件)
若是想给上边生成的distro更名字,须要用到编辑命令
cobbler profile edit --help查看如何使用
cobbler profile list
CentOS-7-1503-x86_64
cobbler profile rename --name=CentOS-7-1503-x86_64 --newname=CentOS-7-1503-x86_64-minimal
cobbler profile list---更名成功
CentOS-7-1503-x86_64-minimal
vim centos7.conf---修改kickstart文件
install
xconfig --startxonboot
keyboard --vckeymap=cn --xlayouts='cn'
reboot
rootpw --iscrypted $1$HDHf2v4i$LMo.xGHfxQDO43c.g/
timezone Asia/Shanghai
url --url="http://172.16.100.67/cobbler/ks_mirror/CentOS-7_x86_64-1503/"---这里改成导入光盘的路径
lang zh_CN
user --groups=wheel --name=mageedu --password=$6$1eW$..... --iscrypted --gecos="MageEdu"
firewall --disabled
network --bootproto=dhcp
auth --useshadow --passalgo=sha512
text
firstboot --disable
selinux --permissive
ignoredisk --only-use=sda
bootloader --location=mbr --boot-drive=sda
zerombr
clearpart --all --initlabel
part /boot --asprimary --fstype="xfs" --size=512
part swap --fstype="swap" --size=2048
part /usr --fstype="xfs" --size=20480
part / --fstype="xfs" --size=20480
%packagesbr/>@base
@core
lftp
screen
wget
tree
cp centos7.cfg /var/lib/cobbler/kickstarts/---先把kickstart文件复制到这里
cobbler profile add --name=CentOS-7-x86_64-1503-server --distro=CentOS-7-1503-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg
cobbler profile list---能够看到如今就有了两个,都是基于同一个发行版,可是使用不一样的kikstart文件,安装出来不一样的系统环境
CentOS-7-1503-x86_64-minimal
CentOS-7-x86_64-1503-server
cobbler sync---每一次修改完成后都须要同步一下,这个同步操做实际上是在/var/lib/tftpboot/pxelinux.cfg/下生成default文件
vim default
DEFAULT
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.com---这里是能够本身修改的,改为本身想要的名称
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local
LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT -1
LABEL CentOS-7-1503-x86_64-minimal
kernel /images/CentOS-7-103-x86_64/vmlinuz
MENU LABEL CentOS-7-1503-x86_64-minimal
append initrd=/images/CentOS-7-1503-x86_64/initrd.img ksdevice=bootif lang= kssendmac text
ks=http://172.16.100.67/cblr/svc/op/ks/profile/CentOS-7-1503-x86_64-minimal
ipappend 2
LABEL CentOS-7-x86_64-1503-server
kernel /images/CentOS-7-1503-x86_64/vmlinuz
MENU LABEL CentOS-7-x86_64-1503-server
append initrd=/images/CentOS-7-1503-x86_64/initrd.img ksdevice=bootif lang= kssendmac text
ks=http://172.16.100.67/cblr/svc/op/ks/profile/CentOS-7-x86_64-1503-server
ipappen 2
MENU end
而后客户端就能够启动了,自动从cobbler服务器获取地址并自动安装
安装过程当中视频里出现了问题,是kickstart文件指定要从光盘安装
vim /var/lib/cobbler/kickstarts/centos7.cfg
视频中未找到问题缘由,忽略便可
下面讲解的是在centos7的cobbler环境下部署centos6系统
umount /media/cdrom---卸载光盘,卸载以前的centos7系统
mount -r /dev/cdrom /media/cdrom---挂载centos6系统
cobbler import --name=CentOS-6-x86_64 --path=/media/cdrom---cobbler依然会提供centos6的最小化安装,依然会导入/var/www/cobbler/ks_mirror/下
cobbler distro list---导入完成才会显示
CentOS-6-x86_64
CentOS-7-1503-x86_64
cobbler profile list
CentOS-6-x86_64---自动帮你生成最小化安装的profile
CentOS-7-1503-x86_64-minimal
CentOS-7-x86_64-1503-server
cobbler sync
而后讲解cobbler-web
确保如下服务开启
systemctl start dhcpd.service
systemctl start tftp.socket
systemctl start rsyncd.socket
systemctl start cobblerd.service
systemctl start httpd.service
yum info cobbler-web---属于epel源,用python-django(web框架)研发的
yum install cobbler-web
vim /etc/cobbler/modules.conf
[authentication]---认证
mocule = anth_configfile
[authorization]---受权
module = authz_allowall---容许全部人访问
[dns]
module = manage_bind
[dhcp]
module=manage_isc
htdigest -h---仍然有httpd提供
htdigest -c /etc/cobbler/users.digest Cobbler cblradmin(用户名)---会出现一个交互式命令行,输入密码便可
systemctl restart cobblerd.service---因为是新的定义,因此须要重启cobbler服务而后使用浏览器访问172.16.100.67/cobbler_web便可看到页面