加入收藏 | 设为首页 | 会员中心 | 我要投稿 源码门户网 (https://www.92codes.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > 建站资源 > 优化 > 正文

Puppet 搭建与部署,看这一篇就够了

发布时间:2019-09-06 01:30:09 所属栏目:优化 来源:何以重见
导读:副标题#e# Puppet工作原理 让管理员只集中于要管理的目标,而忽视实现的细节。puppet既可以在单机上使用,也可以以C/S结构使用。在大规模使用puppet的情况下,通常使用C/S结构,在这种结构中puppet客户端只运行puppetclient,Puppet服务端只运行puppetmaste

由于服务端和客户端的sshs_config文件默认一样,此时将服务端的/etc/ssh/sshd_config复制到模块默认路径中去。

  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/ #修改权限 

9)创建测试节点配置文件,并将ssh加载进去。

  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)将测试节点载入puppet,即修改site.pp。

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

11)修改服务器维护的sshd_config配置文件

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

12)重启puppet服务

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

2.客户端主动拉取

一般在小规模自动化集群中,如代码上线需要重启服务时,为了防止出现网站暂时性无法访问的问题,每台客户端运行一次puppet agent -t命令,选择模式根据客户端集群规模的大小。根据经验,一般puppet服务器到各客户端会建立ssh信任,然后自定义shell脚本,ssh批量让客户端执行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)此时命令在客户端执行成功,验证如下:

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

3)查看服务器ssh服务是否重启,端口是否生效。

  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.服务器推送同步

(编辑:源码门户网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!