cobbler批量化安装系统

项目实施

一:硬件条件

要想批量部署操作系统,得具备以下条件:

客户机支持 pxe 网络引导

服务器端和客户端建立网络通信(DHCP)

服务器端要有可供客户机开机引导的引导文件

服务器端的可引导文件还必须能传递到客户机(TFTP)

客户机无人值守安装包括安装定制的软件或服务(KICKSTART)文件

二:PXE(预启动执行环境):

提供了一种使用网络接口(Network Interface)启动计算机的机制。这种机制让计算机的启动可以不依赖本地数据存储设备(如硬盘)或本地已安装的操作系统

PXE:支持工作站通过网络从远端服务器下载映像

工作原理:

PXE Client发送广播包请求DHCP分配IP地址DHCP

Server回复请求,给出IP地址以及Boot

PXE Client从Server下载引导文件执行引导程序

三:Kickstart

KickStart 是一种无人职守安装方式,是由redhat公司为了解决无人值守安装操作系统而设计的。系统管理员通过创建一个单一的 kickstart 配置文件就可以实现自动化安装操作系统

四:cobbler

是一个linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装,重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等

Cobbler是一个应用程序,可以大批量的部署操作系统,可以同时部署多个不同的操作系统,配合kickstart文件可以定制和无人值守的方式部署操作系统。

Cobbler是一个应用程序,可以大批量的部署操作系统,可以同时部署多个不同的操作系统,配合kickstart文件可以定制和无人值守的方式部署操作系统。

六:实现cobbler批量化安装centos7系统

一:安装cobbler

1:基础配置——服务器配置

注意虚拟网卡信息

网卡0:nat模式—静态IP地址(避免干扰)。

nat模式网关要自己主机虚拟网卡配置,注意网关、域名地址?

网卡1:仅主机模式,静态ip地址

不用使用特殊ip地址,如主机位为1,254, 不要与虚拟网卡ip地址,域名地址发生冲突

2: 更换yum源

 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo  #将 http 的文件下载并保存到/etc/yum.repos.d/CentOS-Base.repo 下
 curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

3: 使用yum安装cobbler

 yum -y install cobbler cobbler-web dhcp tftp pykickstart httpd xinetd rsync syslinux debmirror fenxe-agents 
 ​
 rpm -ql cobbler  # 查看安装的文件,下面列出部分。

4:cobbler语法检查前先启动http与cobbler

 systemctl start httpd.service
 systemctl start cobblerd.service
 cobbler check

5: 进行语法检查

 [root@Cobbler ~]# 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, and yaboot. 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.

6: 解决当中的报错

 #修改server参数的值为提供cobbler服务的主机相应的IP地址或主机名
 sed -i 's/server: 127.0.0.1/server: 192.168.100.2/' /etc/cobbler/settings
 #修改next_server参数的值为提供PXE服务的主机相应的IP地址
 sed -i 's/next_server: 127.0.0.1/next_server: 192.168.100.2/' /etc/cobbler/settings
 #启用cobbler的dhcp管理
 sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings
 #防止重装
 sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings
 #修改完成后的root密码
 sed -ri "/default_password_crypted/s#(.*: ).*#\1\"`openssl passwd -1 -salt 'cobbler' '123456'`\"#" /etc/cobbler/settings
 sed -i 's#yes#no#' /etc/xinetd.d/tftp
 cobbler get-loaders       #找不到get-loader命令
 ​
 systemctl start rsyncd
 systemctl enable rsyncd
 systemctl enable tftp.socket
 systemctl start tftp.socket
 systemctl restart cobblerd.service
 ​
 #修改dhcp模块,ip地址为仅主机模式的ip地址,且默认主机地址要为1即网络号.1
 此处ip地址,为另外一张网卡仅主机的IP地址是静态的
 vim /etc/cobbler/dhcp.template

 安装 debmirro,如果用不到可以忽略
 # yum -y install debmirror
 # sed -i  's|@dists=.*|#@dists=|'  /etc/debmirror.conf
 # sed -i  's|@arches=.*|#@arches=|'  /etc/debmirror.conf
 cobbler sync     #无报错
 cobbler check   #

7:启动rsync服务

 systemctl start rsyncd.service
 systemctl enable rsyncd.service

8:修改安装完成后的root密码

 openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'
 random-phrase-here  随机字符串
 your-password-here  密码
 [root@Cobbler ~]# openssl passwd -1 -salt 'cobbler' '123456'
 $1$CLSN$LpJk4x1cplibx3q/O4O/K/
 # vim /etc/cobbler/settings
 default_password_crypted: "$1$CLSN$LpJk4x1cplibx3q/O4O/K/"

9: 重启cobbler服务,生效

 # systemctl restart cobblerd.service
 ​
 # cobbler sync

10: 再次验证是否生效

问题1:debian系统需要 都忽略即可

