Skip to content

Instantly share code, notes, and snippets.

@imkarthikk
Created March 9, 2015 12:32
Show Gist options
  • Save imkarthikk/772f86858f90efa55687 to your computer and use it in GitHub Desktop.
Save imkarthikk/772f86858f90efa55687 to your computer and use it in GitHub Desktop.
Graphite, UWSGI and nginx setup on Ubuntu 14.04
# update packages
sudo apt-get update
# install python and graphite dependencies
sudo apt-get install -y python python-dev python-virtualenv libevent-dev python-pip python-cairo python-django-tagging python-twisted python-memcache python-pysqlite2
# install web server
sudo apt-get install -y nginx uwsgi uwsgi-plugin-python
# install postgresql and dependencies
sudo apt-get install -y postgresql libpq-dev python-psycopg2
# edit the file
sudo vi /etc/nginx/sites-available/default
# add the following server block
server {
listen 8080 ;
access_log /var/log/nginx/example.access.log;
error_log /var/log/nginx/example.error.log;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
}
}
# create a new file
sudo vi /etc/uwsgi/apps-available/graphite.ini
# add the following contents
[uwsgi]
processes = 2
socket = 127.0.0.1:3031
gid = www-data
uid = www-data
virtualenv = /opt/graphite
chdir = /opt/graphite/conf
module = wsgi:application
sudo ln -s /etc/uwsgi/apps-available/graphite.ini /etc/uwsgi/apps-enabled/
# database
sudo -u postgres psql
CREATE USER graphite WITH PASSWORD 'password';
CREATE DATABASE graphite WITH OWNER graphite;
\q
# create a new user
sudo adduser graphite
# add user to sudoers
su - root
visudo
# add an entry for the graphite user
# User privilege specification
root ALL=(ALL:ALL) ALL
graphite ALL=(ALL:ALL) ALL
# log in as graphite user
su graphite
cd /opt
sudo mkdir graphite
sudo chown graphite graphite
sudo chgrp graphite graphite
virtualenv graphite
source graphite/bin/activate
# install graphite and dependencies
pip install carbon graphite-web whisper 'Twisted<12.0' django==1.5 simplejson psycopg2 django-tagging
cd /opt/graphite/conf/
sudo mkdir examples
sudo mv *.example examples
sudo cp examples/storage-schemas.conf.example storage-schemas.conf
sudo cp examples/storage-aggregation.conf.example storage-aggregation.conf
sudo cp examples/carbon.conf.example carbon.conf
sudo cp examples/graphite.wsgi.example wsgi.py
# copy the local_settings.py file and edit
sudo cp /opt/graphite/webapp/graphite/{local_settings.py.example,local_settings.py}
sudo vi /opt/graphite/webapp/graphite/local_settings.py
# uncomment the following lines
SECRET_KEY = 'replace_with_string_from_any_secret_key_generator'
TIME_ZONE = 'America/New_York'
USE_REMOTE_USER_AUTHENTICATION = True
DEBUG = True
DATABASES = {
'default': {
'NAME': 'graphite',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'USER': 'graphite',
'PASSWORD': 'password',
'HOST': '127.0.0.1',
'PORT': ''
}
}
# type ‘yes’ when prompted to create a user
sudo /opt/graphite/bin/python /opt/graphite/webapp/graphite/manage.py syncdb
sudo chown -R www-data:www-data /opt/graphite/webapp/ /opt/graphite/storage/
# link
sudo vi /opt/graphite/lib/python2.7/site-packages/dist-packages.pth
# add this line to the file
/usr/lib/python2.7/dist-packages
sudo /opt/graphite/bin/python /opt/graphite/bin/carbon-cache.py start
sudo service nginx restart
sudo service uwsgi restart
Copy link

ghost commented Jan 24, 2017

thanks .. :)

@Nimrod007
Copy link

Nimrod007 commented Sep 14, 2017

if some1 runs into

c/_cffi_backend.c:15:17: fatal error: ffi.h: No such file or directory

before line #74 missing apt-get install libffi-dev

@Alexanderalisrawi
Copy link

Alexanderalisrawi commented Sep 18, 2017

After executing the command in line 74, the directory conf under /opt/graphite/ was not there
Could you please help, thanks!

@harshalyeole-tudip
Copy link

sudo /opt/graphite/bin/python /opt/graphite/webapp/graphite/manage.py syncdb

I got following error here:

/opt/graphite/bin/python: can't open file '/opt/graphite/webapp/graphite/manage.py': [Errno 2] No such file or directory

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