Skip to content

Instantly share code, notes, and snippets.

@textarcana
Last active March 18, 2024 11:21
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save textarcana/4611024 to your computer and use it in GitHub Desktop.
Save textarcana/4611024 to your computer and use it in GitHub Desktop.
This gist contains everything you need to install StatsD and Graphite on CentOS 6.3.

This gist contains everything you need to install StatsD and Graphite on CentOS 6.3. Unless I forgot something. If I did, shoot a reminder email to noah at one more bug dot com. tl;dr: womm, ymmv, yolo.

I (mostly) followed the steps shown in the EZUnix wiki

And I also referred back to this gist by Michael Grace

WSGISocketPrefix /var/run/wsgi
<VirtualHost *:80>
ServerName graphite
DocumentRoot "/opt/graphite/webapp"
ErrorLog /opt/graphite/storage/log/webapp/error.log
CustomLog /opt/graphite/storage/log/webapp/access.log common
# I've found that an equal number of processes & threads tends
# to show the best performance for Graphite (ymmv).
WSGIDaemonProcess graphite processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120
WSGIProcessGroup graphite
WSGIApplicationGroup %{GLOBAL}
WSGIImportScript /opt/graphite/conf/graphite.wsgi process-group=graphite application-group=%{GLOBAL}
# XXX You will need to create this file! There is a graphite.wsgi.example
# file in this directory that you can safely use, just copy it to graphite.wgsi
WSGIScriptAlias / /opt/graphite/conf/graphite.wsgi
Alias /content/ /opt/graphite/webapp/content/
<Location "/content/">
SetHandler None
</Location>
# XXX In order for the django admin site media to work you
# must use the path to your django installation, which is
# probably something like:
# /usr/lib/python2.6/site-packages/django
Alias /media/ "/usr/lib/python2.6/site-packages/django/contrib/admin/media/"
<Location "/media/">
SetHandler None
</Location>
# The graphite.wsgi file has to be accessible by apache. It won't
# be visible to clients because of the DocumentRoot though.
<Directory /opt/graphite/conf/>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
# run as root
#
# based on http://www.ezunix.org/index.php?title=Install_statsd_and_graphite_on_CentOS_or_RHEL
rpm -i http://ftp.uninett.no/linux/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum -y update
yum -y install python-devel.x86_64 python-pip.noarch mod_wsgi.x86_64 mod_python.x86_64 python-sqlite2.x86_64 \
bitmap.x86_64 pycairo.x86_64 python-zope-interface.x86_64 python-simplejson.x86_64 django-tagging.noarch \
python-pip.noarch python-twisted-web.x86_64 bitmap bitmap-fonts gcc-c++.x86_64 \
openssl-devel.x86_64 git.x86_64 make.x86_64
pip-python install carbon
pip-python install graphite-web
pip-python install whisper
pushd /opt/graphite/conf
cp carbon.conf.example carbon.conf
cp storage-schemas.conf.example storage-schemas.conf
cp storage-aggregation.conf.example storage-aggregation.conf
cp graphTemplates.conf.example graphTemplates.conf
cp graphite.wsgi.example graphite.wsgi
# Graphite defaults to the Chicago time zone (because that's Django's default).
cp /opt/graphite/webapp/graphite/local_settings.py.example /opt/graphite/webapp/graphite/local_settings.py
# then uncomment and edit the TIME_ZONE line. Etc./UTC is recommended.
echo '
[stats]
priority = 110
pattern = ^stats\..*
retentions = 10:2160,60:10080,600:262974
' >> storage-schemas.conf
echo '
[counters]
pattern = stats.counts.*
xFilesFactor = 0.0
aggregationMethod = sum
' >> storage-aggregation.conf
echo '
Include "/etc/httpd/vhosts/*.conf"
' >> /etc/httpd/conf/httpd.conf
# replace /etc/httpd/vhosts/graphite-vhost.conf with the
# graphite-vhost.conf from this repo.
chown -R apache:apache /opt/graphite/storage/
# or optionally:
# chown -R apache:apache /opt/graphite
cd /opt/graphite/webapp/graphite
sudo python manage.py syncdb
# This will create a Django admin user named 'root'. You will also
# have to pick an email address and password.
cd /opt/graphite/
./bin/carbon-cache.py start
# disable SELinux enforcement or all you will see is a stack trace to the effect of:
# "DatabaseError: attempt to write a readonly database"
#
# See the comment thread on this answer: http://stackoverflow.com/questions/3319112/sqlite-read-only-database/3330616#3330616
# and also see https://answers.launchpad.net/graphite/+question/178172
echo 0 >/selinux/enforce
# Note that if you do not have the 'graphite' vhost defined in DNS,
# then you need to update your /etc/hosts and map 'graphite' to the
# host IP address. This must be done on both the host and
# client(s). You may have more luck using a Fully Qualified Domain
# Name (FQDN) such as 'graphite.dev'
#
# Start Apache. Graphite should now be running and you should be able
# to see it in a Web browser on port 80
service apache start
cd /tmp
git clone http://github.com/joyent/node.git
cd node
git checkout v0.8
./configure && make && make install
cd /tmp
wget --no-check-certificate http://npmjs.org/install.sh
sh install.sh
/usr/local/bin/npm install express
cd /tmp
git clone http://github.com/etsy/statsd.git
cp -R /tmp/statsd /opt/graphite
cd /opt/graphite/statsd
cp exampleConfig.js local.js
# edit local.js and update the config for graphiteHost
nohup /usr/local/bin/node stats.js local.js &
@laapsaap
Copy link

I followed your wonderful script, but chown -R apache:apache /opt/graphite/storage/ was not enough getting errors below. I had to chown -R apache:apache /opt/graphite/ Thank you for your scripts!

[Wed Aug 28 15:10:36 2013] [error] [client 192.168.1.40] mod_wsgi (pid=1366): Target WSGI script '/opt/graphite/conf/graphite.wsgi' cannot be loaded as Python module.
[Wed Aug 28 15:10:36 2013] [error] [client 192.168.1.40] mod_wsgi (pid=1366): Exception occurred processing WSGI script '/opt/graphite/conf/graphite.wsgi'.

@dnozay
Copy link

dnozay commented Sep 4, 2013

You don't actually need to disable selinux (or you would have already done it by default in your installation)
http://devinvenable.blogspot.com/2010/01/apache-modwsgi-django-selinux.html
chcon -R -t httpd_sys_content_t /opt/graphite/storage/

Copy link

ghost commented Nov 7, 2013

Git clones now need to be changed to https URLs. I received RPC errors otherwise.

@kevburnsjr
Copy link

This gave me Twisted 13.2 which is incompatible with carbon-cache. Had to downgrade to Twisted 12.

Error:

Traceback (most recent call last):
  File "./bin/carbon-cache.py", line 28, in <module>
    from carbon.util import run_twistd_plugin
  File "/opt/graphite/lib/carbon/util.py", line 21, in <module>
    from twisted.scripts._twistd_unix import daemonize
ImportError: cannot import name daemonize

Solution:

pip install 'Twisted<12.0'

Other solutions
http://stackoverflow.com/questions/19894708/cant-start-carbon-12-04-python-error-importerror-cannot-import-name-daem

@kevburnsjr
Copy link

Line 80 Should read

service httpd start

@kevburnsjr
Copy link

Lines 84 and 95 should use https. Trying to clone from an http url won't work.

https://github.com/joyent/node.git
https://github.com/etsy/statsd.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment