graphite+nginx+grafana监控部署

  前言:graphite用到了python,而我在此之前,真的只是知道python是个什么东东,不知道pip,不知道easy_install,不知道python不同版本之间竟然几乎完全不兼容,第一次安装时,用2.6.X安装时报错,查找问题说是版本低了,然后赶紧去官网下个3.X.X的版本,再一安装,尼玛错误更多,简直坑爹啊。最后把版本定在2.7.11,为嘛选择这个版本,因为提示2.6低了,3.x高了,那就选2.7.11,如果一旦出错,我再接着往下降,好在2.7.11好使。然后就开始了一段揪心的安装调试路程。。。。。。开始在测试环境部署时,选择了apache,尼玛简直了,配置麻烦,还不停的出错出错再出错,线上环境我肯定不能再用apache了~~~总之,是特别的虐心。。。。其实安装完毕之后,发现其实部署很简单,不过以就下几步。。。
 
     Step1. 更新软件包索引与系统
sudo yum update
sudo yum upgrade
 
Step2.安装python2.7.11
./configure --prefix= /usr/local/python/python2.7.11  --enable-shared CFLAGS=-fPIC
make
make install
错误:
安装完成之后,进入bin目录下,执行python命令,报错
./python2: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
 
解决方法如下:
1.编辑      vi /etc/ld.so.conf
如果是非root权限帐号登录,使用 sudo vi /etc/ld.so.conf
添加上python2.7的lib库地址,如我的/usr/local/Python2.7/lib,保存文件
 
2.执行 /sbin/ldconfig -v命令,如果是非root权限帐号登录,使用 sudo  /sbin/ldconfig -v。这样 ldd 才能找到这个库,执行python2.7就不会报错了
 
Step2.安装pip
python get-pip.py
get-pip.py文件自行准备
 
Step3. 安装依赖
 
yum install gcc bitmap bitmap-fonts hope  poppler pixman
 
pip install pyOpenSSL python-memcached pycrypto uWSGI python-ldap fields  flask requests txamqp MySQL-python "Django<1.5” "django-tagging==0.3.6" pysqlite damonize "pycairo<1.2.6”
 
如果这里找不到pycairo<1.2.6 则需要源码安装
wget https://www.cairographics.org/releases/cairo-1.2.6.tar.gz
 
yum install openldap openldap24-libs openldap-clients openldap-devel openssl-devel
 
Step4.安装zone-interface
wget https://pypi.python.org/packages/a9/8d/cea179e663f9656f07d09b0b181299a2d8949fb6491ce3c5bc923ca9dd9f/zope.interface-3.8.0.tar.gz#md5=8ab837320b4532774c9c89f030d2a389
tar -xf zope.interface-3.8.0.tar.gz
cd zope.interface-3.8.0
python setup.py install
 
Step5.安装twisted
wget  https://pypi.python.org/packages/c7/82/c71021c15625960e11b32cdba7c93bf9cdf79b9fe4f0a2dcde3a97ffcad3/Twisted-11.1.0.tar.bz2#md5=972f3497e6e19318c741bf2900ffe31c
tar -xf  Twisted-11.1.0.tar.bz2
cd Twisted-11.1.0
python setup.py install
 
Step6.安装graphite
文件下载:
wget https://launchpad.net/graphite/0.9/0.9.10/+download/graphite-web-0.9.10.tar.gz
wget https://launchpad.net/graphite/0.9/0.9.10/+download/carbon-0.9.10.tar.gz
wget https://launchpad.net/graphite/0.9/0.9.10/+download/whisper-0.9.10.tar.gz
wget https://launchpad.net/graphite/0.9/0.9.10/+download/check-dependencies.py
 
首先解压安装包:
tar -xf graphite-web-0.9.10.tar.gz
tar -xf carbon-0.9.10.tar.gz
tar -xf whisper-0.9.10.tar.gz
 
然后进入相应目录,执行setup.py:
graphite默认安装在opt/graphite文件夹下,如果需要,将路径进行实际修改
cd carbon-0.9.10
python setup.py install
 
cd ../graphite-web-0.9.10
python setup.py install
 
cd ../whisper-0.9.10
python setup.py install
 
Step7.配置graphite
 
