Skip to content

Instantly share code, notes, and snippets.

@joemiller
Created April 12, 2012 01:43
Show Gist options
  • Save joemiller/2364144 to your computer and use it in GitHub Desktop.
Save joemiller/2364144 to your computer and use it in GitHub Desktop.
script to setup a sensu client and server for quick testing
#!/bin/sh
#
# The purpose of this script is to setup all the pre-reqs needed to
# standup a quick single-node Sensu client + server for use during
# testing.
#
# I don't recommend using this for a production setup, but if you must,
# then you should replace the SSL keys and certs with your own.
# You can use the script from this repo to help with SSL certs:
# https://github.com/joemiller/joemiller.me-intro-to-sensu
# run:
# ./ssl_certs.sh clean
# ./ssl_certs.sh generate
#
centos_ver=`grep CentOS /etc/redhat-release |perl -p -e 's/^CentOS.+(\d\.\d+).+$/$1/'`
## install erlang + rabbitmq
if echo $centos_ver | egrep -q '^5'; then
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
wget -O /etc/yum.repos.d/epel-erlang.repo http://repos.fedorapeople.org/repos/peter/erlang/epel-erlang.repo
fi
if echo $centos_ver | egrep -q '^6'; then
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
fi
yum -y install erlang
rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
rpm -Uvh http://www.rabbitmq.com/releases/rabbitmq-server/v2.7.1/rabbitmq-server-2.7.1-1.noarch.rpm
mkdir /etc/rabbitmq/ssl
cat <<EOF >/etc/rabbitmq/ssl/server_key.pem
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAkr3kAozTvqtrbwYn1wMKWWHYhL7AedCa3AMKigY+Kyg3n3zf
X50HoICT8xTqddNPelB7kGX2Ia8cB9zIvZMXNL6u2fgzYIAeNVicnoyPZiRCgMiD
JXQL0/Fjc3yFblbYZIvIDNC5w9Fm+MrUlzw/PPd3OacekWYuJEck7f3tnLhGgBp4
skWlzsPCM3HbzLi7O23TPcKKz1g3L5NISmx6Dh+fZv4cLRTFFiDqLzZemuyfyCYM
6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c1k1LLzk/VQiVu3gaUe/uXSfk0HDK6u74zoWpNhPEvpnnc
K8w67tvntDcmslHMi5yCr6NdDFYQX1XNM9zla39ni915QBMSckb7nyQieSXrDLoE
MQ8SIbTT5IitYuvRMsAw+k9v/rd1Qy/UKwasNbU/LsT1JAltDpzsRMSdUuFjRRIj
nWBOiDY0dYwUC1iSR1MpsY4Lw0bpoyNyY8iEF5Sghy31tnfjkE2SwA==
-----END CERTIFICATE-----
EOF
cat <<EOF >/etc/rabbitmq/rabbitmq.config
[
{rabbit, [
{ssl_listeners, [5671]},
{ssl_options, [{cacertfile,"/etc/rabbitmq/ssl/cacert.pem"},
{certfile,"/etc/rabbitmq/ssl/server_cert.pem"},
{keyfile,"/etc/rabbitmq/ssl/server_key.pem"},
{verify,verify_peer},
{fail_if_no_peer_cert,true}]}
]}
].
EOF
rabbitmq-plugins enable rabbitmq_management
/sbin/chkconfig rabbitmq-server on
/etc/init.d/rabbitmq-server start
/usr/sbin/rabbitmqctl add_vhost /sensu
/usr/sbin/rabbitmqctl add_user sensu mypass
/usr/sbin/rabbitmqctl set_permissions -p /sensu sensu ".*" ".*" ".*"
## install redis ##
yum -y install redis
/sbin/chkconfig redis on
/etc/init.d/redis start
## setup a bare minimum config for sensu ##
cat <<EOF >/etc/sensu/config.json
{
"rabbitmq": {
"ssl": {
"private_key_file": "/etc/sensu/ssl/client_key.pem",
"cert_chain_file": "/etc/sensu/ssl/client_cert.pem"
},
"port": 5671,
"host": "localhost",
"user": "sensu",
"password": "mypass",
"vhost": "/sensu"
},
"redis": {
"host": "localhost",
"port": 6379
},
"api": {
"host": "localhost",
"port": 4567
},
"dashboard": {
"host": "localhost",
"port": 8080,
"user": "admin",
"password": "secret"
}
}
EOF
cat <<EOF >/etc/sensu/conf.d/client.json
{
"client": {
"name": "`hostname`",
"address": "10.0.0.1",
"subscriptions": [ "test" ]
}
}
EOF
mkdir /etc/sensu/ssl
cat <<EOF >/etc/sensu/ssl/client_key.pem
-----BEGIN RSA P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i
melwHhl3egESi2/OvGszMIUCYD5uaio4DBMZfipJTV9gq23ap1jsefwclXVRf7NC
iUFIdC+x1vYWweCGJLIn1TXtatG8JB+HrKZLNAfQhfFF+W0CAwEAAaMvMC0wCQYD
VR0TBAIwADALBgNVHQ8EBAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwIwDQYJKoZI
hvcNAQEFBQADggEBAIAIp8XBHArNgZZNM7PM1wQSZOy+sMMlUYRfDhHXbqp0uuI0
qFHR2KzLSSkQcBZOLLD+ctmyCcZsCKSPsbXyfLLWesDPG7RY+HDqgQKGI+GzvmBo
ig/C7lIvykyK3lZhsIZgizKPPHmQfSP+LU2JmdZH37aWfLFXimddWPXrde5Ig+qL
mV4l5eoe7BSQiuPEyhjhzxEi0Y3V7ctpl0YSuIbmE7abmP4fJJHHe9vZm0hLNhav
/2jm/c58IUootdl1rgGWkosSTjHvl//6YbgObB62mSNaNPafzm/NPKLBRYKRP/2O
QRw9RNsasb9Kb3Bslc9haQ9kki7Qrfng7ffBWGg=
-----END CERTIFICATE-----
EOF
## finish ##
echo "You should now be able to start sensu:"
echo " sudo /etc/init.d/sensu-server start"
echo " sudo /etc/init.d/sensu-client start"
echo " sudo /etc/init.d/sensu-api start"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment