Centos7+puppet+foreman,实现部署OS Centos 7 Puppet之foreman介绍安装测试 pxe+http+kickstart实验原理

 

1、简介

  1. 须要实现操做系统的部署

        foreman提供了一个基于kickstart的部署工具,输入一台服务器的部署网卡的mac地址和hostname、ip等信息,就能自动的帮咱们部署完,而且,还能够生成一个部署iso,用于该服务器的从新部署。html

    

     foreman经过代理DNS、DHCP、TFTP完成了kickstart、cobbler、jumpstart等各类自动化安装系统工具的图形统一管理串口,实现的结果是只须要在foreman上指定各类模板(pxe、ks),不一样的模板还能够嵌套各类片断(snippet)达到统1、简化的目的。完成以后,即可以添加节点,关联定义的各类模板生成各类pxe和ks文件实现自动化安装。linux

 

  二、foreman工做流程

  

    

Steps
  1. On the New Host page, the default VM configuration is shown and compute profiles can be applied.
  2. An unused IP address is requested from the DHCP smart proxy associated with the subnet.
  3. The IP address field is filled in on the New Host page.
  4. n/a
  5. The New Host page is submitted.
  6. Foreman contacts the compute resource to create the virtual machine.
  7. The compute resource creates a virtual machine on a hypervisor.
  8. The VM’s MAC address is returned from the compute resource and stored on the host.
  9. A reservation is created on the DHCP smart proxy associated with the subnet.
  10. DNS records are set up:
    1. A forward DNS record is created on the smart proxy associated with the domain.
    2. A reverse DNS record is created on the DNS smart proxy associated with the subnet.
  11. A PXELinux menu is created for the host in the TFTP smart proxy associated with the subnet.
  12. Foreman contacts the compute resource to power on the VM.
  13. The compute resource powers up the virtual machine.
  14. The host requests a DHCP lease from the DHCP server.
  15. The DHCP lease response is returned with TFTP options (next-server, filename) set.
  16. The host requests the bootloader and menu from the TFTP server.
  17. The PXELinux menu and OS installer for the host is returned over TFTP.
  18. The installer requests the “provision” template/script from Foreman.
  19. Foreman renders the template and returns the resulting kickstart/preseed to the host.
  20. Autosigning configuration for Salt (or Puppet) is added on the Salt or Puppet CA smart proxy.
  21. The installer notifies Foreman of a successful build in the postinstall script.
  22. The PXELinux menu is reverted to a “local boot” template.
  23. The host requests its configuration from Salt or Puppet.
  24. The host receives appropriate configuration using data defined in Foreman.
  25. Configuration reports and facts are sent from Salt or Puppet to Foreman and stored.

  三、具体部署围着以下流程:

    安装软件源---》安装foreman---》web界面设置 Provisioning Setup---》手动配置智能代理(dhcp、dns、tftp等)---》web界面部署第一个节点---》开启虚拟机开始自动安装oswebpack

    web界面设置包括以下:(其中第一个节点加入foreman后,foreman会利用这个台节点建立一些信息,咱们也能够按照需求新建一些信息,这个示例利用了这些信息,咱们主要是配置安装源及模板的设置。)web

        architectures:定义软件架构apache

        hardware models:软件架构vim

        installation media:安装源windows

        partition tables:分区方法centos

        provisioning templates:部署模板服务器

        operating systems:最后一项配置,依赖以前的几项配置,选各类配置如软硬件架构,各类模板

架构

   四、foreman的安装能够参考

    Centos 7 Puppet之foreman介绍安装测试

2、设置资源及host菜单 

  一、解决安装源

    1)先挂载光盘

    2)用httpd作源

      咱们前面已经部署了foreman因此系统已经部署了apache服务,

      把挂载的光盘内容放在httpd目录

        

         mkdir -p /mnt/repo/centos7
         mount /dev/cdrom /media

      查看http目录关注标红的行便可,知道其默认目录为

        cat /etc/httpd/conf.d/05-foreman.conf 

root@www pxelinux.cfg]# cat /etc/httpd/conf.d/05-foreman.conf 
# ************************************
# Vhost template in module puppetlabs-apache
# Managed by Puppet
# ************************************

<VirtualHost *:80>
  ServerName www.puppet-foreman.com

  ## Vhost docroot
  DocumentRoot "/usr/share/foreman/public"

  ## Directories, there should at least be a declaration for /usr/share/foreman/public

  <Directory "/usr/share/foreman/public">
    Options SymLinksIfOwnerMatch
    AllowOverride None
    Require all granted
  </Directory>。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。。。。
