Katello:创建产品,存储库,内容视图,生命周期环境,激活密钥

时间:2020-03-21 11:45:55  来源:igfitidea点击:

我们将使用Katello创建包含RPM存储库的产品,还将创建内容视图并将该内容视图提升到生命周期环境。

本文是KVM,Katelo和Puppet系列测试环境项目的一部分。

测试环境

我们在CentOS 7服务器上安装了Katello:

katello.igi.local(10.11.1.4)有关安装说明,请参见此处

请参见下图,以确定本文适用的homelab部分。

本文中使用的一些Katello定义

所有这些都可以在Katello官方用户教程中找到,因此,我仅参考要点。

内容库集合(RPM或者Puppet)。

存储库的产品集合,内容托管者订阅产品。

库特殊的预先创建的生命周期环境,其中创建存储库,并将内容同步或者上载到该环境。
内容托管者可以在同步或者上载内容后订阅库并接收内容。

一个或者多个存储库和/或者Puppet模块的Content View快照。

发布发布内容视图是为了将其内容锁定在适当的位置,内容视图的内容将被克隆并应用所有过滤器,发布会创建内容视图的新版本。

提升内容视图可以克隆到不同的生命周期环境(开发,测试,生产)。

如果我们不熟悉Katello,建议我们给Katello官方用户教程。

锤式CLI

Hammer是Foreman的CLI工具。
我们将专门使用Hammer。

如果我们不熟悉Hammer,请查看以下速查表:https://access.redhat.com/articles/2258471

本文假定保存的凭据位于'~/.hammer/cli.modules.d/foreman.yml'中。

# cat ~/.hammer/cli.modules.d/foreman.yml
:foreman:
 :host: 'https://katello.igi.local/'
 :username: 'admin'
 :password: '**'

由于许多锤子命令是特定于组织的,因此我们可以为锤子命令设置默认的组织和默认位置,这样我们就不必每次都指定它。

# hammer defaults add --param-name organization --param-value "theitroad"
# hammer defaults add --param-name location --param-value "HomeLab"

检查确认:

# hammer defaults list
-------------|-------
PARAMETER    | VALUE  
-------------|-------
organization | theitroad
location     | HomeLab
-------------|-------

配置Katello

步骤1:创建Katello产品

创建一个将用于RPM存储库的产品。

# hammer product create \
  --name "el7_repos" \
  --description "Various repositories to use with CentOS 7"

检查确认:

# hammer product list
---|-----------|-------------------------------------------|--------------|--------------|----------
ID | NAME

| DESCRIPTION

| ORGANISATION | REPOSITORIES | SYNC STATE
---|-----------|-------------------------------------------|--------------|--------------|----------
1  | el7_repos | Various repositories to use with CentOS 7 | theitroad

| 0

|

---|-----------|-------------------------------------------|--------------|--------------|----------

步骤2:下载并导入GPG密钥

GPG密钥提供了一种方法来验证在存储库或者产品中找到的软件包的完整性。

创建一个文件夹来存储GPG密钥:

# mkdir /etc/pki/rpm-gpg/import/
# cd /etc/pki/rpm-gpg/import/

请注意,我们所需的GPG密钥将取决于我们计划使用的存储库。
就我而言,我将需要以下所列的那些。

CentOS 7签名GPG密钥:

# wget http://mirror.centos.org/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
# hammer gpg create \
  --key "RPM-GPG-KEY-CentOS-7" \
  --name "RPM-GPG-KEY-CentOS-7"

EPEL 7签名GPG密钥:

# wget https://archive.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7Server
# hammer gpg create \
  --key "RPM-GPG-KEY-EPEL-7Server" \
  --name "RPM-GPG-KEY-EPEL-7Server"

MySQL签名GPG密钥:

# wget https://repo.mysql.com/RPM-GPG-KEY-mysql
# hammer gpg create \
  --key "RPM-GPG-KEY-mysql" \
  --name "RPM-GPG-KEY-mysql"

Puppet签名GPG密钥:

