centos6用cobbler批量部署centos、ubuntu系统

简介:

安装cobbler,需要epel或者rpmforge源,若需要部署debian/ubuntu类系统,需要安装debmirror,需要epel源。到http://dl.fedoraproject.org/pub找适合自己系统的包。我的是centos6.2-x86_64所以安装下面这个epel源 
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6Server/x86_64/epel-release-6-8.noarch.rpm 

从下面地址找适合自己系统的debmirror包 
http://rpmfind.net/linux/rpm2html/search.php?query=debmirror 


安装cobbler与debmirror相关软件 
yum install cobbler dhcp xinetd fence-agents pykickstart ed patch perl perl-Compress-Zlib perl-Digest-SHA perl-LockFile-Simple perl-libwww-perl 

开始安装debmirror, 
rpm -Uvh ftp://rpmfind.net/linux/epel/6/x86_64/debmirror-2.14-2.el6.noarch.rpm 

修改/etc/debmirror.conf配置文件,注释掉@dists和@arches两行 
vim /etc/debmirror.conf 

#@dists="sid"; 

#@arches="i386"; 


开启cobbler服务并下载loaders 
/etc/init.d/cobblerd restart && /etc/init.d/httpd restart && cobbler get-loaders 


设置开机启动项 
chkconfig xinetd on && chkconfig httpd on && chkconfig dhcpd on && chkconfig ip6tables off && chkconfig iptables off 

修改cobbler配置 
默认的,经过cobbler安装后的系统root密码是cobbler 
如果不改,在cobbler check时会提示不安全。还是改一下把。假设预设root密码为admaster,则用openssl passwd -1 -salt转换可得到md5码加密的字串 
openssl passwd -1 -salt 1 admaster 
复制得到的字串后 
vim /etc/cobbler/settings 
全文搜索default_password_crypted后面的引号里粘上复制的那串 
继续全文搜索127.0.0.1替换成相应服务器ip 
若cblr和tftp是同一台机器的情况可以全文查找替换 
:%s/127.0.0.1/192.168.44.249/g 
如果不同则分别设置 
设置cobbler server的IP地址 
server: 192.168.44.249 
设置PXE server的IP地址 
next-server: 192.168.44.250 
开启自动dhcp管理 
manage_dhcp: 1 
开启自动rsync管理 
manage_rsync: 1 


开启tftp和rsync 
将两个服务配置文件的disable = yes改成no 
sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp && sed -i '/disable/s/yes/no/g' /etc/xinetd.d/rsync 

配置dhcp模板 
vim /etc/cobbler/dhcp.template 
将网段、网关、路由写好保存退出 

先重新加载一下cobbler的配置,再同步所有设置 
/etc/init.d/cobblerd restart && cobbler sync 


当执行cobbler sync时报如下错误

dhcpd -t failed
Exception occured: <class 'cobbler.cexceptions.CX'>
Exception value: 'cobbler trigger failed: cobbler.modules.sync_post_restart_services'
Exception Info:
 File "/usr/lib/python2.6/site-packages/cobbler/remote.py", line 89, in run
   rc = self._run(self)
  File "/usr/lib/python2.6/site-packages/cobbler/remote.py", line 184, in runner
   return self.remote.api.sync(self.options.get("verbose",False),logger=self.logger)
  File "/usr/lib/python2.6/site-packages/cobbler/api.py", line 701, in sync
   return sync.run()
  File "/usr/lib/python2.6/site-packages/cobbler/action_sync.py", line 155, in run
   utils.run_triggers(self.api, None, "/var/lib/cobbler/triggers/sync/post/*", logger=self.logger)
  File "/usr/lib/python2.6/site-packages/cobbler/utils.py", line 918, in run_triggers
   raise CX("cobbler trigger failed: %s" % m.__name__)

!!! TASK FAILED !!!

是dhcp服务没起来的原因,查看/etc/dhcp/dhcpd.conf,可能是网段超出或者掩码不正确。具体问题可以执行tailf -100 /var/log/messages


导入系统iso 
mkdir /cdrom 
mount -o loop -t iso9660 ~/iso/CentOS-6.2-x86_64-bin-DVD1.iso /cdrom 
cobbler import --path=/cdrom --name=CentOS-6.2 --arch=x86_64 
umount -l /cdrom 
mount -o loop -t iso9660 ~/iso/ubuntu-12.04.4-server-amd64.iso /cdrom 
cobbler import --path=/cdrom --name=Ubuntu-12.04.4-Server --arch=x86_64

