Deploying Cassandra with Puppet
Posted on August 6th, 2011
(this is update remake of the puppet recipe on my blog)
Cassandra is a peer-to-peer architecture which is typically deployed on a large number of servers. Deploying, managing, and upgrading these systems is more administrative time especially as your cluster grows. Puppet provides a simple way to install Cassandra.
Getting ready
For this recipe you will need a server running puppet.
How to do it…
Puppet has a file server built in. By default the root of the file server is /var/lib/puppet/files. Create a folder for cassandra. Download a release into that folder, rename the files that are different per cluster.
mkdir /var/lib/puppet/file/cassandra
cd /var/lib/puppet/files/cassandra
wget apache-cassandra-0.8.1.tar.gz
tar -xf apache-cassandra-0.8.1.tar.gz
mv apache-cassandra-0.8.1/conf/cassandra.yaml apache-cassandra-0.8.1/conf/cassandra.yaml.bak
mv apache-cassandra-0.8.1/conf/cassandra-env.sh apache-cassandra-0.8.1/conf/cassandra-env.sh.bak
create a puppet manifest for Cassandra /etc/puppet/manifests/cassandra.pp. Create the base requirements that and Cassandra instance would share.
class cassandra_base {
package { "jdk" :
ensure => installed
}
group { "cassandra": }
user { "cassandra":
home => "/home/cassandra",
shell => "/bin/bash",
require => Group["cassandra"]
}
file { ["/var/lib/cassandra","/var/log/cassandra","/var/lib/cassandra/saved_caches"]:
type => directory,
owner => cassandra,
group => cassandra,
ensure => directory,
mode =>755,
require => User["cassandra"]
}
file { "/etc/init.d/cassandra":
path => "/etc/init.d/cassandra",
mode => 744,
source => "puppet:///cassandra/cassandra.init",
require => Package["jdk"]
}
}
Now extend the base definition for a specific version of Cassandra.
class cassandra_0_8_2 inherits cassandra_base {
file {
"/usr/local/apache-cassandra-0.8.2":
owner => root,
group => root,
path => "/usr/local/apache-cassandra-0.8.2",
source => "puppet:///mainfiles/cassandra/apache-cassandra-0.8.2",
recurse => true
}
file {
"/usr/local/apache-cassandra-0.8.2/bin":
mode => 755,
path => "/usr/local/apache-cassandra-0.8.2/bin",
source => "puppet:///mainfiles/cassandra/apache-cassandra-0.8.2/bin",
recurse => true,
require => File [ "/usr/local/apache-cassandra-0.8.2" ]
}
file { "/usr/local/cassandra":
ensure => link,
target => "/usr/local/apache-cassandra-0.8.2",
require => File[ "/usr/local/apache-cassandra-0.8.2" ]
}
}
Extend this one more time per cluster. Use the fqdn function in puppet so each node can get its own copy of the configuration file.
class cassandra_lab_0_8_2 inherits cassandra_0_8_2 {
file { "/usr/local/cassandra/conf/cassandra-env.sh":
path => "/usr/local/cassandra/conf/cassandra-env.sh",
owner => "root",
group => "root",
source => "puppet:///cassandra/lab-0.8.2/cassandra-env.sh"
}
file { "/usr/local/cassandra/conf/cassandra.yaml":
path => "/usr/local/cassandra/conf/cassandra.yaml",
owner => "root",
group => "root",
source => "puppet:///cassandra/lab-0.8.2/cassandra.yaml."+fqdn()
}
}
Now setup the configuration files for this cluster.
mkdir /var/lib/puppet/files/cassandra/lab-0.8.2
cp /var/lib/puppet/files/cassandra/cassandra-0.8.2/conf/cassandra.yaml.bak /var/lib/puppet/files/cassandra/lab-0.8.2/cassandra.yaml.server1.domain.com
For each server in the cluster include the class we created.
node 'server1.domain.com','server2.domain.com'{
include cassandra_lab_0_8_2
}
How it works…
The puppet configuration management system copies files from the server to clients. This makes it easy to replicate installations across large clusters of servers. Puppet file directives copy since files or recursive directories from the puppet server to the client. Puppet also installs system users and groups as well as packages in a platform independent way.
Tags: cassandra, nosql, puppet
Filed under Chapter 7 Administration |
Leave a Reply
You must be logged in to post a comment.