教育行業(yè)A股IPO第一股(股票代碼 003032)

全國咨詢/投訴熱線:400-618-4000

puppet是什么?puppet學(xué)習(xí)筆記

更新時間:2019年01月24日17時01分 來源:puppet是什么 瀏覽次數(shù):

puppet資源file資源介紹

資源的介紹

資源是puppet最基本的元素,每個資源的定義都具有標(biāo)題、類型以及一系列的屬性。puppet的特性就是處理資源與資源之間的依賴關(guān)系。

任何相同類型的資源都會具有一些相同的屬性。

資源定義有如下的特性:

1.puppet使用title在編譯時期區(qū)分每個資源,使用命名變量(namevar)在執(zhí)行時區(qū)分資源。

2.在同一類資源中title和namevar都是唯一的。

3.每個類型都有部分屬性有默認(rèn)值

4,如果不指定namevar,則默認(rèn)賦予其title的值。

file資源

Description

Manages files, including their content, ownership, and permissions.The file type can manage normal files, directories, and symlinks; the type should be specified in the ensure attribute. Note that symlinks cannot be managed on Windows systems.

File contents can be managed directly with the content attribute, or downloaded from a remote source using the source attribute; the latter can also be used to recursively serve directories (when the recurse attribute is set to true or local). On Windows, note that file contents are managed in binary mode; Puppet never automatically translates line

endings.

Autorequires: If Puppet is managing the user or group that owns a file, the file resource will autorequire them. If Puppet is managing any parent directories of a file, the file resource will autorequire them.

這個是官方對于puppet file資源的介紹,下面我們從使用的角度出發(fā),如何去配置file資源。

file資源的作用

1.管理文件、目錄、軟鏈接

2.管理文件內(nèi)容、屬性、權(quán)限

3.通過屬性開指定文件來源,也可以通過source屬性從遠(yuǎn)程服務(wù)器中下載。

設(shè)置recurse屬性為true或者local傳輸整個目錄

file資源可使用的參數(shù)

ensure 默認(rèn)為文件或目錄

backup 通過filebucket備份文件

checksum 檢查文件是否被修改的方法

ctime 只讀屬性,文件的更新時間

mtime 只讀屬性,文件的修改時間

content 文件的內(nèi)容,與source和target互斥

force 強(qiáng)制執(zhí)行刪除文件、軟鏈接機(jī)目錄的操作

owner 用戶名或用戶ID

group 指定文加年的用戶組或組id

link 軟鏈接

mode 文件權(quán)限配置,通常采用數(shù)字符號

path 文件路徑

注意:以上是我們的常見參數(shù),基本滿足日常的需求,如果需要更多的參數(shù)可以參考官方文檔予以查看。

資源示例

環(huán)境如下所示:

服務(wù)端:

1. 192.168.3.248 (master.example.com)

客戶端:

2. 192.168.3.249 (agent1.example.com)

3. 192.168.3.239 (agent2.example.com)

在puppet的服務(wù)段為agent1.example.com和agent2.example.com創(chuàng)建對應(yīng)的配置文件,因?yàn)閮烧叩闹鳈C(jī)名只有號碼的差別,所以這里采用正則表達(dá)式的方式對兩者進(jìn)行創(chuàng)建。

(1)首先在/etc/puppet/manifests/目錄下創(chuàng)建節(jié)點(diǎn)目錄nodes:

[root@master manifests]# mkdir /etc/puppet/manifests/nodes

然后在nodes目錄下創(chuàng)建配置文件:

[root@master nodes]# touch agent.example.com.pp

---------------------
0 分享到:
和我們在線交談!