自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Puppet 搭建與部署,看這一篇就夠了

開(kāi)發(fā) 架構(gòu)
讓管理員只集中于要管理的目標(biāo),而忽視實(shí)現(xiàn)的細(xì)節(jié)。puppet既可以在單機(jī)上使用,也可以以C/S結(jié)構(gòu)使用。在大規(guī)模使用puppet的情況下,通常使用C/S結(jié)構(gòu),在這種結(jié)構(gòu)中puppet客戶(hù)端只運(yùn)行puppetclient,Puppet服務(wù)端只運(yùn)行puppetmaster。

[[275950]]

Puppet工作原理

讓管理員只集中于要管理的目標(biāo),而忽視實(shí)現(xiàn)的細(xì)節(jié)。puppet既可以在單機(jī)上使用,也可以以C/S結(jié)構(gòu)使用。在大規(guī)模使用puppet的情況下,通常使用C/S結(jié)構(gòu),在這種結(jié)構(gòu)中puppet客戶(hù)端只運(yùn)行puppetclient,Puppet服務(wù)端只運(yùn)行puppetmaster。具體的工作流程如圖所示:

 

環(huán)境

使用四臺(tái)服務(wù)器模擬搭建puppet環(huán)境,拓?fù)鋱D如下所示:

 

環(huán)境表

 

實(shí)驗(yàn)步驟

1.搭建Puppet Master

(1)規(guī)劃三臺(tái)服務(wù)器主機(jī)名

  1. [root@localhost ~]# vim /etc/hostname 
  2. master.test.cn 
  3. [root@localhost ~]# vim /etc/hosts 
  4. 192.168.126.138 master.test.cn 
  5. 192.168.126.148 client01.test.cn 
  6. 192.168.126.158 client02.test.cn 

(2)服務(wù)器時(shí)間同步

由于puppet需要使用SSL證書(shū),依賴(lài)時(shí)間同步,所以需要搭建NTP服務(wù)器

1)搭建NTP Server

  1. [root@localhost ~]# yum install ntp -y 
  2. [root@localhost ~]# vim /etc/ntp.conf 
  3.  
  4. 添加以下兩行:server 127.127.1.0           #指定本地作為時(shí)間源服務(wù)器 
  5. fudge 127.127.1.0 stratum 8 

其作用是當(dāng) /etc/ntp.conf 中定義的server都不可用時(shí),將使用local時(shí)間作為NTP服務(wù)提供給NTP客戶(hù)端。

2)啟動(dòng)ntp服務(wù)并設(shè)置開(kāi)機(jī)自啟動(dòng)

  1. [root@localhost ~]# systemctl stop firewalld.service 
  2. [root@localhost ~]# systemctl disable firewalld.service 
  3. [root@localhost ~]# setenforce 0 
  4. [root@localhost ~]# systemctl start ntpd.service 
  5. [root@localhost ~]# systemctl enable ntpd.service 
  6. [root@localhost ~]# ntpstat    #同步 
  7. synchronised to NTP server (193.228.143.13) at stratum 3 
  8.    time correct to within 517 ms 
  9.    polling server every 64 s 

3)puppetmaster作為NTP客戶(hù)端的配置

  1. [root@master ~]# yum install ntpdate -y 
  2. [root@master ~]# ntpdate 192.168.126.159 
  3.  6 Aug 09:45:03 ntpdate[3488]: adjust time server 192.168.126.159 offset -0.072288 sec    #調(diào)整時(shí)間服務(wù)器192.168.126.159偏移-0.072288秒 

4)配置YUM源

  1. [root@master ~]# yum install epel-release -y 
  2.  
  3. [root@master ~]# yum install puppet-server -y   #安裝puppet服務(wù)端 

5)啟動(dòng)puppet主程序

  1. [root@master ~]# systemctl stop firewalld.service 
  2. [root@master ~]# systemctl disable firewalld.service 
  3. [root@master ~]# setenforce 0 
  4. [root@master ~]# systemctl start puppetmaster.service 
  5. [root@master ~]# systemctl enable puppetmaster.service 

2.搭建puppetclient(兩臺(tái)客戶(hù)端配置一樣)

1)通過(guò)域名ping通puppetmaster

  1. [root@client01 ~]# ping master.test.cn 
  2. PING master.test.cn (192.168.126.138) 56(84) bytes of data. 
  3. 64 bytes from master.test.cn (192.168.126.138): icmp_seq=1 ttl=64 time=1.06 ms 
  4. 64 bytes from master.test.cn (192.168.126.138): icmp_seq=2 ttl=64 time=3.27 ms 
  5. 64 bytes from master.test.cn (192.168.126.138): icmp_seq=3 ttl=64 time=0.382 ms 
  6. 64 bytes from master.test.cn (192.168.126.138): icmp_seq=4 ttl=64 time=0.660 ms 

2)服務(wù)器時(shí)間同步

  1. [root@client01 ~]# yum install ntpdate -y 
  2. [root@client01 ~]# vim /etc/ntp.conf 
  3. server 127.127.1.0           #指定本地作為時(shí)間源服務(wù)器 
  4. fudge 127.127.1.0 stratum 8 
  5.  
  6. [root@client01 ~]# ntpdate 192.168.126.159 
  7.  6 Aug 10:01:12 ntpdate[3303]: adjust time server 192.168.126.159 offset -0.012348 sec 

3)配置YUM源

  1. [root@client01 ~]# yum install epel-release -y 
  2.  
  3. [root@client01 ~]# yum install puppet -y    #安裝puppet客戶(hù)端 

4)修改puppet的配置文件/etc/puppet/puppet.conf

  1. [root@client01 ~]# vim /etc/puppet/puppet.conf 
  2. [main] 
  3.     # The Puppet log directory. 
  4.     # The default value is '$vardir/log'
  5.     logdir = /var/log/puppet 
  6.  
  7.     # Where Puppet PID files are kept. 
  8.     # The default value is '$vardir/run'
  9.     rundir = /var/run/puppet 
  10.  
  11.     # Where SSL certificates are kept. 
  12.     # The default value is '$confdir/ssl'
  13.     ssldir = $vardir/ssl 
  14.     server = master.test.cn    #添加puppet master的地址 

5)分別在puppetclient01和puppetclient01上進(jìn)行注冊(cè)

  1. [root@client01 ~]# puppet agent --server=master.test.cn --no-daemonize --verbose 
  2. Info: Creating a new SSL key for client01.test.cn 
  3. Info: Caching certificate for ca 
  4. Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml 
  5. Info: Creating a new SSL certificate request for client01.test.cn 
  6. Info: Certificate Request fingerprint (SHA256): C1:1F:11:32:53:96:AA:91:16:9F:CE:F2:AD:D2:3F:56:C7:9B:D9:87:5C:F8:2D:30:7D:FE:49:66:46:2A:D9:FC 
  7. Info: Caching certificate for ca 

6)查看申請(qǐng)注冊(cè)的客戶(hù)端

  1. [root@master ~]# puppet cert --list 
  2.   "client01.test.cn" (SHA256) C1:1F:11:32:53:96:AA:91:16:9F:CE:F2:AD:D2:3F:56:C7:9B:D9:87:5C:F8:2D:30:7D:FE:49:66:46:2A:D9:FC 
  3.   "client02.test.cn" (SHA256) 7C:C9:22:59:B2:1E:2B:F5:12:30:4D:88:D9:B1:AF:60:FE:02:65:7 

7)對(duì)未注冊(cè)的客戶(hù)端進(jìn)行注冊(cè)

  1. [root@master ~]# puppet cert sign --all 
  2. Notice: Signed certificate request for client01.test.cn 
  3. Notice: Removing file Puppet::SSL::CertificateRequest client01.test.cn at '/var/lib/puppet/ssl/ca/requests/client01.test.cn.pem' 
  4. Notice: Signed certificate request for client02.test.cn 
  5. Notice: Removing file Puppet::SSL::CertificateRequest client02.test.cn at '/var/lib/puppet/ssl/ca/requests/client02.test.cn.pem' 

8)查看已經(jīng)注冊(cè)的客戶(hù)端

  1. [root@master ~]# ll /var/lib/puppet/ssl/ca/signed/ 
  2. 總用量 12 
  3. -rw-r--r--. 1 puppet puppet 1952 8月   6 21:22 client01.test.cn.pem 
  4. -rw-r--r--. 1 puppet puppet 1952 8月   6 21:22 client02.test.cn.pem 
  5. -rw-r--r--. 1 puppet puppet 2021 8月   6 21:06 master.test.cn.pem 

