一 Cobbler介绍
Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows。该工具使用python开发,小巧轻便,使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP、DNS、以及yum仓库、构造系统ISO镜像。
Cobbler支持命令行管理,web界面管理,还提供了API接口,可以方便二次开发使用。
Cobbler客户端Koan支持虚拟机安装和操作系统重新安装,使重装系统更便捷。
Cobbler提供以下服务集成:
* PXE服务支持
* DHCP服务管理
* DNS服务管理
* 电源管理
* Kickstart服务支持
* yum仓库管理
Cobbler相关文件介绍
1、Cobbler配置文件目录:/etc/cobbler
/etc/cobbler/settings #cobbler主配置文件
/etc/cobbler/dhcp.template #DHCP服务的配置模板
/etc/cobbler/tftpd.template #tftp服务的配置模板
/etc/cobbler/rsync.template #rsync服务的配置模板
/etc/cobbler/iso #iso模板配置文件
/etc/cobbler/pxe #pxe模板文件
/etc/cobbler/power #电源的配置文件
/etc/cobbler/users.conf #Web服务授权配置文件
/etc/cobbler/users.digest #用于web访问的用户名密码配置文件
/etc/cobbler/dnsmasq.template #DNS服务的配置模板
/etc/cobbler/modules.conf #Cobbler模块配置文件
2、Cobbler数据目录:/var/lib/cobbler
/var/lib/cobbler/config #配置文件
/var/lib/cobbler/triggers #Cobbler命令
/var/lib/cobbler/kickstarts #默认存放kickstart文件
/var/lib/cobbler/loaders #存放的各种引导程序
3、系统安装镜像目录:/var/www/cobbler
/var/www/cobbler/ks_mirror #导入的系统镜像列表
/var/www/cobbler/images #导入的系统镜像启动文件
/var/www/cobbler/repo_mirror #yum源存储目录
4、日志目录:/var/log/cobbler
/var/log/cobbler/install.log #客户端系统安装日志
/var/log/cobbler/cobbler.log #cobbler日志
二 Cobbler 安装
1. 安装环境
OS:centos7 gnome
Cobbler: 2.6.9-1.el7
Cobbler-web: 2.6.9-1.el7
2. 安装epel源
目的是配置cobbler源
# rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
3. 安装cobbler相关软件
# yum install -y tftp-serverpykickstart dnsmasq httpd
debmirror //如果需要安装ubuntu等使用deb包管理器的OS则需安装
4. 安装cobbler
a.依赖包
需先下载python-markdown、python-imaging(iso有)、python-pygments、python-cheetah、python-simplejson、python-django-bash-completion、python-django
b.安装cobbler
yuminstall -y cobbler cobbler-web
5. 配置cobbler
a. 启动相关服务
# chkconfig httpd on
# chkconfig cobblerd on
# chkconfig dnsmasq on
# service httpd restart
# service cobblerd restart
# service dnsmasq restart
b. 关闭selinux
# sestatus //查看状态
# vi /etc/selinux/config //需重启生效
//注释掉原有的两行
SELINUXTYPE=disabled
或 # setenforce 0
c. 关闭防火墙或开启相关端口
# service firewalld stop
d. tftp服务和rsync服务
# sed -i '/disable/c\\tdisable\t\t\t= no'/etc/xinetd.d/tftp //将disable设为no
# vi /etc/xinetd.d/rsync //centos7 默认不生成该文件
servicersync
{
disable =no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
# service xinetd restart
e. 下载启动菜单
#cobbler get-loaders //需要联网
f. cobbler-web登录验证
# sed -i 's/authn_denyall/authn_configfile/g'/etc/cobbler/modules.conf
设置密码
# htdigest /etc/cobbler/users.digest "Cobbler"cobbler
g. 设置debmirror(可选)
# sed -i -e 's|@dists=.*|#@dists=|' /etc/debmirror.conf
# sed -i -e 's|@arches=.*|#@arches=|' /etc/debmirror.conf
h. 配置dnsmasq
# vi /etc/cobbler/dnsmasq.template
修改“dhcp-range”
i. 设置cobbler管理dnsmasq
默认他是使用bind管理dns,isc实现dhcp
# vi /etc/cobbler/modules.conf
[dns]
#module =manage_bind
module =manage_dnsmasq
[dhcp]
#module =manage_isc
module = manage_dnsmasq
j. 开启命令行更新配置
# cp/etc/cobbler/settings /etc/cobbler/settings.bak
# sed -i's/^[[:space:]]\+/ /' /etc/cobbler/settings
# sed -i's/allow_dynamic_settings: 0/allow_dynamic_settings: 1/g' /etc/cobbler/settings
# servicecobblerd restart
重启服务后即可通过命令行编辑配置
# cobbler settingreport //显示所有配置
# cobbler settingreport [--name=option] //显示某个配置
# cobbler settingedit --name=option --value=value //编辑配置
k. 修改设置
(1)
# cobblersetting edit --name=server --value=10.168.0.168 //cobbler登陆服务器地址
# cobblersetting edit --name=next_server --value=10.168.0.168 //TFTP服务器 IP地址
# cobblersetting edit --name=pxe_just_once --value=1 //ks脚本关闭pxe,这样就不会重复安装
(2)
配置cobbler管理rsync,dhcp,dns:
# cobblersetting edit --name=manage_rsync --value=1
# cobblersetting edit --name=manage_dhcp --value=1
# cobblersetting edit --name=manage_dns --value=1
(3)
修改待安装OS的root密码:
# opensslpasswd -1 -salt 'random-phrase-here' 'openstack'
将生成的加密密码覆盖/etc/cobbler/settings中的default_password_crypted
(4)
# service cobblerd restart //重启cobblerd
# cobbler sync //同步配置
# cobbler check //检查cobbler的设置
根据check的结果修改,其中1是ubuntu系统需要的,可以不装
登录cobbler web界面:https://10.168.0.168/cobbler_web
l. 制作centos7镜像
(1)将镜像挂载到/media
(2)执行导入
在“Actions”选项卡中选择“Import DVD”
(3)查看导入结果
选择“Events“选项卡查看结果
可以“Distros”中看到已经导入了centos7
(4)修改kickstart
在“kickstart Templates”中新建centos7.ks文件
在“Profiles”中点击“cent7-x86_64”,修改默认的ks文件
# kickstart template for Fedora 8 and later.
# (includes %end blocks)
# do not use with earlier distros
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth --useshadow --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --enabled
# Run the Setup Agent on first boot
firstboot --disable
ignoredisk --only-use=sda
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
url --url=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone Asia/Shanghai
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
#autopart
part /boot --fstype=xfs --asprimary --size=350
part swap --fstype=swap --asprimary --size=2000 --maxsize=50000 --grow
part / --fstype=xfs --asprimary --grow --size=8000
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
%packages
$SNIPPET('func_install_if_enabled')
gcc
sysstat
net-tools
wget
vim
libxml2-python
%end
%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end
%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')
### Repo Setup ###
rm -f /etc/yum.repos.d/CentOS*
rm -f /root/ip_hostname.sh
cd /root
wget http://10.168.0.168/cobbler/ks_mirror/config/ip_hostname.sh
sh /root/ip_hostname.sh
rm -f /root/ip_hostname.sh
echo "alias vi=vim" >> /etc/profile
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
%end
也可使用图形界面生成,需要先安装图形界面:
# yum install system-config-kickstart
然后在图形界面的终端中执行
# system-config-kickstart
(5)服务器安装
服务器配置成网络启动(PXE),重启获取到IP后,进入如下界面
若原来没有OS,等待默认时间后自动安装,若原来有OS,进入OS,或手动选择“centos7-x86_64”进行安装
m. 重装系统
在原来有OS的服务器重装OS,需要利用koan(kickstart over a network)
(1)添加依赖包
将4.a中的包和koan包放到/var/www/cobbler/ks_mirror/centos7-x86_64/Packages,该目录是在4.l这一步导入镜像时生成的。
(2)重新生成repodata
# yum install createrepo
# cd /var/www/cobbler/ks_mirror
# createrepo centos7-x86_64
修改生成的repomd.xml
# vi /var/www/cobbler/ks_mirror/centos7-x86_64/repodata/repomd.xml
//将原文件中的group相关内容加入到该文件中
<datatype="group">
<datatype="group_gz">
修改目标服务器的yum源:
# vi /etc/yum.repos.d/cent.repo
baseurl=http://10.168.0.168/cobbler/ks_mirror/centos7-x86_64
# yum clean all //清除原有的yum数据
# yum install koan
(3)查看系统列表
# koan --server=10.168.0.168 --list=profiles
(4)重装
# koan --server=10.168.0.168--profile=centos7-x86_64 --replace-self
# reboot
在从硬盘启动后,会进入一个类似"kick***"的启动项,然后开始重装
参考文章:http://dreamway.blog.51cto.com/1281816/1166589