设为首页 收藏本站
查看: 961|回复: 0

[经验分享] cobbler自动化安装Linux系统

[复制链接]

尚未签到

发表于 2017-11-22 15:40:42 | 显示全部楼层 |阅读模式
cobbler简介
  Cobbler是一个Linux服务器快速网络安装的服务,而且在经过调整也可以支持网络安装windows。该工具使用python开发,小巧轻便(才15k行python代码),可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS,TFTP、RSYNC以及yum仓库、构造系统ISO镜像。
Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler是kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler客户端Koan支持虚拟机安装和操作系统重新安装,使重装系统更便捷。

cobbler安装部署
  操作系统:CentOS release 7.1
  防火墙、Selinux关闭
  安装eple源



# yum -y install epel-release
  安装cobbler所需要的软件包



# yum -y install cobbler cobbler-web pykickstart httpd dhcp tftp-server
  启动服务



# /etc/init.d/httpd start
# /etc/init.d/cobblerd start
  初次启动httpd会有报错



Starting httpd: httpd: apr_sockaddr_info_get() failed for Template
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
#遇见报错需要修改apache的配置文件,添加一行
# vim /etc/httpd/conf/httpd.conf
ServerName localhost:80
  启动服务后,使用cobbler check检查配置文件查看是否有问题,一般第一次启动的时候会有报错,不过不用管,重启cobbler后就会正常



# cobbler check
Traceback (most recent call last):
File "/usr/bin/cobbler", line 36, in <module>
sys.exit(app.main())
File "/usr/lib/python2.6/site-packages/cobbler/cli.py", line 657, in main
rc = cli.run(sys.argv)
File "/usr/lib/python2.6/site-packages/cobbler/cli.py", line 270, in run
self.token         = self.remote.login("", self.shared_secret)
File "/usr/lib64/python2.6/xmlrpclib.py", line 1199, in __call__
return self.__send(self.__name, args)
File "/usr/lib64/python2.6/xmlrpclib.py", line 1489, in __request
verbose=self.__verbose
File "/usr/lib64/python2.6/xmlrpclib.py", line 1253, in request
return self._parse_response(h.getfile(), sock)
File "/usr/lib64/python2.6/xmlrpclib.py", line 1392, in _parse_response
return u.close()
File "/usr/lib64/python2.6/xmlrpclib.py", line 838, in close
raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 1: "<class 'cobbler.cexceptions.CX'>:'login failed'">
  再次运行cobbler check检查配置文件,会出现如下错误,检查的时候一定要要在httpd与cobbler都启动的情况下检查



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.
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 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : 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.
5 : change 'disable' to 'no' in /etc/xinetd.d/rsync
6 : file /etc/xinetd.d/rsync does not exist
7 : debmirror package is not installed, it will be required to manage debian deployments and repositories
8 : 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
9 : 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/setting配置文件,将server行的IP改为本机IP
# sed -i 's#server: 127.0.0.0#server: 本机IP#g' /etc/cobbler/settings
2.需要修改/etc/cobbler/setting配置文件,将server_next行的IP改为本机IP
# sed -i 's#next_server: 127.0.0.1#next_server: 本机IP#g' /etc/cobbler/settings
3.修改/etc/xinetd.d/tftp配置文件,将disable = yes改为no
# sed -i 's#disable.*  = yes#disable                 = no #g' /etc/xinetd.d/tftp
4.运行cobbler get-loaders命令就行
5.修改/etc/xinetd.d/rsync配置文件,将disable = yes改为no
# sed -i 's#disable.*= yes# disable = no#g' /etc/xinetd.d/rsync
6.
7.安装debmirror包,如果不安装debian系统可以忽略
# yum install -y debmirror
8.使用openssl设置一个新的密码来代替默认密码
# openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'"
9.安装cman fence-agents
# yum install -y cman fence-agents
  再次检测配置文件,会有关于debian的报错。注释配置文件就行



注释如下两行
# vim /etc/debmirro.conf
#@dists="sid";
#@arches="i386";
  然后执行cobbler sync,同步更改后的配置文件



# cobbler sync
  cobbler可以管理dhcp,tftp,rsync服务



# vim /etc/cobbler/setting
manage_dhcp  = 1
manage_tftp  = 1
manage_rsync = 1
  cobbler管理dhcp后,只需修改cobbler提供的dhcp模板就行,不需要单独的修改dhcp服务的配置文件



