主頁 > 作業系統 > 自動化運維工具之Puppet master/agent模型、站點清單和puppet多環境設定

自動化運維工具之Puppet master/agent模型、站點清單和puppet多環境設定

2020-12-08 06:16:38 作業系統

  前文我們了解了puppe中模塊的使用,回顧請參考https://www.cnblogs.com/qiuhom-1874/p/14086315.html;今天我來了解下puppet的master/agent模型以及站點清單的相關話題;

  在說puppet的master/agent模型前,我們要先來回顧下master/agent的作業程序

  如上圖所示,puppet的master/agent模型的作業程序;首先agent向master發送自己的主機名和facts資訊,然后對應的master收到資訊后,會根據對應的主機名來查找和agent相關的配置,然后把對應的配置(主要是類和模塊中的資源清單內容)編譯好,master把編譯好的catalog發送給agent;agent收到master發送到catalog后,首先要在本機查找相關資源的狀態,如果對應資源的狀態和編譯好的catalog中的狀態一樣,則不改變其狀態或者跳過;如果對應的資源狀態和catalog中的狀態不一樣,此時agent就會應用catalog,把對應資源強制更改為和catalog中的狀態一樣;最后agent把應用報告發送給master;此時agent就變成了我們在資源清單中定義的系統狀態;這里需要注意一點catalog是一個二進制檔案,不能直接查看,這個二進制檔案是通過master上定義的模塊,或類等資源清單中的內容編譯而成;

  master和agent的通信

  在puppet的master/agent模型中,master和agent通信是以https協議通信;使用https通信就意味著要有證書驗證,有證書就會有ca;在puppet的master/agent模型中,它內置了ca,意思就是我們不需要再手動搭建ca;對應master的證書,私鑰檔案以及ca的證書私鑰檔案,puppet master都會自動生成;對于agent的私鑰和證書簽署檔案也會由puppet agent自動生成;并且在第一次啟動agent時,它默認會把生成的證書簽發檔案發送給master,等待master簽發證書;在master上簽發證書,這一步需要人工手動干預;證書簽發好以后,master和agent才可以正常通信;默認情況下agent是每30分鐘到master上拉取一次相關配置,這也就意味著我們在master端上的資源清單內容最多不超過30分鐘就能在對應的agent上得到應用;

  站點清單

  在上述master/agent模型的作業程序中,agent向master發送主機名和facts,然后對應master把對應主機名的配置進行編譯然后發送給對應agent;這里master根據什么來查找對應主機名的對應配置呢?通常情況下如果我們在master端上不定義站點清單,對應的agent就無法獲取到對應的配置;也就說站點清單是用來定義哪些agent上,應該跑哪些資源或模塊;這個邏輯和我們在使用ansible一樣,定義好角色以后,還需要額外的playbook來定義那些主機上應該應用那些角色;對于puppet也是一樣,我們定義好模塊以后,至于哪些主機應用哪些模塊這個是需要我們定義站點清單;

  puppet的master/agent模型的搭建

  部署master端

  配置主機名決議

