第一次独立完成puppet脚本编写

利用puppet管理solrcloud

主脚本

1./etc/puppet/manifests/zookeeper.pp

/* vim set :expandtab:shiftwidth=4:tabstop=4:smarttab: */


#= globalvar

#= sae

#= cron

#= user

#= account

#= stdlib

#= zookeeper

#= solr

#= jetty


node /sae$/ {

    include globalvar

    include globalvar::user

        include account::list


    stage { "basic": before => Stage["main"] }


    class { "sae::directory":

        logs => true,

        stage => "basic",

    }


    $idc = getidc($clientcert)


    class { "sae::hosts": idc => $idc, stage => "basic", hosts=>[

        "10.67.15.144 mongodb-internal.sae.sina.com.cn",

    ] }

    class { "sae::resolv": idc => $idc }


    if $idc == 'bx' {

        $ipaddress_internal = $ipaddress_eth1

        $netdev_internal = "eth1"

    } else {

        if 'bond0' in $interfaces {

            $ipaddress_internal = $ipaddress_bond0

            $dev_inter = 'bond0'

        } elsif 'eth1' in $interfaces {

            $ipaddress_internal = $ipaddress_eth1

            $dev_inter = 'eth1'

        }

    }


    $gateway  = getgateway($ipaddress_internal)

    class { "sae::route": stage => "basic", rules => [

        "add 10.0.0.0/8 via $gateway dev $netdev_internal",

        "add 172.16.0.0/16 via $gateway dev $netdev_internal",

        "add 192.168.0.0/16 via $gateway dev $netdev_internal",

    ]}


    class { "sae::yum": }

    class { "sae::pkg": sendmail => "STOP", }

    class { "sae::cron": }

    class { "sae::ntpdate": }

    class { "sae::sysctl": }

    class { "sae::iptables": }


    class { "sae::bashrc": }

    class { "sae::hostname": }


    class { "user": users => [

        $globalvar::user::saere,

        $globalvar::user::conglei,

        $globalvar::user::shijiang,

        $globalvar::user::wanghai1,

        $globalvar::user::mingming6,

        $globalvar::user::renzhong1,

        $globalvar::user::liulei5,

        $globalvar::user::lintao3,

        $globalvar::user::chenfeng2,

        $globalvar::user::liren2,

        $globalvar::user::tengfei5,

        $globalvar::user::liangqi,

        $globalvar::user::wangyang15,

        $globalvar::user::zhiyun1,

        $globalvar::user::suyang,

        $globalvar::user::wanghai1,

        $globalvar::user::yuwei5,

        $globalvar::user::zhantao,

    ]}


        $admin_accounts = $account::list::all_staff

        $absent_admins = difference($account::list::all_staff,$admin_accounts)


        account { $admin_accounts: operation => 'add', }

        account { $absent_admins: operation => 'del', }


   class { "account::sudoers": }

   class { "zookeeper":

        pkg_version => "3.4.6-1" ,

        zookeep_servers => ["server.224=10.13.144.224:9984:9985",

                            "server.225=10.13.144.225:9984:9985",

                            "server.226=10.13.144.226:9984:9985",

                            "server.227=10.13.144.227:9984:9985",

                          ],

         }


   class { "jetty":

        pkg_version => "8.1.15-3" ,

        leader_zookeepers => ["-Dbootstrap_confdir=/usr/local/sae/solr/solr.home/collection1/conf",

                              "-Dcollection.configName=myconf",

                              "-DnumShards=2",

                             ],

         }


   class { "solr": pkg_version => "4.6-3" }

}


2./etc/puppet/modules/solr/manifests/init.pp

/* vim:expandtab:shiftwidth=4:tabstop=4:smarttab: */

class solr(

    $pkg_version = "",

    $index_data = "/data0/solr_data/data",

    $maxDocs = "100000",

    $maxTime = "1800000",

    $cache_size = "10000",

    $cache_initialSize = "10000",

    $cache_autowarmCount = "5000",

)

{

   include globalvar

   package { "${globalvar::pkg_prefix}solr":

        ensure => $pkg_version,

   }



   file { "${globalvar::install_prefix}/solr/solr.home/solr.xml":

    source => "${globalvar::modulepath}/solr/files/solr.xml",

        require => Package["${globalvar::pkg_prefix}solr"],

   }

   file { "${globalvar::install_prefix}/solr/solr.home/collection1/core.properties":

        source => "${globalvar::modulepath}/solr/files/core.properties",

        require => Package["${globalvar::pkg_prefix}solr"],

   }

   file { "${globalvar::install_prefix}/solr/solr.home/collection1/conf/solrconfig.xml":

        content => template("solr/solrconfig.xml.erb"),

        require => Package["${globalvar::pkg_prefix}solr"],

   }

   exec { "create_solrdata":

        command => "/bin/mkdir -p /data0/solr_data/data/",

        unless => "/usr/bin/test -d /data0/solr_data/data/",

        require => Package["${globalvar::pkg_prefix}solr"],

   }

}

