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

[经验分享] puppet结合Mcollective + activemq

[复制链接]

尚未签到

发表于 2015-11-26 14:29:11 | 显示全部楼层 |阅读模式
  Mcollecitve+activemq安装配置比较繁琐,本来想在window上安装好的,但是puppetlabs官方没有提供安装指令,网上教程也比较少,捣鼓几天也没出来,只是在centos环境中安装配置成功。
  activemq是消息中间间,我试了,可以单独安装在一台服务器上,也可以安装在装有puppet master的服务器上。
  现以两台机器进行说明:
  [PS:两台机器都已分别装好puppet master, puppet client]
  A服务器:puppet master + mcollective-client + activemq
  B服务器:puppet client + mcollective-*
  


  1.在A中安装ActiveMQ
  yum install -y activemq
  A的主机域名为mas2.domain.com,而且mas2.domain.com证书已认证安装,所以可以直接进入下面的配置ActiveMQ,要是将ActiveMQ单独安装一台新的服务器C上,还有在C上安装puppet client,以便认证。参考刘宇的《puppet实战》
  


  2.配置ActiveMQ
  (1)配置用户
  增加Mcollective用户,推荐用mcollective,
  <simpleAuthenticationPlugin>
<users>
<!--authenticationUser username=&quot;${activemq.username}&quot; password=&quot;${activemq.password}&quot; groups=&quot;admins,everyone&quot;/ -->
<authenticationUser username=&quot;mcollective&quot; password=&quot;secret&quot; groups=&quot;mcollective,admins,everyone&quot;/>
<authenticationUser username=&quot;admin&quot; password=&quot;secret&quot; groups=&quot;mcollective,admins,everyone&quot;/>
</users>
</simpleAuthenticationPlugin>
  (2)配置TLS
  PS:所有的密码均是secret
  1)创建Truststore
  keytool -import -alias &quot;activemq&quot; -file /var/lib/puppet/ssl/certs/ca.pem -keystore truststore.jks
   DSC0000.jpg

密码:secret

  2)验证上面是否创建成功:
  keytool -list -keystore truststore.jks
  输入密码可以查看:
   DSC0001.jpg

openssl x509 -in /var/lib/puppet/ssl/certs/ca.pem -fingerprint -md5


  3)创建KeyStore,和1)的操作类&#20284;
  PS:密码均是secret
  cat /var/lib/puppet/ssl/private_keys/mas2.domain.com.pem var/lib/puppet/ssl/certs/mas2.domain.com.pem > temp.pem
  openssl pkcs12 -export -in temp.pem -out activemq.p12 -name mas2.domain.com
  keytool -importkeystore -destkeystore keystore.jks -srckeystore activemq.p12 -srcstoretype PKCS12 -alias mas2.domain.com
  4)验证3)
  keytool -list -keystore keystore.jks
   DSC0002.jpg

openssl x509 -in /var/lib/puppet/ssl/certs/mas2.domain.com.pem -fingerprint -md5
  5)将文件复制到/etc/acitvemq下:
  cp keystore.jks truststore.jks /etc/activemq/
  查看/etc/activemq
   DSC0003.jpg


  (3)配置sslContext
  sslContext要放在Plugins和SystemUsage中间:
  在/etc/activemq/activemq.xml添加:
  <sslContext>
<sslContext
keyStore =&quot;keystore.jks&quot; keyStorePassword=&quot;secret&quot;
trustStore=&quot;truststore.jks&quot; trustStorePassword=&quot;secret&quot;
/>
</sslContext>(4)配置ActiveMQ监听端口
  vim /etc/activemq/activemq.xml
<transportConnectors>
<transportConnector name=&quot;openwire&quot; uri=&quot;tcp://0.0.0.0:61616&quot;/>
<transportConnector name=&quot;stompssl&quot; uri=&quot;stomp+ssl://0.0.0.0:61614?needClientAuth=true&quot;/>
</transportConnectors>
  (5)启动ActiveMQ和验证Stomp监听TCP端口
  service activemq start
netstat -an|grep 61614
   DSC0004.jpg
  PS:不是ActiveMQ开启之后马上就可以监听,可能需要等一两分钟。
  这样中间件ActiveMQ安装配置就OK了。
  


  3.Mcollective 安装
  Mcollective Client安装在puppet master上
  yum install -y mcollective-*
  Mcollective Server 安装在puppet client上
  yum install -y mcollective-*
  4.MCollective控制端配(Mcollective client端)置
  Mcollective client端就是Puppet Master端
  1)生产Mcollective 应用层共享证书
  sudo ppuppet cert generate mcollective-servers
  2)配置/etc/mcollective/client.cfg
  参考:https://docs.puppetlabs.com/mcollective/configure/client.html
  

# Connector settings (required):
# -----------------------------
connector = activemq
direct_addressing = 1
# ActiveMQ connector settings:
plugin.activemq.pool.size = 1
plugin.activemq.pool.1.host = mas2.domain.com
plugin.activemq.pool.1.port = 61614
plugin.activemq.pool.1.user = mcollective
plugin.activemq.pool.1.password = secret
plugin.activemq.pool.1.ssl = 1
plugin.activemq.pool.1.ssl.ca = /var/lib/puppet/ssl/certs/ca.pem
plugin.activemq.pool.1.ssl.cert = /var/lib/puppet/ssl/certs/mas2.domain.com.pem
plugin.activemq.pool.1.ssl.key = /var/lib/puppet/ssl/private_keys/mas2.domain.com.pem
plugin.activemq.pool.1.ssl.fallback = 0

# Security plugin settings (required):
# -----------------------------------
securityprovider = ssl
# SSL plugin settings:
plugin.ssl_server_public = /var/lib/puppet/ssl/certs/mcollective-servers.pem
plugin.ssl_client_private = /var/lib/puppet/ssl/private_keys/mas2.domain.com.pem
plugin.ssl_client_public = /var/lib/puppet/ssl/certs/mas2.domain.com.pem
# PSK plugin settings:
plugin.psk = j9q8kx7fnuied9e
# Interface settings (optional):
# ------------------------------
# Discovery settings:
default_discovery_method = mc
# default_discovery_options = /etc/mcollective/nodes.txt
# Performance settings:
direct_addressing_threshold = 10
ttl = 60
discovery_timeout = 2
publish_timeout = 2
threaded = false
# Miscellaneous settings:
color = 1
rpclimitmethod = first
# Subcollectives (optional):
# -----------------------------------
collectives = mcollective,uk_collective
main_collective = mcollective
# Advanced settings and platform defaults:
# -----------------------------------
logger_type = console
loglevel = warn
logfile = /var/log/mcollective.log
keeplogs = 5
max_log_size = 2097152
logfacility = user
libdir = /usr/libexec/mcollective
#rpchelptemplate = /etc/mcollective/rpc-help.erb
#helptemplatedir = /etc/mcollective
ssl_cipher = aes-256-cbc
#Facts
#---------------------------------------
factsource = yaml
plugin.yaml = /etc/mcollective/facts.yaml

4.Mcollective 节点(Mcollective Server)配置  
  1)创建MCollective模板
  

mkdir /etc/puppet/modules/mcollective/{manifests,files,templates} -p
sudo mkdir -p /etc/puppet/modules/mcollective/files/pem/clientsvim /etc/puppet/modules/mcollective/manifests/init.pp

  
  



class mcollective(
$activemq_server,
$mcollective_password){
package {
['mcollective','mcollective-puppet-agent','mcollective-service-agent']:
ensure => installed,
}
service {
&quot;mcollective&quot;:
ensure => running,
enable => true,
require => Package['mcollective'],
}
file {'/etc/mcollective':
ensure => directory,
source => &quot;puppet:///modules/mcollective/pem&quot;,
recurse => remote,
notify => Service['mcollective'],
}
file{&quot;/etc/mcollective/facts.yaml&quot;:
owner    => root,
group    => root,
mode     => 400,
loglevel => debug, # reduce noise in Puppet reports
content  => inline_template(&quot;<%= scope.to_hash.reject { |k,v| k.to_s =~ /(uptime_seconds|timestamp|free)/ }.to_yaml
%>&quot;), # exclude rapidly changing facts
}
file{&quot;/etc/mcollective/server.cfg&quot;:
ensure => file,
content => tempalte(&quot;mcollective/server.cfg.erb&quot;),
notify => Service['mcollective'],
}
}
  


  3)创建server.cfg.erb
  

sudo vim /etc/puppet/modules/mcollective/templates/server.cfg.erb
  
  

  <% ssldir = '/var/lib/puppet/ssl' %>
