Cobbler 自动化部署神器批量安装系统(1)

1.Cobbler 介绍

  • Cobbler是一个Linux服务器快速网络安装的服务,而且在经过调整也可以支持网络安装windows。

  • 该工具使用python开发,小巧轻便(才15k行python代码),可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS,TFTP、RSYNC以及yum仓库、构造系统ISO镜像。

  • Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。

  • Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。

Cobbler官网


2. Cobbler核心组件

组件 介绍
distro 表示一个发行版,用于标记一个发行版的最关键资源是kernel和ramdisk
profile 对于某一个特定的发行版(distro),加上kickstart文件,以及可能的存储库(repository)和一些内核参数,就是profile
system 对于某一个发行版(distro),使用一个特定的配置文件(profile)配置的一个或多个机器,就是system
repository 保存一个yum或rsync存储库的镜像信息
image 可替换一个包含不属于此类别的文件的发行版对象(例如,无法分为kernel和initrd的对象)

3. 安装环境准备

[root@localhost ~]$ cat /etc/redhat-release 
CentOS release 6.10 (Final)
[root@localhost ~]$ setenforce 0
[root@localhost ~]$ service iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@localhost ~]$ yum install python-devel python-devel gcc gcc-c++ automake autoconf ntpdate wget -y
[root@localhost ~]$ wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

注意:

	虚拟机最好使用 (NAT)模式 ,因为稍后会搭建DHCP服务器在同一个局域网内有多个DHCP
服务器会起冲突,VMware NAT模式的DHCP服务也要关闭掉。

  • 虚拟机DHCP关闭方法菜单栏点击 编辑 → 虚拟网络编辑器 → 更改设置 → 选择NAT网卡

关闭DHCP

4 开始安装Cobbler

#一会安装Cobbler-web的时候会有一个依赖,先解决
Error: Package: cobbler-web-2.6.11-7.git95749a6.el6.noarch (epel)
           Requires: Django >= 1.4
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

[root@localhost ~]$ pip install --upgrade pip==9.0.3
#安装9.0.3版本pip
[root@localhost ~]$ pip install Django==1.4
#安装指定版本的Django框架
[root@localhost ~]$ yum install cobbler dhcp tftp-server pykickstart httpd -y
#安装Cobbler等所需服务
[root@localhost ~]$ wget https://mirrors.huaweicloud.com/epel/6/x86_64/Packages/c/cobbler-web-2.6.11-7.git95749a6.el6.noarch.rpm
#手动下载安装包
[root@localhost ~]$ rpm -ivh cobbler-web-2.6.11-7.git95749a6.el6.noarch.rpm --nodeps
[root@localhost ~]$ rpm -ql cobbler

cobbler文件介绍

/etc/cobbler                  # 配置文件目录
/etc/cobbler/settings         # cobbler主配置文件,这个文件是YAML格式,Cobbler是python写的程序。
/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模块配置文件

/var/lib/cobbler              # Cobbler数据目录
/var/lib/cobbler/config       # 配置文件
/var/lib/cobbler/kickstarts   # 默认存放kickstart文件
/var/lib/cobbler/loaders      # 存放的各种引导程序

/var/www/cobbler              # 系统安装镜像目录
/var/www/cobbler/ks_mirror    # 导入的系统镜像列表
/var/www/cobbler/images       # 导入的系统镜像启动文件
/var/www/cobbler/repo_mirror  # yum源存储目录

/var/log/cobbler              # 日志目录
/var/log/cobbler/install.log  # 客户端系统安装日志
/var/log/cobbler/cobbler.log  # cobbler日志

4. 配置Cobbler

[root@localhost ~]$ sed -i "s/#ServerName www.example.com:80/ServerName 192.168.244.254/g" /etc/httpd/conf/httpd.conf
#替换成自己的IP或域名
[root@localhost ~]$ service httpd restart
[root@localhost ~]$ service cobblerd restart
[root@localhost ~]$ cobbler check
# 检测Cobbler的配置,如果看不到下面的结果,再次执行service cobblerd restart

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 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
    https://github.com/cobbler/cobbler/wiki/Selinux
4 : change 'disable' to 'no' in /etc/xinetd.d/tftp
5 : 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.
6 : change 'disable' to 'no' in /etc/xinetd.d/rsync
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、2个问题,顺便修改其他功能
[root@localhost ~]$ sed -i 's/server: 127.0.0.1/server: 192.168.244.254/' /etc/cobbler/settings
#Cobbler服务器的IP
[root@localhost ~]$ sed -i 's/next_server: 127.0.0.1/next_server: 192.168.244.254/' /etc/cobbler/settings
#Cobbler DHCP服务器的IP
[root@localhost ~]$ sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings
#使用Cobbler来管理DHCP服务
[root@localhost ~]$ sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings
#防止循环安装系统,适用于服务器第一项启动项是PXE启动

# 第3个问题 关闭selinux
[root@localhost ~]$ vim /etc/sysconfig/selinux 
SELINUX=disabled
#把enforcing更改成disabled

# 第4个问题  开启tftp
[root@localhost ~]$ vim /etc/xinetd.d/tftp

# 第5个问题
[root@localhost ~]$ cobbler get-loaders
# 自动从官网下载
[root@localhost ~]$ cd /var/lib/cobbler/loaders/
# 下载的内容
[root@localhost loaders]# ls
COPYING.elilo     COPYING.yaboot  grub-x86_64.efi  menu.c32    README
COPYING.syslinux  elilo-ia64.efi  grub-x86.efi     pxelinux.0  yaboot

# 第6个问题 开启rsync
[root@localhost ~]$ vim /etc/xinetd.d/rsync
        disable = no
# 把yes改成no

# 第8个问题 设置新装系统的默认root密码123456
[root@localhost ~]$ vim /etc/cobbler/setting
default_password_crypted: "$1$hahaha$hSxFjZSHRoiEn4DYrrGUI."

5. 配置DHCP服务

#修改Cobbler的DHCP模板,不要直接修改DHCP本身的配置文件,因为cobbler会覆盖dhcp的配置文件
[root@localhost ~]$ vim /etc/cobbler/dhcp.template
#仅修改下面列出的字段
subnet 192.168.244.0 netmask 255.255.255.0 {
   
     option routers             192.168.244.2;
     option domain-name-servers 192.168.244.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.244.100 192.168.244.200;
重启系统
[root@localhost ~]$ reboot


开机后执行
[root@localhost ~]$ service iptables stop
[root@localhost ~]$ service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

[root@localhost ~]$ service cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]

6.Cobbler同步配置

# 同步最新cobbler配置,它会根据配置自动修改dhcp/tftp等服务。
[root@localhost ~]$ cobbler sync
task started: 2018-11-27_065923_sync
task started (id=Sync, time=Tue Nov 27 06:59:23 2018)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/efidefau
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值