#files就不说了,重点说下erb

3./etc/puppet/modules/zookeeper/manifests/init.pp

/* vim:expandtab:shiftwidth=4:tabstop=4:smarttab: */

class zookeeper (

    $myid = $ipaddress,

    $pkg_version = "",

    $zookeep_servers = [],

)

{

    include globalvar

    package { "${globalvar::pkg_prefix}zookeeper":

        ensure => $pkg_version,

    }


    exec { "create_zdata":

        command => "/bin/mkdir -p ${globalvar::install_prefix}/zookeeper/zdata/",

        unless => "/usr/bin/test -d ${globalvar::install_prefix}/zookeeper/zdata/",

    }


    file { "myid":

        path => "${globalvar::install_prefix}/zookeeper/zdata/myid",

        content => template("zookeeper/myid.erb"),

    require => Package["${globalvar::pkg_prefix}zookeeper"],

    }


    file { "${globalvar::install_prefix}/zookeeper/conf/zoo.cfg":

        content => template("zookeeper/zoo.cfg.erb"),

        require => Package["${globalvar::pkg_prefix}zookeeper"],

    }


    file { "${globalvar::install_prefix}/zookeeper/conf/log4j.properties":

        source => "${globalvar::modulepath}/zookeeper/files/log4j.properties",

        require => Package["${globalvar::pkg_prefix}zookeeper"],

    }


    file { "${globalvar::install_prefix}/zookeeper/conf/configuration.xsl":

        source => "${globalvar::modulepath}/zookeeper/files/configuration.xsl",

        require => Package["${globalvar::pkg_prefix}zookeeper"],

    }


    file { "${globalvar::install_prefix}/zookeeper/bin/zkServer.sh":

               owner => "root",

               group => "root",

               mode => "755",

               require => Package["${globalvar::pkg_prefix}zookeeper"],

       }


    exec { "zookeeper_restart":

        command => "${globalvar::install_prefix}/zookeeper/bin/zkServer.sh restart",

        require => Package["${globalvar::pkg_prefix}zookeeper"],

    }

}


文件

/etc/puppet/modules/solr/templates/zoo.cfg.erb

# The number of milliseconds of each tick

tickTime=6000

# The number of ticks that the initial

# synchronization phase can take

initLimit=10

# The number of ticks that can pass between

# sending a request and getting an acknowledgement

syncLimit=5

# the directory where the snapshot is stored.

# do not use /tmp for storage, /tmp here is just

# example sakes.

dataDir=../zdata

# the port at which the clients will connect

clientPort=9983

#

# Be sure to read the maintenance section of the

# administrator guide before turning on autopurge.

#

# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance

#

# The number of snapshots to retain in dataDir

autopurge.snapRetainCount=3

# Purge task interval in hours

# Set to "0" to disable auto purge feature

autopurge.purgeInterval=1


###for语法

<% @zookeep_servers.each do |zookeep_server| -%>

<%= zookeep_server %>

<% end -%>


4./etc/puppet/modules/jetty/manifests/init.pp

/* vim:expandtab:shiftwidth=4:tabstop=4:smarttab: */

class jetty (

    $pkg_version = "",

    $port = "8983",

    $DzkHost = "-DzkHost=10.13.144.224:9983,10.13.144.225:9983,10.13.144.226:9983,10.13.144.227:9983",

    $leader_zookeepers = [],

)

{


    include globalvar


    package { "${globalvar::pkg_prefix}jetty":

       ensure => $pkg_version,

    }


    file { "${globalvar::install_prefix}/jetty/start.ini":

       content => template("jetty/start.ini.erb"),

       require => Package["${globalvar::pkg_prefix}jetty"],

    }


    file { "${globalvar::install_prefix}/jetty/bin/web.sh":

       source => "${globalvar::modulepath}/jetty/files/web.sh",

       require => Package["${globalvar::pkg_prefix}jetty"],

    }


    file { "${globalvar::install_prefix}/jetty/etc/jetty.xml":

       source => "${globalvar::modulepath}/jetty/files/jetty.xml",

       require => Package["${globalvar::pkg_prefix}jetty"],

    }


    file { "${globalvar::install_prefix}/jetty/etc/keystore":

       source => "${globalvar::modulepath}/jetty/files/keystore",

       require => Package["${globalvar::pkg_prefix}jetty"],

    }


    file { "${globalvar::install_prefix}/jetty/etc/log4j.properties":

       source => "${globalvar::modulepath}/jetty/files/log4j.properties",

       require => Package["${globalvar::pkg_prefix}jetty"],

    }


    file { "${globalvar::install_prefix}/jetty/etc/logging.properties":

       source => "${globalvar::modulepath}/jetty/files/logging.properties",

       require => Package["${globalvar::pkg_prefix}jetty"],

    }


    file { "${globalvar::install_prefix}/jetty/etc/realm.properties":

       source => "${globalvar::modulepath}/jetty/files/realm.properties",

       require => Package["${globalvar::pkg_prefix}jetty"],

    }


    file { "${globalvar::install_prefix}/jetty/etc/webdefault.xml":

       source => "${globalvar::modulepath}/jetty/files/webdefault.xml",

       require => Package["${globalvar::pkg_prefix}jetty"],

    }


}

