cobbler原理知识介绍
distribution:指定发行版本,pxe只能为一个发行版提供一个安装场景(使用kickstart的情况下)
这是cobbler的最核心组件
定义distribution是为指明某个发行版的内核(kernel)和ramdisk文件(initrd),从而确定是哪个版本,安装启动之后,能找到后面的仓库repository,下载后面要完成安装的各个组件
通过distribution和repository定义profile,指明系统的版本,指定安装需要的包的URL,然后,通过kickstart文件,实现自动化安装,每个kickstart不同,安装的包都是不同的
注意:kickstart一变化,我们的profile就是一个新的样式
安装cobbler程序
[[email protected] ~]# yum install cobbler
如果是干净的CentOS6.5操作系统,它会自动解决依赖关系,包括syslinux,createrepo,tftp,xinetd还有一些系列的python包,因为系统自带httpd了,httpd也是其依赖包
启动cobbler服务,并进行初始化
[[email protected] ~]# service httpd start [[email protected] ~]# service cobblerd start
此时安装的cobbler还有一些问题,我们可以使用cobbler的check命令查看,并且修改一些选项
[[email protected] ~]# 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、[[email protected] ~]# vim /etc/cobbler/settings server: 192.168.81.132
2、[[email protected] ~]# vim /etc/cobbler/settings next_server: 192.168.81.132
3、[[email protected] ~]# cp -a /usr/share/syslinux/* /var/lib/cobbler/loaders/
4、[[email protected] ~]# chkconfig rsync on
6、[[email protected] ~]# yum install pykickstart
7、[[email protected] ~]# openssl passwd -1 -salt `openssl rand -hex 4` Password: #输入12345 $1$53f481cf$GTTafWaZfepR7NI966y4n. [[email protected] ~]# vim /etc/cobbler/settings default_password_crypted: "$1$53f481cf$GTTafWaZfepR7NI966y4n."
8、[[email protected] ~]# yum install cman fence-agents
解决所有的问题之后,重启cobbler服务,再同步一下
[[email protected] ~]# service cobblerd restart [[email protected] ~]# cobbler sync
此时,在check一次,查看是否还有问题
[[email protected] ~]# cobbler check
下面安装cobbler所依赖的服务
包括tftp、dns、dhcp、rsync
rsync这里采用cobbler管理的包
dhcp我们自行安装
[[email protected] ~]# yum install dhcp
配置dhcp服务,定义域,IP地址范围信息
[[email protected] ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf #提供配置文件
#覆盖原来的配置文件
[[email protected] ~]# 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服务
[[email protected] ~]# service dhcpd configtest Syntax: OK [[email protected] ~]# service dhcpd start
tftp服务在安装cobbler服务时被作为依赖包已经安装了,下面我们要启动tftp服务 [[email protected] ~]# chkconfig tftp on [[email protected] ~]# service xinetd start
定义distro,其实是提供kernel和initrd的过程(可以使用distro或import命令)
使用import命令导入光盘镜像文件
[[email protected] ~]# mount /dev/cdrom /mnt/ #先挂着一个系统光盘 [[email protected] ~]# cobbler import --name=CentOS-6.5-x86_64 --path=/mnt/
可以在import导入时指定kickstart文件,但是,此处不指定,在profile中指定
导入的时候,会在httpd的目录下生成我们定义的distro
[[email protected] ~]# ls /var/www/cobbler/ks_mirror/ CentOS-6.5-x86_64 config
其实,就是创建一个yum源了,把光盘内的文件都拷贝过来了
查看我们刚刚定义好的distr
[[email protected] ~]# cobbler distro list CentOS-6.5-x86_64
创建定义profile,提供kickstart文件(可以利用安装系统生成的anaconda.cfg)
稍作修改
[[email protected] ~]# 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文件是否有语法错误
[[email protected] ~]# ksvalidator anaconda-ks.cfg
将anaconda.cfg更名为CentOS6.5.cfg
定义一个名为CentOS-6.5-x86_64-basic的prifile
[[email protected] ~]# cobbler profile add --name=CentOS-6.5-x86_64-basic --distro=CentOS-6.5-x86_64 --kickstart=/root/CentOS6.5.cfg
查看我们新建的profile
[[email protected] ~]# cobbler profile list CentOS-6.5-x86_64 #默认生成的 CentOS-6.5-x86_64-basic
对于上面的信息,同步一下
[[email protected] ~]# cobbler sync
测试阶段:
创建一个空的虚拟机,并将cobbler的服务器与空白虚拟机放在同一个网段中
此时,我们可以加入CentOS5.5的系统镜像
将原有的CentOS6.5的光盘卸载,挂载5.5的镜像
[[email protected] ~]#umount /mnt [[email protected] ~]# mount /dev/cdrom /mnt
[[email protected] ~]# cobbler import --name=CentOS5.5 --path=/mnt
[[email protected] ~]# cobbler distro list CentOS-6.5-x86_64 CentOS5.5-i386 #新增的CentOS5.5 CentOS5.5-xen-i386
提供ks文件,对CentOS5.5安装生成的anaconda.cfg稍作修改
[[email protected] ~]# vim centos5.5.cfg # Kickstart file automatically generated by anaconda. install url --url=http://192.168.81.132/cobbler/ks_mirror/CentOS5.5 #指定repository路径 lang en_US.UTF-8 keyboard us xconfig --startxonboot network --device eth0 --bootproto dhcp rootpw --iscrypted $1$ofs1QigI$4F9iBT74yj9v72Y6MgX5P. reboot firewall --disabled authconfig --enableshadow --enablemd5 selinux --disabled timezone --utc Asia/Shanghai bootloader --location=mbr --driveorder=sda --append="rhgb quiet" # 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 --linux part /boot --fstype ext3 --size=500 part /usr --fstype ext3 --size=6000 part /home --fstype ext3 --size=3000 part / --fstype ext3 --size=100 --grow part pv.3 --size=100 --grow repo --name="CentOS" --baseurl=http://192.168.81.132/cobbler/ks_mirror/CentOS5.5 %packages @base @chinese-support @core @development-tools @dialup @editors @gnome-desktop @games @graphical-internet @printing @text-internet @base-x keyutils trousers fipscheck device-mapper-multipath imake xorg-x11-server-Xnest xorg-x11-server-Xvfb
此处,不能校验ks文件的语法,检查时,会报一个缺少end的结尾,但是,加上去之后,安装过程到一半就会卡在,提升,应该安全的重启你的系统,所以,此处不加end,才能安装完成。
定义一个profile,指定kickstart文件,指定distro
[[email protected] ~]# cobbler profile add --name=CentOS5.5-basic --distro=CentOS5.5-i386 --kickstart=/root/centos5.5.cfg
查看现有的profile
[[email protected] ~]# cobbler profile list CentOS-6.5-x86_64 CentOS-6.5-x86_64-basic CentOS5.5-basic CentOS5.5-i386 CentOS5.5-xen-i386
同步一下
[[email protected] ~]# cobbler sync
测试
到此,我们的cobbler部署CentOS5和CentOS6的过程就完成,cobbler是PXE装机的再一次封装,相比PXE而言,PXE的环境只能有一个操作系统的安装,但是,cobbler可以实现多个系统的安装部署,操作上更加简易,但是,PXE的过程对于我们了解cobbler还是非常重要的,无论哪种安装方法,不同的kickstart的指定就代表着不同的安装方法。