puppet部署多台服务器

puppet部署多台服务器

利用puppet实现自动化部署

配置前准备:

  图中:蓝线表示各个服务器之间通信

     红线表示puppetmaster主机向各个agent主机部署信道

A主机puppet-master主机:192.168.126.129

B主机做两种服务:keepalived高性能和nginx反代

            192.168.126.130

C主机做两种服务:keepalived高性能和nginx反代

            192.168.126.131

D主机tomcat服务:192.168.126.132

E主机tomcat服务:192.168.126.133

F主机memcached服务:192.168.126.134

G主机memcached服务:192.168.126.135

注意:各个主机必须时间同步

    此次安装puppet版本为3.8.7

一、配置puppetmaster/agent建立安全通信

  1、将各个主机的主机名写入到/etc/hosts文件中,以便于域名解析

    puppet部署多台服务器    

注意:将此文件内容分别写入各个主机的/etc/hosts文件中

  2、安装puppet服务所需要的包

   1)在master主机上安装以下包

facter-2.4.6-1.el7.x86_64.rpm

puppet-3.8.7-1.el7.noarch.rpm

puppet-server-3.8.7-1.el7.noarch.rpm

   2)在各个agent主机上安装以下包

      facter-2.4.6-1.el7.x86_64.rpm

puppet-3.8.7-1.el7.noarch.rpm

   3、修改配置文件

    1)配置master主机:/etc/puppet/puppet.conf

      [main]

       …

       environmentpath = $confdir/environments(此配置文件只加上此句就行了)

       …

      [agent]

       …

    2)配置agent主机:/etc/puppet/puppet.conf

      [main]

       …

       listen = true(开启监听端口默认为8139

       environmet = production(运行于production环境,

       …

      [agent]

       …

       server = node1.zq.com(设定以node1.zq.com主机位puppetmaster

       …

    注意: environmet指令有三个值分别为:productiontestingdevelopment

      Agent主机设置的为那个环境,那么在master主机的/etc/puppet/environment/目录下必须有与环境名相同名字的目录。并且此目录下必须包含manifestsmodules两个目录,在manitests目下有site.pp文件,里面包含向各个agent主机需要部署的服务,而modules目录下就各个服务的模块

  3)配置agent主机:/etc/puppet/auth.conf

    加入以下段落:(表示允许master主机可以部署服务)

     path /run

method save

auth any

allow node1.zq.com  

      注意:这几句指令必须在path /”指令的前面

   4、签署CA认证,建立安全通信

     1master主机

       启动服务

       Systemctl  start  puppetmaster.service  

       puppet部署多台服务器

       查看8140端口已开启

     2)在agent主机

        启动服务

        Systemctl  start  puppetagent.service

     3)签署认证

       master主机上认证

       执行:puppet cert list –all (查看agent的证书签署请求)

       执行:puppet cert sign –all ((签署所有的请求)

       puppet部署多台服务器     

二、创建模块

   注意:我的此次试验是在production环境下作的

 创建前配置:

  创建目录文件

   mkdir -pv /etc/puppet/environments/production /{manifests,modules}

1、创建模块memcached

  (1)cd  /etc/puppet/environments/production/modules

  (2)mkdir  ./memcached/memcached/{manifests,templates,files,spec.lib,tests}

  (3)Vim ./manifests/init.pp(每一个模块中都必须含此文件)添加内容如下:

    class memcached {

         package{‘memcached’:

             ensure => latest,

            } ->

         service{‘memcached’:

             ensure => running,

             enable => true,

             }

     }

2、创建tomcat模块

    注意:为测试我为两台tomcat主机分别放了不同主页面

  (1)cd  /etc/puppet/environments/production/modules/

  (2)mkdir  ./tomcat/{manifests,templates,files,spec.lib,tests}

  (3)Vim ./tomcat/manifests/init.pp添加内容如下:

      class tomcat {

          package{[‘tomcat’,’tomcat-admin-webapps’,’tomcat-docs-webapp’,’tomcat-webapps’,’java-1.8.0-openjdk’]:

               ensure => latest,

              } ->

          exec{‘mkdir’:

            command => ‘mkdir -pv /var/lib/tomcat/webapps/test/{classes,lib,WEB_INF}’,

            path    => ‘/bin:/sbin:/usr/bin:/usr/sbin’,

            creats => ‘/var/lib/tomcat/webapps/test’,

              } ->

          service{‘tomcat’:

                ensure => running,

                enable => true,

              }

       }

    4)创建子类(子类文件名必须和子类名相同)

       Vim  ./tomcat/manfests/mem.pp内容如下:

         class tomcat::mem inherits tomcat{

              file{‘server.xml’:

                path   => ‘/etc/tomcat/server.xml’,

                source => ‘puppet:///modules/tomcat/server_memcached.xml’,

                } ->

              file{‘javolution-5.4.3.1.jar’:

                path   => ‘/usr/share/tomcat/lib/javolution-5.4.3.1.jar’,

                source => ‘puppet:///modules/tomcat/javolution-5.4.3.1.jar’,

                } ->

              file{‘memcached-session-manager-tc7-2.1.1.jar’:

                path   => ‘/usr/share/tomcat/lib/memcached-session-manager-tc7-2.1.1.jar’,

                source => ‘puppet:///modules/tomcat/memcached-session-manager-tc7-2.1.1.jar’,

                } ->

              file{‘spymemcached-2.11.1.jar’:

                path   => ‘/usr/share/tomcat/lib/spymemcached-2.11.1.jar’,

                source => ‘puppet:///modules/tomcat/spymemcached-2.11.1.jar’,

               } ->

              file{‘memcached-session-manager-2.1.1.jar’:

                path   => ‘/usr/share/tomcat/lib/memcached-session-manager-2.1.1.jar’,

                source => ‘puppet:///modules/tomcat/memcached-session-manager-2.1.1.jar’,

                } ->

              file{‘msm-javolution-serializer-2.1.1.jar’:

                path   => ‘/usr/share/tomcat/lib/msm-javolution-serializer-2.1.1.jar’,

                source => ‘puppet:///modules/tomcat/msm-javolution-serializer-2.1.1.jar’,

                }

              case $ipaddress_ens32 {

                ‘192.168.126.132’: { $i = tomcata.jsp }

                ‘192.168.126.133’: { $i = tomcatb.jsp }

                 default: { $i = tomcata.jsp }

                } ->

              file{‘index.jsp’:

                 path   => ‘/var/lib/tomcat/webapps/test/index.jsp’,

                 source => “puppet:///modules/tomcat/$i”,

                }

        }

     5)放置文件cd ./tomcat/files/

        javolution-5.4.3.1.jar

   msm-javolution-serializer-2.1.1.jar

   spymemcached-2.11.1.jar

   memcached-session-manager-2.1.1.jar

   memcached-session-manager-tc7-2.1.1.jar

   上面的文件问做session-server所需要的类文件

server_memcached.xml(主配置文件)在此文件中加入session配置

 puppet部署多台服务器

tomcata.jsp(tomcat1主机上的主页面)内容如下:

 puppet部署多台服务器

tomcatb.jsptomcat2主机上的主页面)

   puppet部署多台服务器

3、创建nginx模块

   (1)cd  /etc/puppet/environments/production/modules/

   (2)mkdir  ./nginx/{manifests,templates,files,spec.lib,tests}

   (3)Vim ./nginx/manifests/init.pp添加内容如下:

      class nginx {

           package{‘nginx’:

              ensure => latest,

             } ->

          service{‘nginx’:

              ensure => running,

              enable => true,

             }

       }

   (4)创建子类Vim ./nginx/manifests/proxy.pp添加内容如下:

        class nginx::proxy inherits nginx{

            file{‘nginx.conf’:

              path   => ‘/etc/nginx/nginx.conf’,

              source => ‘puppet:///modules/nginx/proxy.conf’,

             }

           Package[‘nginx’] -> File[‘nginx.conf’] ~> Service[‘nginx’]

     }

      (5)放置文件

       cd ./nginx/files/

  proxy.conf

       puppet部署多台服务器

 4、创建keepalived模块(设置其虚拟IP:192.168.126.110)

   (1)cd  /etc/puppet/environments/production/modules/

   (2)mkdir  ./keepalived/{manifests,templates,files,spec.lib,tests}

   (3)Vim ./keepalived/manifests/init.pp添加内容如下:

       class keepalived {

            package{‘keepalived’:

                ensure => latest,

              } ->

           service{‘keepalived’:

                ensure => running,

                enable => true,

              }

       }

     (4)子类 vim ./keepalived/manifests/vip.pp内容如下:

        class keepalived::vip inherits keepalived{

              if $ipaddress_ens32 == ‘192.168.126.130’ {

             file{‘keepalived.conf’:

                  path   => ‘/etc/keepalived/keepalived.conf’,

                source => “puppet:///modules/keepalived/keepaliveda.conf”,

               }

            } else {

             file{‘keepalived.conf’:

                path   => ‘/etc/keepalived/keepalived.conf’,

                source => “puppet:///modules/keepalived/keepalivedb.conf”,

               }

            }

            file{‘notify.sh’:

               path   => ‘/etc/keepalived/notify.sh’,

              source => ‘puppet:///modules/keepalived/notify.sh’,

             }

       }