11:重启所有服务

 systemctl restart httpd.service
 systemctl restart cobblerd.service
 systemctl restart dhcpd.service
 systemctl restart rsyncd.service
 systemctl restart tftp.socket

12: 开机自启相关服务(二选一)

 # 启动相关服务并设置开机启动(可选) 与第二种方法二选一
 chkconfig httpd on
 chkconfig xinetd on
 chkconfig cobblerd on
 chkconfig dhcpd on
 /etc/init.d/httpd restart
 /etc/init.d/xinetd restart
 /etc/init.d/cobblerd restart
 /etc/init.d/dhcpd restart
 # 编写Cobbler相关服务启动脚本(可选)
 cat >>/etc/init.d/cobbler<<EOF
 #!/bin/bash
 # chkconfig: 345 80 90
 # description:cobbler
 ​
 case \$1 in
   start)
     /etc/init.d/httpd start
     /etc/init.d/xinetd start
     /etc/init.d/dhcpd start
     /etc/init.d/cobblerd start
     ;;
 ​
   stop)
     /etc/init.d/httpd stop
     /etc/init.d/xinetd stop
     /etc/init.d/dhcpd stop
     /etc/init.d/cobblerd stop
     ;;
 ​
   restart)
     /etc/init.d/httpd restart
     /etc/init.d/xinetd restart
     /etc/init.d/dhcpd restart
     /etc/init.d/cobblerd restart
     ;;
 ​
   status)
     /etc/init.d/httpd status
     /etc/init.d/xinetd status
     /etc/init.d/dhcpd status
     /etc/init.d/cobblerd status
     ;;
 ​
   sync)
     cobbler sync
     ;;
 ​
   *)
     echo "Input error,please in put 'start|stop|restart|status|sync'!"
     exit 2
     ;;
 ​
 esac
 EOF
 ​
 # chmod +x /etc/init.d/cobbler
 # chkconfig cobbler on

13: 导入镜像到cobbler中

 # mkdir /mnt/centos7.6
 # mount -t iso9660 -o loop CentOS-7-x86_64-Minimal-1810.iso  /mnt/centos7.6
 # cobbler import --path=/mnt/centos7.6 --name=CentOS-7.6-2009-x86_64 --arch=x86_64


  • –path 镜像路径

  • –name 指定安装源的名字

  • –arch 指定导入镜像的体系结构

二:kickstarts文件配置:

——完成安装操作系统时的交互功能,目的为了减少交互过程

在传统安装操作系统时,需要大量的交互操作,为了减少交互的过程,kickstart就产生了,我们需要提前定义好这个kickstart的配置文件,并让安装程序知道kickstart配置文件的位置,在安装过程中读取kickstart配置即可实现无人值守的自动化安装操作系统。

ks配置文件: 记录安装完centos系统后的安装过程

1、修改 kickstart 文件(内存必须 2G 以上)

默认的kickstarts文件放在/var/lib/cobbler/kickstarts/目录下

一般centos系统安装完成后会在/root/anaconda-ks.cfg产生一个ks配置文件,记录安装过程,我们可以根据这个文件修改一下,修改好后放到/var/lib/cobbler/kickstarts目录

 mv sample_end.ks sample_end.ks.back
 #将原生成的ks文件备份重命名备份一下

