由于需要测量程序的各种指标,使用dropwizard metrics,数据直接输出到graphite.
看了很多别人安装graphite的文章,回馈下,写下自己的安装过程。
1、查看系统版本
cat /proc/version
Linux version 4.4.10-1-pve (root@elsa) (gcc version 4.9.2 (Debian 4.9.2-10) )
2、git下载源码
Graphite-web: git clone https://github.com/graphite-project/graphite-web.git
Carbon: git clone https://github.com/graphite-project/carbon.git
Whisper: git clone https://github.com/graphite-project/whisper.git
Ceres: git clone https://github.com/graphite-project/ceres.git
3、安装各种requirement
yum install python-devel
yum install pycairo-devel
(pycairo-devel.x86_64.0.1.8.10-8.el7)
yum install cairo-devel
(cairo-devel-1.14.2)
pip install django
(django-1.9.9,注意django必须是1.9.9,1.8和1.10都失败!)
pip install django-tagging
(django-tagging-0.4.3)
pip install python-memcached
(python-memcached-1.58 six-1.10.0)
yum install openldap-devel
(openldap-devel-2.4.40-9.el7_2.x86_64)
pip install python-ldap
(python-ldap-2.4.27)
yum install rrdtool rrdtool-devel
(rrdtool.x86_64 0:1.4.8-9.el7)
pip install rrdtool
(rrdtool-0.1.5)
pip install pytz
(pytz-2016.6.1)
pip install pyparsing
(pyparsing-2.1.8)
pip install txamqp
(txAMQP-0.6.2.tar.gz)
pip install whitenoise
(whitenoise-3.2.1)
yum install pcre
4、检查依赖,并安装
./graphite-web/check-dependencies.py
显示:[REQUIRED] Unable to import the 'cairocffi' module, attempting to fall back to pycairo
All optional dependencies are met.
All necessary dependencies are met.
Graphite-web,Carbon,Whisper,Ceres,上面模块安装到缺省的位置(/opt/graphite/),分别执行python setup.py install
5、修改配置
配置 graphite-web: cd /opt/graphite/webapp/graphite; cp local_settings.py.example local_settings.py; 修改 local_settings.py 设置 TIME_ZONE = 'Asia/Shanghai'
6、创建数据库
PYTHONPATH=/opt/graphite/webapp django-admin.py migrate --settings=graphite.settings --run-syncdb
7、生成静态文件目录static目录
PYTHONPATH=/opt/graphite/webapp django-admin.py collectstatic --noinput --settings=graphite.settings
8、安装nginx或者tengine
安装nginx,
wget http://nginx.org/download/nginx-1.10.1.tar.gz
wget http://zlib.net/zlib-1.2.8.tar.gz
wget https://sourceforge.net/projects/pcre/files/pcre/8.39/pcre-8.39.tar.gz/download
yum install openssl
wget https://www.openssl.org/source/openssl-1.0.2h.tar.gz
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=../pcre-8.39 --with-zlib=../zlib-1.2.8 --with-openssl=../openssl-1.0.2h
make
make install
nginx安装完毕
9、安装uwsgi并配置
pip install uwsgi
配置graphite.ini
[uwsgi]
#post-buffering = 32768
#buffer-size = 32768
chdir=/opt/graphite/conf/
wsgi-file=graphite.wsgi
master=true
pidfile=/tmp/graphite.pid
vacuum=true
#max-requests=10000
daemonize=/opt/graphite/log/access_graphite.log
#processes=15
socket=127.0.0.1:43210
#stats=127.0.0.1:1234
#listen=1024
测试时可以使用该命令:uwsgi --chdir /opt/graphite/conf/ --wsgi-file graphite.wsgi --socket 127.0.0.1:43210
10、配置nginx
编辑nginx.conf,配置upstream,listen,server等
11、修改store规则
cd /opt/graphite/conf
copy模板文件: ls | awk '{a=$1;sub(/.example/,"",a);print "cp "$1" "a;}'|sh
修改/opt/graphite/conf/storage-schema.conf 增加自己的业务单元[xxxxx]
12、启动
启动carbon /opt/graphite/bin/carbon-cache.py start
(如果提示service_identity, 执行pip install service_identity)
启动uwsgi, uwsgi graphite.ini
启动nginx, nginx
访问http://xx.xx.xx.xx/ 或者 http://xx.xx.xx.xx/graphite/
成功之后,启动/opt/graphite/examples/python example-client.py,然后再去web查看测试数据是否显示正确。
注意业务配置:
1、storage-schemas.conf 指标保存的周期,和过期后向更粗粒度聚合后的保存周期。
2、storage-aggregation.conf 指标过期后的聚合规则
3、aggregation-rules.conf 实时的指标聚合规则,根据接收到的指标生成新指标并保存。需要运行carbon-aggregator.py
4、rewrite-rules.conf 重写指标名称,根据正则表达式。