# wget https://yum.puppetlabs.com/RPM-GPG-KEY-puppet
# hammer gpg create \
  --key "RPM-GPG-KEY-puppet" \
  --name "RPM-GPG-KEY-puppet"

Zabbix签名GPG密钥:

# wget http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX
# hammer gpg create \
  --key "RPM-GPG-KEY-ZABBIX" \
  --name "RPM-GPG-KEY-ZABBIX"

Remi签署GPG密钥(对于PHP 7.x):

# wget https://rpms.remirepo.net/RPM-GPG-KEY-remi
# hammer gpg create \
  --key "RPM-GPG-KEY-remi" \
  --name "RPM-GPG-KEY-remi"

Graylog签名GPG密钥:

# wget https://raw.githubusercontent.com/Graylog2/fpm-recipes/master/recipes/graylog-repository/files/rpm/RPM-GPG-KEY-graylog
# hammer gpg create \
  --key "RPM-GPG-KEY-graylog" \
  --name "RPM-GPG-KEY-graylog"

MongoDB签名GPG密钥:

# wget https://www.mongodb.org/static/pgp/server-3.6.asc
# hammer gpg create \
  --key "server-3.6.asc" \
  --name "RPM-GPG-KEY-mongodb"

Elasticsearch签名GPG密钥:

# wget https://artifacts.elastic.co/GPG-KEY-elasticsearch
# hammer gpg create \
  --key "GPG-KEY-elasticsearch" \
  --name "GPG-KEY-elasticsearch"

Bacula签署GPG密钥:

# wget https://copr-be.cloud.fedoraproject.org/results/slaanesh/Bacula/pubkey.gpg \
  -O slaanesh-bacula.gpg
# hammer gpg create \
  --key "slaanesh-bacula.gpg" \
  --name "RPM-GPG-KEY-slaanesh-bacula"

Lynis签名GPG密钥(此为可选):

# wget https://packages.cisofy.com/keys/cisofy-software-rpms-public.key
# hammer gpg create \
  --key "cisofy-software-rpms-public.key" \
  --name "RPM-GPG-KEY-cisofy"

检查确认:

# hammer gpg list --order ID
---|--------------------------------
ID | NAME

---|--------------------------------
1  | RPM-GPG-KEY-CentOS-7

2  | RPM-GPG-KEY-EPEL-7Server

3  | RPM-GPG-KEY-mysql

5  | RPM-GPG-KEY-cisofy

7  | GPG-KEY-elasticsearch

8  | RPM-GPG-KEY-puppet

9  | RPM-GPG-KEY-ZABBIX

10 | RPM-GPG-KEY-remi

11 | RPM-GPG-KEY-graylog

12 | RPM-GPG-KEY-mongodb

14 | RPM-GPG-KEY-slaanesh-bacula

---|--------------------------------

步骤3:建立储存库

CentOS 7基本资料库:

# hammer repository create \
  --product "el7_repos" \
  --name "base_x86_64" \
  --label "base_x86_64" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --gpg-key "RPM-GPG-KEY-CentOS-7" \
  --url "http://mirror.centos.org/centos/7/os/x86_64/" \
  --mirror-on-sync "no"

CentOS 7 Extras存储库:

# hammer repository create \
  --product "el7_repos" \
  --name "extras_x86_64" \
  --label "extras_x86_64" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --gpg-key "RPM-GPG-KEY-CentOS-7" \
  --url "http://mirror.centos.org/centos/7/extras/x86_64/"
  --mirror-on-sync "no"

CentOS 7更新资料库:

# hammer repository create \
  --product "el7_repos" \
  --name "updates_x86_64" \
  --label "updates_x86_64" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --gpg-key "RPM-GPG-KEY-CentOS-7" \
  --url "http://mirror.centos.org/centos/7/updates/x86_64/"
  --mirror-on-sync "no"

EPEL 7资料库:

# hammer repository create \
  --product "el7_repos" \
  --name "epel_x86_64" \
  --label "epel_x86_64" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --gpg-key "RPM-GPG-KEY-EPEL-7Server" \
  --url "https://dl.fedoraproject.org/pub/epel/7Server/x86_64/"

MySQL 5.7资料库:

# hammer repository create \
  --product "el7_repos" \
  --name "mysql_57_x86_64" \
  --label "mysql_57_x86_64" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --gpg-key "RPM-GPG-KEY-mysql" \
  --url "https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/"

用于安全审核的Lynis存储库(此是可选的):

# hammer repository create \
  --product "el7_repos" \ 
  --name "lynis" \
  --label "lynis" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --gpg-key "RPM-GPG-KEY-cisofy" \
  --url "https://packages.cisofy.com/community/lynis/rpm/"

Katello存储库,用于从中下载最新的客户端。
目前尚未签署GPG。

# hammer repository create \
  --product "el7_repos" \
  --name "katello_agent_x86_64" \
  --label "katello_agent_x86_64" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --url "https://fedorapeople.org/groups/katello/releases/yum/latest/client/el7/x86_64/"

Puppet资料库:

# hammer repository create \
  --product "el7_repos" \
  --name "puppet_pc1_x86_64" \
  --label "puppet_pc1_x86_64" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --gpg-key "RPM-GPG-KEY-puppet" \
  --url "https://yum.puppetlabs.com/el/7Server/PC1/x86_64/"

Zabbix 3.0 LTS存储库:

# hammer repository create \
  --product "el7_repos" \
  --name "zabbix_30_x86_64" \
  --label "zabbix_30_x86_64" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --gpg-key "RPM-GPG-KEY-ZABBIX" \
  --url "http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/"

Remi PHP 5.6存储库。
请注意,PHP 5.6将在2016年12月之前获得安全支持。

# hammer repository create \
  --product "el7_repos" \
  --name "remi_php_56_x86_64" \
  --label "remi_php_56_x86_64" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --gpg-key "RPM-GPG-KEY-remi" \
  --url "https://mirrors.ukfast.co.uk/sites/remi/enterprise/7/php56/x86_64/"

Remi PHP 7.2存储库:

# hammer repository create \
  --product "el7_repos" \
  --name "remi_php_72_x86_64" \
  --label "remi_php_72_x86_64" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --gpg-key "RPM-GPG-KEY-remi" \
  --url "https://mirrors.ukfast.co.uk/sites/remi/enterprise/7/php72/x86_64/"

Remi安全存储库:

# hammer repository create \
  --product "el7_repos" \
  --name "remi_safe_x86_64" \
  --label "remi_safe_x86_64" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --gpg-key "RPM-GPG-KEY-remi" \
  --url "https://mirrors.ukfast.co.uk/sites/remi/enterprise/7/safe/x86_64/"

Graylog 2.4资源库:

# hammer repository create \
  --product "el7_repos" \
  --name "graylog_24_x86_64" \
  --label "graylog_24_x86_64" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --gpg-key "RPM-GPG-KEY-graylog" \
  --url "https://packages.graylog2.org/repo/el/stable/2.4/x86_64/"

Elasticsearch 5.x存储库。
在我撰写本文时,Graylog 2.4不适用于Elasticsearch6.x。

# hammer repository create \
  --product "el7_repos" \
  --name "elasticsearch_5_x86_64" \
  --label "elasticsearch_5_x86_64" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --gpg-key "GPG-KEY-elasticsearch" \
  --url "https://artifacts.elastic.co/packages/5.x/yum"

MongoDB 3.6存储库:

# hammer repository create \
  --product "el7_repos" \
  --name "mongodb_36_x86_64" \
  --label "mongodb_36_x86_64" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --gpg-key "RPM-GPG-KEY-mongodb" \
  --url "https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/3.6/x86_64/"

Bacula资料库:

# hammer repository create \
  --product "el7_repos" \
  --name "slaanesh_bacula_x86_64" \
  --label "slaanesh_bacula_x86_64" \
  --content-type "yum" \
  --download-policy "on_demand" \
  --gpg-key "RPM-GPG-KEY-slaanesh-bacula" \
  --url "https://copr-be.cloud.fedoraproject.org/results/slaanesh/Bacula/epel-7-x86_64/"

