Cobbler实现自动化部署

     Cobbler介绍


     Cobbler是一款基于py开发的自动化部署工具,针对于物理机使用,可以对电源、配置、DHCP、DNS、TFTP、RSYNC以及YUM仓库、系统ISO镜像构建等做管理。方式简约而便捷。

     

    部署环境


1)关闭Selinux和Firewalld、iptables。

2)网络配置
      VMnet 4 :
      eth0: static
      ip address: 10.0.0.8
      netmask: 255.255.255.0

    开始部署


安装epel源

yum install -y http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

安装cobbler包

yum install -y tftp tftp-server xinetd httpd dhcp pykickstart cobbler cobbler-web

cobbler路径介绍

/var/lib/cobbler/kickstarts/ #kicktart文件存放路径,默认使用sample_end.ks.
/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日志

启动apache和cobbler服务

systemctl start httpd
^start^enable
systemctl start cobblerd
^start^enable

cobbler check

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, andyaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.

5 :enable and start rsyncd.service with systemctl

6 :debmirror package is not installed, it will be required to manage debian deployments and repositories

7 :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

8 :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.

按照提示解决

/etc/cobbler/settings:
修改:  ->next_server: ip #PXE东西放哪
       -> server: ip.
       -> manage_dhcp: 1 管理dhcp
       -> restart_dhcp: 1
       -> defaults_password_crypted:
          - 通过方式 openssl passwd -1 -salt '随机短语' '密码' #生成随机码

/etc/xinetd.d/tftp 
       -> disable改成no

开启rsyncd和tftp服务 

systemctl start rsyncd
^start^enable
systemctl start xinetd
^start^enable

配置cobbler模板管理dhcp

编辑 '/etc/cobbler/dhcp.template'
subnet 10.0.0.0 netmask 255.255.255.0 {
     option routers             10.0.0.17;
     option domain-name-servers 1.2.4.8;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        10.0.0.100 10.0.0.120;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;

镜像制作

cobbler import --path=/mnt/centos7 --name=Centos-7.4 --arch=x86_64 
#导入包到/var/www/cobbler/ks_mirrors中。(可以将镜像文件复制到/opt下,做个软链接)

修改cobbler提示语

编辑 '/etc/cobbler/pxe/pxedefault.template' #修改cobbler提示语
-> MENU TITLE Cobbler | http://cobbler.github.io/
-> MENU TITLE Cobbler by example | http://csdn.blog.net/changsha_csdn

同步cobbler

systemctl restart cobblerd
cobbler sync #同步,输出显示修改的内容

创建一台新的机器通过网络引导启动


网卡接口标准化制定

cobbler profile edit --name=centos7.4_x86_64 --kopts='net.ifnames=0 biosdevname=0' 

使用定制的ks文件

cobbler profile edit --name=centos7.4_x84_64-- 
kickstart=/var/lib/cobbler/kickstart/centos7.cfg

调用cobbler的API自动装机不询问

eg.cobbler system add --name=zfy --mac=00:0C:29:53:E0:F7 --profile=CentOS-7.4-x86_64 --ip-address=10.0.0.118  --subnet=255.255.255.0 --gateway=10.0.0.1 --interface=eth0 --static=1 --hostname=zfy.changsha.com --name-servers="1.2.4.8 8.8.8.8"
#添加一台主机,安装指定的profile,设置主机名以及将ip设置为静态

cobbler web 界面可视化管理

安装cobbler-web

[ `rpm -qa|grep cobbler-web|wc -l` -eq 0 ]&&yum install -y cobbler-web
[root@lb01 pxe]# rpm -ql cobbler-web|grep httpd
/etc/httpd/conf.d/cobbler_web.conf
[root@lb01 pxe]# cat /etc/httpd/conf.d/cobbler_web.conf
# This configuration file enables the cobbler web
# interface (django version)

<Directory "/usr/share/cobbler/web/">
        <IfModule mod_ssl.c>
            SSLRequireSSL
        </IfModule>
        <IfModule mod_nss.c>
            NSSRequireSSL
        </IfModule>
        SetEnv VIRTUALENV 
        Options Indexes MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>

<Directory "/var/www/cobbler_webui_content/">
        <IfModule mod_ssl.c>
            SSLRequireSSL
        </IfModule>
        <IfModule mod_nss.c>
            NSSRequireSSL
        </IfModule>
        Options +Indexes +FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>

# Use separate process group for wsgi
WSGISocketPrefix /var/run/wsgi
WSGIScriptAlias /cobbler_web /usr/share/cobbler/web/cobbler.wsgi
WSGIDaemonProcess cobbler_web display-name=%{GROUP}
WSGIProcessGroup cobbler_web
WSGIPassAuthorization On

<IfVersion >= 2.4>
    <Location /cobbler_web>
        Require all granted
    </Location>
    <Location /cobbler_webui_content>
	Require all granted
    </Location>
</IfVersion>

访问 https://10.0.0.17/cobbler_web 即可

Version:2.8.3

注意:访问web是https协议,不是http!!!如果错误各位多指教!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值