- 修改配置文件
cd /opt/graphite/conf
执行:
for i in graphite.wsgi carbon.conf  storage-schemas.conf storage-aggregation.conf; do cp $i.example $i; done
 
 
- 修改数据库配置信息
cd /opt/graphite/webapp/graphite
cp local_settings.py.example  local_settings.py
修改local_setting的数据库信息
DATABASES = {
    'default': {
        'NAME':'graphite’, #database name
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'graphite',
        'PASSWORD': ‘graphite',
        'HOST': ‘127.0.0.1',
        'PORT': ‘3306'
    }
}
执行数据库建库命令:python manage.py syncdb
 
 
修改bug,可能是因为我的版本为题导致的,
vim  /opt/graphite/lib/carbon/util.py
第19行改为:
#from twisted.scripts._twistd_unix import daemonize
import daemonize
 
Step8.修改数据存储模式:
vi /opt/graphite/conf/storage-schemas.conf
以下是我的配置,仅供参考,可以根据你实际需求修改
[carbon]
pattern = ^carbon\.
retentions = 60:90d
 
[launch]
priority = 100            #优先级
pattern = ^launch\.
retentions = 10:7d,60:31d
 
[default_1min_for_1day]
pattern = .*
retentions = 1:10d,60:31d
 
存储模式(storage-schemas ) 配置文件由多个条目组成,每个条目中包含一个模式,用于匹配指标项名称和保留期定义。默认情况下,包含两个条目:Carbon和 全部其他 。
carbon 条目匹配以“carbon”字符串开头的指标项名称。默认情况下,Carbon守护进程每60秒发布一次它们自己内部的指标项(这一间隔是可以更改的)。例如,carbon-cache进程会发布指标项,用于标识该进程每分钟创建的指标项文件的数量。保留期的定义则表示数据点每60秒记录一次,并保存90天。
 
Step9.测试carbon
截止此时,carbon 部分已经安装完毕,可以使用
/opt/graphite/bin/carbon-cache.py start进行启动,启动默认端口2003
carbon测试:
python  /opt/graphite/examples/example-client.py
sending message
 
--------------------------------------------------------------------------------
system.loadavg_1min 0.00 1467022197
system.loadavg_5min 0.01 1467022197
system.loadavg_15min 0.00 1467022197
 
查看数据文件:
[root@th29 examples]# cd /opt/graphite/storage/whisper/
[root@th29 whisper]# ls
carbon  system
 
文件存在,说明安装成功
 
Step10.启动graphite web
因监控访问web量较小,可以直接使用django做web容器,当然,你也可以使用uwsgi启动。
nohup  python  /opt/graphite/webapp/graphite/manage.py runserver 0.0.0.0:8088 > /data/logs/graphite/graphite.log 2>&1 &
 
Step11.配置nginx
在nginx.conf文件中添加:
server {
listen 80;
server_name graphite.senyang.com;
access_log /data/log/nginx/graphite_access_log;
location / {
    proxy_pass http://127.0.0.1:8088;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for; proxy_set_header Host $host:$server_port;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_send_timeout 600;
        client_max_body_size 1024M; # Set higher depending on your needs
}
location /static/admin/{
    alias /usr/local/python/python2.7.11/lib/python2.7/site-packages/django/contrib/admin/static/admin/;
}
修改完毕之后先测试:
../sbin/nginx -t
测试通过进行启动或者reload nginx 配置文件
../sbin/nginx -s reload
 
Step12.修改本地host文件
将graphite.senyang.com的IP地址指向你服务器的ip
 
Step13.graphite end


 
 
Step14.grafana安装
grafana安装很简单,解压后直接启动即可
wget https://grafanarel.s3.amazonaws.com/builds/grafana-3.0.4-1464167696.linux-x64.tar.gz
tar -xf grafana-3.0.4-1464167696.linux-x64.tar.gz
mv grafana-3.0.4-1464167696.linux-x64 grafana-3.0.4
cd  grafana-3.0.4
cd bin
./grafana-server > /data/logs/grafana/grafana.log 2>&1 &
 grafana这就启动了。启动默认端口3000
浏览器可以直接打开:http://127.0.0.1:3000
 
Step15.nginx配置grafana
同graphite配置类似,这里不做重复阐述


 
 
Step16,grafana和graphite数据链接配置
1.在grafana里添加graphite datasource
早些grafana版本需要在后台修改配置文件,现在最新的版本直接通过界面操作即可。


 
 
type:这里肯定是grap
url:为graphite的web地址
access:选择proxy
如果你的graphite有用户密码验证,勾选上http Auth
添加成功后:


 
2.配置dashboards
 


 
到此,部署结束~~~
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

猜你喜欢

转载自mox-sir.iteye.com/blog/2308190