Linux Cobbler实现系统自动安装

上一篇文章>pxe系统批量自动安装

一、Cobbler简介


  • Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
  • Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
  • Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
  • Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。

二、Cobbler编译安装


操作系统:rhel7.3
Python版本:2.7
安装包百度网盘链接: https://pan.baidu.com/s/1AOZ8vF4JyUSeFRn-sd100w 提取码: 4tnb

1、依赖安装

(1)yum安装
[root@server1 ~]# yum install -y createrepo httpd mkisofs python-netaddr \ 
python-urlgrabber xinetd rsync syslinux tftp-server yum-utils mod_ssl mod_wsgi \
git make python-devel python-setuptools fence-agents pykickstart dhcp rpm-build \ 
edpatch perl-Compress-Zlib perl-libwww-perl perl-Digest-SHA
(2)安装PyYAML

下载地址:https://pypi.org/project/PyYAML/#files

[root@server1 ~]# wget https://files.pythonhosted.org/packages/9f/2c/9417b5c774792634834e730932745bc09a7d36754ca00acf1ccd1ac2594d/PyYAML-5.1.tar.gz
[root@server1 ~]# tar xf PyYAML-5.1.tar.gz
[root@server1 ~]# cd PyYAML-5.1/
[root@server1 PyYAML-5.1]# python setup.py install
(3)安装Django
### 这里是Python2.7,如果是Python3的话可以装Django2版本
[root@server1 ~]# wget https://media.djangoproject.com/releases/1.10/Django-1.10.8.tar.gz
[root@server1 ~]# tar xf Django-1.10.8.tar.gz 
[root@server1 ~]# cd Django-1.10.8/
[root@server1 Django-1.10.8]# python setup.py install
(4)安装Markdown

下载地址:https://pypi.org/project/Markdown/#files

[root@server1 ~]# wget https://files.pythonhosted.org/packages/3c/52/7bae9e99a7a4be6af4a713fe9b692777e6468d28991c54c273dfb6ec9fb2/Markdown-3.0.1.tar.gz
[root@server1 ~]# tar xf Markdown-3.0.1.tar.gz 
[root@server1 ~]# cd Markdown-3.0.1/
[root@server1 Markdown-3.0.1]# python setup.py install
(5)安装Cheetah

下载地址:https://pypi.org/project/Cheetah/2.4.4/#files

[root@server1 ~]# wget https://files.pythonhosted.org/packages/cd/b0/c2d700252fc251e91c08639ff41a8a5203b627f4e0a2ae18a6b662ab32ea/Cheetah-2.4.4.tar.gz
[root@server1 ~]# tar xf Cheetah-2.4.4.tar.gz 
[root@server1 ~]# cd Cheetah-2.4.4/
[root@server1 Cheetah-2.4.4]# python setup.py install

2、安装Cobbler

联网安装链接:https://cobbler.github.io/manuals/quickstart/
下载地址:https://github.com/cobbler/cobbler/releases/tag/v2.8.4

[root@server1 ~]# wget https://github.com/cobbler/cobbler/archive/v2.8.4.tar.gz
[root@server1 ~]# tar xf v2.8.4.tar.gz
[root@server1 ~]# cd cobbler-2.8.4/
[root@server1 cobbler-2.8.4]# make && make install
[root@server1 cobbler-2.8.4]# mkdir -p /var/www/cobbler/web /srv/www/cobbler/svc

###检测,没有报错cobbler也会启动,手动启动命令systemctl restart cobblerd
[root@server1 cobbler-2.8.4]# make webtest

3、常用命令

cobbler check            ###核对当前设置是否有问题
cobbler list             ###列出所有的cobbler元素
cobbler report           ###列出元素的详细信息
cobbler sync             ###同步配置到数据目录,更改配置最好都要执行下
cobbler reposync         ###同步yum仓库
cobbler distro           ###查看导入的发行版系统信息
cobbler system           ###查看添加的系统信息
cobbler profile          ###查看配置信息

三、配置Cobbler


1、配置settings

### 生成加密密码,前面的“dreamya”为干扰码,可自行设置,这里“123456”就是root密码
[root@server1 ~]# openssl passwd -1 -salt 'dreamya' '123456'     
$1$dreamya$cNDemAQyzv5/63XPbALwY.

[root@server1 ~]# vim /etc/cobbler/settings
101 default_password_crypted: "$1$dreamya$cNDemAQyzv5/63XPbALwY."
242 manage_dhcp: 1             ###如果使用cobbler配置dhcp可以打开(即修改为1),否则直接配置dhcp即可
261 manage_rsync: 1
272 next_server: 10.10.10.1 (IP修改成本机地址)
292 pxe_just_once: 1            ###防止重装
384 server: 10.10.10.1 (IP修改成本机地址)

2、配置DHCP

不通过cobbler设置dhcp参考博客:https://blog.csdn.net/Dream_ya/article/details/79245704