。。。。。。。
<Directory ~ /usr/share/foreman/public/(assets|webpack)> # Use standard http expire header for assets instead of ETag <IfModule mod_expires.c> Header unset ETag FileETag None ExpiresActive On ExpiresDefault "access plus 1 year" </IfModule>。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。。。。。
。。。。。 </VirtualHost> PassengerPreStart http://www.puppet-foreman.com:80 [root@www pxelinux.cfg]#

        得知目录进行mv

         mv /mnt/repo/ /usr/share/foreman/public/

 

     3)建立安装源文件

      vim /etc/yum.repo.d/all_deps.repo

      

[root@www pxelinux.cfg]# cat /etc/yum.repos.d/all_deps.repo 
[centos7]
name=centos7
baseurl=http://192.168.216.234/repo/centos7
gpgcheck=0
enabled=1

      添加好源后记得yum clean all   yum makecache

  二、了解host导航菜单

    

    架构,定义x86_64,i386,unix,windows等

    硬件型号,定义硬件具体型号

    安装介质,定义安装源媒介或者路径

    操做系统,定义操做系统具体型号好比centos,redhat,bsdfree等

    模板

      分区表

      置备模板

  三、设置安装介质

    咱们如今添加安装介质,能够是URL或者nfs,咱们用刚刚添加源的URL

      http://192.168.216.234/repo/centos7

    因为架构和硬件型号及操做系统,咱们装玩foreman后本机就已经识别好,因此先添加安装介质

     流程:主机---》安装介质---》建立媒体---》添加:name、path、操做系统

    

  四、克隆置备模板并自定义编写ks

    编辑模板须要具备ks知识,我这里随便克隆一下,也没改,先测试一下

    流程:主机---》置备模板---》选则kickstart default pxelinux 模板 克隆按钮---》编辑相应的信息---》name,code---》类型-这里选pxelinux---》组合-这里操做系统选centos7---》提交

    图示以下:

      1)主机---》置备模板---》

    2)选则kickstart default pxelinux 模板 克隆按钮---》

      3)编辑相应的信息---》name,code---》

    4)类型-这里选pxelinux---》

    5)组合-这里操做系统选centos7---》提交

 

  五、设置操做系统(operating system)

     流程:主机---》操做系统--->点击主机”CentOS 7.6.1810“ ---》操做系统参数---》分区表---》安装介质---》模板---》提交

    1)主机---》操做系统--->点击主机”CentOS 7.6.1810“ ---》

    2)操做系统参数---》

 

    3)分区表---》

    4)安装介质

    5)模板---》提交

     

 

 

 

 

 

 

 

 

    注意:建立主机能够添加三个模板,一个是pxelinux模板,一个是置备模板,一个是彻底模板,而且不是锁定状态,因此须要克隆一个新的模板,

      

      一、三个原始模板分别是:完成模板:kickstart default finish 

                        置备模板:kickstart default 

                     pxelinux模板:kickstart default  pxelinux

      二、能够运行一下看看效果

      三、克隆时咱们分别在原名称上添加test字样便可,随便更名字

        (上面小结“4”已经说明如何克隆模板,这里不作介绍了)

       具体请参考另一篇文章,具体介绍模板,文章更新后在加上链接

    

3、设置代理及tftp文件

  新版本我没有找到Infrastructure->Provisioning setup导航,这个导航能够就像一个初始化指导同样如图下,输入可用信息,而后生成配置步骤

 

 

  一、手动设置代理服务及设置

      os部署须要tftp及dhcp,dns能够暂时不部署