此時(shí)客戶(hù)端已經(jīng)完成證書(shū)的請(qǐng)求與簽名。

配置實(shí)例

  • 這里為了保護(hù)Linux的ssh端口,修改客戶(hù)端client1的sshd端口,將端口22修改為9922,并實(shí) 現(xiàn)重啟工作。
  • 首先創(chuàng)建ssh模塊,ssh模塊下面有三個(gè)文件:manifests,templates和files。
  • 在manifests里面包含一個(gè)init.pp文件,這是該模塊的初始入口文件,導(dǎo)入模塊時(shí),會(huì)從init.pp開(kāi)始執(zhí)行??梢园阉械拇a都寫(xiě)到init.pp里面,也可以分成多個(gè)pp文件,init再去包含其他文件。定義class類(lèi)名的時(shí)候必須是ssh,這樣才能實(shí)現(xiàn)調(diào)用。
  • file目錄是該模塊的文件發(fā)布目錄,Puppet提供一個(gè)文件分發(fā)機(jī)制,類(lèi)似于rsync的模塊。
  • templates目錄包含erb模型文件,這個(gè)和file資源的template屬性相關(guān),不過(guò)很少用。具體配置如下:

1)創(chuàng)建必要的目錄:

  1. [root@master ~]# cd /etc/puppet/ 
  2. [root@master puppet]# mkdir -p modules/ssh/{manifests,templates,files} 
  3. [root@master puppet]# mkdir manifests/nodes 
  4. [root@master puppet]# mkdir modules/ssh/files/ssh 
  5. [root@master puppet]# chown -R puppet modules/   #修改權(quán)限 

2)查看/etc/puppet/modules/ssh目錄下的結(jié)構(gòu)

  1. [root@master puppet]# ll modules/ssh/ 
  2. 總用量 0 
  3. drwxr-xr-x. 3 puppet root 17 8月   6 21:32 files 
  4. drwxr-xr-x. 2 puppet root  6 8月   6 21:31 manifests 
  5. drwxr-xr-x. 2 puppet root  6 8月   6 21:31 templates 

3)創(chuàng)建模塊配置文件install.pp

  1. [root@master puppet]# vim /etc/puppet/modules/ssh/manifests/install.pp 
  2. 輸入以下信息(首先確定客戶(hù)端已安裝ssh服務(wù)):class ssh::install{ 
  3. package{"openssh"
  4.   ensure=>present, 
  5.   } 

4)創(chuàng)建模塊配置文件config.pp

  1. [root@master puppet]# vim /etc/puppet/modules/ssh/manifests/config.pp 
  2.  
  3. class ssh::config{ 
  4. file {"/etc/ssh/sshd_config":     #配置客戶(hù)端需要同步的文件 
  5. ensure=>present,                  #確認(rèn)客戶(hù)端中有此文件 
  6. owner=>"root",         #文件屬主 
  7. group=>"root",         #文件屬組 
  8. mode=>"0600",          #文件權(quán)限屬性 
  9. source=>"puppet://$puppetserver/modules/ssh/ssh/sshd_config"
  10. #從服務(wù)端同步文件 
  11. require=>Class["ssh::install"],      #調(diào)用install.pp確認(rèn)ssh已經(jīng)安裝 
  12. notify=>Class["ssh::service"],       #如果config.pp發(fā)生變化,通知service.pp 

5)創(chuàng)建模塊配置文件service.pp

  1. [root@master puppet]# vim /etc/puppet/modules/ssh/manifests/service.pp 
  2. class ssh::service{ 
  3. service { "sshd"
  4. ensure=>running,     #確認(rèn)ssh運(yùn)行 
  5. hasstatus=>true,     #puppet該服務(wù)支持status命令,類(lèi)似于service sshd status 
  6. hasrestart=>true,    #puppet該服務(wù)支持restart,類(lèi)似于service sshd restart 
  7. enable=>true,        #服務(wù)器是否開(kāi)機(jī)啟動(dòng) 
  8. require=>Class["ssh::config"]     #確認(rèn)config.pp調(diào)用 

6)創(chuàng)建模塊主配置文件init.pp

  1. [root@master puppet]# vim /etc/puppet/modules/ssh/manifests/init.pp 
  2.  
  3. class ssh { 
  4. include ssh::install,ssh::config,ssh::service  #將配置文件加載到ssh類(lèi)中去 

7)此時(shí)/etc/puppet/modeles/ssh/mainfests目錄下有四個(gè)文件

  1. [root@master puppet]# ll /etc/puppet/modules/ssh/manifests/ 
  2. 總用量 16 
  3. -rw-r--r--. 1 root root 248 8月   6 21:40 config.pp 
  4. -rw-r--r--. 1 root root  60 8月   6 21:46 init.pp 
  5. -rw-r--r--. 1 root root  64 8月   6 21:38 install.pp 
  6. -rw-r--r--. 1 root root 165 8月   6 21:42 service.pp 

8)建立服務(wù)端ssh統(tǒng)一維護(hù)文件

由于服務(wù)端和客戶(hù)端的sshs_config文件默認(rèn)一樣,此時(shí)將服務(wù)端的/etc/ssh/sshd_config復(fù)制到模塊默認(rèn)路徑中去。

  1. [root@master puppet]# cp /etc/ssh/sshd_config /etc/puppet/modules/ssh/files/ssh/ 
  2. [root@master puppet]# chown -R puppet /etc/puppet/modules/ssh/files/ssh/ #修改權(quán)限 

9)創(chuàng)建測(cè)試節(jié)點(diǎn)配置文件,并將ssh加載進(jìn)去。

  1. [root@master puppet]# vim /etc/puppet/manifests/nodes/ssh.pp 
  2. node 'client01.test.cn'
  3. include ssh 
  4.  
  5. node 'client02.test.cn'
  6. include ssh 

