6a36e6cb0f05179fe3f5278f08940087135c24c5
[packages/precise/mcollective.git] / website / reference / basic / gettingstarted.md
1 ---
2 layout: default
3 title: Getting Started
4 ---
5 [Screencasts]: /mcollective/screencasts.html
6 [ActiveMQ]: http://activemq.apache.org/
7 [EC2Demo]: /mcollective/ec2demo.html
8 [Stomp]: http://stomp.codehaus.org/Ruby+Client
9 [DepRPMs]: http://www.marionette-collective.org/activemq/
10 [DebianBug]: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=562954
11 [SecurityWithActiveMQ]: /mcollective/reference/integration/activemq_security.html
12 [ActiveMQClustering]: http://www.devco.net/archives/2009/11/10/activemq_clustering.php
13 [ActiveMQSamples]: http://github.com/puppetlabs/marionette-collective/tree/master/ext/activemq/examples/
14 [ConfigurationReference]: /mcollective/reference/basic/configuration.html
15 [Terminology]: /mcollective/terminology.html
16 [SimpleRPCIntroduction]: /mcollective/simplerpc/
17 [ControllingTheDaemon]: /mcollective/reference/basic/daemon.html
18 [SSLSecurityPlugin]: /mcollective/reference/plugins/security_ssl.html
19 [AESSecurityPlugin]: /mcollective/reference/plugins/security_aes.html
20 [ConnectorStomp]: /mcollective/reference/plugins/connector_stomp.html
21 [MessageFlowCast]: /mcollective/screencasts.html#message_flow
22 [Plugins]: http://projects.puppetlabs.com/projects/mcollective-plugins/wiki
23 [RedHatGuide]: gettingstarted_redhat.html
24 [DebianGuide]: gettingstarted_debian.html
25
26 *NOTE:* We are currently improving the Getting Started documentation.  Red Hat and CentOS users can refer to [our Redhat guide][RedHatGuide]. Debian users can refer to [our Debian guide][DebianGuide].
27
28 Below find a rough guide to get you going, this assumes the client and server is on the same node, but servers don't need the client code installed.
29
30 For an even quicker intro to how it all works you can try our [EC2 based demo][EC2Demo]
31
32 Look at the [Screencasts] page, there are [some screencasts dealing with basic architecture, terminology and so forth][MessageFlowCast] that you might find helpful before getting started.
33
34 ## Requirements
35 We try to keep the requirements on external Gems to a minimum, you only need:
36
37  * A Stomp server, tested against [ActiveMQ]
38  * Ruby
39  * Rubygems
40  * [Ruby Stomp Client][Stomp]
41
42 RPMs for these are available [here][DepRPMs].
43
44 ## ActiveMQ
45 I've developed this against ActiveMQ.  It should work against other Stomp servers but I suspect if you choose
46 one without username and password support you might have problems, please let me know if that's the case
47 and I'll refactor the code around that.
48
49 Full details on setting up and configuring ActiveMQ is out of scope for this, but you can follow these simple
50 setup instructions for initial testing (make sure JDK is installed, see below for Debian specific issue regarding JDK):
51
52 ### Download and Install
53  1. Download the ActiveMQ "binary" package (for Unix) from [ActiveMQ]
54  1. Extract the contents of the archive:
55  1. cd into the activemq directory
56  1. Execute the activemq binary
57
58 {% highlight console %}
59    % tar xvzf activemq-x.x.x.tar.gz
60    % cd activemq-x.x.x
61    % bin/activemq
62 {% endhighlight %}
63
64 Below should help you get stomp and a user going. For their excellent full docs please see [ActiveMQ].
65 There are also tested configurations in [the ext directory][ActiveMQSamples]
66
67 A spec file can be found in the *ext* directory on GitHub that can be used to build RPMs for RedHat/CentOS/Fedora
68 you need *tanukiwrapper* which you can find from *jpackage*, it runs fine under OpenJDK that comes with recent
69 versions of these Operating Systems.  I've uploaded some RPMs and SRPMs [here][DepRPMs].
70
71 For Debian systems you'd be better off using OpenJDK than Sun JDK, there's a known issue [#562954][DebianBug].
72
73 ### Configuring Stomp
74 First you should configure ActiveMQ to listen on the Stomp protocol
75
76 And then you should add a user or two, to keep it simple we'll just add one user, the template file will hopefully make it obvious where this goes, it should be in the _broker_ block:
77
78 *Note: This config is for ActiveMQ 5.4*
79
80 {% highlight xml %}
81 <beans
82   xmlns="http://www.springframework.org/schema/beans"
83   xmlns:amq="http://activemq.apache.org/schema/core"
84   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
85   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
86   http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd
87   http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
88
89     <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" useJmx="true">
90         <managementContext>
91             <managementContext createConnector="false"/>
92         </managementContext>
93
94         <plugins>
95           <statisticsBrokerPlugin/>
96           <simpleAuthenticationPlugin>
97             <users>
98               <authenticationUser username="mcollective" password="marionette" groups="mcollective,everyone"/>
99               <authenticationUser username="admin" password="secret" groups="mcollective,admin,everyone"/>
100             </users>
101           </simpleAuthenticationPlugin>
102           <authorizationPlugin>
103             <map>
104               <authorizationMap>
105                 <authorizationEntries>
106                   <authorizationEntry queue=">" write="admins" read="admins" admin="admins" />
107                   <authorizationEntry topic=">" write="admins" read="admins" admin="admins" />
108                   <authorizationEntry topic="mcollective.>" write="mcollective" read="mcollective" admin="mcollective" />
109                   <authorizationEntry queue="mcollective.>" write="mcollective" read="mcollective" admin="mcollective" />
110                   <authorizationEntry topic="ActiveMQ.Advisory.>" read="everyone" write="everyone" admin="everyone"/>
111                 </authorizationEntries>
112               </authorizationMap>
113             </map>
114           </authorizationPlugin>
115         </plugins>
116
117         <systemUsage>
118             <systemUsage>
119                 <memoryUsage>
120                     <memoryUsage limit="20 mb"/>
121                 </memoryUsage>
122                 <storeUsage>
123                     <storeUsage limit="1 gb" name="foo"/>
124                 </storeUsage>
125                 <tempUsage>
126                     <tempUsage limit="100 mb"/>
127                 </tempUsage>
128             </systemUsage>
129         </systemUsage>
130
131         <transportConnectors>
132             <transportConnector name="openwire" uri="tcp://0.0.0.0:6166"/>
133             <transportConnector name="stomp" uri="stomp://0.0.0.0:6163"/>
134         </transportConnectors>
135     </broker>
136 </beans>
137 {% endhighlight %}
138
139 This creates a user *mcollective* with the password *marionette* and give it access to read/write/admin */topic/mcollective.`*`*.
140
141 Save the above code as activemq.xml and run activemq as - if installing from a package probably _/etc/activemq/activemq.xml_:
142
143 Else your package would have a RC script:
144
145 {% highlight console %}
146   # /etc/init.d/activemq start
147 {% endhighlight %}
148
149 For further info about ActiveMQ settings you might need see [SecurityWithActiveMQ] and [ActiveMQClustering].
150
151 There are also a few known to work and tested [configs in git][ActiveMQSamples].
152
153 ## mcollective
154
155 ### Download and Extract
156 Grab a copy of the mcollective ideally you'd use a package for your distribution else there's a tarfile that
157 you can use, you can extract it wherever you want, the RPMs or deps will put files in Operating System compatible
158 locations.  If you use the tarball you'll need to double check all the paths in the config files below.
159
160 ### Configure
161 You'll need to tweak some configs in */etc/mcollective/client.cfg*, a full reference of config settings can be
162 found [here][ConfigurationReference]:
163
164 Mostly what you'll need to change is the *identity*, *plugin.stomp.`*`* and the *plugin.psk*:
165
166 {% highlight ini %}
167   # main config
168   libdir = /usr/libexec/mcollective
169   logfile = /dev/null
170   loglevel = debug
171   identity = fqdn
172
173   # connector plugin config
174   connector = stomp
175   plugin.stomp.host = stomp.your.net
176   plugin.stomp.port = 6163
177   plugin.stomp.user = unset
178   plugin.stomp.password = unset
179
180   # security plugin config
181   securityprovider = psk
182   plugin.psk = abcdefghj
183 {% endhighlight %}
184
185 You should also create _/etc/mcollective/server.cfg_ here's a sample, , a full reference of config settings can be found here [ConfigurationReference]:
186
187 {% highlight ini %}
188   # main config
189   libdir = /usr/libexec/mcollective
190   logfile = /var/log/mcollective.log
191   daemonize = 1
192   keeplogs = 1
193   max_log_size = 10240
194   loglevel = debug
195   identity = fqdn
196   registerinterval = 300
197
198   # connector plugin config
199   connector = stomp
200   plugin.stomp.host = stomp.your.net
201   plugin.stomp.port = 6163
202   plugin.stomp.user = mcollective
203   plugin.stomp.password = password
204
205   # facts
206   factsource = yaml
207   plugin.yaml = /etc/mcollective/facts.yaml
208
209   # security plugin config
210   securityprovider = psk
211   plugin.psk = abcdefghj
212 {% endhighlight %}
213
214 Replace the *plugin.stomp.host* with your server running ActiveMQ and replace the *plugin.psk* with a Pre-Shared Key of your own.
215
216 The STOMP connector supports other options like failover pools, see [ConnectorStomp] for full details.
217
218 ### Create Facts
219 By default - and for this setup - we'll use a simple YAML file for a fact source, later on you can use Reductive Labs Facter or something else.
220
221 Create */etc/mcollective/facts.yaml* along these lines:
222
223 {% highlight yaml %}
224   ---
225   location: devel
226   country: uk
227 {% endhighlight %}
228
229 ### Start the Server
230 If you installed from a package start it with the RC script, else look in the source you'll find a LSB compatible RC script to start it.
231
232 ### Test from a client
233 If all is setup you can test with the client code:
234
235 {% highlight console %}
236 % mco ping
237 your.domain.com                           time=74.41 ms
238
239 ---- ping statistics ----
240 1 replies max: 74.41 min: 74.41 avg: 74.41
241 {% endhighlight %}
242
243 This sent a simple 'hello' packet out to the network and if you started up several of the *mcollectived.rb* processes on several machines you
244 would have seen several replies, be sure to give each a unique *identity* in the config.
245
246 At this point you can start exploring the discovery features for example:
247
248 {% highlight console %}
249 % mco find --with-fact country=uk
250 your.domain.com
251 {% endhighlight %}
252
253 This searches all systems currently active for ones with a fact *country=uk*, it got the data from the yaml file you made earlier.
254
255 If you use confiuration management tools like puppet and the nodes are setup with classes with *classes.txt* in */var/lib/puppet* then you
256 can search for nodes with a specific class on them - the locations will configurable soon:
257
258 {% highlight console %}
259 % mco find --with-class common::linux
260 your.domain.com
261 {% endhighlight %}
262
263 Chef does not yet support such a list natively but we have some details on the wiki to achieve the same with Chef.
264
265 The filter commands are important they will be the main tool you use to target only parts of your infrastructure with calls to agents.
266
267 See the *--help* option to the various *mco `*`* commands for available options.  You can now look at some of the available plugins and
268 play around, you might need to run the server process as root if you want to play with services etc.
269
270 ### Plugins
271 We provide limited default plugins, you can look on our sister project [MCollective Plugins][Plugins] where you will
272 find various plugins to manage packages, services etc.
273
274 ### Further Reading
275 From here you should look at the rest of the wiki pages some key pages are:
276
277  * [Screencasts] - Get a hands-on look at what is possible
278  * [Terminology]
279  * [Introduction to Simple RPC][SimpleRPCIntroduction] - a simple to use framework for writing clients and agents
280  * [ControllingTheDaemon] - Controlling a running daemon
281  * [AESSecurityPlugin] - Using AES+RSA for secure message encryption and authentication of clients
282  * [SSLSecurityPlugin] - Using SSL for secure message signing and authentication of clients
283  * [ConnectorStomp] - Full details on the Stomp adapter including failover pools