[root@www repodata]# foreman-installer \                   
> --enable-foreman-proxy \                                 
> --foreman-proxy-tftp=true \                              
> --foreman-proxy-tftp-servername=192.168.216.234 \        
> --foreman-proxy-dhcp=true \                              
> --foreman-proxy-dhcp-interface=ens33 \                   
> --foreman-proxy-dhcp-gateway=192.168.216.234 \           
> --foreman-proxy-range="192.168.216.155 192.168.216.165"                   

    若是是没联网的机器关闭下面这个源

    > --foreman-configure-epel-repo=false    关闭

  二、部署tftp还须要copy那个几个文件

      tftp须要提供bootloader,及内核文件,具体什么做用能够参考pxe+http+kickstart实验原理

        文档上也有写:https://www.theforeman.org/manuals/1.21/index.html#4.3.9TFTP

      做用:

      vmlinuz kenrnel file

      vesamenu.32 图形菜单

      isolinux.cfg 开机菜单设定

      initrd.img 开启过程当中核心组件参数

      

  cd  /usr/share/foreman/public/repo/centos7
 cp isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default   #这个其实不用拷了,后面说说
 cp images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/boot
 cp isolinux/{vesamenu.c32,boot.msg,splash.png} /var/lib/tftpboot/

   这里手动设置其实很是简单几个要点

    一、tftp默认目录必须存在

    二、pxe引导先决条件:(/usr/share/syslinux中)

        pxelinux.0

        menu.c32

        chain.c32

    三、内核文件放在/var/lib/tftpboot/boot/  

    四、须要准备/var/lib/tftpboot/pxelinux.cfg/default

      其实这个文件不须要手动写,咱们在定义host得时候其实能够pxe和ks一块儿部署了,只是以前没有找到方法耽误了很长时间。下面介绍如何操做

4、开始部署节点

  一、主机导航菜单建立主机

  流程:主机---》建立主机---》主机---》操做系统---》接口---》puppet类---》参数---》附加信息

    1)主机---》建立主机

 

    2)主机---》

 

    3)操做系统---》

 

    4)接口---》

      点击编辑添加箭头指向的信息,也就是你须要建立主机的mac/ip/域名

 

    虚拟机得mac在下图能够看到

 

    5)puppet类---》参数---》

      这里咱们暂时不用设置

    6)附加信息

 

 

  二、提交后

 

  

  三、建立好后自动建立pxe文件

    以前还纳闷没有pxe文件怎么执行安装菜单那,原理foreman建立主机后就已经生成了以mac为名称的文件

    下面是示例,由于以前又克隆一个主机因此是新的主机,所哟mac地址不一样

[root@www pxelinux.cfg]# ll 
total 16
-rw-r--r-- 1 foreman-proxy foreman-proxy  557 Jun  4 11:53 01-00-50-56-2f-4e-fe
-rw-r--r-- 1 foreman-proxy foreman-proxy 1058 Jun  3 17:49 default
drwxr-xr-x 2 root          root           142 Jun  3 15:33 test

[root@www pxelinux.cfg]# cat 01-00-50-56-2f-4e-fe 
# This file was deployed via 'Kickstart default PXELinux test' template


DEFAULT menu
MENU TITLE Booting into OS installer (ESC to stop)
TIMEOUT 100
ONTIMEOUT installer

LABEL installer
  MENU LABEL Kickstart default PXELinux test
  KERNEL boot/centos7-test1-pPa2hWu9wvb7-vmlinuz
  APPEND initrd=boot/centos7-test1-pPa2hWu9wvb7-initrd.img ks=http://www.puppet-foreman.com/unattended/provision?token=241cc771-e27d-4f81-99a9-30e4cbc7628b  network ksdevice=bootif ks.device=bootif BOOTIF=00-00-50-56-2f-4e-fe kssendmac ks.sendmac inst.ks.sendmac
  IPAPPEND 2

  

  三、启动虚拟机

    建立虚拟机的步骤这里就省略了,能够自行建立便可

    启动虚拟机

    看到菜单

回车下一步就自行安装了,上面已经部署了分区及置备的ks 须要什么添加什么便可,开始自动部署之旅吧

   

 

 

5、排错

  一、出现以下错误的状况

 

   注意出错的信息:failed to fetch kickstart 获取ks失败

  由于实验环境没有设置dns,因此咱们能够把pxe文件的里面的ks=http://www.puppet-foreman.com域名换成你的ip便可。

 

 

参考1:https://www.theforeman.org/manuals/1.20/index.html#7.3GettingHelp

参考2:http://www.javashuo.com/article/p-doadlpfk-hr.html

参考3:http://www.javashuo.com/article/p-pbnudqkc-m.html

参考4:https://projects.theforeman.org/projects/foreman/wiki/TemplateWriting#PXE-Menus

参考5:https://projects.theforeman.org/projects/foreman/wiki

 参考6:https://projects.theforeman.org/projects/foreman/wiki/Dynamic_disk_partitioning

 

转载请注明出处:http://www.javashuo.com/article/p-aenabsqb-gr.html 

相关文章
相关标签/搜索