首页 > 代码库 > cobbler 自动化安装系统

cobbler 自动化安装系统

Kickstart概述
Kickstart 安装选项,包含语言选择、防火墙、密码、网络、分区设置等
2.安装Cobbler所需要的服务
yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd xinetd -y
The following are potential configuration items that you may want to fix:
3 : change ‘disable‘ to ‘no‘ in /etc/xinetd.d/tftp
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
5.根据上面提示修改相关配置
既然cobbler集成了所有功能,记住一点配置文件的修改都围绕Cobbler就不会有问题
第一、二步
[root@lx02 ~]# vim /etc/cobbler/settings
将next_server: 127.0.0.1 改为 next_server: 192.168.56.10
将server: 127.0.0.1更改为server: 192.168.56.10
将manage_dhcp: 0更改为manage_dhcp: 1
第三步
[root@lx02 ~]# cobbler get-loaders
第四步

disable = no
[root@lx02 ~]#systemctl restart xinetd.service
第七步
使用opessl生成一个密码
[root@lx02 ~]# openssl passwd -1 -salt ‘lx‘ ‘lx‘
[root@lx02 ~]# vim /etc/cobbler/settings
将101 default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac." 更改为下面openssl生成的密码
default_password_crypted: "$1$oldboy$fXF8f078vI9J/q9XyXA8e/"
[root@lx02 ~]# /etc/init.d/cobblerd restart
重启服务
[root@lx ~]# systemctl restart cobblerd.service
再次cobbler check,发现只有下面三个选项,就表示OK
[root@lx ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : enable and start rsyncd.service with systemctl
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
Restart cobblerd and then run ‘cobbler sync‘ to apply changes
修改dhcp模版配置文件
[root@lx ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.56.0 netmask 255.255.255.0 {
option routers 192.168.56.2;
option domain-name-servers 192.168.56.2;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.56.120 192.168.56.254;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
#Cobbler密码修改
1 htdigest /etc/cobbler/users.digest "Cobbler" cobbler
注意每次修改完cobbler配置的时候注意使用cobbler sync
cobbler sync
启动服务
[root@lx ~]# systemctl restart httpd.service
[root@lx ~]# systemctl restart xinetd.service
[root@lx ~]# systemctl restart rsyncd.service
[root@lx ~]# systemctl restart cobblerd.service
为cobber主机添加镜像

挂载镜像
[root@lx ~]# mount /dev/cdrom /mnt/
导入镜像(centos6 和 centos7)
[root@lx ~]# cobbler import --path=/mnt/ --name=CentOS-7-x86_64 --arch=x86_64
[root@lx ~]# cobbler import --path=/mnt/ --name=CentOS-6-x86_64 --arch=x86_64
查看镜像
[root@lx ~]# ll /var/www/cobbler/ks_mirror/
[root@lx ~]# cobbler list[root@lx kickstarts]# cobbler list
distros:
CentOS-6-x86_64
CentOS-7-x86_64
profiles:
CentOS-6-x86_64
CentOS-7-x86_64
上传ks.cfg文件
[root@lx ~]# cd /var/lib/cobbler/kickstarts/
[root@lx kickstarts]# rz CentOS-7-x86_64.cfg
[root@lx kickstarts]# rz CentOS-6-x86_64.cfg
修改cobbler加载启动ks文件
1
2 cobbler profile edit --name=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg
cobbler profile edit --name=CentOS-6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6-x86_64.cfg
修改linux内核使得网卡变为eth0
1 cobbler profile edit --name=CentOS-7-x86_64 --kopts=‘net.ifnames=0 biosdevname=0‘
查看最终修改结果
[root@lx kickstarts]# cobbler profile report --name=CentOS-7-x86_64
Name : CentOS-7-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : CentOS-7-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg
Kickstart Metadata : {}
Management Classes : []
Management Parameters : <<inherit>>
Name Servers : []
Name Servers Search Path : []
Owners : [‘admin‘]
Parent Profile :
Internal proxy :
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Repos : []
Server Override : <<inherit>>
Template Files : {}
Virt Auto Boot : 1
Virt Bridge : xenbr0
Virt CPUs : 1
Virt Disk Driver Type : raw
Virt File Size(GB) : 5
Virt Path :
Virt RAM (MB) : 512
Virt Type : kvm
所有的操作完毕之后都需要执行cobbler sync
________________________________________
新建虚拟机测试
新建一个虚拟机
启动虚拟机

正在安装

________________________________________
修改Cobbler密码
访问https://192.168.56.101/cobbler_web,将原来的密码更换为lx

New password:
Re-type new password:
cobbler web密码生成存放目录
/etc/cobbler/users.digest 密码管理文件
________________________________________

安装epel源

安装koan
yum install -y koan
查看Cobbler服务端可用镜像
[root@bogon ~]# koan –server=192.168.56.101 –list=profiles
- looking for Cobbler at http://192.168.56.101:80/cobbler_api
CentOS-7-x86_64
CentOS-6-x86_64
在已经的客户端进行重装系统操作

reboot
等待……….
________________________________________
Cobbler构建本地yum仓库
1.添加repo
2同步repo
[root@linux-node1~]#cobbler reposync
3添加openstack的repo到对应的profile
4修改kickstart文件。添加。(些到%post %end中间)
%post
systemctl disable postfix.service
$yum_config_stanza
%end
5添加定时任务,定期同步repo
________________________________________
Cobbler使用python调用API
#!/usr/bin/python
import xmlrpclib
server = xmlrpclib.Server("http://192.168.56.11/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
"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://192.168.56.11/cobbler_api","cobbler","cobbler")
print ret
if __name__ == ‘__main__‘:
main()

写了这么多,最后小编要放大招了!其实上面做了这么多并没有完全真正实现部署几百台机器,那么如何做到呢?
1.根据mac地址创建机器,mac地址唯一
cobbler system add --name=linux-node2.oldboyedu.com --mac=00:50:56:31:6C:DF --profile=CentOS-7-x86_64 \
--ip-address=192.168.56.102 --subnet=255.255.255.0 --gateway=192.168.56.2 --interface=eth0 \
--static=1 --hostname=linux-node2.oldboyedu.com --name-server="192.168.56.2" \
--kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg
2.由于我们已经做了资产录入管理,所以我们可以很轻松知道mac地址
3.使用API的方式调用cobbler,具体参见上面编写python脚本
总结:使用python调用资产管理系统的API得到mac地址,传入到python脚本中那么创建百台服务器安装都不是事

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 自动化安装系统