cobbler自动化装机的实现(CentOS7版)

mac2024-07-01  48

操作系统:CentOS Linux release 7.4.1708 (Core)

cobbler版本:2.8.5

1.cobbler简介

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

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

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

Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。

Cobbler官网http://cobbler.github.io

1.1 cobbler集成的服务

         PXE服务支持

    DHCP服务管理

    DNS服务管理(可选bind,dnsmasq)

    电源管理

    Kickstart服务支持

    YUM仓库管理

    TFTP(PXE启动时需要)

    Apache(提供kickstart的安装源,并提供定制化的kickstart配置)

2.cobbler的安装与配置

2.1 环境准备

[root@bj-ops-localenv-01 ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) [root@bj-ops-localenv-01 ~]# uname -r 3.10.0-1062.4.1.el7.x86_64 [root@bj-ops-localenv-01 ~]# getenforce Disabled [root@bj-ops-localenv-01 ~]# systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon    Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)    Active: inactive (dead)      Docs: man:firewalld(1)

替换yum源

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

2.2 使用yum源安装cobbler2.8.5

yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd cman debmirror

2.3 在宿主机em1上绑定虚拟网卡em1:0 并启动

[root@bj-ops-localenv-01 network-scripts]# cat ifcfg-em1:0 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static DEFROUTE=yes IPV4_FAILURE_FATAL=no NAME=em1:0 DEVICE=em1:0 ONBOOT=yes IPADDR=10.0.0.100 NETMASK=255.255.255.0 DNS1=223.6.6.6 DNS2=114.114.114.114

2.4 修改相关服务的配置

vim /etc/cobbler/dhcp.template (只贴出要修改的部分)

subnet 10.0.0.0 netmask 255.255.255.0 {      option routers             10.0.0.100;      #option domain-name-servers 10.0.0.100;      option subnet-mask         255.255.255.0;      range dynamic-bootp        10.0.0.100 10.0.0.140;      default-lease-time         21600;      max-lease-time             43200;      next-server                192.168.12.137;

vim /etc/cobbler/settings(只贴出要修改的部分)

default_password_crypted: "$1$icifbsa$GlSk4KZPpIscQsOpLkZh0/" 

注:openssl passwd -1 -salt '任意字母' '你的密码' 获得上面的加密密码,你的密码就是装机完成后的root密码

manage_dhcp: 1     #关闭管理dhcp功能

next_server: 192.168.0.100  #指出下一步要找的服务器,此处为本机IP,因为所有服务同在一台服务器上

server: 192.168.0.100  #cobbler服务IP,此处为本机IP

vi /etc/debmirror.conf (只贴出要修改的部分)

#@dists="sid";

#@arches="i386";  #这两个地方注释掉即可,不然过会 cobbler check 会报错

下载引导操作系统的必须文件,否则下面cobbler check会报错

cobbler get-loaders

修改由xinetd服务管理的tftp,rsync的香相关文件

/etc/xinetd.d/tftp

/etc/xinetd.d/rsync

把文件中的 disabled   =yes 改为disabled  =no

注:Centos7系统有可能要先安装rsync服务并启动

防止重装

sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings

2.5 四部曲,启动服务,检查错误,导入镜像文件,同步文件

重启所有服务

systemctl restart httpd

systemctl restart htcpd

systemctl restart xinetd

systemctl restart cobbler

cobbler检查

cobbler check    #确保没有报错,继续下一步

导入操作系统的ISO文件

#先mount  iso文件

mount -o loop /path/CentOS-7.1-x86_64.iso /mnt

#导入 . --name=名字任意,--path=刚才你mount的路径

cobbler import --path=/mnt/ --name=CentOS-7.1-x86_64 --arch=x86_64

以上检查无误后执行同步

cobbler sync

3 准备好ks自动应答文件

#platform=x86, AMD64, or Intel EM64T # System authorization information auth  --useshadow  --enablemd5 # System bootloader configuration bootloader --location=mbr # Partition clearing information #clearpart --all --initlabel # Use text mode install text # Firewall configuration firewall --enabled # Run the Setup Agent on first boot firstboot --enable # System keyboard keyboard us # System language lang en_US.UTF-8 # Use network installation url --url=$tree # If any cobbler repo definitions were referenced in the kickstart profile, include them here. $yum_repo_stanza # Network information $SNIPPET('network_config') # Reboot after installation reboot #Root password #rootpw --iscrypted $default_password_crypted # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # System timezone timezone  Asia/Shanghai # Install OS instead of upgrade install # Clear the Master Boot Record #zerombr # Allow anaconda to partition the system as needed #autopart %pre $SNIPPET('log_ks_pre') $kickstart_start $SNIPPET('pre_install_network_config') # Enable installation monitoring $SNIPPET('pre_anamon') %packages #$SNIPPET('func_install_if_enabled') #$SNIPPET('puppet_install_if_enabled') @base @core @development-libs @development-tools @editors @text-internet keyutils trousers fipscheck device-mapper-multipath imake lrzsz %post $SNIPPET('log_ks_post') # Start yum configuration $yum_config_stanza # End yum configuration $SNIPPET('post_install_kernel_options') $SNIPPET('post_install_network_config') $SNIPPET('func_register_if_enabled') $SNIPPET('puppet_register_if_enabled') $SNIPPET('download_config_files') $SNIPPET('koan_environment') $SNIPPET('redhat_register') $SNIPPET('cobbler_register') # Enable post-install boot notification $SNIPPET('post_anamon') # Start final steps $kickstart_done # End final steps

到这就大功告成啦,可以去cobbler的web界面玩耍玩耍了,由于篇幅较大就留在下一篇文章了

参考文档:

https://www.cnblogs.com/txwsqk/archive/2011/08/09/2132803.html

https://www.cnblogs.com/clsn/p/7839965.html

https://blog.oldboyedu.com/autoinstall-cobbler/

 http://www.cnblogs.com/clsn/p/7833333.html

 

 

 

 

 

最新回复(0)