[root@server1 ~]# vim /etc/cobbler/dhcp.template
...
subnet 10.10.10.0 netmask 255.255.255.0 {
     ### 下面这2个IP都是设置为本机ip
     option routers             10.10.10.1;
     option domain-name-servers 10.10.10.1;
     option subnet-mask         255.255.255.0;
     ### 设置生成IP范围
     range dynamic-bootp        10.10.10.110 10.10.10.150;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
     ...
}

3、配置tftp

[root@server1 ~]# vim /etc/cobbler/tftpd.template
service tftp
{
        disable                 = no       ###yes修改为no
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = $user
        server                  = $binary
        server_args             = -B 1380 -v -s $args
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

4、导入镜像

(1)通过光驱导入镜像

Linux Cobbler实现系统自动安装_第1张图片

(2)挂载镜像
[root@server1 ~]# mkdir /rhel7.3
[root@server1 ~]# mount /dev/sr0 /rhel7.3/
mount: /dev/sr0 is write-protected, mounting read-only
(3)导入镜像

自定制使用ks:cobbler profile add --name=安装选择时的名字 --kickstart=/var/lib/cobbler/kickstarts/xx.ks --distro=rhel7.3-x86_64 --kopts=‘net.ifnames=0 biosdevname=0’

[root@server1 ~]# cobbler import --path=/rhel7.3/ --name=rhel7.3 --arch=x86_64
[root@server1 ~]# cobbler distro list                     ###查看导入的镜像
   rhel7.3-x86_64

[root@server1 ~]# cobbler profile report rhel7.3-x86_64   ###查看镜像信息

5、下载cobbler相关的包

### 需要确定http和cobbler是启动的,下面这部是需要连接外网的,也可以把上面的百度网盘链接的loaders的包解压放入即可
[root@server1 ~]# systemctl restart httpd
[root@server1 ~]# cobbler get-loaders
task started: 2019-03-20_225257_get_loaders
task started (id=Download Bootloader Content, time=Wed Mar 20 22:52:57 2019)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***

[root@server1 ~]# ls /var/lib/cobbler/loaders/ 
COPYING.elilo     COPYING.yaboot  grub-x86_64.efi  menu.c32    README
COPYING.syslinux  elilo-ia64.efi  grub-x86.efi     pxelinux.0  yaboot

6、同步配置

### 如果想修改网卡名可以先执行此命令:cobbler profile edit --name=rhel7.3-x86_64 --kopts='net.ifnames=0 biosdevname=0'
[root@server1 ~]# cobbler sync
[root@server1 ~]# systemctl restart httpd && systemctl enable httpd
[root@server1 ~]# systemctl restart xinetd && systemctl enable xinetd
[root@server1 ~]# systemctl restart cobblerd && chkconfig cobblerd on
[root@server1 ~]# systemctl restart dhcpd && systemctl enable dhcpd

四、安装新镜像


1、创建新的虚拟机

Linux Cobbler实现系统自动安装_第2张图片
Linux Cobbler实现系统自动安装_第3张图片
Linux Cobbler实现系统自动安装_第4张图片
Linux Cobbler实现系统自动安装_第5张图片
Linux Cobbler实现系统自动安装_第6张图片
Linux Cobbler实现系统自动安装_第7张图片
Linux Cobbler实现系统自动安装_第8张图片
Linux Cobbler实现系统自动安装_第9张图片
Linux Cobbler实现系统自动安装_第10张图片

Linux Cobbler实现系统自动安装_第11张图片
Linux Cobbler实现系统自动安装_第12张图片
Linux Cobbler实现系统自动安装_第13张图片
Linux Cobbler实现系统自动安装_第14张图片
Linux Cobbler实现系统自动安装_第15张图片
Linux Cobbler实现系统自动安装_第16张图片

2、安装test1

Linux Cobbler实现系统自动安装_第17张图片

Linux Cobbler实现系统自动安装_第18张图片
接下来就是等待自动进行安装!!!
Linux Cobbler实现系统自动安装_第19张图片
执行修改网卡名效果图:
Linux Cobbler实现系统自动安装_第20张图片
五、UEFI启动ks


firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url=$tree
# Root password
rootpw --iscrypted $1$nD88pFjh$H9Kd9/Zp2J3jR.dxP9JBv0
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone  Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=em1 --onboot=on
# System bootloader configuration
bootloader --location=mbr
#bootloader --append=" crashkernel=auto" --location=mbr  --driveorder=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
#需要使用下面那个,mbr可以使用上面这个
#clearpart --all  --drives=sda
clearpart --none --initlabel


part /boot/efi --fstype="efi" --ondisk=sda --size=1024 --fsoptions="defaults,uid=0,gid=0,umask=0077,shortname=winnt"
part swap --fstype="swap" --size=2048
part / --fstype="ext4" --size=102400
part /boot --fstype="ext4" --size=1024

%pre
parted -s /dev/sda mklabel gpt
%end

%packages
@base
%end

你可能感兴趣的:(运维)