近期研究LogStash和Elasticsearch过程中,注意到了statsD和Graphite的组合,前者负责数据的初步处理,后者负责数据展现,相得益彰,在部署过程中,主要是Graphite遇到了一些依赖方面的问题,而statsD的部署可以说是非常简单。
系统版本:CentOS release 6.5 (Final)
Python版本:Python 2.7.6
部署Graphite
系统依赖:
yum -y install libpng-devel mysql-devel mysql nginx
Graphite是一个Django的项目,所以必须有基础的Python环境,并推荐使用pip作为Python模块的管理工具:
easy_install pip
pip install Django==1.5.8 pip install django-tagging
pip install mysql-python
pip install carbon pip install whisper pip install graphite-web
wget http://cairographics.org/releases/cairo-1.12.0.tar.gz -O /tmp/cairo-1.12.0.tar.gz cd /tmp/ tar xvzf cairo-1.12.0.tar.gz cd cairo-1.12.0 ./configure && make && make install && ldconfig export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig wget http://cairographics.org/releases/py2cairo-1.10.0.tar.bz2 -O /tmp/py2cairo-1.10.0.tar.bz2 cd /tmp/ bzip2 -d py2cairo-1.10.0.tar.bz2 tar xvf py2cairo-1.10.0.tar cd /tmp/py2cairo-1.10.0 ./waf configure && ./waf build && ./waf install
cd /opt/graphite/conf cp carbon.conf.example carbon.conf cp storage-schemas.conf.example storage-schemas.conf
以下是数据库配置:
#Initialize deprecated database settings DATABASE_ENGINE = '' DATABASE_NAME = '' DATABASE_USER = '' DATABASE_PASSWORD = '' DATABASE_HOST = '' DATABASE_PORT = '' DATABASES = { 'default': { 'NAME': 'graphite', 'ENGINE': 'django.db.backends.mysql', 'USER': 'root', 'PASSWORD': 'xxxxx', 'HOST': '192.168.2.244', 'PORT': '3306' } }
SECRET_KEY = 'gdhr=wufuyf701&j602f&#hx4f=!ojj5y)7s9_u(m$%x1j(k0d'
cd /opt/graphite/webapp/graphite python manage.py syncdb
pip uninstall Twisted pip install "Twisted<12.0"
启动,carbon-cache服务:
cd /opt/graphite bin/carbon-cache.py start
pip install uwsgi
cd /opt/graphite/conf cp graphite.wsgi.example wsgi.py cd /opt/graphite/ vim grapite.ini
[uwsgi] socket = 127.0.0.1:8630 chdir=/opt/graphite/conf module=wsgi master=True processes = 4 pidfile=/var/run/uwsgi-graphite.pid vacuum=True max-requests=5000 daemonize=/var/log/uwsgi-graphite.log stats = 127.0.0.1:9192 protocol=http
server { listen 8081; server_name a00; proxy_buffer_size 64k; proxy_buffers 32 32k; proxy_busy_buffers_size 128k; location / { include uwsgi_params; proxy_pass http://127.0.0.1:8630; } location /static/admin/ { alias /usr/local/lib/python2.7/site-packages/django/contrib/admin/static/admin/; } }
nginx -s reload
部署statsD:
statsD的部署非常简单,并且只需要非常简单的配置就能够和Graphite结合起来,那我们先看一下部署:
cd /opt/ git clone https://github.com/etsy/statsd.git cd statsd cp exampleConfig.js Config.js # Here configure Config.js, using backends graphite! node stats.js Config.js
{ graphitePort: 2003 , graphiteHost: "a01" , port: 8125 , backends: [ "./backends/graphite" ] , debug: true }
echo "hello.world:1|c" | nc -u -w0 127.0.0.1 8125