检查确认:

# hammer repository list --order ID
---|------------------------|-----------|--------------|------------------------------------------------------------------------------
ID | NAME

| PRODUCT   | CONTENT TYPE | URL

---|------------------------|-----------|--------------|------------------------------------------------------------------------------
1  | base_x86_64

| el7_repos | yum

| http://mirror.centos.org/centos/7/os/x86_64/

2  | extras_x86_64

| el7_repos | yum

| http://mirror.centos.org/centos/7/extras/x86_64/

3  | updates_x86_64

| el7_repos | yum

| http://mirror.centos.org/centos/7/updates/x86_64/

4  | epel_x86_64

| el7_repos | yum

| https://dl.fedoraproject.org/pub/epel/7Server/x86_64/

5  | mysql_57_x86_64

| el7_repos | yum

| https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/

6  | lynis

| el7_repos | yum

| https://packages.cisofy.com/community/lynis/rpm/

7  | katello_agent_x86_64   | el7_repos | yum

| https://fedorapeople.org/groups/katello/releases/yum/latest/client/el7/x86_64/
8  | puppet_pc1_x86_64

| el7_repos | yum

| https://yum.puppetlabs.com/el/7Server/PC1/x86_64/

9  | zabbix_30_x86_64

| el7_repos | yum

| http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/

10 | remi_php_56_x86_64     | el7_repos | yum

| https://mirrors.ukfast.co.uk/sites/remi/enterprise/7/php56/x86_64/

11 | graylog_24_x86_64

| el7_repos | yum

| https://packages.graylog2.org/repo/el/stable/2.4/x86_64/

12 | mongodb_36_x86_64

| el7_repos | yum

| https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/3.6/x86_64/

13 | elasticsearch_5_x86_64 | el7_repos | yum

| https://artifacts.elastic.co/packages/5.x/yum

14 | remi_php_72_x86_64     | el7_repos | yum

| https://mirrors.ukfast.co.uk/sites/remi/enterprise/7/php72/x86_64/

15 | remi_safe_x86_64

| el7_repos | yum

| https://mirrors.ukfast.co.uk/sites/remi/enterprise/7/safe/x86_64/

16 | slaanesh_bacula_x86_64 | el7_repos | yum

| https://copr-be.cloud.fedoraproject.org/results/slaanesh/Bacula/epel-7-x86_64/
----|------------------------|-----------|--------------|------------------------------------------------------------------------------

步骤4:同步存储库

由于我们已经按顺序创建了存储库,因此可以使用以下循环通过使用存储库ID来同步所有存储库:

# for i in $(seq 1 16); do \
  hammer repository synchronize \
  --product "el7_repos" \
  --id "$i"; \
  done

如果这不是一个选择,那么我们可能必须将它们一对一地同步。

请注意,初始同步可能需要一段时间。

步骤5:建立内容检视

内容视图是一个或者多个存储库的快照。

# hammer content-view create \
  --name "el7_content" \
  --description "Content view for CentOS 7"

检查确认:

# hammer product list
---|-----------|-------------------------------------------|--------------|--------------|-----------------
ID | NAME

| DESCRIPTION

| ORGANISATION | REPOSITORIES | SYNC STATE

---|-----------|-------------------------------------------|--------------|--------------|-----------------
1  | el7_repos | Various repositories to use with CentOS 7 | theitroad

| 16

| Syncing Complete.
---|-----------|-------------------------------------------|--------------|--------------|-----------------

步骤6:将存储库添加到内容视图

同样,由于我们是按顺序创建存储库的,因此可以使用下面的循环通过使用存储库ID将它们全部添加到内容视图中:

# for i in $(seq 1 16); do \
  hammer content-view add-repository \
  --name "el7_content" \
  --product "el7_repos" \
  --repository-id "$i"; \
  done

