puppet ActiveMQ MCollective CentOS6 安装笔记

Puppet 在CentOS6 上安装activemq mcollective 笔记

安装activemq mcollective 环境

rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm
yum -y install java-1.8.0-openjdk activemq

编辑activemq的配置文件:/etc/activemq/activemq.xml

cat /etc/activemq/activemq.xml|grep -v "^$"
<beans
 xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
 <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
 <property name="locations">
 <value>file:${activemq.conf}/credentials.properties</value>
 </property>
 </bean>
 <broker xmlns="http://activemq.apache.org/schema/core" brokerName="computer001" dataDirectory="${activemq.data}" schedulePeriodForDestinationPurge="60000">
 <destinationPolicy>
 <policyMap>
 <policyEntries>
 <policyEntry topic=">" >
 <pendingMessageLimitStrategy>
 <constantPendingMessageLimitStrategy limit="1000"/>
 </pendingMessageLimitStrategy>
 </policyEntry>
 </policyEntries>
 </policyMap>
 </destinationPolicy>
 <managementContext>
 <managementContext createConnector="false"/>
 </managementContext>
 <persistenceAdapter>
 <kahaDB directory="${activemq.data}/kahadb"/>
 </persistenceAdapter>
 <systemUsage>
 <systemUsage>
 <memoryUsage>
 <memoryUsage percentOfJvmHeap="70" />
 </memoryUsage>
 <storeUsage>
 <storeUsage limit="100 gb"/>
 </storeUsage>
 <tempUsage>
 <tempUsage limit="50 gb"/>
 </tempUsage>
 </systemUsage>
 </systemUsage>
<plugins>
 <simpleAuthenticationPlugin>
 <users>
 <authenticationUser username="client" password="client_password" groups="servers,clients,everyone"/>
 <authenticationUser username="server" password="server_password" groups="servers,everyone"/>
 </users>
 </simpleAuthenticationPlugin>
 
 <authorizationPlugin>
 <map>
 <authorizationMap>
 <authorizationEntries>
 <authorizationEntry queue="mcollective.>" write="clients" read="clients" admin="clients" />
 <authorizationEntry topic="mcollective.>" write="clients" read="clients" admin="clients" />
 <authorizationEntry queue="mcollective.nodes" read="servers" admin="servers" />
 <authorizationEntry queue="mcollective.reply.>" write="servers" admin="servers" />
 <authorizationEntry topic="mcollective.*.agent" read="servers" admin="servers" />
 <authorizationEntry topic="mcollective.registration.agent" write="servers" read="servers" admin="servers" />
 <authorizationEntry topic="ActiveMQ.Advisory.>" read="everyone" write="everyone" admin="everyone"/>
 </authorizationEntries>
 </authorizationMap>
 </map>
 </authorizationPlugin>
</plugins>
<managementContext>
<managementContext createConnector="true" connectorPort="1099"/> 
 </managementContext>
 <transportConnectors>
 <transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
 <transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
 <transportConnector name="stomp+nio" uri="stomp+nio://0.0.0.0:61613?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
 <transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
 <transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
 </transportConnectors>
 <shutdownHooks>
 <bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
 </shutdownHooks>
 </broker>
 <import resource="jetty.xml"/>
</beans>

配置文件,请参考:https://github.com/jorhett/learning-mcollective/blob/master/examples/activemq_59.xml

 

配置actvemq web控制台


cat /etc/activemq/jetty.xml |grep authenticate
<property name="authenticate" value="true" /> 将false 改为true,即可

启动activemq 服务

/etc/init.d/activemq start 

MC服务端安装 


yum install mcollective -y

MC服务端配置文件 


cat /etc/mcollective/server.cfg

daemonize = 1
direct_addressing = 1
# ActiveMQ connector settings:
connector = activemq
plugin.activemq.pool.size = 1
plugin.activemq.pool.1.host = 192.168.200.51 #填写activemq的IP地址或者dns,使用dns需要解析
plugin.activemq.pool.1.port = 61613 &amp;nbsp; #端口
plugin.activemq.pool.1.user = server # 用户名
plugin.activemq.pool.1.password = server_password #密码
plugin.activemq.heartbeat_interval = 30 &amp;nbsp;#心跳间隔
 
# How often to send registration messages
registerinterval = 600
 
# Plugins
securityprovider = psk
plugin.psk = psk_password
 
#
libdir = /usr/libexec/mcollective
logfile = /var/log/mcollective.log
loglevel = info


 

