设为首页 收藏本站
查看: 682|回复: 0

[经验分享] 第一次独立完成puppet脚本编写

[复制链接]

尚未签到

发表于 2018-8-2 11:35:17 | 显示全部楼层 |阅读模式
  利用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"] }

  >  logs => true,
  stage => "basic",
  }
  $idc = getidc($clientcert)

  >  "10.67.15.144 mongodb-internal.sae.sina.com.cn",
  ] }

  >  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)

  >  "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",
  ]}

  >
  >
  >
  >
  >
  >
  >
  >
  >  $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>
  # These control what>  # 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
  #===========================================================

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-545315-1-1.html 上篇帖子: puppet学习—httpd+passenger安装DashBoard 下篇帖子: linux下puppet的“资源”管理
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表