如何设置Foreman在Ubuntu 16.04上管理Puppet节点

时间:2020-03-05 15:29:29  来源:igfitidea点击:

Foreman是一个开源工具,可帮助系统管理员在其生命周期中管理服务器,从供应和配置来管理和配置来管理和配置。
我们可以轻松自动化重复的任务,快速部署应用程序,并主动地管理更改,使用Puppet,Chef,Salt,Ansible和Foreman的智能代理体系结构,使用VMS和裸机或者云中的内部前提。
工头提供全面的交互设施,包括网络前端,CLI和RESTful API,使我们可以在坚实的基础上构建更高级别的业务逻辑。

使用Foreman我们可以发现,配置和升级整个裸机基础架构,创建和管理私有和公共云的实例。
我们可以在一组主机中使用它并在批量中管理它们,无论位置如何,请查看审计或者故障排除的历史更改。

准备工作

在移动到工头安装之前必须确保一些基本要求。
第一件事是其中创建一个新的VM,我们有root权限,配置其FQDN和主机名,可以使用以下命令SETU。

# hostnamectl set-hostname ksh-u16

然后在主机名之前使用FQDN编辑"主机"文件。

# vi /ete/hosts
127.0.0.1 ksh-u16.theitroad.com ksh-u16

保存并关闭文件并运行以下命令以检查是否已配置FQDN。

# hostname -f

我们将在输出中看到FQDN。
现在通过在命令行终端中发出以下命令,使用最新的更新和安全修补程序更新系统。

# apt-get update
# apt-get upgrade

选择"Y"键进行确认并启动系统更新。
一旦所有更新完成,我们都很好地走向工头安装。

在Ubuntu 16安装工头16

现在,我们将使用其安装程序安装Foreman,其中包括运行Foreman所需的所有所需组件,该组件是具有SSL和乘客模块的Puppet Master和Agent,Apache Web服务器。

首先,我们将使存储库能够使用以下命令使用Puppet Agent和Puppet Server使用Puppet 4.x。

# apt-get -y install ca-certificates
# wget https://apt.puppetlabs.com/puppetlabs-release-pc1-xenial.deb
# dpkg -i puppetlabs-release-pc1-xenial.deb

然后使用下面的命令来启用工头repo。

echo "deb http://deb.theforeman.org/xenial 1.14" > /etc/apt/sources.list.d/foreman.list
echo "deb http://deb.theforeman.org/plugins 1.14" >> /etc/apt/sources.list.d/foreman.list
apt-get -y install ca-certificates
wget -q https://deb.theforeman.org/pubkey.gpg -O- | apt-key add 

使用以下命令下载Forman Installer。

# apt-get update && apt-get -y install foreman-installer

现在我们将运行ForeMan安装程序,但在运行安装程序之前,请确保Ping $(hostname -f)显示真实的IP地址,而不是127.0.1.1.
如果存在,则更改或者删除此条目/etc/hosts。

安装运行是非交互式的,但可以通过在Foreman-Installer - Help中列出的任何选项或者运行Foreman-Installer -I以进行交互模式来自定义配置。
添加-v将禁用进度列并显示所有更改。

要运行安装程序,请执行以下命令。

# foreman-installer
Installing Done [100%] [...........................................................................]
Success!
* Foreman is running at https://ksh-u16.theitroad.com
Initial credentials are admin/cwGbVjM2zGP5aDwm
* Foreman Proxy is running at https://ksh-u16.theitroad.com:8443
* Puppetmaster is running at port 8140
The full log is at /var/log/foreman-installer/foreman.log

完成后,安装程序将打印一些详细信息,如上所述,我们将找到Foreman,Smart Proxy和Puppet Master详细信息。

工头web界面

让我们与上面提到的Foreman Web URL一起打开我们喜欢的浏览器,并如下所示登录我们提供的凭据。

https://ksh-u16.theitroad.com

Puppet管理

安装成功后,Foreman Installer将在主机上设置Puppet Master,与Foreman完全集成。
首先在Foreman主机上运行Puppet代理,该主机将将第一个Puppet报告发送给Foreman,自动在Foreman的数据库中创建主机。

# puppet agent --test
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for ksh-u16.centricait.com
Info: Applying configuration version '1485372953'
Notice: Applied catalog in 0.23 seconds

现在在Foreman Web界面中,单击"主机"选项卡,ForeMan主机应在列表中可见,并具有"确定"状态。
这表示其状态正常,在最后一个Puppet 运行中没有更改。

下载Puppet 模块

接下来,我们将使用以下命令使用Puppet Forge管理从Puppet Forge管理NTP服务的Puppet模块。

# puppet module install puppetlabs/ntp
Notice: Preparing to install into /etc/puppetlabs/code/environments/production/modules ...
Notice: Downloading from https://forgeapi.puppet.com ...
Notice: Installing -- do not interrupt ...
/etc/puppetlabs/code/environments/production/modules
└─┬ puppetlabs-ntp (v6.0.0)
└── puppetlabs-stdlib (v4.15.0)

在Foreman中,转到配置>类,然后单击"从主机名(右上角)导入",以从Puppet Master读取可用的Puppet 类并填充Foreman的数据库。
如果安装正确,则"NTP"类将出现在Puppet类列表中,如下所示。

其中我们需要检查图标,然后单击"更新"按钮。
NTP模块现在导入到工头,并准备与主机一起使用。

使用Puppet 模块

单击列表中的"NTP"类,更改为SMART类参数选项卡,然后在左侧选择服务器参数。
勾选覆盖复选框,因此Foreman管理类的"服务器"参数,并在提交页面之前根据需要更改默认值。

现在更改回主机选项卡,然后单击"员工主机"上的"编辑"。
在Puppet类选项卡上,展开NTP模块,然后单击+图标以将NTP类添加到主机,然后保存主机。

要查看Puppet配置,请单击yaml按钮在主页上返回时,它将显示通过ENC(外部节点分类器)接口传递给Puppet的NTP类和服务器参数。
重新运行Foreman主机上的"Puppet代理--test"以查看由Puppet和NTP模块自动重新配置的NTP服务。

单击yaml后,我们可以在网页上获取以下输出。

--
classes:
ntp:
authprov: ''
broadcastclient: ''
config: ''
config_dir: ''
config_epp: ''
config_file_mode: ''
config_template: ''
tos_minsane: ''
udlc: ''
udlc_stratum: ''
parameters:
puppetmaster: ksh-u16.theitroad.com
domainname: theitroad.com
root_pw:
puppet_ca: ksh-u16.theitroad.com
foreman_env: production
owner_name: Admin User
owner_email: [email protected]
foreman_subnets: []
foreman_config_groups: []
environment: production

添加更多Puppet 管理主机

安装了Puppet 代理的其他主机可以通过在Puppet.conf中设置服务器= ksh-u16.theitroad.com来使用此Puppet 主。
通过去基础架构>智能代理>证书或者在Puppet Master上使用以下命令签署他们的证书。

# puppet cert list
# puppet cert sign

可以将Puppet类添加到前部门而不是单个主机中的主机组,从而同时启用许多主机的标准配置。
主机组通常用于表示服务器角色。