[root@master ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.16.151 master.test.org master
192.168.16.152 node01.test.org node01
192.168.16.153 node02.test.org node02
[root@master ~]# 

  提示:除了各服務器之間的主機名決議,我們還需要注意確保各服務器時間同步,關閉selinux,確保iptables是關閉狀態;

  安裝puppet-server包

[root@master ~]# yum install -y puppet-server

  提示:在master端安裝puppet-server這個包默認會把puppet當作依賴包一并安裝;

  啟動服務

[root@master ~]# systemctl start puppetmaster.service 
[root@master ~]# ss -tnl
State       Recv-Q Send-Q          Local Address:Port                         Peer Address:Port              
LISTEN      0      128                         *:22                                      *:*                  
LISTEN      0      100                 127.0.0.1:25                                      *:*                  
LISTEN      0      128                         *:8140                                    *:*                  
LISTEN      0      128                      [::]:22                                   [::]:*                  
LISTEN      0      100                     [::1]:25                                   [::]:*                  
[root@master ~]# 

  提示:puppet master默認會監聽在tcp的8140埠,用于接收agent來master獲取配置;所以請確保master端的8140埠能夠正常處于監聽狀態;

  部署agent端

  安裝puppet

[root@node01 ~]# yum install -y  puppet 

  編輯組態檔,配置puppet server的地址

  提示:編輯/etc/puppet/puppet.conf檔案,將server=puppetmaster主機的主機名配置上,如上;如果使用主機名的形式,請確保對應agent能夠正常決議;

  啟動服務

[root@node01 ~]# systemctl start puppet
[root@node01 ~]# ss -tnl
State       Recv-Q Send-Q          Local Address:Port                         Peer Address:Port              
LISTEN      0      128                         *:22                                      *:*                  
LISTEN      0      100                 127.0.0.1:25                                      *:*                  
LISTEN      0      128                      [::]:22                                   [::]:*                  
LISTEN      0      100                     [::1]:25                                   [::]:*                  
[root@node01 ~]# ps aux |grep puppet
root      1653  0.0  0.0 115404  1436 ?        Ss   15:27   0:00 /bin/sh /usr/bin/start-puppet-agent agent  --no-daemonize
root      1654 26.7  2.2 317640 41888 ?        Sl   15:27   0:02 /usr/bin/ruby /usr/bin/puppet agent --no-daemonize
root      1680  0.0  0.0 112808   968 pts/0    S+   15:28   0:00 grep --color=auto puppet
[root@node01 ~]# 

  提示:puppet agent雖然也是一個守護行程作業,但它主要不是對外提供服務,它之所以要作業為守護行程,是因為它要周期性的到master端拉取和自己相關的配置;所以它不會監聽任何埠;

  在master端查看未簽發證書串列

[root@master ~]# puppet cert list
  "node01.test.org" (SHA256) AD:01:59:E7:6C:97:E7:5E:67:09:B9:52:94:0D:37:89:82:8B:EE:49:BB:4D:FC:E1:51:64:BE:EF:71:47:15:11
  "node02.test.org" (SHA256) E1:EC:5B:0C:BF:B7:4C:B9:4F:10:A9:12:34:8B:7A:36:E3:A1:D4:EC:DD:DD:DC:F4:05:48:0B:85:B5:70:AC:28
[root@master ~]# 

  提示:puppet默認會自己維護一個ca,我們只需要用對應的子命令進行管理即可;以上命令表示列出未簽發的證書串列(即收到的agent證書簽發檔案串列);從上面的資訊可以看到現在node01和node02都沒有簽發證書;

  在master端簽發證書

[root@master ~]# puppet cert list
  "node01.test.org" (SHA256) AD:01:59:E7:6C:97:E7:5E:67:09:B9:52:94:0D:37:89:82:8B:EE:49:BB:4D:FC:E1:51:64:BE:EF:71:47:15:11
  "node02.test.org" (SHA256) E1:EC:5B:0C:BF:B7:4C:B9:4F:10:A9:12:34:8B:7A:36:E3:A1:D4:EC:DD:DD:DC:F4:05:48:0B:85:B5:70:AC:28
[root@master ~]# puppet cert sign node01.test.org
Notice: Signed certificate request for node01.test.org
Notice: Removing file Puppet::SSL::CertificateRequest node01.test.org at '/var/lib/puppet/ssl/ca/requests/node01.test.org.pem'
[root@master ~]# puppet cert list
  "node02.test.org" (SHA256) E1:EC:5B:0C:BF:B7:4C:B9:4F:10:A9:12:34:8B:7A:36:E3:A1:D4:EC:DD:DD:DC:F4:05:48:0B:85:B5:70:AC:28
[root@master ~]# puppet cert sign --all
Notice: Signed certificate request for node02.test.org
Notice: Removing file Puppet::SSL::CertificateRequest node02.test.org at '/var/lib/puppet/ssl/ca/requests/node02.test.org.pem'
[root@master ~]# puppet cert list
[root@master ~]# puppet cert list --all
+ "master.test.org" (SHA256) 0C:CC:20:EE:F5:FC:73:21:0B:15:73:EF:A5:0B:3A:F8:01:DB:F7:07:7C:DB:78:87:80:87:FC:F2:BF:E7:2F:30 (alt names: "DNS:master.test.org", "DNS:puppet", "DNS:puppet.test.org")
+ "node01.test.org" (SHA256) 34:BE:E1:1E:26:15:56:56:C3:A0:0D:FB:7F:01:B1:80:35:EC:1D:07:26:C7:05:CA:6E:19:8C:75:9A:A4:67:4E
+ "node02.test.org" (SHA256) E7:B6:B0:FD:04:61:A8:87:D9:E5:DA:51:8B:1D:E0:AD:11:F0:A2:65:43:6D:C4:8D:54:C8:75:8B:DF:CC:51:93
[root@master ~]# 

  提示:簽發證書需要用cert sign+對應要簽發的證書的主機名;如果不想一個一個指定來簽發,也可以使用--all選項來簽發所有未簽發的證書;到此puppet的master/agent模型就搭建好了;后續我們只需要在master端上定義模塊和站點清單即可;

  示例:在master上創建redis模塊,主要功能是安裝啟動redis,并讓其配置為主從復制模式;

  在master端上創建模塊目錄結構

[root@master ~]# mkdir -pv /etc/puppet/modules/redis/{manifests,files,templates,lib,spec,tests}
mkdir: created directory ‘/etc/puppet/modules/redis’
mkdir: created directory ‘/etc/puppet/modules/redis/manifests’
mkdir: created directory ‘/etc/puppet/modules/redis/files’
mkdir: created directory ‘/etc/puppet/modules/redis/templates’
mkdir: created directory ‘/etc/puppet/modules/redis/lib’
mkdir: created directory ‘/etc/puppet/modules/redis/spec’
mkdir: created directory ‘/etc/puppet/modules/redis/tests’
[root@master ~]# tree /etc/puppet/modules/redis/
/etc/puppet/modules/redis/
├── files
├── lib
├── manifests
├── spec
├── templates
└── tests

6 directories, 0 files
[root@master ~]# 

  在/etc/puppet/modules/redis/manifests/目錄下創建資源清單

[root@master ~]# cat /etc/puppet/modules/redis/manifests/init.pp 
class redis{
        package{"redis":
                ensure  => installed,
        }
        service{"redis":
                ensure  => running,
                enable  => true,
                hasrestart      => true,
                restart => 'service redis restart',
        }
}
[root@master ~]# cat /etc/puppet/modules/redis/manifests/master.pp 
class redis::master($masterport='6379',$masterpass='admin') inherits redis {
        file{"/etc/redis.conf":
                ensure  => file,
                content => template('redis/redis-master.conf.erb'),
                owner   => 'redis',
                group   => 'root',
                mode    => '0644',
        }
        Service["redis"]{
                subscribe       => File["/etc/redis.conf"],
                restart => 'systemctl restart redis'
        }
}
[root@master ~]# cat /etc/puppet/modules/redis/manifests/slave.pp 
class redis::slave($masterip,$masterport='6379',$masterpass='admin') inherits redis {
        file{"/etc/redis.conf":
                ensure  => file,
                content => template('redis/redis-slave.conf.erb'),
                owner   => 'redis',
                group   => 'root',
                mode    => '0644',
        }
        Service["redis"]{
                subscribe       => File["/etc/redis.conf"],
                restart => 'systemctl restart redis'
        }
}
[root@master ~]# 

  在templates目錄創建對應的模版檔案

  redis-master.conf.erb檔案內容

[root@master ~]# cat /etc/puppet/modules/redis/templates/redis-master.conf.erb
bind 0.0.0.0
protected-mode yes
port <%= @masterport %>
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile /var/log/redis/redis.log
databases 16
requirepass <%= @masterpass %>
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
[root@master ~]# 
View Code

  redis-slave.conf.erb檔案內容

[root@master ~]# cat /etc/puppet/modules/redis/templates/redis-slave.conf.erb
bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile /var/log/redis/redis.log
databases 16
slaveof <%= @masterip %> <%= @masterport %>
masterauth <%= @masterpass %>
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
[root@master ~]# 
View Code

  redis模塊目錄和檔案存放情況,以及模版檔案中需要傳遞引數

[root@master ~]# tree /etc/puppet/modules/redis/
/etc/puppet/modules/redis/
├── files
├── lib
├── manifests
│   ├── init.pp
│   ├── master.pp
│   └── slave.pp
├── spec
├── templates
│   ├── redis-master.conf.erb
│   └── redis-slave.conf.erb
└── tests

6 directories, 5 files
[root@master ~]# grep -Ei "^port|requirepass|masterauth|slaveof" /etc/puppet/modules/redis/templates/redis-master.conf.erb 
port <%= @masterport %>
requirepass <%= @masterpass %>
[root@master ~]# grep -Ei "^port|requirepass|masterauth|slaveof" /etc/puppet/modules/redis/templates/redis-slave.conf.erb 
port 6379
slaveof <%= @masterip %> <%= @masterport %>
masterauth <%= @masterpass %>
[root@master ~]# 

  提示:到此redis模塊就準備好了;

  定義站點清單檔案

[root@master ~]# cat /etc/puppet/manifests/site.pp
node 'node01.test.org'{
	class{"redis::master":
		masterport	=> "6379",
		masterpass	=> "admin123.com"
	}
}
node 'node02.test.org'{
	class{"redis::slave":
		masterip	=> '192.168.16.152',
		masterport	=> '6379',
		masterpass	=> 'admin123.com'
	}
}
[root@master ~]# 

  提示:站點清單必須是在/etc/puppet/manifests/目錄下,名字必須為site.pp,其內容必須由關鍵字node來定義對應一個主機或一類主機要應用的資源;站點清單也可以使用類的繼承和我們在定義類時的使用差不多;

  在node01上獲取自己相關的配置

  提示:可以看到在node01上手動拉取配置能夠獲取到對應到配置;

  取消--noop 選項跑一遍,看看對應到redis是否啟動?組態檔是否上我們指定到就配置?

[root@node01 ~]# puppet agent -v --no-daemonize 
Notice: Starting Puppet client version 3.6.2
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for node01.test.org
Warning: The package type's allow_virtual parameter will be changing its default value from false to true in a future release. If you do not want to allow virtual packages, please explicitly set allow_virtual to false.
   (at /usr/share/ruby/vendor_ruby/puppet/type.rb:816:in `set_default')
Info: Applying configuration version '1607328529'
Info: /Stage[main]/Redis::Master/File[/etc/redis.conf]: Filebucketed /etc/redis.conf to puppet with sum d43fae161baaf47638d0bb571785974d
Notice: /Stage[main]/Redis::Master/File[/etc/redis.conf]/content: content changed '{md5}d43fae161baaf47638d0bb571785974d' to '{md5}32a39b519eb7a9f70a4bdf4705a7afc0'
Notice: /Stage[main]/Redis::Master/File[/etc/redis.conf]/mode: mode changed '0640' to '0644'
Info: /Stage[main]/Redis::Master/File[/etc/redis.conf]: Scheduling refresh of Service[redis]
Info: /Stage[main]/Redis::Master/File[/etc/redis.conf]: Scheduling refresh of Service[redis]
Notice: /Stage[main]/Redis/Service[redis]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Redis/Service[redis]: Unscheduling refresh on Service[redis]
Notice: Finished catalog run in 0.32 seconds
^CNotice: Caught INT; calling stop
[root@node01 ~]# ss -tnl
State      Recv-Q Send-Q                    Local Address:Port                                   Peer Address:Port              
LISTEN     0      128                                   *:22                                                *:*                  
LISTEN     0      100                           127.0.0.1:25                                                *:*                  
LISTEN     0      128                                   *:6379                                              *:*                  
LISTEN     0      128                                [::]:22                                             [::]:*                  
LISTEN     0      100                               [::1]:25                                             [::]:*                  
[root@node01 ~]# grep -Ei "^port|bind|requirepass" /etc/redis.conf 
bind 0.0.0.0
port 6379
requirepass admin123.com
[root@node01 ~]# 

  提示:可以看到node01上的reids已經正常啟動,并且組態檔中的內容也是我們傳遞引數的內容;

  在node02上手動拉取配置并運行,看看對應redis是否正常運行?組態檔下是否是我們指定傳遞的引數的組態檔?

[root@node02 ~]# puppet agent -v --no-daemonize 
Notice: Starting Puppet client version 3.6.2
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for node02.test.org
Warning: The package type's allow_virtual parameter will be changing its default value from false to true in a future release. If you do not want to allow virtual packages, please explicitly set allow_virtual to false.
   (at /usr/share/ruby/vendor_ruby/puppet/type.rb:816:in `set_default')
Info: Applying configuration version '1607328529'
Notice: /Stage[main]/Redis/Package[redis]/ensure: created
Info: FileBucket got a duplicate file {md5}d98629fded012cd2a25b9db0599a9251
Info: /Stage[main]/Redis::Slave/File[/etc/redis.conf]: Filebucketed /etc/redis.conf to puppet with sum d98629fded012cd2a25b9db0599a9251
Notice: /Stage[main]/Redis::Slave/File[/etc/redis.conf]/content: content changed '{md5}d98629fded012cd2a25b9db0599a9251' to '{md5}d1f0efeaee785f0d26eb2cd82acaf1f9'
Notice: /Stage[main]/Redis::Slave/File[/etc/redis.conf]/mode: mode changed '0640' to '0644'
Info: /Stage[main]/Redis::Slave/File[/etc/redis.conf]: Scheduling refresh of Service[redis]
Info: /Stage[main]/Redis::Slave/File[/etc/redis.conf]: Scheduling refresh of Service[redis]
Notice: /Stage[main]/Redis/Service[redis]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Redis/Service[redis]: Unscheduling refresh on Service[redis]
Notice: Finished catalog run in 10.62 seconds
^CNotice: Caught INT; calling stop
[root@node02 ~]# ss -tnl
State      Recv-Q Send-Q                    Local Address:Port                                   Peer Address:Port              
LISTEN     0      128                                   *:22                                                *:*                  
LISTEN     0      100                           127.0.0.1:25                                                *:*                  
LISTEN     0      128                                   *:6379                                              *:*                  
LISTEN     0      128                                [::]:22                                             [::]:*                  
LISTEN     0      100                               [::1]:25                                             [::]:*                  
[root@node02 ~]# grep -Ei "^port|requirepass|slaveof|masterauth" /etc/redis.conf
port 6379
slaveof 192.168.16.152 6379
masterauth admin123.com
[root@node02 ~]# 

  提示:可以看到node02上的redis已經正常跑起來了,并且組態檔中的對應引數也是為指定傳入的引數;

  驗證:在node01上登陸redis,創建一個key,看看對應node02上的redis是否正常將node01上創建的key同步到node02上的redis上?

[root@node01 ~]# redis-cli 
127.0.0.1:6379> AUTH admin123.com
OK
127.0.0.1:6379> set test test
OK
127.0.0.1:6379> get test
"test"
127.0.0.1:6379> exit
[root@node01 ~]# redis-cli  -h node02.test.org -a admin123.com 
node02.test.org:6379> get test
"test"
node02.test.org:6379> 

  提示:可以看到在node01上的redis上寫入一個key在node02上能夠看到對應key的值,說明redis的主從復制正常;以上就是puppet master/agent模型上安裝啟動redis主從的簡單示例;

  puppet多環境設定

  所謂多環境指一個agent通過指定不同的環境名稱,可以在master上獲取不同環境的配置清單,從而實作在不同的環境中,對應的agent拉取不同的配置到本地應用;默認不配置多環境,在agent來master拉取配置都是拉取的生產環境的配置(production);

  示例:在master端上配置多個環境,對應節點使用傳遞不同環境來獲取不同環境的配置

  提示:在master端端組態檔中新整以上master配置段,并指明environmentpath位置;這里需要注意,更改了組態檔需要重啟服務才可生效;

  查看confdir的位置

[root@master ~]# puppet config print |grep confdir
confdir = /etc/puppet
[root@master ~]# 

  在/etc/puppet目錄下創建environments目錄,并在其下創建對應環境名的目錄以及子目錄

[root@master ~]# mkdir -pv /etc/puppet/environments/{testing,development,production}/{manifests,modules}
mkdir: created directory ‘/etc/puppet/environments’
mkdir: created directory ‘/etc/puppet/environments/testing’
mkdir: created directory ‘/etc/puppet/environments/testing/manifests’
mkdir: created directory ‘/etc/puppet/environments/testing/modules’
mkdir: created directory ‘/etc/puppet/environments/development’
mkdir: created directory ‘/etc/puppet/environments/development/manifests’
mkdir: created directory ‘/etc/puppet/environments/development/modules’
mkdir: created directory ‘/etc/puppet/environments/production’
mkdir: created directory ‘/etc/puppet/environments/production/manifests’
mkdir: created directory ‘/etc/puppet/environments/production/modules’
[root@master ~]# tree /etc/puppet/environments/
/etc/puppet/environments/
├── development
│   ├── manifests
│   └── modules
├── production
│   ├── manifests
│   └── modules
└── testing
    ├── manifests
    └── modules

9 directories, 0 files
[root@master ~]# 

  提示:在每個環境目錄下必須創建manifests和modules目錄,manifests目錄用于存放站點清單,modules用于存放模塊;

  在testing環境下創建安裝memcached,并指定監聽在11211埠的模塊和站點清單,配置development環境下的memcached監聽在11212埠,配置prediction環境的memcached監聽在11213埠

  創建memcached模塊目錄結構

[root@master ~]# mkdir -pv /etc/puppet/environments/testing/modules/memcached/{manifests,templates,files,lib,spec,tests}
mkdir: created directory ‘/etc/puppet/environments/testing/modules/memcached’
mkdir: created directory ‘/etc/puppet/environments/testing/modules/memcached/manifests’
mkdir: created directory ‘/etc/puppet/environments/testing/modules/memcached/templates’
mkdir: created directory ‘/etc/puppet/environments/testing/modules/memcached/files’
mkdir: created directory ‘/etc/puppet/environments/testing/modules/memcached/lib’
mkdir: created directory ‘/etc/puppet/environments/testing/modules/memcached/spec’
mkdir: created directory ‘/etc/puppet/environments/testing/modules/memcached/tests’
[root@master ~]# tree /etc/puppet/environments/testing/modules/memcached/
/etc/puppet/environments/testing/modules/memcached/
├── files
├── lib
├── manifests
├── spec
├── templates
└── tests

6 directories, 0 files
[root@master ~]# 

  在testing環境下的manifests目錄下創建init.pp檔案

[root@master ~]# cat /etc/puppet/environments/testing/modules/memcached/manifests/init.pp
class memcached{
	package{"memcached":
		ensure	=> installed,
	} ->
	file{"/etc/sysconfig/memcached":
		ensure	=> file,
		source	=> 'puppet:///modules/memcached/memcached',
		owner	=> 'root',
		group	=> 'root',
		mode	=> '0644',
	} ~>
	service{"memcached":
		ensure	=> running,
		enable	=> true
	}
}
[root@master ~]# 

  在testing環境下的files目錄提供memcached組態檔

[root@master ~]# cat /etc/puppet/environments/testing/modules/memcached/files/memcached 
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""
[root@master ~]# 

  在testing環境下的manifests目錄下創建站點檔案site.pp

[root@master ~]# cat /etc/puppet/environments/testing/manifests/site.pp 
node 'node02.test.org'{
	include memcached
}
[root@master ~]# 

  提示:到此testing環境的memcached模塊的配置和站點清單就配置好了;

  配置development環境下的memcached模塊和站點清單

  復制testing環境下的模塊到development

[root@master ~]# cp -a /etc/puppet/environments/testing/modules/memcached/ /etc/puppet/environments/development/modules/
[root@master ~]# tree /etc/puppet/environments/development/modules/
/etc/puppet/environments/development/modules/
└── memcached
    ├── files
    │   └── memcached
    ├── lib
    ├── manifests
    │   └── init.pp
    ├── spec
    ├── templates
    └── tests

7 directories, 2 files
[root@master ~]# 

  編輯files目錄下的memcached組態檔,修改監聽埠為11212

[root@master ~]# cat /etc/puppet/environments/development/modules/memcached/files/memcached
PORT="11212"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""
[root@master ~]# 

  提示:testing和development環境下的memcached除了組態檔不同,站點清單一樣;

  復制testing環境下的站點清單到development環境下

[root@master ~]# cp /etc/puppet/environments/testing/manifests/site.pp /etc/puppet/environments/development/manifests/
[root@master ~]# cat /etc/puppet/environments/development/manifests/site.pp 
node 'node02.test.org'{
	include memcached
}
[root@master ~]# 

  提示:到此development環境下到memcached模塊和站點清單檔案就配置好了;

  配置production環境下的memcached模塊和站點清單 

  復制testing環境下到memcached模塊

[root@master ~]# cp -a /etc/puppet/environments/testing/modules/memcached/ /etc/puppet/environments/production/modules/
[root@master ~]# tree /etc/puppet/environments/production/modules/
/etc/puppet/environments/production/modules/
└── memcached
    ├── files
    │   └── memcached
    ├── lib
    ├── manifests
    │   └── init.pp
    ├── spec
    ├── templates
    └── tests

7 directories, 2 files
[root@master ~]# 

  編輯files目錄下的memcached組態檔,修改監聽埠為11213

[root@master ~]# cat /etc/puppet/environments/production/modules/memcached/files/memcached
PORT="11213"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""
[root@master ~]# 

  復制站點檔案到production環境下

[root@master ~]# cp /etc/puppet/environments/testing/manifests/site.pp /etc/puppet/environments/production/manifests/
[root@master ~]# cat /etc/puppet/environments/production/manifests/site.pp 
node 'node02.test.org'{
	include memcached
}
[root@master ~]# 

  提示:到此三個環境到memcached模塊和站點清單都準備好了;

  在node02上使用不同的環境來啟動監聽不同的埠的memcached

  使用testing環境

[root@node02 ~]# puppet agent -v --no-daemonize --environment=testing 
Notice: Starting Puppet client version 3.6.2
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for node02.test.org
Warning: The package type's allow_virtual parameter will be changing its default value from false to true in a future release. If you do not want to allow virtual packages, please explicitly set allow_virtual to false.
   (at /usr/share/ruby/vendor_ruby/puppet/type.rb:816:in `set_default')
Info: Applying configuration version '1607334372'
Notice: /Stage[main]/Memcached/Service[memcached]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Memcached/Service[memcached]: Unscheduling refresh on Service[memcached]
Notice: Finished catalog run in 0.29 seconds
^CNotice: Caught INT; calling stop
[root@node02 ~]# ss -tnl
State      Recv-Q Send-Q                    Local Address:Port                                   Peer Address:Port              
LISTEN     0      128                                   *:22                                                *:*                  
LISTEN     0      100                           127.0.0.1:25                                                *:*                  
LISTEN     0      128                                   *:11211                                             *:*                  
LISTEN     0      128                                   *:6379                                              *:*                  
LISTEN     0      128                                [::]:22                                             [::]:*                  
LISTEN     0      100                               [::1]:25                                             [::]:*                  
LISTEN     0      128                                [::]:11211                                          [::]:*                  
[root@node02 ~]# 

  提示:可以看到在node02上使用--envrionment選項指定為testing環境,對應啟動的memcached的埠為11211;

  使用development環境

[root@node02 ~]# puppet agent -v --no-daemonize --environment=development
Notice: Starting Puppet client version 3.6.2
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for node02.test.org
Warning: The package type's allow_virtual parameter will be changing its default value from false to true in a future release. If you do not want to allow virtual packages, please explicitly set allow_virtual to false.
   (at /usr/share/ruby/vendor_ruby/puppet/type.rb:816:in `set_default')
Info: Applying configuration version '1607334662'
Info: /Stage[main]/Memcached/File[/etc/sysconfig/memcached]: Filebucketed /etc/sysconfig/memcached to puppet with sum 05503957e3796fbe6fddd756a7a102a0
Notice: /Stage[main]/Memcached/File[/etc/sysconfig/memcached]/content: content changed '{md5}05503957e3796fbe6fddd756a7a102a0' to '{md5}b69eb8ec579bb28f4140f7debf17f281'
Info: /Stage[main]/Memcached/File[/etc/sysconfig/memcached]: Scheduling refresh of Service[memcached]
Notice: /Stage[main]/Memcached/Service[memcached]: Triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.34 seconds
^CNotice: Caught INT; calling stop
[root@node02 ~]# ss -tnl
State      Recv-Q Send-Q                    Local Address:Port                                   Peer Address:Port              
LISTEN     0      128                                   *:22                                                *:*                  
LISTEN     0      100                           127.0.0.1:25                                                *:*                  
LISTEN     0      128                                   *:6379                                              *:*                  
LISTEN     0      128                                   *:11212                                             *:*                  
LISTEN     0      128                                [::]:22                                             [::]:*                  
LISTEN     0      100                               [::1]:25                                             [::]:*                  
LISTEN     0      128                                [::]:11212                                          [::]:*                  
[root@node02 ~]# 

  提示:可以看到使用development環境,對應啟動的memcached的埠就是11212;

  使用production環境

[root@node02 ~]# puppet agent -v --no-daemonize --environment=production
Notice: Starting Puppet client version 3.6.2
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for node02.test.org
Warning: The package type's allow_virtual parameter will be changing its default value from false to true in a future release. If you do not want to allow virtual packages, please explicitly set allow_virtual to false.
   (at /usr/share/ruby/vendor_ruby/puppet/type.rb:816:in `set_default')
Info: Applying configuration version '1607334761'
Info: /Stage[main]/Memcached/File[/etc/sysconfig/memcached]: Filebucketed /etc/sysconfig/memcached to puppet with sum b69eb8ec579bb28f4140f7debf17f281
Notice: /Stage[main]/Memcached/File[/etc/sysconfig/memcached]/content: content changed '{md5}b69eb8ec579bb28f4140f7debf17f281' to '{md5}f7cdb226870b0164bbdb8671eb11e433'
Info: /Stage[main]/Memcached/File[/etc/sysconfig/memcached]: Scheduling refresh of Service[memcached]
Notice: /Stage[main]/Memcached/Service[memcached]: Triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.33 seconds
^CNotice: Caught INT; calling stop
[root@node02 ~]# ss -tnl
State      Recv-Q Send-Q                    Local Address:Port                                   Peer Address:Port              
LISTEN     0      128                                   *:22                                                *:*                  
LISTEN     0      100                           127.0.0.1:25                                                *:*                  
LISTEN     0      128                                   *:6379                                              *:*                  
LISTEN     0      128                                   *:11213                                             *:*                  
LISTEN     0      128                                [::]:22                                             [::]:*                  
LISTEN     0      100                               [::1]:25                                             [::]:*                  
LISTEN     0      128                                [::]:11213                                          [::]:*                  
[root@node02 ~]# 

  提示:可以看到memcached監聽地址就變為了11213;如以上測驗沒有任何問題,接下來就可以確定對應agent的環境,配置agent的環境;

  配置agent端的環境

  提示:在agent的組態檔中使用environment指定對應的環境名稱,保存退出重啟puppetagent服務,現在這臺agent就會周期性的到master端拉取testing環境的相關配置;

  以上就是puppet的master/agent模型以及多環境相關配置的使用和測驗;

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/231256.html

標籤:Linux

上一篇:KaLi添加路由問題,設定開機自啟動腳本rc.local檔案不存在問題

下一篇:CentOS8.2同步阿里云Ceph鏡像到本地,本地搭建ceph倉庫

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • CA和證書

    1、在 CentOS7 中使用 gpg 創建 RSA 非對稱密鑰對 gpg --gen-key #Centos上生成公鑰/密鑰對(存放在家目錄.gnupg/) 2、將 CentOS7 匯出的公鑰,拷貝到 CentOS8 中,在 CentOS8 中使用 CentOS7 的公鑰加密一個檔案 gpg -a ......

    uj5u.com 2020-09-10 00:09:53 more
  • Kubernetes K8S之資源控制器Job和CronJob詳解

    Kubernetes的資源控制器Job和CronJob詳解與示例 ......

    uj5u.com 2020-09-10 00:10:45 more
  • VMware下安裝CentOS

    VMware下安裝CentOS 一、軟硬體準備 1 Centos鏡像準備 1.1 CentOS鏡像下載地址 下載地址 1.2 CentOS鏡像下載程序 點擊下載地址進入如下圖的網站,選擇需要下載的版本,這里選擇的是Centos8,點擊如圖所示。 決定選擇Centos8后,選擇想要的鏡像源進行下載,此 ......

    uj5u.com 2020-09-10 00:12:10 more
  • 如何使用Grep命令查找多個字串

    如何使用Grep 命令查找多個字串 大家好,我是良許! 今天向大家介紹一個非常有用的技巧,那就是使用 grep 命令查找多個字串。 簡單介紹一下,grep 命令可以理解為是一個功能強大的命令列工具,可以用它在一個或多個輸入檔案中搜索與正則運算式相匹配的文本,然后再將每個匹配的文本用標準輸出的格式 ......

    uj5u.com 2020-09-10 00:12:28 more
  • git配置http代理

    git配置http代理 經常遇到克隆 github 慢的問題,這里記錄一下幾種配置 git 代理的方法,解決 clone github 過慢。 目錄 git配置代理 git單獨配置github代理 git配置全域代理 配置終端環境變數 git配置代理 主要使用 git config 命令 git單獨 ......

    uj5u.com 2020-09-10 00:12:33 more
  • Linux npm install 裝包時提示Error EACCES permission denied解

    npm install 裝包時提示Error EACCES permission denied解決辦法 ......

    uj5u.com 2020-09-10 00:12:53 more
  • Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包

    Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包。 18 (flaskApi) [root@67 flaskDemo]# yum -y install nginx 19 已加載插件:fastestmirror, langpacks 20 Loading ......

    uj5u.com 2020-09-10 00:13:13 more
  • Linux查看服務器暴力破解ssh IP

    在公網的服務器上經常遇到別人爆破你服務器的22埠,用來挖礦或者干其他嘿嘿嘿的事情~ 這種情況下正確的做法是: 修改默認ssh的22埠 使用設定密鑰登錄或者白名單ip登錄 建議服務器密碼為復雜密碼 創建普通用戶登錄服務器(root權限過大) 建立堡壘機,實作統一管理服務器 統計爆破IP [root ......

    uj5u.com 2020-09-10 00:13:17 more
  • CentOS 7系統常見快捷鍵操作方式

    Linux系統中一些常見的快捷方式,可有效提高操作效率,在某些時刻也能避免操作失誤帶來的問題。 ......

    uj5u.com 2020-09-10 00:13:31 more
  • CentOS 7作業系統目錄結構介紹

    作業系統存在著大量的資料檔案資訊,相應檔案資訊會存在于系統相應目錄中,為了更好的管理資料資訊,會將系統進行一些目錄規劃,不同目錄存放不同的資源。 ......

    uj5u.com 2020-09-10 00:13:35 more
最新发布
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:43:21 more
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:42:36 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:26:53 more
  • 設定Windows主機的瀏覽器為wls2的默認瀏覽器

    這里以Chrome為例。 1. 準備作業 wsl是可以使用Windows主機上安裝的exe程式,出于安全考慮,默認情況下改功能是無法使用。要使用的話,終端需要以管理員權限啟動。 我這里以Windows Terminal為例,介紹如何默認使用管理員權限打開終端,具體操作如下圖所示: 2. 操作 wsl ......

    uj5u.com 2023-04-19 09:25:49 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:19:04 more
  • Linux學習筆記

    IP地址和主機名 IP地址 ifconfig可以用來查詢本機的IP地址,如果不能使用,可以通過install net-tools安裝。 Centos系統下ens33表示主網卡;inet后表示IP地址;lo表示本地回環網卡; 127.0.0.1表示代指本機;0.0.0.0可以用于代指本機,同時在放行設 ......

    uj5u.com 2023-04-18 06:52:01 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:50 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:01 more
  • 你是不是暴露了?

    作者:袁首京 原創文章,轉載時請保留此宣告,并給出原文連接。 如果您是計算機相關從業人員,那么應該經歷不止一次網路安全專項檢查了,你肯定是收到過資訊系統技術檢測報告,要求你加強風險監測,確保你提供的系統服務堅實可靠了。 沒檢測到問題還好,檢測到問題的話,有些處理起來還是挺麻煩的,尤其是線上正在運行的 ......

    uj5u.com 2023-04-05 16:52:56 more
  • 細節拉滿,80 張圖帶你一步一步推演 slab 記憶體池的設計與實作

    1. 前文回顧 在之前的幾篇記憶體管理系列文章中,筆者帶大家從宏觀角度完整地梳理了一遍 Linux 記憶體分配的整個鏈路,本文的主題依然是記憶體分配,這一次我們會從微觀的角度來探秘一下 Linux 內核中用于零散小記憶體塊分配的記憶體池 —— slab 分配器。 在本小節中,筆者還是按照以往的風格先帶大家簡單 ......

    uj5u.com 2023-04-05 16:44:11 more