启动MC server服务

/etc/init.d/mcollective  start

注:每台MC 服务端都需要安装,并确保每台机器时间都是同步。

MC客户端安装

yum -y install mcollective-client

注:仅客户端需要安装。

MC客户端配置

cat /etc/mcollective/client.cfg

daemonize = 1
direct_addressing = 1
# ActiveMQ connector settings:
connector = activemq
plugin.activemq.pool.size = 1
plugin.activemq.pool.1.host = 192.168.200.51
plugin.activemq.pool.1.port = 61613
plugin.activemq.pool.1.user = client
plugin.activemq.pool.1.password = client_password
plugin.activemq.heartbeat_interval = 30
 
# How often to send registration messages
registerinterval = 600
 
# Plugins
securityprovider = psk
plugin.psk = psk_password
 
#
libdir = /usr/libexec/mcollective
logfile = /var/log/mcollective.log

ttl = 60
color = 1
rpclimitmethod = first

# Facts
factsource = yaml
plugin.yaml = /etc/mcollective/facts.yaml


MC客户端测试

 # mco ping

computer001 time=70.62 ms

computer002 time=30.12 ms

computer003 time=30.02 ms

此blog都是以前个人笔记,不保证时效性,更多请继续关注puppetfans文章!

puppet 变量作用域

上篇介绍了puppet 变量归类,本篇介绍下puppet 变量作用域。

根据puppet变量作用域可以分为全局变量,节点变量,类变量,以及子类变量

  • 全局变量: 在site.pp里定义的变量。
     cat /etc/puppet/manifests/site.pp    $role = default 
  • 节点变量: 在node里定义的变量。
     node 'www.puppetfans.com' {  $dbname =  puppetfans } 
  • 类变量:    在class中定义的变量。
    class "base" { $username = puppetfans }
  • 子类变量
     class "base01"  { name = $::base::username }

 

CentOS 上安装puppet 教程

安装puppet主要方式,有两种通过包管理器,以及源码安装,源码安装puppet不推荐,在CentOS上推荐通过yum来安装。

安装puppet之前确保服务器能连网,添加puppet 官方yum源,地址为https://yum.puppetlabs.com/。

CentOS 6 安装puppet 3.x 示例

sudo rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-el- 6.noarch.rpm
sudo yum -y install puppet-server 
sudo yum -y install puppet

默认配置文件都在/etc/puppet目录下:

CentOS 6 安装puppet 4.x 示例

sudo rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-pc1-el-6.noarch.rpm
sudo yum -y install puppetserver 
sudo yum -y install puppet 

puppet 4.x  所有bin文件都保存在/opt/puppetlabs/bin目录下,需要注意 添加可执行文件路径到$PATH变量,不然会报找不到puppet命令。配置文件保存在/etc/puppetlabs/puppet/puppet.conf

 

puppet 配置文件示例:

vardir = /opt/puppetlabs/server/data/puppetserver
logdir = /var/log/puppetlabs/puppetserver
rundir = /var/run/puppetlabs/puppetserver
pidfile = /var/run/puppetlabs/puppetserver/puppetserver.pid
codedir = /etc/puppetlabs/code

Puppet 默认使用JVM内存大小2G,如需调整,步骤如下:

编辑 /etc/sysconfig/puppetserver文件

修改如下参数值:

JAVA_ARGS="-Xms2g -Xmx2g"

更多JVM参数调整,可参阅Orace官方文档

 

日志路径:/var/log/puppet

查看所有配置参数

puppet config print all

puppet facter 使用方法及示例

puppet facter 使用方法

查看所有facter

facter 或者facter -p

查看内核版本

facter kernelversion

 

 

以yaml格式显示所有facts

facter -y

以json格式显示所有facts

facter -j

facter 使用示例:

在manifests代码清单里使用facter 函数

notify { "OS is ${::facts[‘operatingsystem’]}": }

直接在manifests代码清单里使用

nofify {"productnmae is $::productname"}

获取 facter hash数组值(puppet 4版本)

[puppetfans@li664-233 nginx]$ sudo /opt/puppetlabs/bin/facter system_uptime
{
days => 3,
hours => 93,
seconds => 336477,
uptime => "3 days"
}
[puppetfans@li664-233 nginx]$ sudo /opt/puppetlabs/bin/facter system_uptime.hours
93

puppet augeas 使用示例

puppet augeas 资源使用