(5)放置文件

 keepaliveda.confkeepalived主节点配置文件)

            puppet部署多台服务器

keepalivedb.conf keepalived次节点配置文件)

       puppet部署多台服务器

notify.sh(通知脚本)

      puppet部署多台服务器

三、puppet-master主机部署

1、创建部署文件

  vim /etc/puppet/environment/production/manifets/site.pp内容如下:

   node ‘node2.zq.com’ {

       include nginx::proxy

       include keepalived::vip

       }

    node ‘node3.zq.com’ {

       include nginx::proxy

       include keepalived::vip

       }

    node ‘node4.zq.com’ {

       include tomcat::mem

        }

    node ‘node5.zq.com’ {

      include  tomcat::mem

       }

    node ‘node6.zq.com’ {

      include memcached

      }

    node ‘node7.zq.com’ {

      include memcached

      }

 2、执行部署

    puppet kick node2.zq.com

      puppet kick node3.zq.com

      puppet kick node4.zq.com

      puppet kick node5.zq.com

      puppet kick node6.zq.com

      puppet kick node7.zq.com

 四、测试:

           在测试主机的hosts文件中加入一条解析:

                 192.168.126.110  www.zq.com

输入URLwww.zq.com/test

 puppet部署多台服务器

  puppet部署多台服务器

puppet部署成功
 

 

 

 

 

 

 

 

 

 

 

 

 

 

原创文章,作者:zq,如若转载,请注明出处:http://www.178linux.com/82554

(1)
zqzq
上一篇 2017-07-23
下一篇 2017-07-23

相关推荐

  • Linux初学笔记(markdown格式)

    Linux基础命令笔记

    Linux干货 2018-03-26
  • 进程理论和相关工具的使用

    内核的功用 进程管理、文件系统、网络功能、内存管理、驱动程序、安全功能等     Process: 运行中的程序的一个副本,是被载入内存的一个指令集合 进程ID(Process ID,PID)号码被用来标记各个进程     UID、GID、和SELinux语境决定对文件…

    Linux干货 2017-08-28
  • 条件判断工具 test or [ ]

    概述         条件判断是学习shell脚本之前要掌握的重点基础。条件判断分为以下几类:文件判断、数值判断、字符判断。而文件判断还可以细分到:文件类型判断、文件权限判断、文件所属判断、文件之间属性判断;      &nbsp…

    Linux干货 2016-02-14
  • M22 使用NFS实现web共享发布

    实验目的: 搭建两个LAMP web发布系统搭建WordPress博客网站,并使用NFS作为共享的网络文件系统使这两个web服务器发布的内容一致。 实验工具: webServer1 Centos6.8 172.18.55.6 webServer2 Centos7.3 172.18.55.7 nfsServer Centos7.3 172.18.55.71 w…

    2017-04-26
  • 单引号、双引号和反引号使用方法

        首先向马哥和马哥团队敬个礼,谢谢你们带我进入Linux的世界,刚开始接触linux时,经常看到单引号、双引号和反引号特殊符号,经常搞混淆和误用,应该用双引号,有时用到单引号。经过几天的混乱引用,总算搞明白了一些,简单总一下三者的使用和区别。  单引号 ‘’     单引号里的内容全部以普通字符的含义进…

    Linux干货 2015-07-29
  • N21-北京-泥人-马哥教育网络班21期+第一周课程练习

    马哥教育网络班21期  第一周课程练习 一、计算机的组成 1、计算机主要由以下几部分组成:运算器 控制器 存储器(编址存储单元)、 输入、输出设备   2、运算器负责运算:只能做二进制的数学、逻辑运算, 控制器:控制由哪得到数据,放到哪去,协调运算器、存储器、输入、输出等设备 运算器、控制器整合到一起就是常说的中央处理器,也就是CPU。 …

    Linux干货 2016-07-12