使用virtualbox 安裝兩臺(tái)虛擬機(jī)來(lái)搭建Puppet服務(wù)端和客戶端的測(cè)試環(huán)境。
系統(tǒng)版本: CentOS 7.6 64位
內(nèi)核版本: 3.10.0-957
puppetserver版本: 5.3.10-1.el7
puppet-agent版本: 5.5.17-1.el7
機(jī)器名/IP地址:
服務(wù)端: pp-master / 192.168.31.123
客戶端: pp-agent / 192.168.31.124
【準(zhǔn)備】
關(guān)閉防火墻和SELINUX
將2臺(tái)主機(jī)的IP和主機(jī)名添加到/etc/hosts里,確保互相可以ping同對(duì)方的主機(jī)名
【安裝】
分別在pp-master,pp-agent下載并安裝puppet repo
rpm -ivh https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm
生成puppet repo的文件路徑 /etc/yum.repos.d/puppet5.repo
在pp-master上面安裝puppetserver和puppet
yum install puppetserver puppet -y
在pp-agent上面安裝puppet
yum install puppet -y
【配置】
puppet的配置文件 /etc/puppetlabs/puppet/puppet.conf
服務(wù)器端puppet.conf
默認(rèn)配置如下:
[master]
vardir = /opt/puppetlabs/server/data/puppetserver
logdir = /var/log/puppetlabs/puppetserver
rundir = /var/run/puppetlabs/puppetserver
pidfile = /var/run/puppetlabs/puppetserver/puppetserver.pid
codedir = /etc/puppetlabs/code
將如下main配置添加進(jìn)服務(wù)器端puppet.conf
[main]
certname = pp-master
server = pp-master
environment = production
runinterval = 10m
strict_variables = true
certname(證書(shū)名)和server(服務(wù)器名)都設(shè)置為 pp-master
environment(環(huán)境)默認(rèn)為production(生產(chǎn)環(huán)境)
runinterval(運(yùn)行間隔時(shí)間)設(shè)置為10分鐘
strict_variables(強(qiáng)制變量)設(shè)定為true
將如下main配置添加進(jìn)客戶端puppet.conf
[main]
certname = pp-agent
server = pp-master
environment = production
runinterval = 10m
證書(shū)名為本機(jī)hostname: pp-agent
服務(wù)器端為pp-master
環(huán)境默認(rèn)為production
運(yùn)行間隔時(shí)間為10分鐘
編輯hiera配置 /etc/puppetlabs/puppet/hiera.yaml
---
:backends:
- yaml
:yaml:
:datadir: "/etc/puppetlabs/code/environments/%{environment}/hieradata"
:hierarchy:
- "hosts/%{::trusted.certname}"
- common
:yaml:
# datadir is empty here, so hiera uses its defaults:
# - /etc/puppetlabs/code/environments/%{environment}/hieradata on *nix
# - %CommonAppData%\PuppetLabs\code\environments\%{environment}\hieradata on Windows
# When specifying a datadir, make sure the directory exists.
:datadir:
客戶端host配置存放在路徑/etc/puppetlabs/code/environments/production/hieradata/hosts/pp-agent
配置內(nèi)容:
---
classes:
- helloworld
首先定義一個(gè)叫helloworld的模塊用于測(cè)試
模塊目錄:
/etc/puppetlabs/code/environments/production/modules/helloworld
目錄下有3個(gè)目錄:
helloworld/
├── files
│ └── hw.txt
├── manifests
│ └── init.pp
└── templates
files和templates目錄下存放模板文件,該模板文件為hw.txt
manifests的init.pp文件用于定義模塊需要哪些資源和操作
init.pp
class helloworld {
file { '/tmp/hw.txt':
ensure => 'file',
source => 'puppet:///modules/helloworld/hw.txt',
mode => '0644',
owner => 'root',
group => 'root',
}
}
該模塊定義了一個(gè)helloworld的類,資源為file,其內(nèi)容為"Hello world!".
'/tmp/hw.txt' 為客戶端生成的文件路徑和名稱
ensure 定義該類型為文件,其他還有l(wèi)ink, directory, 或者可以定義為present和absent表示該文件存在或不存在
mode為文件權(quán)限644
owner文件所有者為root
group文件組為root
【服務(wù)】
啟動(dòng)服務(wù)器端服務(wù)
systemctl start puppetserver
systemctl start puppet
啟動(dòng)客戶端服務(wù)systemctl start puppet
客戶端執(zhí)行puppet agent -t 用戶拉取配置
服務(wù)器端需要對(duì)證書(shū)簽名,puppet cert sign --all
【測(cè)試】
客戶端執(zhí)行puppet agent -t 命令后,可以看到文件已經(jīng)生成
Notice: /Stage[main]/Helloworld/File[/tmp/hw.txt]/ensure: defined content as '{md5}59ca0efa9f5633cb0371bbc0355478d8'
Notice: Applied catalog in 0.60 seconds
至此,一個(gè)簡(jiǎn)單的Puppet CS環(huán)境搭建完成。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)站題目:搭建Puppet服務(wù)-創(chuàng)新互聯(lián)
分享鏈接:http://www.chinadenli.net/article0/gsjio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、網(wǎng)站改版、外貿(mào)建站、網(wǎng)站導(dǎo)航、商城網(wǎng)站、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容