Linux下Graphite的安装及部署

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


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


1.安装graphite依赖


yum install -y pycairo,mod_python,python-ldap,python-memcached,python-sqlite2,bitmap,bitmap-fonts,python-devel,mod_wsgi
pip install Django==1.5.1
pip install django-tagging
pip install twisted

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


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


2.1.安装whisper

tar -zxvf whisper-0.9.12.tar.gz
cd whisper-0.9.12
python setup.py install

Whisper 脚本现在应该在应有的位置上:
[root@VMS04798 graphite]# ls -l /usr/bin/whisper*
-rwxr-xr-x 1 root root 1658 Apr 13 14:48 /usr/bin/whisper-create.py
-rwxr-xr-x 1 root root 2902 Apr 13 14:48 /usr/bin/whisper-dump.py
-rwxr-xr-x 1 root root 1780 Apr 13 14:48 /usr/bin/whisper-fetch.py
-rwxr-xr-x 1 root root 1071 Apr 13 14:48 /usr/bin/whisper-info.py
-rwxr-xr-x 1 root root  675 Apr 13 14:48 /usr/bin/whisper-merge.py
-rwxr-xr-x 1 root root 5984 Apr 13 14:48 /usr/bin/whisper-resize.py
-rwxr-xr-x 1 root root  919 Apr 13 14:48 /usr/bin/whisper-set-aggregation-method.py
-rwxr-xr-x 1 root root  970 Apr 13 14:48 /usr/bin/whisper-update.py


2.2.安装carbon

tar -zxvf carbon-0.9.12.tar.gz
cd carbon-0.9.12
python setup.py install

/opt/graphite 现在应该有carbon的lib 包和配置文件:
[root@VMS04798 graphite]# ls -l /opt/graphite
total 48
drwxr-xr-x 2 apache apache    4096 Apr 13 14:48 bin
drwxrwxrwx 2 apache apache    4096 Apr 15 18:34 conf
drwxr-xr-x 2 apache apache    4096 Apr 13 15:40 examples
drwxr-xr-x 4 apache apache    4096 Apr 13 14:47 lib
drwxr-xr-x 6 apache apache    4096 Apr 15 16:19 storage

2.3.安装graphite-web

tar -zxvf graphite-web-0.9.12.tar.gz
cd graphite-web-0.9.12
python check-dependencies.py
python setup.py install

修改配置:
cp graphite.wsgi.example graphite.wsgi
cd /opt/graphite/webapp/graphite
cp local_settings.py.example local_settings.py

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

3.启动一个Carbon进程

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


cd /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

编辑carbon.conf,并添加以下内容:
$ vim /opt/graphite/conf/carbon.conf
[cache]
LINE_RECEIVER_INTERFACE = 0.0.0.0
LINE_RECEIVER_PORT = 2003

PICKLE_RECEIVER_INTERFACE = 0.0.0.0
PICKLE_RECEIVER_PORT = 2004

CACHE_QUERY_INTERFACE = 0.0.0.0
CACHE_QUERY_PORT = 7002

编辑storage-schemas,并添加以下内容:
vim storage-schemas.conf
[system_1min]
pattern = ^system\..*
priority = 100
retentions = 60s:31d,5m:90d

编辑storage-aggregation.conf,并添加以下内容:
vim storage-aggregation.conf
[system_1min]
pattern = ^system\..*
xFilesFactor = 0.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.制造一些测试数据

cd /opt/graphite/bin
./carbon-cache.py start
cd /opt/graphite/examples
python example-client.py

最后,你可以检索关于 Whisper 文件的元数据信息,使用 whisper-info 脚本:
[root@VMS04798 examples]# whisper-info.py /opt/graphite/storage/whisper/system/loadavg_1min.wsp
maxRetention: 604800
xFilesFactor: 0.5
aggregationMethod: sum
fileSize: 120988


Archive 0
retention: 604800
secondsPerPoint: 60
points: 10080
size: 120960
offset: 28

whisper-dump脚本是一个更完整的脚本,其可以输出所有存储保留时期的原始数据以及关于 Whisper 文件的元数据信息:
[root@VMS04798 examples]#whisper-dump.py /opt/graphite/storage/whisper/system/loadavg_1min.wsp
Meta data:
  aggregation method: sum
  max retention: 86400
  xFilesFactor: 0.5


Archive 0 info:
  offset: 28
  seconds per point: 60
  points: 1440
  retention: 86400
  size: 17280


Archive 0 data:
0: 1400609220, 1
1: 0,          0
2: 0,          0
3: 0,          0
4: 0,          0
5: 0,          0
...
1437: 0,          0
1438: 0,          0
1439: 0,          0

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


5.安装nginx与uwsgi


graphite-web是基于django开发的


5.1 nginx安装

tar -zxvf nginx-1.2.8.tar.gz
cd nginx-1.2.8  
./configure --prefix=/usr/local/nginx 
make
make install

5.2 uwsgi安装

pip install uwsgi

配置uwsgi:
/opt/graphite/webapp
vim graphite.ini 

uWSGI的配置如下:
[uwsgi]
post-buffering = 32768
buffer-size = 32768
chdir=/opt/graphite/conf/
module=graphite.wsgi
master=true
pidfile=/tmp/graphite.pid
vacuum=true
max-requests=10000
daemonize=/var/log/graphite/access_graphite.log
processes=15
socket=127.0.0.1:49156
stats=127.0.0.1:1716
listen=1024

配置Nginx:
cd /usr/local/nginx/conf/sites-enabled
vim graphite.conf

以下是Nginx虚拟主机的配置
server {
   listen 8080;
   server_name 127.0.0.1
   charset utf-8;
   access_log /var/log/nginx/graphite.access.log;
   error_log  /var/log/nginx/graphite.error.log;
   location / {
    include uwsgi_params;
    uwsgi_pass 127.0.0.1:49156;
    }
}


7.启动graphite

至此所有全部搞定,先开carbon,再开uwsgi,最后nginx。
/opt/graphite/bin/carbon-cache.py start
/opt/graphite/webapp
uwsgi graphite.ini
/usr/local/nginx/sbin/nginx

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



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

猜你喜欢

转载自blog.csdn.net/wangli61289/article/details/45077795