10)將測(cè)試節(jié)點(diǎn)載入puppet,即修改site.pp。

  1. [root@master puppet]# vim /etc/puppet/manifests/site.pp 
  2.  
  3. import "nodes/ssh.pp" 

11)修改服務(wù)器維護(hù)的sshd_config配置文件

  1. [root@master puppet]# vim /etc/puppet/modules/ssh/files/ssh/sshd_config 
  2. Port 22    #修改為9922 

12)重啟puppet服務(wù)

  1. [root@master puppet]# systemctl restart puppetmaster.service 

2.客戶(hù)端主動(dòng)拉取

一般在小規(guī)模自動(dòng)化集群中,如代碼上線(xiàn)需要重啟服務(wù)時(shí),為了防止出現(xiàn)網(wǎng)站暫時(shí)性無(wú)法訪(fǎng)問(wèn)的問(wèn)題,每臺(tái)客戶(hù)端運(yùn)行一次puppet agent -t命令,選擇模式根據(jù)客戶(hù)端集群規(guī)模的大小。根據(jù)經(jīng)驗(yàn),一般puppet服務(wù)器到各客戶(hù)端會(huì)建立ssh信任,然后自定義shell腳本,ssh批量讓客戶(hù)端執(zhí)行puppet同步命令。

1)Client01端:

  1. [root@client01 ~]# puppet agent -t 
  2. .....//省略 
  3. Notice: /Stage[main]/Ssh::Config/File[/etc/ssh/sshd_config]/content: 
  4. --- /etc/ssh/sshd_config    2017-08-07 10:28:25.000000000 +0800 
  5. +++ /tmp/puppet-file20180806-5162-jc80yr    2018-08-06 22:25:58.726506429 +0800 
  6. @@ -14,7 +14,7 @@ 
  7.  # SELinux about this change. 
  8.  # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER 
  9.  # 
  10. -#Port 22 
  11. +Port 9922 
  12.  #AddressFamily any 
  13.  #ListenAddress 0.0.0.0 
  14.  #ListenAddress :: 
  15. .....//省略 
  16.  
  17. Client02端:....//省略 
  18. Notice: /Stage[main]/Ssh::Config/File[/etc/ssh/sshd_config]/content: 
  19. --- /etc/ssh/sshd_config    2017-08-07 10:28:25.000000000 +0800 
  20. +++ /tmp/puppet-file20180806-4667-149tj11   2018-08-06 22:27:39.362282788 +0800 
  21. @@ -14,7 +14,7 @@ 
  22.  # SELinux about this change. 
  23.  # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER 
  24.  # 
  25. -#Port 22 
  26. +Port 9922 
  27.  #AddressFamily any 
  28.  #ListenAddress 0.0.0.0 
  29.  #ListenAddress :: 
  30. ......//省略 