# /etc/mcollective/server.cfg
# ActiveMQ connector settings:
connector = activemq
direct_addressing = 1
plugin.activemq.pool.size = 1
plugin.activemq.pool.1.host = <%= @activemq_server %>
plugin.activemq.pool.1.port = 61614
plugin.activemq.pool.1.user = mcollective
plugin.activemq.pool.1.password = <%= @mcollective_password %>
plugin.activemq.pool.1.ssl = 1
plugin.activemq.pool.1.ssl.ca = <%= ssldir %>/certs/ca.pem
plugin.activemq.pool.1.ssl.cert = <%= ssldir %>/certs/<%= scope.lookupvar('::clientcert') %>.pem
plugin.activemq.pool.1.ssl.key = <%= ssldir %>/private_keys/<%= scope.lookupvar('::clientcert') %>.pem
plugin.activemq.pool.1.ssl.fallback = 0
# SSL security plugin settings:
securityprovider = ssl
plugin.ssl_client_cert_dir = /etc/mcollective/clients
plugin.ssl_server_private = /etc/mcollective/server_private.pem
plugin.ssl_server_public = /etc/mcollective/server_public.pem
#
plugin.puppet.resource_allow_managed_resources = true
plugin.puppet.resource_type_whitelist = exec, file
# Facts, identity, and classes:
identity = <%= scope.lookupvar('::fqdn') %>
factsource = yaml
plugin.yaml = /etc/mcollective/facts.yaml
classesfile = /var/lib/puppet/state/classes.txt
# No additional subcollectives:
collectives = mcollective
main_collective = mcollective
# Registration:
# We don't configure a listener, and only send these messages to keep the
# Stomp connection alive. This will use the default &quot;agentlist&quot; registration
# plugin.
registerinterval = 600
# Auditing (optional):
# If you turn this on, you must arrange to rotate the log file it creates.
rpcaudit = 1
rpcauditprovider = logfile
plugin.rpcaudit.logfile = /var/log/mcollective-audit.log
# Authorization:
# If you turn this on now, you won't be able to issue most MCollective
# commands, although `mco ping` will work. You should deploy the
# ActionPolicy plugin before uncommenting this; see &quot;Deploy Plugins&quot; below.
# rpcauthorization = 1
# rpcauthprovider = action_policy
# plugin.actionpolicy.allow_unconfigured = 1
# Logging:
logger_type = file
loglevel = info
logfile = /var/log/mcollective.log
keeplogs = 5
max_log_size = 2097152
logfacility = user
# Platform defaults:
# These settings differ based on platform; the default config file created by
# the package should include correct values. If you are managing settings as
# resources, you can ignore them, but with a template you'll have to account
# for the differences.
<% if scope.lookupvar('::osfamily') == 'RedHat' -%>
libdir = /usr/libexec/mcollective
daemonize = 1
<% elsif scope.lookupvar('::osfamily') == 'Debian' -%>
libdir = /usr/share/mcollective/plugins
daemonize = 1
<% else -%>
# INSERT PLATFORM-APPROPRIATE VALUES FOR LIBDIR AND DAEMONIZE
<% end %>

(4)复制证书  
  

cp /var/lib/puppet/ssl/private_keys/mcollective-servers.pem  /etc/puppet/modules/mcollective/files/pem/server_private.pem
cp /var/lib/puppet/ssl/public_keys/mcollective-server.pem  /etc/puppet/modules/mcollective/files/pem/server_public.pem
chmod 0644 /etc/puppet/modules/mcollective/files/pem/server_*
cp /var/lib/puppet/ssl/certs/mas2.domain.com.pem   /etc/puppet/modules/mcollective/files/pem/clients
chmod 0644 /etc/puppet/modules/mcollective/files/pem/clients

(5)配置节点  
  

vim /etc/puppet/manifests/nodes/c5.domain.com.pp

node 'c6.domain.com' {
#include test
class {&quot;mcollective&quot;:
activemq_server => &quot;mas2.domain.com&quot;,
mcollective_password => &quot;secret&quot;,
}
}

  (6)应用puppet代码
  puppet agent -t

(7)验证
  在puppet master 输入:
  mco  findmco ping DSC0005.jpg
  通过mcollectve 实现主动推送:
  mco puppet runonce -v DSC0006.jpg






  

运维网声明 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-143958-1-1.html 上篇帖子: 把玩云计算之puppet学习指南——master与agent通信 下篇帖子: puppet笔记(1)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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