由于cobbler在导入initrd.gz的时候出错,所以手动把光盘netboot里面的复制过来覆盖。
cp /cdrom/install/netboot/ubuntu-installer/amd64/initrd.gz /var/lib/tftpboot/images/Ubuntu-12.04.4-Server-x86_64 
提示覆盖选y


配置kickstart文件 
mkdir -p /var/www/ks/ 

编写centos6的ks.cfg 
vim /var/www/ks/centos6.cfg 
# centos6/ks.cfg 
firewall --disabled 
install 
url --url http://192.168.44.249/cobbler/ks_mirror/CentOS-6.2-x86_64


text 
firstboot --disable 
rootpw admaster 
auth --useshadow --enablemd5 
lang en_US 
keyboard us 
selinux --disabled 
logging --level=info 
reboot 
timezone --isUtc Asia/Shanghai 
network --bootproto=dhcp --device=eth0 --onboot=on 
zerombr 
bootloader --location=mbr 
clearpart --all --initlabel 
part swap --fstype="swap" --size=4096 
part /boot --fstype="ext4" --size=200 
part / --fstype="ext4" --size=1 --grow 
%packages 
openssh-server 
openssh 
vim


如需安装图形界面,在vim下面添加下面这三行

@ X Window System
@ Desktop
@ Desktop Platform


编写ubuntuserver12的ks文件 
vim /var/www/ks/ubuntuserver12.cfg 
#以下是阿谢的ks.cfg for ubuntu server 12 
install 
url --url http://192.168.44.249/cobbler/ks_mirror/Ubuntu-12.04.4-Server-x86_64 

preseed passwd/root-login boolean true 
lang en_US 
langsupport --default en_US.UTF-8 en_US.UTF-8 

keyboard us 
mouse 
timezone Asia/Shanghai 

rootpw --disabled 
user john --fullname "john chu" --password admaster 
reboot 
text 

bootloader --location=mbr 
zerombr yes 
clearpart --all --initlabel 

partman-lvm/device_remove_lvm boolean true  
partman-md/device_remove_md boolean true


part / --fstype ext4 --size 1 --grow --asprimary 

# 不设置swap时安装过程中会提示要不要重新添加swap分区 
part swap --size 4096 

auth  --useshadow  --enablemd5 
network --bootproto=dhcp --device=eth0 
firewall --disabled 
skipx 

%packages 
@ Base 
openssh-server 
openssh-client 
vim 
gcc 
make 


指定各系统所对应的ks文件位置 
cobbler profile edit --name=CentOS-6.2-x86_64 --kickstart=/var/www/ks/centos6.cfg 
cobbler profile edit --name=Ubuntu-12.04.4-Server-x86_64 --kickstart=/var/www/ks/ubuntuserver12.cfg 
--name后面是/var/lib/cobbler/config/profiles.d目录里json文件名,如果提示错误就去看看json的名字到底是什么把name改成相应的即可 


若需删除已导入系统安装源,先查看都有哪些安装源 
cobbler list 
选中一个不顺眼的直接remove profile和distro 
cobbler profile remove --name=CentOS-6.2-i386 
cobbler distro remove --name=CentOS-6.2-i386 
验证是否已成功删除 
cobbler profile find --distro=CentOS-6.2-i386 
结果为空表示成功 

注意CentOS-6.2 x86_64的dvd镜像在导入时候会被cobbler错误地识别成既有i386又有x86_64,所以不要删除i386的,否则x86_64也没了,我遇到过一次,可以把pxelinux.cfg/default这个启动菜单修改一下即可 


修改pxe启动菜单default 
vim /var/lib/tftpboot/pxelinux.cfg/default
TIMEOUT改成你希望的秒数x10,因为这个值的单位是100毫秒
TOTALTIMEOUT不知道干啥的 
centos的append后写上ks=http://你kickstart服务器ip/cobbler/ks/配置文件名,这样写 
append initrd=/images/CentOS-6.2-x86_64/initrd.img ksdevice=eth0 lang=  kssendmac text  ks=http://192.168.44.249/cobbler/ks/centos6.cfg

ubuntu的append这样写
append initrd=/images/Ubuntu-12.04.4-Server-x86_64/initrd.gz ksdevice=eth0 ks=http://192.168.44.249/cobbler/ks/ubuntuserver12.cfg

以上ksdevice表示从哪块网卡进行安装


关闭selinux 
sed -i '/SELINUX/s/permissive/disabled/g' /etc/selinux/config && sed -i '/SELINUX/s/enforcing/disabled/g' /etc/selinux/config && setenforce 0 

