[转]Linux下Graphite的安装及部署

转自:http://blog.csdn.net/wangli61289/article/details/45077795

Graphite是一个Django的项目,所以必须有基础的Python环境,并推荐使用pip作为Python模块的管理工具,我这里安装的Python版本是Python2.7.6。

 

按照Graphite官网(http://graphite.wikidot.com/installation)安装graphite依赖,特别强调Django的安装版本是Django1.5.x(1.6以上版本会有一些模块变更,导致不兼容)

 

1.安装graphite依赖

 
[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. yum install -y pycairo,mod_python,python-ldap,python-memcached,python-sqlite2,bitmap,bitmap-fonts,python-devel,mod_wsgi  
  2. pip install Django==1.5.1  
  3. pip install django-tagging  
  4. pip install twisted  


还有一个需要注意的地方就是默认安装的Twisted在这里不兼容,会导致报出:ImportError: cannot import name daemonize 这样的错误,而要解决这个问题,需要做的就是修正一下版本:
pip uninstall Twisted  
pip install "Twisted<12.0"
可以使用pip freeze查看安装列表


2.安装Graphite的三个主要组件

 

2.1.安装whisper

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. tar -zxvf whisper-0.9.12.tar.gz  
  2. cd whisper-0.9.12  
  3. python setup.py install  


Whisper 脚本现在应该在应有的位置上:

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. [root@VMS04798 graphite]# ls -l /usr/bin/whisper*  
  2. -rwxr-xr-x 1 root root 1658 Apr 13 14:48 /usr/bin/whisper-create.py  
  3. -rwxr-xr-x 1 root root 2902 Apr 13 14:48 /usr/bin/whisper-dump.py  
  4. -rwxr-xr-x 1 root root 1780 Apr 13 14:48 /usr/bin/whisper-fetch.py  
  5. -rwxr-xr-x 1 root root 1071 Apr 13 14:48 /usr/bin/whisper-info.py  
  6. -rwxr-xr-x 1 root root  675 Apr 13 14:48 /usr/bin/whisper-merge.py  
  7. -rwxr-xr-x 1 root root 5984 Apr 13 14:48 /usr/bin/whisper-resize.py  
  8. -rwxr-xr-x 1 root root  919 Apr 13 14:48 /usr/bin/whisper-set-aggregation-method.py  
  9. -rwxr-xr-x 1 root root  970 Apr 13 14:48 /usr/bin/whisper-update.py  


2.2.安装carbon

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. tar -zxvf carbon-0.9.12.tar.gz  
  2. cd carbon-0.9.12  
  3. python setup.py install  


/opt/graphite 现在应该有carbon的lib 包和配置文件:

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. [root@VMS04798 graphite]# ls -l /opt/graphite  
  2. total 48  
  3. drwxr-xr-x 2 apache apache    4096 Apr 13 14:48 bin  
  4. drwxrwxrwx 2 apache apache    4096 Apr 15 18:34 conf  
  5. drwxr-xr-x 2 apache apache    4096 Apr 13 15:40 examples  
  6. drwxr-xr-x 4 apache apache    4096 Apr 13 14:47 lib  
  7. drwxr-xr-x 6 apache apache    4096 Apr 15 16:19 storage  

2.3.安装graphite-web

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. tar -zxvf graphite-web-0.9.12.tar.gz  
  2. cd graphite-web-0.9.12  
  3. python check-dependencies.py  
  4. python setup.py install  


修改配置:

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. cp graphite.wsgi.example graphite.wsgi  
  2. cd /opt/graphite/webapp/graphite  
  3. cp local_settings.py.example local_settings.py  


编辑local_settings.py,务必重新设置SECRET_KEY,根据需要调整TIME_ZONE(TIME_ZONE='Asia/Shanghai')和其它参数。

3.启动一个Carbon进程

Carbon安装自带了默认的端口和很多其他的配置文件,拷贝已经存在的示例文件。

 

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. cd /opt/graphite/conf  
  2. cp carbon.conf.example carbon.conf  
  3. cp storage-schemas.conf.example storage-schemas.conf  
  4. cp storage-aggregation.conf.example storage-aggregation.conf  


编辑carbon.conf,并添加以下内容:

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. $ vim /opt/graphite/conf/carbon.conf  
  2. [cache]  
  3. LINE_RECEIVER_INTERFACE = 0.0.0.0  
  4. LINE_RECEIVER_PORT = 2003  
  5.   
  6. PICKLE_RECEIVER_INTERFACE = 0.0.0.0  
  7. PICKLE_RECEIVER_PORT = 2004  
  8.   
  9. CACHE_QUERY_INTERFACE = 0.0.0.0  
  10. CACHE_QUERY_PORT = 7002  


编辑storage-schemas,并添加以下内容:

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. vim storage-schemas.conf  
  2. [system_1min]  
  3. pattern = ^system\..*  
  4. priority = 100  
  5. retentions = 60s:31d,5m:90d  


编辑storage-aggregation.conf,并添加以下内容:

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. vim storage-aggregation.conf  
  2. [system_1min]  
  3. pattern = ^system\..*  
  4. xFilesFactor = 0.5  
  5. aggregationMethod = sum  


如果我们的Whisper文件xFilesFactor值是0.5,这意味着仅仅只有至少50%数据点被呈现的时候,它才将聚集数据点。如果超过50%数据点是null,Whisper将创建一个null聚合。在我们的示例中(60s=1m)5m/1m=5也即至少有3个点才开始聚合,因为3/5=0.6才满足xFilesFactor=0.5的聚合条件。你可以给xFilesFactor设置0-1之间的任何值。0表明了即使只有一个数据点非空,聚合就应该被完成。1 表明了只有所有的数据非空,集合才能完成。

4.制造一些测试数据

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. cd /opt/graphite/bin  
  2. ./carbon-cache.py start  
  3. cd /opt/graphite/examples  
  4. python example-client.py  


最后,你可以检索关于 Whisper 文件的元数据信息,使用 whisper-info 脚本:

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. [root@VMS04798 examples]# whisper-info.py /opt/graphite/storage/whisper/system/loadavg_1min.wsp  
  2. maxRetention: 604800  
  3. xFilesFactor: 0.5  
  4. aggregationMethod: sum  
  5. fileSize: 120988  
  6.   
  7.   
  8. Archive 0  
  9. retention: 604800  
  10. secondsPerPoint: 60  
  11. points: 10080  
  12. size: 120960  
  13. offset: 28  


whisper-dump脚本是一个更完整的脚本,其可以输出所有存储保留时期的原始数据以及关于 Whisper 文件的元数据信息:

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. [root@VMS04798 examples]#whisper-dump.py /opt/graphite/storage/whisper/system/loadavg_1min.wsp  
  2. Meta data:  
  3.   aggregation method: sum  
  4.   max retention: 86400  
  5.   xFilesFactor: 0.5  
  6.   
  7.   
  8. Archive 0 info:  
  9.   offset: 28  
  10.   seconds per point: 60  
  11.   points: 1440  
  12.   retention: 86400  
  13.   size: 17280  
  14.   
  15.   
  16. Archive 0 data:  
  17. 0: 1400609220, 1  
  18. 1: 0,          0  
  19. 2: 0,          0  
  20. 3: 0,          0  
  21. 4: 0,          0  
  22. 5: 0,          0  
  23. ...  
  24. 1437: 0,          0  
  25. 1438: 0,          0  
  26. 1439: 0,          0  


如果Metrics与storage-aggregation.conf中的pattern没有匹配上,默认的aggregation方法是average,xFilesFactor=0.5


5.安装nginx与uwsgi

 

graphite-web是基于django开发的

 

5.1 nginx安装

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. tar -zxvf nginx-1.2.8.tar.gz  
  2. cd nginx-1.2.8    
  3. ./configure --prefix=/usr/local/nginx   
  4. make  
  5. make install  

5.2 uwsgi安装

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. pip install uwsgi  


配置uwsgi:

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. /opt/graphite/webapp  
  2. vim graphite.ini   


uWSGI的配置如下:

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. [uwsgi]  
  2. post-buffering = 32768  
  3. buffer-size = 32768  
  4. chdir=/opt/graphite/conf/  
  5. module=graphite.wsgi  
  6. master=true  
  7. pidfile=/tmp/graphite.pid  
  8. vacuum=true  
  9. max-requests=10000  
  10. daemonize=/var/log/graphite/access_graphite.log  
  11. processes=15  
  12. socket=127.0.0.1:49156  
  13. stats=127.0.0.1:1716  
  14. listen=1024  


配置Nginx:

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. cd /usr/local/nginx/conf/sites-enabled  
  2. vim graphite.conf  


以下是Nginx虚拟主机的配置

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. server {  
  2.    listen 8080;  
  3.    server_name 127.0.0.1  
  4.    charset utf-8;  
  5.    access_log /var/log/nginx/graphite.access.log;  
  6.    error_log  /var/log/nginx/graphite.error.log;  
  7.    location / {  
  8.     include uwsgi_params;  
  9.     uwsgi_pass 127.0.0.1:49156;  
  10.     }  
  11. }  



7.启动graphite

至此所有全部搞定,先开carbon,再开uwsgi,最后nginx。

[plain]  view plain  copy
 
 print ? 在CODE上查看代码片 派生到我的代码片
  1. /opt/graphite/bin/carbon-cache.py start  
  2. /opt/graphite/webapp  
  3. uwsgi graphite.ini  
  4. /usr/local/nginx/sbin/nginx  


打开浏览器,输入http://ip:8080就能看到效果了。



参考文档:
http://segmentfault.com/a/1190000002533877
http://segmentfault.com/a/1190000002573509

猜你喜欢

转载自currentj.iteye.com/blog/2317566
今日推荐