步骤7:创建生命周期环境

生命周期环境就像内容宿主使用的内容视图版本的容器。
对于不同的生命周期环境,我们可以有不同的“容器”(例如dev,qa,prod)。

有一种特殊的没有父级的生命周期环境,称为“库”。
该库充当同步内容(例如产品,Puppet模块和已发布内容视图)的主要容器,并且每个组织都有一个库。

实际上,我们可以将库环境用作我们的测试环境测试环境(仅仅是因为它已经存在),并且所有经过测试并随后变得稳定的东西都可以升级到后续环境。
按照这种逻辑,我们将生命周期环境称为“稳定”。

# hammer lifecycle-environment create \
  --name "stable" \
  --label "stable" \
  --prior "Library"

检查确认:

# hammer lifecycle-environment list
---|---------|-------
ID | NAME    | PRIOR  
---|---------|-------
1  | Library |

2  | stable  | Library
---|---------|-------

步骤8:发布内容视图

我们需要发布内容视图,以便将其内容(RPM存储库)锁定在适当的位置。

# hammer content-view publish \
  --name "el7_content" \
  --description "Publishing repositories"

检查确认:

# hammer content-view version list
---|-------------------------------|---------|----------------------
ID | NAME

| VERSION | LIFECYCLE ENVIRONMENTS
---|-------------------------------|---------|----------------------
2  | el7_content 1.0

| 1.0     | Library

1  | Default Organization View 1.0 | 1.0     | Library

---|-------------------------------|---------|----------------------

步骤9:将版本升级到生命周期环境

内容视图的初始版本为1.0版,包含最近同步的RPM存储库,并且没有任何更改,因此可以将其提升到我们稳定的生命周期环境。

# hammer content-view version promote \
  --content-view "el7_content" \
  --version "1.0" \
  --to-lifecycle-environment "stable"

检查确认:

# hammer content-view version list
---|-------------------------------|---------|----------------------
ID | NAME

| VERSION | LIFECYCLE ENVIRONMENTS
---|-------------------------------|---------|----------------------
2  | el7_content 1.0

| 1.0     | Library, stable

1  | Default Organization View 1.0 | 1.0     | Library

---|-------------------------------|---------|----------------------

步骤10:创建激活密钥

激活密钥提供了一种定义可以在注册期间应用于内容主机的属性的方法。

我们将创建一个名为“ el7-key”的新密钥。

# hammer activation-key create \
  --name "el7-key" \
  --description "Key to use with CentOS7" \
  --lifecycle-environment "stable" \
  --content-view "el7_content" \
  --unlimited-hosts

检查确认:

# hammer activation-key list
---|---------|----------------|-----------------------|------------
ID | NAME    | HOST LIMIT     | LIFECYCLE ENVIRONMENT | CONTENT VIEW
---|---------|----------------|-----------------------|------------
1  | el7-key | 0 of Unlimited | stable

| el7_content 
---|---------|----------------|-----------------------|------------

步骤11:将订阅添加到激活密钥

列出组织订阅:

# hammer subscription list
---|----------------------------------|-----------|----------|----------|---------|---------|---------------------|-----------|--------
ID | UUID

| NAME

| TYPE     | CONTRACT | ACCOUNT | SUPPORT | END DATE

| QUANTITY  | CONSUMED
---|----------------------------------|-----------|----------|----------|---------|---------|---------------------|-----------|--------
1  | 8a8b818461b4f6b00161b4fea2bc0007 | el7_repos | Physical |

|

|

| 2048/02/13 20:54:01 | Unlimited | 0

---|----------------------------------|-----------|----------|----------|---------|---------|---------------------|-----------|--------

将上面的订阅添加到我们的激活密钥中:

# hammer activation-key add-subscription \
  --name "el7-key" \
  --quantity "1" \
  --subscription-id "1"

步骤12:备份Katello配置

备份我们的Katello配置是一个好主意,这样我们就不会丢失到目前为止所做的任何更改:

# katello-backup /mnt/backup/--features=all -y