自定义ks文件,用于完成操作系统安装时的过程

 自定义的ks文件
 # 最小换安装
 # cat /var/lib/cobbler/kickstarts/centos7u6-x64.ks
 #Kickstart Configurator for cobbler by Jason Zhao
 #platform=x86, AMD64, or Intel EM64T
 #System  language
 lang en_US
 #System keyboard
 keyboard us
 #Sytem timezone
 timezone Asia/Shanghai
 #Root password
 rootpw --iscrypted $default_password_crypted
 #Use text mode install
 text
 #Install OS instead of upgrade
 install
 #Use NFS installation Media
 url --url=$tree
 #System bootloader configuration
 bootloader --location=mbr
 #Clear the Master Boot Record
 zerombr
 #Partition clearing information
 clearpart --all --initlabel
 #Disk partitioning information
 part /boot --fstype xfs --size 1024 --ondisk sda
 part swap --fstype="swap" --size 2048 --ondisk sda
 part / --fstype xfs --size 1 --grow --ondisk sda
 #System authorization infomation
 auth  --useshadow  --enablemd5
 #Network information
 $SNIPPET('network_config')
 # network --bootproto=dhcp --device=em1 --onboot=on
 # Reboot after installation
 reboot
 #Firewall configuration
 firewall --disabled
 #SELinux configuration
 selinux --disabled
 #Do not configure XWindows
 skipx
 #Package install information
 %pre
 $SNIPPET('log_ks_pre')
 $SNIPPET('kickstart_start')
 $SNIPPET('pre_install_network_config')
 # Enable installation monitoring
 $SNIPPET('pre_anamon')
 %end
  
 %packages
 @ base
 @ core
 sysstat
 iptraf
 ntp
 lrzsz
 ncurses-devel
 openssl-devel
 zlib-devel
 OpenIPMI-tools
 mysql
 nmap
 screen
 %end
  
 %post
 systemctl disable postfix.service
 %end
 ​
 # 图形化安装
 #platform=x86, AMD64, or Intel EM64T
 #version=DEVEL
 # Install OS instead of upgrade
 install
 # Keyboard layouts
 keyboard 'us'
 # Root password
 rootpw --iscrypted $1$m1pE0DG6$vALBphGGynqvUzfJaWZ6U1
 # Use network installation
 url --url="$tree"
 # System language
 lang en_US
 # Firewall configuration
 firewall --disabled
 # System authorization information
 auth  --useshadow  --passalgo=sha512
 # Use graphical install
 graphical
 firstboot --disable
 # SELinux configuration
 selinux --disabled
 ​
 # Network information
 network  --bootproto=dhcp --device=eth0
 network  --bootproto=dhcp --device=eth1
 # Reboot after installation
 reboot
 # System timezone
 timezone Asia/Shanghai
 # System bootloader configuration
 bootloader --location=mbr
 # Clear the Master Boot Record
 zerombr
 # Partition clearing information
 clearpart --all --initlabel
 # Disk partitioning information
 part /boot --asprimary --fstype="xfs" --size=1024
 part swap --fstype="swap" --size=2048
 part / --fstype="xfs" --grow --size=1
 %packages
 @base
 @core
 @compat-libraries
 @debugging
 @development
 @gnome-desktop
 @X Window System
 %end

2: 查看 kickstart 的配置信息

  cobbler profile  report  --name=CentOS-7.6-2009-x86_64
 Name                           : CentOS-7.6-1810-x86_64
 TFTP Boot Files                : {}
 Comment                        :
 DHCP Tag                       : default
 Distribution                   : CentOS-7.6-1810-x86_64
 Enable gPXE?                   : 0
 Enable PXE Menu?               : 1
 Fetchable Files                : {}
 Kernel Options                 : {}
 Kernel Options (Post Install)  : {}
 Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks  # 这里还是默认的ks配置文件

3、修改指定的 kickstart 文件

 # cobbler profile list  #查看已有的启动文件名
 CentOS-7.6-2009-x86_64
 #cobbler profile getks --name "CentOS-7.6-2009-x86_64" #自检,/var/lib/cobbler/kickstart/sample_end.ks  文件信息

 #指定启动文件,要手写,不要复制
 # cobbler profile edit --name=CentOS-7.6-2009-x86_64  --  kickstart=/var/lib/cobbler/kickstarts/centos7u6-x64.ks  
 ​
 #修改centos配置文件中的kickstart值
 # cobbler profile edit --name=CentOS-7.6-2009-x86_64 --kopts='net.ifnames=0 biosdevname=0'   
 # cobbler sync   #执行rsync同步,同步成功

4: 查看kickstart 关联是否成功,注意是否修改成功

 cobbler profile report --name=CentOS-7.6-2009-x86_64 | grep -i kickstart
 Kickstart                      : /var/lib/cobbler/kickstarts/centos7u6-x64.ks
 Kickstart Metadata             : {}

5:修改启动菜单

 cobbler system add  --name=default --profile=CentOS-7.6-2009-x86_64
 # cobbler  system list
    default
 # cobbler sync   # 同步,然后在查看一下default的配置
 # cat /var/lib/tftpboot/pxelinux.cfg/default
 DEFAULT menu
 PROMPT 0
 MENU TITLE Cobbler | http://cobbler.github.io/
 TIMEOUT 200
 TOTALTIMEOUT 6000
 ONTIMEOUT CentOS-7.6-1810-x86_64
 ​
 ​
 ​
 LABEL local
         MENU LABEL (local)
         MENU DEFAULT
         LOCALBOOT -1
 ​
 LABEL CentOS-7.6-1810-x86_64
         kernel /images/CentOS-7.6-1810-x86_64/vmlinuz
         MENU LABEL CentOS-7.6-1810-x86_64
         append initrd=/images/CentOS-7.6-1810-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://10.10.1.13/cblr/svc/op/ks/profile/CentOS-7.6-1810-x86_64
         ipappend 2
 ​
 ​
 ​
 ​
 MENU end

检测客户端获取ip地址连接数已经操作状态

 cobbler status

客户端操作:

1:硬件配置,内存需2G以上

自动弹出配置

遇到问题:

1:镜像文件是Minimal版本,没有base包,改换DVD版本即可

2:查看,防火墙是否开启、tftp服务,69号端口是否正常,以及eth1 网卡的ip地址不要与v1虚拟卡的ip地址一致,会冲突

一定要注意ip地址问题

  • 28
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值