使用augeas前提需要安装augeas 包。

  • augtool可执行命令路径:

puppet 3 版本      /usr/bin/augtool

puppet 4 版本  /opt/puppetlabs/puppet/bin/augtool

  • augtool 使用示例
    [root@puppetmaster ~]# augtool
    augtool> ls /augeas/load  #显示所有可用的资源
    Libvirtd_qemu/ = (none)
    Libvirtd_lxc/ = (none)
    Libvirtd/ = (none)
    VMware_Config/ = (none)
    Login_defs/ = (none)
    Networks/ = (none)
    Splunk/ = (none)
    Thttpd/ = (none)
    Odbc/ = (none)
    Nsswitch/ = (none)
    Netmasks/ = (none)
    ...

改变特定文件里参数值

augtool> set /files/etc/ssh/sshd_config/PermitrootLogin no
augtool> save

以树形结构来展示数据

cat /etc/hosts
/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.181 puppet puppetmaster
192.168.200.181 files.puppetfans.cn
192.168.200.182 Xkefu
192.168.200.187 xkefu187

augtool> ls /files/etc/hosts
1/ = (none)
2/ = (none)
3/ = (none)
4/ = (none)
5/ = (none)
6/ = (none)

augtool> ls /files/etc/hosts/6
ipaddr = 192.168.200.187
canonical = xkefu187

查看augeas版本

augtool> ls /augeas/
root = /
context = /files
variables = (none)
version/ = 1.0.0
save = overwrite
span = disable
load/ = (none)
files/ = (none)

augeas 更多使用方法

Admin commands:
help - print help
load - (re)load files under /files
quit - exit the program
retrieve - transform tree into text
save - save all pending changes
store - parse text into tree
transform - add a file transform

Read commands:
dump-xml - print a subtree as XML
get - get the value of a node
label - get the label of a node
ls - list children of a node
match - print matches for a path expression
print - print a subtree
span - print position in input file corresponding to tree

Write commands:
clear - clear the value of a node
clearm - clear the value of multiple nodes
ins - insert new node
insert - insert new node (alias of 'ins')
mv - move a subtree
move - move a subtree (alias of 'mv')
rename - rename a subtree label
rm - delete nodes and subtrees
set - set the value of a node
setm - set the value of multiple nodes
touch - create a new node

Path expression commands:
defnode - set a variable, possibly creating a new node
defvar - set a variable

Type 'help <command>' for more information on a command

继续阅读“puppet augeas 使用示例”

puppet stage 使用示例

puppet stage 使用示例

【puppet stage使用方法】

class puppetfans::stages {
stage { 'first': before => Stage['main'] }
stage { 'last': require => Stage['main'] }
class pe_first {
notify { 'This will be done first': }
} 

class pe_last {
notify { 'This will be done last': }
}

class { 'pe_first':
stage => 'first',
}

class { 'pe_last':
stage => 'last',
}
}

 

可以使用如下测试puppet stage效果 :

node 'basenode' {
class {'roles::web': }
class {'roles::db': }
include puppetfans::stages
}

puppet 节点继承与类继承用法

puppet 节点继承用法:

node $name [inherits $parent_node]
{ [ Puppet code, resources and classes applied to the node ] }

puppet  node  inherits 用法示例:

node  'www.puppetfans.com' inherits basenode {}

puppet 类继承用法, puppet class inherits 用法示例:

class puppet {
file { '/etc/puppet/puppet.conf':
content => template('puppet/client/puppet.conf'),
}
}
class puppet::server inherits puppet {
File['/etc/puppet/puppet.conf'] {
content => template('puppet/server/puppet.conf'),
}
}

puppet 语法学习变量

变量类型

字符串

 $a_string = 'This is a string value'

数组

 $an_array = [ 'This', 'forms', 'an', 'array' ] 

哈希

 $a_hash = { 'subject' => 'Hashes',
'predicate' => 'are written',
'object' => 'like this',
'note' => 'not actual grammar!',
'also note' => [ 'nesting is', { 'allowed' => 'of course' } ],
}

使用变量示例:

$x = $a_string
$y = $an_array[1]
$z = $a_hash['object']

$download_server = 'img2.puppetfans.com'
$url = "https://${download_server}/pkg/puppet-ebook.tar.gz"

$packages = [ 'apache2', 'libapache2-mod-php5', 'libapache2-mod-passenger', ]
package { $packages:
ensure => 'installed'
}