2)此時(shí)命令在客戶(hù)端執(zhí)行成功,驗(yàn)證如下:

  1. [root@client01 ~]# cat /etc/ssh/sshd_config | grep Port 
  2. Port 9922 
  3. #GatewayPorts no 

3)查看服務(wù)器ssh服務(wù)是否重啟,端口是否生效。

  1. [root@client01 ~]# netstat -tunlp | grep ssh 
  2. tcp        0      0 0.0.0.0:9922            0.0.0.0:*               LISTEN      5428/sshd 
  3. tcp6       0      0 :::9922                 :::*                    LISTEN      5428/sshd 

3.服務(wù)器推送同步

1)當(dāng)大規(guī)模部署時(shí),采用服務(wù)器推送模式。

  1. client: 
  2. [root@client02 ~]# vim /etc/puppet/puppet.conf 
  3. 最后一行添加 
  4.   listen = true   #使puppet監(jiān)聽(tīng)8139端口 

2)驗(yàn)證配置文件auth.conf定義了一些驗(yàn)證信息及訪(fǎng)問(wèn)權(quán)限

  1. [root@client02 ~]# vim /etc/puppet/auth.conf 
  2. 最后一行添加 
  3. allow *     #允許任何服務(wù)端推送 

3)啟動(dòng)puppet客戶(hù)端

  1. [root@client02 ~]# systemctl start puppetagent.service 
  2.  
  3. [root@client02 ~]# cat /etc/ssh/sshd_config  #查看 
  4. ......//省略 
  5. Port 9922 
  6. #AddressFamily any 
  7. #ListenAddress 0.0.0.0 
  8. #ListenAddress :: 
  9. ......//省略 

4)開(kāi)始往客戶(hù)端推送

  1. Master: 
  2. [root@master puppet]# puppet kick client02.test.cn 
  3. Triggering client02.test.cn 
  4. Getting status 
  5. status is success 
  6. client02.test.cn finished with exit code 0 
  7. Finished 

5)校驗(yàn)結(jié)果如下

  1. [root@master puppet]# cat /etc/ssh/sshd_config | grep Port 
  2. #Port 22 
  3. #GatewayPorts no 

6)查看服務(wù)器ssh服務(wù)是否重啟,端口是否生效。

  1. [root@client02 ~]# netstat -tunlp | grep ssh 
  2. tcp        0      0 0.0.0.0:9922            0.0.0.0:*               LISTEN      4908/sshd 
  3. tcp6       0      0 :::9922                 :::*                    LISTEN      4908/sshd 

實(shí)驗(yàn)成功,僅供參考。

責(zé)任編輯:武曉燕 來(lái)源: 51CTO博客
相關(guān)推薦

2023-02-10 09:04:27

2020-02-18 16:20:03

Redis ANSI C語(yǔ)言日志型

2022-06-20 09:01:23

Git插件項(xiàng)目

2022-08-01 11:33:09

用戶(hù)分析標(biāo)簽策略

2021-04-08 07:37:39

隊(duì)列數(shù)據(jù)結(jié)構(gòu)算法

2023-09-11 08:13:03

分布式跟蹤工具

2018-05-22 08:24:50

PythonPyMongoMongoDB

2023-10-17 08:15:28

API前后端分離

2024-09-23 08:00:00

消息隊(duì)列MQ分布式系統(tǒng)

2020-07-03 08:21:57

Java集合框架

2019-05-14 09:31:16

架構(gòu)整潔軟件編程范式

2017-03-11 22:19:09

深度學(xué)習(xí)

2022-04-07 10:39:21

反射Java安全

2023-11-18 09:30:42

模型AI

2022-07-06 12:07:06

Python函數(shù)式編程

2019-04-01 10:43:59

Linux問(wèn)題故障

2022-05-19 08:28:19

索引數(shù)據(jù)庫(kù)

2020-10-21 14:12:02

Single Sign

2023-11-06 07:21:13

內(nèi)存結(jié)構(gòu)Jvm

2020-10-18 07:32:06

SD-WAN網(wǎng)絡(luò)傳統(tǒng)廣域網(wǎng)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)