博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cobbler自动化安装Linux系统
阅读量:5068 次
发布时间:2019-06-12

本文共 8994 字,大约阅读时间需要 29 分钟。

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 Templatehttpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName#遇见报错需要修改apache的配置文件,添加一行# vim /etc/httpd/conf/httpd.confServerName localhost:80

启动服务后,使用cobbler check检查配置文件查看是否有问题,一般第一次启动的时候会有报错,不过不用管,重启cobbler后就会正常

# cobbler checkTraceback (most recent call last):  File "/usr/bin/cobbler", line 36, in 
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:
:'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/tftp4 : 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/rsync6 : file /etc/xinetd.d/rsync does not exist7 : debmirror package is not installed, it will be required to manage debian deployments and repositories8 : 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 one9 : 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/settingmanage_dhcp  = 1manage_tftp  = 1manage_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 typetext#Use network installationurl --url=http://10.0.0.222/cobbler/links/CentOS-6.7-x86_64/#System authorization informationauth --useshadow --enablemd5 #Root password rootpw 123456rootpw --iscrypted $1$123456$wOSEtcyiP2N/IfIl15W6Z0#System bootloaderbootloader --location=mbr#Clear the Master Boot Recordzerombr#Run the Setup Agent firs boot firstboot --disable#System Keyboardkeyboard us#System Languagelang en_US#System Timezonetimezone --isUtc Asia/Shanghai#Installation logging levellogging --level=info#Firewall configurationfirewall --disable#Selinux configurationselinux --disable#Disk partition informationpart /boot --bytes-per-inode=4096 --fstype="ext4" --size=200part / --asprimary --bytes-per-inode=4096 --fstype="ext4" --size=10240reboot#This packages is for CentOS6.7%packages@base@core@compat-libraries@debugging@development@hardware-monitoring@performance@perl-runtime@large-systemslrzsz treetelnetnmap%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_apiCentOS-6.7-x86_64

在已经的客户端进行重装系统操作 ,这个操作一定要在客户端操作

# koan --replace-self --server=10.0.0.222 --profile=CentOS-6.7-x86_64

Cobbler使用python调用API

#!/usr/bin/pythonimport xmlrpclibserver = 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 retdef 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 retif __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中间)

%postsystemctl disable postfix.service$yum_config_stanza%end

添加定时任务,定期同步repo

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

 

转载于:https://www.cnblogs.com/ebay/p/7443299.html

你可能感兴趣的文章
一天一道算法题--5.30---递归
查看>>
switchcase的用法
查看>>
React.js 小书 Lesson15 - 实战分析:评论功能(二)
查看>>
Java基础03 构造器与方法重载
查看>>
kafka的使用
查看>>
团队计划会议-01
查看>>
Linux0.11内核--加载可执行二进制文件之1.copy_strings
查看>>
编写Nginx启停服务脚本
查看>>
这些老外的开源技术养活了很多国产软件
查看>>
看图软件推荐
查看>>
【IdentityServer4文档】- 欢迎来到 IdentityServer4
查看>>
安全测试的一些漏洞和测试方法
查看>>
spring框架学习笔记(八)
查看>>
探索 ConcurrentHashMap 高并发性的实现机制
查看>>
keil C 51 strlen库函数使用
查看>>
JS取得绝对路径
查看>>
排球积分程序(三)——模型类的设计
查看>>
tomcat URL乱码问题
查看>>
wpf首次项目开发技术总结wpf页面
查看>>
python numpy sum函数用法
查看>>