关闭iptables防火墙 
/etc/init.d/iptables stop 

打开dhcpd和xinetd 
/etc/init.d/dhcpd restart && /etc/init.d/xinetd restart 


检查cobbler是否已配置完毕并按照提示进行修正 
cobbler check 
出现以下提示 
1 : debmirror package is not installed, it will be required to manage debian deployments and repositories 
2 : 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
3 : reposync is not installed, need for cobbler reposync, install/upgrade yum-utils?
4 : yumdownloader is not installed, needed for cobbler repo add with --rpm-list parameter, install/upgrade yum-utils?

5 : One or more repos need to be processed by cobbler reposync for the first time before kickstarting against them: Ubuntu-12.04.4-Server-x86_64


第一是提示如果需要安装debian/ubuntu系统,必须安装debmirror包 
方法在前面有 
第二点是因为没有修改默认root密码cobbler 
第三、四、五点问题不大,可以忽略 


客户端通过pxe网络启动 
在引导菜单中选择需要安装的系统即可 


若日后哪台服务器需要重装系统了,在这台服务器上需要安装koan工具,是依托rpmforge,先在这机器上安装rpmforge,去http://pkgs.repoforge.org/rpmforge-release/查看适合自己系统的包,比如我的是centos6.2-x86_64所以这样装 
rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
安装好rpmforge后,安装koan 
yum install koan



本文转自 朱科强 51CTO博客,原文链接:http://blog.51cto.com/zhukeqiang/1383667,如需转载请自行联系原作者

相关文章
|
3月前
|
Ubuntu 编译器 开发工具
在Ubuntu系统上搭建RISC-V交叉编译环境
以上步骤涵盖了在Ubuntu系统上搭建RISC-V交叉编译环境的主要过程。这一过程涉及了安装依赖、克隆源码、编译安装工具链以及设置环境变量等关键步骤。遵循这些步骤,可以在Ubuntu系统上搭建一个用于RISC-V开发的强大工具集。
434 22
|
3月前
|
Ubuntu 网络协议 网络安全
解决Ubuntu系统的网络连接问题
以上步骤通常可以帮助解决大多数Ubuntu系统的网络连接问题。如果问题仍然存在,可能需要更深入的诊断,或考虑联系网络管理员或专业技术人员。
785 18
|
3月前
|
监控 关系型数据库 MySQL
在CentOS系统中,如何统计哪个进程打开了文件描述符?
利用上述方法,你可以有效地监控和统计CentOS系统中的进程打开的文件描述符数量,以帮助排查错误或优化系统配置。通过组合使用各种工具和命令,可以获得对系统状态和行为的深入了解,进而做出相应的调整和
197 5
|
4月前
|
Ubuntu 安全 关系型数据库
安装MariaDB服务器流程介绍在Ubuntu 22.04系统上
至此, 您已经在 Ubuntu 22.04 系统上成功地完成了 MariadB 的标准部署流程,并且对其进行基础但重要地初步配置加固工作。通过以上简洁明快且实用性强大地操作流程, 您现在拥有一个待定制与使用地强大 SQL 数据库管理系统。
345 18
|
4月前
|
Ubuntu 安全 关系型数据库
安装MariaDB服务器流程介绍在Ubuntu 22.04系统上
至此, 您已经在 Ubuntu 22.04 系统上成功地完成了 MariadB 的标准部署流程,并且对其进行基础但重要地初步配置加固工作。通过以上简洁明快且实用性强大地操作流程, 您现在拥有一个待定制与使用地强大 SQL 数据库管理系统。
368 15
|
4月前
|
存储 Ubuntu iOS开发
在Ubuntu 22.04系统上安装libimobiledevice的步骤
为了获取更多功能或者解决可能出现问题,请参考官方文档或者社区提供支持。
279 14
|
4月前
|
Ubuntu
在Ubuntu系统上设置syslog日志轮替与大小限制
请注意,在修改任何系统级别配置之前,请务必备份相应得原始档案并理解每项变更可能带来得影响。
572 2
|
5月前
|
XML Ubuntu Java
如何在Ubuntu系统上安装和配置JMeter和Ant进行性能测试
进入包含 build.xml 的目录并执行:
272 13
|
5月前
|
缓存 监控 Linux
CentOS系统如何查看当前内存容量。
以上方法都不需要特殊软件或者复杂配置即可执行,在CentOS或其他Linux发行版中都适合运行,并且它们各自透露出不同角度对待问题解答方式:从简单快速到深入详尽;从用户态到核心态;从操作层数到硬件层数;满足不同用户需求与偏好。
411 8