cobbler原理知识介绍
distribution:指定发行版本,pxe只能为一个发行版提供一个安装场景(使用kickstart的情况下)
这是cobbler的最核心组件
定义distribution是为指明某个发行版的内核(kernel)和ramdisk文件(initrd),从而确定是哪个版本,安装启动之后,能找到后面的仓库repository,下载后面要完成安装的各个组件
通过distribution和repository定义profile,指明系统的版本,指定安装需要的包的URL,然后,通过kickstart文件,实现自动化安装,每个kickstart不同,安装的包都是不同的
注意:kickstart一变化,我们的profile就是一个新的样式
安装cobbler程序
[root@localhost ~]# yum install cobbler
如果是干净的CentOS6.5操作系统,它会自动解决依赖关系,包括syslinux,createrepo,tftp,xinetd还有一些系列的python包,因为系统自带httpd了,httpd也是其依赖包
启动cobbler服务,并进行初始化
[root@localhost ~]# service httpd start
[root@localhost ~]# service cobblerd start
此时安装的cobbler还有一些问题,我们可以使用cobbler的check命令查看,并且修改一些选项
[root@localhost ~]# cobbler check
The following are potential configuration items that you may want to fix:
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 will use it.
#cobbler中的server不能指定localhost,要指定当前主机的IP地址
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
#需要将next_server的地址该为网络中的地址,而不是当前主机(127.0.0.1)
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 and 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.
#缺少启动的选项,如果在能连接到互联网的状况下,可以使用cobbler get-loaders解决,如果不能联网,则可以将syslinux生成的包中的文件拷贝过来
4 : change 'disable' to 'no' in /etc/xinetd.d/rsync
#确保rsync服务能够启动
5 : debmirror package is not installed, it will be required to manage debian deployments and repositories
#在CentOS上,可以忽略这点
6 : ksvalidator was not found, install pykickstart
#关于kickstart的python包没有安装
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
#用户的密码默认是没有加密的,要使用openssl工具加密一个字符串,然后填到配置文件中
8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
#fecing工具没有找到,要安装cman和fence-agentbs工具包
Restart cobblerd and then run 'cobbler sync' to apply changes.
对应上面的问题,解决如下:
1、[root@localhost ~]# vim /etc/cobbler/settings
server: 192.168.81.132
2、[root@localhost ~]# vim /etc/cobbler/settings
next_server: 192.168.81.132
3、[root@localhost ~]# cp -a /usr/share/syslinux/* /var/lib/cobbler/loaders/
4、[root@localhost ~]# chkconfig rsync on
6、[root@localhost ~]# yum install pykickstart
7、[root@localhost ~]# openssl passwd -1 -salt `openssl rand -hex 4`
Password: #输入12345
$1$53f481cf$GTTafWaZfepR7NI966y4n.
[root@localhost ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$53f481cf$GTTafWaZfepR7NI966y4n."
8、[root@localhost ~]# yum install cman fence-agents
解决所有的问题之后,重启cobbler服务,再同步一下
[root@localhost ~]# service cobblerd restart
[root@localhost ~]# cobbler sync
此时,在check一次,查看是否还有问题
[root@localhost ~]# cobbler check
下面安装cobbler所依赖的服务
包括tftp、dns、dhcp、rsync
rsync这里采用cobbler管理的包
dhcp我们自行安装
[root@localhost ~]# yum install dhcp
配置dhcp服务,定义域,IP地址范围信息
[root@localhost ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf #提供配置文件
#覆盖原来的配置文件
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf #更改配置文件
option domain-name "365lsy.com";
option domain-name-servers ns.365lsy.com;
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.81.0 netmask 255.255.255.0 {
range 192.168.81.10 192.168.81.30;
option domain-name-servers ns.365lsy.com
option routers 192.168.81.132
}
next-server 192.168.81.132; #指定tftp的地址
filename "pxelinux.0";
检查一下配置文件,没有问题的话,启动dhcp服务
[root@localhost ~]# service dhcpd configtest
Syntax: OK
[root@localhost ~]# service dhcpd start
tftp服务在安装cobbler服务时被作为依赖包已经安装了,下面我们要启动tftp服务
[root@localhost ~]# chkconfig tftp on
[root@localhost ~]# service xinetd start
定义distro,其实是提供kernel和initrd的过程(可以使用distro或import命令)
使用import命令导入光盘镜像文件
[root@localhost ~]# mount /dev/cdrom /mnt/ #先挂着一个系统光盘
[root@localhost ~]# cobbler import --name=CentOS-6.5-x86_64 --path=/mnt/
可以在import导入时指定kickstart文件,但是,此处不指定,在profile中指定
导入的时候,会在httpd的目录下生成我们定义的distro
[root@localhost ~]# ls /var/www/cobbler/ks_mirror/
CentOS-6.5-x86_64 config
其实,就是创建一个yum源了,把光盘内的文件都拷贝过来了
查看我们刚刚定义好的distr
[root@localhost ~]# cobbler distro list
CentOS-6.5-x86_64
创建定义profile,提供kickstart文件(可以利用安装系统生成的anaconda.cfg)
稍作修改
[root@localhost ~]# vim anaconda-ks.cfg
# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
url --url=http://192.168.81.132/cobbler/ks_mirror/CentOS-6.5-x86_64/ #指定repository的URL路径
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --noipv6
# Reboot after installation
reboot
firewall --disabled
authconfig --useshadow --passalgo=sha512
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
zerombr #添加此选项
clearpart --all
part /boot --fstype=ext4 --size=200
part pv.008002 --size=61440
volgroup vg0 --pesize=8192 pv.008002
logvol / --fstype=ext4 --name=root --vgname=vg0 --size=20480
logvol swap --name=swap --vgname=vg0 --size=2048
logvol /usr --fstype=ext4 --name=usr --vgname=vg0 --size=10240
logvol /var --fstype=ext4 --name=var --vgname=vg0 --size=20480
%packages
@Base
@Core
@base
@basic-desktop
@chinese-support
@client-mgmt-tools
@core
@desktop-platform
@fonts
@general-desktop
@graphical-admin-tools
@legacy-x
@network-file-system-client
@perl-runtime
@remote-desktop-clients
@x11
ibus-table-cangjie
ibus-table-erbi
ibus-table-wubi
lftp
%end
验证ks文件是否有语法错误
[root@localhost ~]# ksvalidator anaconda-ks.cfg
将anaconda.cfg更名为CentOS6.5.cfg
定义一个名为CentOS-6.5-x86_64-basic的prifile
[root@localhost ~]# cobbler profile add --name=CentOS-6.5-x86_64-basic --distro=CentOS-6.5-x86_64 --kickstart=/root/CentOS6.5.cfg
查看我们新建的profile
[root@localhost ~]# cobbler profile list
CentOS-6.5-x86_64 #默认生成的
CentOS-6.5-x86_64-basic
对于上面的信息,同步一下
[root@localhost ~]# cobbler sync
测试阶段:
创建一个空的虚拟机,并将cobbler的服务器与空白虚拟机放在同一个网段中
[root@60sec /]# vim /etc/cobbler/settings
next_server: 192.168.83.137
server: 192.168.83.137
manage_tftpd: 0
[root@60sec /]# yum -y install syslinux
[root@60sec /]# chkconfig rsync on
[root@60sec /]# yum -y install pykickstart
[root@60sec /]# openssl passwd -1 -salt'openssl rand -hex 4'
Password:
$1$openssl $.oduSwbhLj6jqAwVsLo/H1
[root@60sec /]# vim /etc/cobbler/settings
default_password_crypted: "penssl$.oduSwbhLj6jqAwVsLo/H1"
[root@60sec /]# cd /usr/share/syslinux/
[root@60sec syslinux]# cp -r ./*/var/lib/cobbler/loaders/
安装dhcp服务
[root@60sec /]# yum -y install dhcp
[root@60sec /]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample/etc/dhcp/dhcpd.conf
[root@60sec /]# vim /etc/dhcp/dhcpd.conf
option domain-name "60sec.com";
option domain-name-servers172.16.0.1,192.168.83.137;
default-lease-time 43300;
max-lease-time 86500;
subnet 192.168.83.0 netmask 255.255.255.0 {
range 192.168.83.50 192.168.83.100;
option routers 192.168.83.137;
}
next-server 192.168.83.137;
filename="pxelinux.0";
[root@60sec /]# service dhcpd start
Starting dhcpd: [ OK ]
开启tftp服务
[root@60sec /]# chkconfig tftp on
[root@60sec /]# service xinetd start
Starting xinetd: [ OK ]
定义distro,挂载光盘并导入
[root@60sec /]# mount -r /dev/cdrom /media/
[root@60sec /]# cobbler import --name=centos-6.5-x86_64 --path=/media
如果有kickstart文件,使用“--kickstart=/path/to/kickstart_file”进行导入,也可使用以下命令
[root@60sec mnt]# ksvalidatorcentos6.x86_64.cfg
cobbler使用profile来为特定的需求类别提供所需要安装配置,即在distro的基础上通过提供kickstart文件来生成一个特定的系统安装配置。distro的profile可以出现在PXE的引导菜单中作为安装的选择之一。
[root@60sec mnt]# cobbler profile add--name=CenTos-6.5-x86_64-basic --distro=centos-6.5-x86_64 --kickstart=/mnt/centos6.x86_64.cfg
[root@60sec mnt]# cobbler profile list
CenTos-6.5-x86_64-basic
Centos-6.5-x86_64
[root@60sec mnt]# cobbler sync
[root@60sec mnt]# service cobblerd restart
可修改相关信息
[root@60sec mnt]# vim/var/lib/tftpboot/pxelinux.cfg/default