subnet 10.0.0.0 netmask 255.255.255.0 {       #本机电脑所在的子网
option routers             10.0.0.2;     #设置客户端默认网关
option domain-name-servers 10.0.0.2;     #设置客户端默认DNS
option subnet-mask         255.255.255.0;
range dynamic-bootp        10.0.0.100 10.0.0.254;  #客户端获取到的地址范围
default-lease-time         21600;
max-lease-time             43200;
next-server                $next_server;
  注意:每次修改完cobbler配置信息的时候一定要使用check sync同步配置文件。
  给cobbler服务器导入镜像
  挂载镜像



将有镜像的分区挂载到服务上
# mount /dev/cdrom /mnt
  导入镜像



# cobbler import --path=/mnt --name=CentOS-6.7-x86_64 --arch=x86_64
# --path 镜像路径
# --name 为安装源定义一个名字
# --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64
# 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-6.6-x86_64,如果重复,系统会提示导入失败。
  查看镜像



# ll /var/www/cobbler/ks_mirror/
# cobbler distro list
  配置ks配置文件



# more CentOS-6.7-x86_64.ks
#Install OS
install
#Install type
text
#Use network installation
url --url=http://10.0.0.222/cobbler/links/CentOS-6.7-x86_64/

#System authorization information
auth --useshadow --enablemd5
#Root password rootpw 123456
rootpw --iscrypted $1$123456$wOSEtcyiP2N/IfIl15W6Z0
#System bootloader
bootloader --location=mbr
#Clear the Master Boot Record
zerombr
#Run the Setup Agent firs boot
firstboot --disable
#System Keyboard
keyboard us
#System Language
lang en_US
#System Timezone
timezone --isUtc Asia/Shanghai
#Installation logging level
logging --level=info
#Firewall configuration
firewall --disable
#Selinux configuration
selinux --disable
#Disk partition information
part /boot --bytes-per-inode=4096 --fstype="ext4" --size=200
part / --asprimary --bytes-per-inode=4096 --fstype="ext4" --size=10240
reboot
#This packages is for CentOS6.7
%packages
@base
@core
@compat-libraries
@debugging
@development
@hardware-monitoring
@performance
@perl-runtime
@large-systems
lrzsz
tree
telnet
nmap
%end
  配置完成后需要cobbler sync
  然后启动一台新的机器就可以使用cobbler安装系统了。
  cobbler重装
  由于我是选择安装7的操作系统,现在由于我对centos7的操作系统不熟悉,想要重装为6的操作系统,该如何做呢?
  安装koan



# yum install -y koan
  查看cobbler可用的镜像



# koan --server=10.0.0.222 --list=profiles
- looking for Cobbler at http://10.0.0.222:80/cobbler_api
CentOS-6.7-x86_64
  在已经的客户端进行重装系统操作 ,这个操作一定要在客户端操作



# koan --replace-self --server=10.0.0.222 --profile=CentOS-6.7-x86_64
  Cobbler使用python调用API



#!/usr/bin/python
import xmlrpclib
server = xmlrpclib.Server("http://xx.xx.xx.xx/cobbler_api")
print server.get_distros()
print server.get_profiles()
print server.get_systems()
print server.get_images()
print server.get_repos()

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import xmlrpclib
class CobblerAPI(object):
def __init__(self,url,user,password):
self.cobbler_user= user
self.cobbler_pass = password
self.cobbler_url = url
def add_system(self,hostname,ip_add,mac_add,profile):
'''
        Add Cobbler System Infomation
'''
        ret = {
"result": True,
"comment": [],
}
#get token
remote = xmlrpclib.Server(self.cobbler_url)
token = remote.login(self.cobbler_user,self.cobbler_pass)
#add system
system_id = remote.new_system(token)
remote.modify_system(system_id,"name",hostname,token)
remote.modify_system(system_id,"hostname",hostname,token)
remote.modify_system(system_id,'modify_interface', {
"macaddress-eth0" : mac_add,
"ipaddress-eth0" : ip_add,
"dnsname-eth0" : hostname,
}, token)
remote.modify_system(system_id,"profile",profile,token)
remote.save_system(system_id, token)
try:
remote.sync(token)
except Exception as e:
ret['result'] = False
ret['comment'].append(str(e))
return ret
def main():
cobbler = CobblerAPI("http://xx.xx.xx.xx/cobbler_api","cobbler","cobbler")
ret = cobbler.add_system(hostname='cobbler-api-test',ip_add='xx.xx.xx.xx',mac_add='xx:xx:xx:xx:xx:xx',profile='CentOS-7-x86_64')
print ret
if __name__ == '__main__':
main()
  添加repo



# cobbler repo add --name=xxoo  --mirror=http://xxoo
  同步repo



# cobbler reposync
  添加repo到对应的profile



# cobbler profile --name=xxoo --repos=xxoo
  修改kickstart文件,添加(写到%post %end中间)



%post
systemctl disable postfix.service
$yum_config_stanza
%end
  添加定时任务,定期同步repo



# echo "1 3 * * * /usr/bin/cobbler reposync --tries=3 --no-fail" >>/va/spool/cron/root

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-409546-1-1.html 上篇帖子: [转]从零开始:在Linux上覆盖安装WINDOWS通用教程(dd) 下篇帖子: 文本排序的王者:玩透sort命令
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表