erb文件

stat.ini.erb

#===========================================================

# Jetty start.jar arguments

# Each line of this file is prepended to the command line

# arguments # of a call to:

#    java -jar start.jar [arg...]

#===========================================================




#===========================================================

# If the arguements in this file include JVM arguments

# (eg -Xmx512m) or JVM System properties (eg com.sun.???),

# then these will not take affect unless the --exec

# parameter is included or if the output from --dry-run

# is executed like:

#   eval $(java -jar start.jar --dry-run)

#

# Below are some recommended options for Sun's JRE

#-----------------------------------------------------------

# --exec

# -Dorg.apache.jasper.compiler.disablejsr199=true

# -Dcom.sun.management.jmxremote

# -Dorg.eclipse.jetty.util.log.IGNORED=true

# -Dorg.eclipse.jetty.LEVEL=DEBUG

# -Dorg.eclipse.jetty.util.log.stderr.SOURCE=true

# -Xmx2000m

# -Xmn512m

# -verbose:gc

# -XX:+PrintGCDateStamps

# -XX:+PrintGCTimeStamps

# -XX:+PrintGCDetails

# -XX:+PrintTenuringDistribution

# -XX:+PrintCommandLineFlags

# -XX:+DisableExplicitGC

# -XX:+UseConcMarkSweepGC

# -XX:ParallelCMSThreads=2

# -XX:+CMSClassUnloadingEnabled

# -XX:+UseCMSCompactAtFullCollection

# -XX:CMSInitiatingOccupancyFraction=80

-Djava.net.preferIPv4Stack=true

-Djetty.home=/usr/local/sae/jetty

-Djetty.logs=/data0/log

-Djava.io.tmpdir=/data0/log

-Dsolr.solr.home=/usr/local/sae/solr/solr.home

-Xms4g

-Xmx4g

"start.ini.erb" 89L, 3001C                                                                                                                           43,1          Top

-Dsolr.solr.home=/usr/local/sae/solr/solr.home

-Xms4g

-Xmx4g

-XX:MaxPermSize=256m

-Xss256k

-XX:+UseG1GC

-XX:MaxGCPauseMillis=10

-XX:GCPauseIntervalMillis=200

-Dorg.tanukisoftware.wrapper.WrapperManager.mbean=true

-Dorg.tanukisoftware.wrapper.WrapperManager.mbean.testing=false

-Djava.util.logging.config.file=/usr/local/sae/jetty/etc/logging.properties

-Dlog4j.configuration=file:/usr/local/sae/jetty/etc/log4j.properties

<% @leader_zookeepers.each do |leader_zookeeper| -%>

<%= leader_zookeeper %>

<% end -%>

-Djetty.port=<%= scope.lookupvar("jetty::port") %>

###调用其他类的变量

<%= scope.lookupvar("jetty::DzkHost") %>

#-----------------------------------------------------------



#===========================================================

# Start classpath OPTIONS.

# These control what classes are on the classpath

# for a full listing do

#   java -jar start.jar --list-options

#-----------------------------------------------------------

OPTIONS=Server,jsp,jmx,resources,websocket,ext,plus,annotations

#-----------------------------------------------------------



#===========================================================

# Configuration files.

# For a full list of available configuration files do

#   java -jar start.jar --help

#-----------------------------------------------------------

#etc/jetty-jmx.xml

etc/jetty.xml

#etc/jetty-annotations.xml

# etc/jetty-ssl.xml

# etc/jetty-requestlog.xml

#etc/jetty-deploy.xml

#etc/jetty-overlay.xml

#etc/jetty-webapps.xml

#etc/jetty-contexts.xml

#etc/jetty-testrealm.xml

#===========================================================


你可能感兴趣的:(BEFORE,include,account)