CentOS 6.5自动化运维之基于cobbler服务的自动化安装操作系统详解
Posted 郑子明
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 6.5自动化运维之基于cobbler服务的自动化安装操作系统详解相关的知识,希望对你有一定的参考价值。
一、Cobbler安装
前提:cobbler由epel源提供,故此需要事先配置指向epel的yum源方可进行类似下面的安装过程。
# yum install -y epel-release
# yum install -y cobbler cobbler-web pykickstart debmirror
# service httpd start
# service cobblerd start
# ss -tuanlp | grep :25151
tcp LISTEN 0 5 127.0.0.1:25151 *:* users:(("cobblerd",1820,8))
执行“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 will use it.
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.
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.
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 them
Restart cobblerd and then run 'cobbler sync' to apply changes.
如上各问题的解决方法如下所示:
1、修改/etc/cobbler/settings文件中的server参数的值为提供cobbler服务的主机相应的IP地址或主机名,如192.168.8.42;
2、修改/etc/cobbler/settings文件中的next_server参数的值为提供PXE服务的主机相应的IP地址,如192.168.8.42;
3、如果当前节点可以访问互联网,执行“cobbler get-loaders”命令即可;否则,需要安装syslinux程序包,此处我们安装cobbler时已经安装好了syslinux,直接复制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目录中;
# cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/cobbler/loaders/
4、执行“chkconfig rsync on”命令即可;
5、注释/etc/debmirror.conf文件中的“@dists="sid";”一行;
#@arches="i386";
6、注释/etc/debmirror.conf文件中的“@arches="i386";”一行;
#@arches="i386";
7、执行“openssl passwd -1 -salt $(openssl rand -hex 4)”生成密码,并用其替换/etc/cobbler/settings文件中default_password_crypted参数的值;
# openssl passwd -1 -salt $(openssl rand -hex 4)
Password:
$1$02a40dac$KLq7oPRMbsv9U/RKJkO2L1
8、执行“yum install cman fence-agents”命令安装相应的程序包即可;
# vim /etc/xinetd.d/tftp
修改disabled改为no
接着重启cobblerd,而后执行“cobbler sync”同步新的配置至cobbler
注:
报错:file /etc/xinetd.d/rsync does not exist
实际上/etc/xinetd.d/rsync文件存在,此条忽略
二、配置及启动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服务
# yum install -y dhcp
定义好所需的“subnet”及其它参数或选项,而后启动dhcpd守护进程即可。本示例中所用的dhcpd的配置如下所示:
option domain-name "chinasoft.com";
option domain-name-servers 192.168.8.251,8.8.8.8;
default-lease-time 43200;
max-lease-time 86400;
log-facility local7;
subnet 192.168.8.0 netmask 255.255.255.0 {
range 192.168.8.210 192.168.8.215;
option routers 192.168.8.254;
}
next-server 192.168.8.42;
filename="pxelinux.0";
接着使用重新启动服务即可
# service dhcpd restart
2.2 配置tftp服务
# chkconfig tftp on
# service xinetd restart
# netstat -unlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 0.0.0.0:111 0.0.0.0:* 1178/rpcbind
udp 0 0 0.0.0.0:631 0.0.0.0:* 1323/cupsd
udp 0 0 0.0.0.0:51485 0.0.0.0:* 1196/rpc.statd
udp 0 0 0.0.0.0:929 0.0.0.0:* 1178/rpcbind
udp 0 0 0.0.0.0:948 0.0.0.0:* 1196/rpc.statd
udp 0 0 0.0.0.0:67 0.0.0.0:* 4036/dhcpd
udp 0 0 0.0.0.0:69 0.0.0.0:* 4058/xinetd
udp 0 0 :::111 :::* 1178/rpcbind
udp 0 0 :::929 :::* 1178/rpcbind
udp 0 0 :::58086 :::*
# service cobblerd restart
三、配置cobbler
cobbler的各主要组件间的关系如下图所示。
3.1 管理distro
使cobbler变得可用的第一步为定义distro,其可以通过为其指定外部的安装引导内核及ramdisk文件的方式实现。而如果已经有完整的系统安装树(如CentOS6的安装镜像)则推荐使用import直接导入的方式进行。
例如,对于已经挂载至/media/目录的CentOS 6.5 x86_64的安装镜像,则可以使用类似如下命令进行导入。
# mount -r /dev/cdrom /media
# cobbler import --name="centos6.5-x86_64" --path=/media/
task started: 2016-04-28_211028_import
task started (id=Media import, time=Thu Apr 28 21:10:28 2016)
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path /var/www/cobbler/ks_mirror/centos6.5-x86_64:
creating new distro: centos6.5-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos6.5-x86_64 -> /var/www/cobbler/links/centos6.5-x86_64
creating new profile: centos6.5-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/centos6.5-x86_64 for centos6.5-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos6.5-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/centos6.5-x86_64
looking for /var/www/cobbler/ks_mirror/centos6.5-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos6.5-x86_64/repodata
*** TASK COMPLETE ***
可以通过访问:http://192.168.8.42/cobbler/ 看到文件列表
可使用“cobbler distro list”列出所有的distro
# cobbler distro list
centos6.5-x86_64
如果有kickstart文件,也可以使用“--kickstart=/path/to/kickstart_file”进行导入,因此import会自动为导入的distro生成一个profile。
3.2 管理profile
cobbler使用profile来为特定的需求类别提供所需要安装配置,即在distro的基础上通过提供kickstart文件来生成一个特定的系统安装配置。distro的profile可以出现在PXE的引导菜单中作为安装的选择之一。
因此,如果需要为前面创建的centos6.5-x86_64这个distro提供一个可引导安装条目,其用到的kickstart文件为/root/anaconda-ks.cfg(只提供了最基本的程序包),则可通过如下命令实现。
# cp anaconda-ks.cfg /var/lib/cobbler/kickstarts/
# cd /var/lib/cobbler/kickstarts/
# vim centos6.5-x86_64.cfg
# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
url --url="http://192.168.8.42/cobbler/ks_mirror/centos6.5-x86_64/"
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --noipv6
rootpw --iscrypted $6$Zo9OJ.qLqnykyR3A$oMfNInpeoBafrlems1hl/yb4Qast3q4AXTloF7ZdqbszFmYlG9cLYgobocFBsc11wGGy/nleM8liSRU.kqvsy0
reboot
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone --utc Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto 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
clearpart --all
zerombr
text
firstboot --disable
part /boot --fstype=ext4 --size=300
part pv.008002 --grow --size=61400
volgroup vg_0 --pesize=4096 pv.008002
logvol /data --fstype=ext4 --name=data --vgname=vg_0 --size=20000
logvol / --fstype=ext4 --name=root --vgname=vg_0 --size=20000
logvol swap --name=swap --vgname=vg_0 --size=4000
logvol /usr/local --fstype=ext4 --name=usr --vgname=vg_0 --size=10000
logvol /web --fstype=ext4 --name=web --vgname=vg_0 --size=25000
%packages
@base
@console-internet
@core
@debugging
@directory-client
@hardware-monitoring
@java-platform
@large-systems
@network-file-system-client
@performance
@perl-runtime
@server-platform
@server-policy
@workstation-policy
pax
oddjob
sgpio
device-mapper-persistent-data
samba-winbind
certmonger
pam_krb5
krb5-workstation
perl-DBD-SQLite
%end
目录/var/lib/cobbler/kickstarts/为cobbler默认存放kickstart配置文件的位置
# cobbler profile add --name=centos6.5-x86_64-basic --distro=centos6.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6.5-x86_64.cfg
查看已经创建的profile
# cobbler profile list
centos6.5-x86_64
centos6.5-x86_64-basic
# cobbler sync
通过查看default文件可以看到我们添加的内容
# cat /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local
LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT -1
LABEL centos6.5-x86_64
kernel /images/centos6.5-x86_64/vmlinuz
MENU LABEL centos6.5-x86_64
append initrd=/images/centos6.5-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://192.168.8.42/cblr/svc/op/ks/profile/centos6.5-x86_64
ipappend 2
LABEL centos6.5-x86_64-basic
kernel /images/centos6.5-x86_64/vmlinuz
MENU LABEL centos6.5-x86_64-basic
append initrd=/images/centos6.5-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://192.168.8.42/cblr/svc/op/ks/profile/centos6.5-x86_64-basic
ipappend 2
新建一个虚拟机,并启动,可以看到能够自动识别到cobbler提供的系统
新增一个开发的环境定制发行版
# cd /var/lib/cobbler/kickstarts
# cp centos6.5-x86_64.cfg centos6.5-x86_64-devel.cfg
# vim centos6.5-x86_64-devel.cfg
添加两个安装包组
@Develepment-tools
@Server-Platform-Development
# cobbler profile add --name=centos6.5-x86_64-development --distro=centos6.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6.5-x86_64-devel.cfg
# cobbler sync
# cat /var/lib/tftpboot/pxelinux.cfg/default
cobbler删除distro
命令行删除:
# cobbler distro remove --name=centos6.7-x86_64
exception on server: 'removal would orphan profile: centos6.7-x86_64'
通过web直接删除
正确的方式:
# cobbler profile remove --name=centos6.7-x86_64
# cobbler distro remove --name=centos6.7-x86_64
四、配置使用cobbler_web
4.1修改认证类型为auth_pam
# vim modules.conf
[authentication]
module = authn_pam
4.2添加cobbler web登录用户
# useradd cobbleruser
# echo 'cobblerpass' | passwd --stdin cobbleruser
4.3编辑users.conf文件
# vim /etc/cobbler/users.conf
[admins]
admin = "cobbleruser"
cobbler = ""
访问:http://192.168.8.42/cobbler_web
至此,cobbler的安装及配置及常用命令已完成
以上是关于CentOS 6.5自动化运维之基于cobbler服务的自动化安装操作系统详解的主要内容,如果未能解决你的问题,请参考以下文章