how-to-install-graphite-on-centos6.6-x86_64
写作缘由:最近看到spark社区有人使用 graphite-grafana监控spark,
spark-developers-list Monitoring Spark with Graphite and Grafana
hammerlab Monitoring Spark with Graphite and Grafana
github grafana-spark-dashboards
因为工作中涉及spark监控,故测试一下,记录如下:(本文主要记录部署测试graphite的过程)
首先,看看 graphite-web的展示效果:
自己测试的web展示,对metric的graph 定制操作还不太熟悉,比较原始不美观,先看看Graphite 简介里的两张图片。
Graphite brower web interface
Graphite CLI web interface
参考链接
graphite site - docs
graphite - github
1prerequisite
1)unix-like os
个人测试环境:
mac os x + boot2docker +docker部署docker测试环境构建container(vm)
创建测试虚拟机
docker run -i -t -d -P -h monitor1 --name monitor1 --volume=/Users/Users_datadir_docker:/docker_vol01 centos:6.6 /bin/bash
dockerIn.sh monitor1
cd /docker_vol01/script_docker/datadir_yum
sh update-yum-repo.sh //设置本地yum repository,使用yum安装rpm包会比较快(具体配置方法,略)
yum install -y which.x86_64
yum install -y tar.x86_64
2)Python 2.6 or greater
python -V //查看版本
注意:python 与 django 有版本兼容问题,安装测试过程发现 python2.6 不能使用 django-1.7,但可以使用 django-1.6
如果要用 django > 1.7,必须使用 python2.7
What Python version can I use with Django?
Django version Python versions
1.4 2.5, 2.6, 2.7
1.5 2.6, 2.7 and 3.2, 3.3 (experimental)
1.6 2.6, 2.7 and 3.2, 3.3
1.7, 1.8 2.7 and 3.2, 3.3, 3.4 “`
- 选择版本1:python2.6
centos6.6通常自带有python2.6.6。为便于python软件安装,先install pip
yum search setuptools
yum install -y python-setuptools.noarch
easy_install pip
- 选择版本2:安装 python2.7 (Django >=1.7), 没有测试
yum install -y xz.x86_64 //解压tar.xz文件依赖的工具
cd app1/python
cp ../../soft/python/Python-2.7.9.tar.xz .
xz -d Python-2.7.9.tar.xz
tar xf Python-2.7.9.tar
mv Python-2.7.9 Python-2.7.9-src
yum install -y gcc.x86_64 //源码编译依赖 c compiler
cd Python-2.7.9-src
./configure
make
make install
3) Pycairo
yum install -y pycairo.x86_64
相关其他参考:
安装使用监控工具Graphite
该文中提到了字体问题,需要安装字体
yum install -y bitmap-fonts-compat.noarch
4)Django 1.4 or greater
Django requires Python. It works with Python 2.7, 3.2 or 3.3. //有问题
Django includes a lightweight web server you can use for testing, so
you won’t need to set up Apache until you’re ready to deploy Django in
production.
方式1:
For python2.6
pip install Django==1.6.10
For python2.7 //没有测试
pip install Django==1.7.6
方式2:下载 django 软件包, 解压安装
https://www.djangoproject.com/download/
https://docs.djangoproject.com/en/1.7/topics/install/
tar zxf /docker_vol01/soft/python/Django-1.7.6.tar.gz
cd Django-1.7.6
python setup.py install //依赖 setuptools
yum install -y python-setuptools.noarch
5)django-tagging 0.3.1 or greater
- 方式1:
pip install django-tagging
- 方式2:源码安装
http://code.google.com/p/django-tagging/ (不能访问)
https://pypi.python.org/pypi/django-tagging#downloads
tar zxf /docker_vol01/soft/python/django-tagging-0.3.4.tar.gz
cd django-tagging-0.3.4/
python setup.py install
6)Twisted 8.0 or greater (10.0+ recommended)
- 方式1:
yum search twisted
yum install -y python-twisted.noarch
7)zope-interface (often included in Twisted package dependency)
yum install -y python-zope-interface.x86_64
在上一步 yum install -y python-twisted.noarch 过程中已安装python-zope-interface-3.5.2-2.1.el6.x86_64
8)pytz
yum search pytz
yum install -y pytz.noarch
9)other dependencies (略)
There are also several other dependencies required for additional
features:Render caching: memcached and python-memcache LDAP authentication:
python-ldap (for LDAP authentication support in the webapp) AMQP
support: txamqp RRD support: python-rrdtool Dependent modules for
additional database support (MySQL, PostgreSQL, etc). See Django
database install instructions and the Django database documentation
for details
2 install graphite
1) 方式1:install from pip
In order to install carbon, you must install the Python Development
Headers yum search python-devel
yum install -y python-devel.x86_64
pip install https://github.com/graphite-project/ceres/tarball/master
pip install whisper
pip install carbon
> 报错:提示依赖 gcc
> 处理方法:yum install -y gcc.x86_64
> 结果:安装gcc后正常
pip install carbon
pip install graphite-web
2)方式2:install from source
(1)download source
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
or https://launchpad.net/graphite/+download
cd /docker_vol01/soft/graphite/
mkdir tmp
cd tmp
tar zxf /docker_vol01/soft/graphite/carbon-0.9.10.tar.gz
tar zxf /docker_vol01/soft/graphite/whisper-0.9.10.tar.gz
tar zxf /docker_vol01/soft/graphite/graphite-web-0.9.10.tar.gz
cp /docker_vol01/soft/graphite/check-dependencies.py .
(2)安装
cd soft/carbon-0.9.10/
python setup.py install
cd soft/whisper-0.9.10/
python setup.py install
cd soft/graphite-web-0.9.10/
python setup.py install
python check-dependencies.py
[root@monitor1 soft]# python check-dependencies.py [FATAL] Failed to
create text with cairo, this probably means cairo cant find any fonts.
Install some system fonts and try again [WARNING] Unable to import the
‘mod_python’ module, do you have mod_python installed for python
2.6.6? mod_python is one of the most common ways to run graphite-web under apache. Without mod_python you will still be able to use the
built in development server; which is not recommended for production
use. wsgi or other approaches for production scale use are also
possible without mod_python [WARNING] Unable to import the ‘memcache’
module, do you have python-memcached installed for python 2.6.6? This
feature is not required but greatly improves performance.[WARNING] Unable to import the ‘ldap’ module, do you have python-ldap
installed for python 2.6.6? Without python-ldap, you will not be able
to use LDAP authentication in the graphite webapp.[WARNING] Unable to import the ‘txamqp’ module, this is required if
you want to use AMQP. Note that txamqp requires python 2.5 or greater.
All necessary dependencies are met. 4 optional dependencies not met.
Please consider the warning messages before proceeding. [root@monitor1
soft]#
3 install and configure apache
yum install -y httpd.x86_64
yum install -y mod_wsgi.x86_64 // graphite 依赖
cd /etc/httpd/conf
cp httpd.conf httpd.conf.org
vi /etc/httpd/conf/httpd.conf
Listen 80
Listen 61080
# Load config files from the config directory "/etc/httpd/conf.d".
#
Include conf.d/*.conf
cp /docker_vol01/soft/graphite/tmp/graphite-web-0.9.10/examples/example-graphite-vhost.conf /etc/httpd/conf.d/example-graphite-vhost.conf.org
cp /docker_vol01/soft/graphite/tmp/graphite-web-0.9.10/examples/example-graphite-vhost.conf /etc/httpd/conf.d/graphite-vhost.conf
cd /etc/httpd/conf.d/
vi graphite-vhost.conf
# NameVirtualHost *:61080
LoadModule wsgi_module modules/mod_wsgi.so
<VirtualHost *:61080>
更新20150320:
这里需要注意 如果配置 grafana等开源展示工具,在配置 graphite访问时,应该 enable CORS(cross-origin request sharing),否则grafa不能访问metric,无法定制graph
处理方法1:
CORS on Apache
To add the CORS authorization to the header using Apache, simply add the following line inside either the , , or sections of your server config (usually located in a *.conf file, such as httpd.conf or apache.conf), or within a .htaccess file:
Header set Access-Control-Allow-Origin “*”
vi /etc/httpd/conf.d/graphite-vhost.conf
在 部分,添加
Header set Access-Control-Allow-Origin “*”
注意权限问题:
chown -R apache /opt/graphite/storage/log/webapp/
[OperationalError: unable to open database file]https://answers.launchpad.net/graphite/+question/178172
chown -R apache:root /opt/graphite
结果:http://172.17.0.7:61080/ 出现界面
其他参考:
Django is “unable to open database file”
Make sure Apache can also write to the parent directory of the
database. SQLite needs to be able to write to this directory. Make
sure each folder of your database file’s full path does not start with
number, eg. /www/4myweb/db (observed on Windows 2000). If
DATABASE_NAME is set to something like
‘/Users/yourname/Sites/mydjangoproject/db/db’, make sure you’ve
created the ‘db’ directory first. Make sure your /tmp directory is
world-writable (an unlikely cause as other thing on your system will
also not work). ls /tmp -ald should produce drwxrwxrwt …. Make sure
the path to the database specified in settings.py is a full path.
chown -R apache:root /opt/graphite/storage
4 configure graphite
http://graphite.wikidot.com/installation
1)Initial Database Creation
https://docs.djangoproject.com/en/dev/ref/databases/
- sqlite
cd /opt/graphite/webapp/graphite/
python manage.py syncdb
- mysql(没有测试)
2) carbon
cd /opt/graphite/conf
cp carbon.conf.example carbon.conf
cp storage-schemas.conf.example storage-schemas.conf
cp graphite.wsgi.example graphite.wsgi
vi storage-schemas.conf
[default_1min_for_1day]
pattern = .*
retentions = 60s:1d
#optional
[everything_1min_1months]
priority = 100
pattern = .*
retentions = 1m:395d
3) configure graphite-web
configure graphite-web
cd /opt/graphite/webapp/graphite
cp local_settings.py.example local_settings.py
vi /opt/graphite/webapp/graphite/local_settings.py
#NOTE: for mysql/postgresql If you use a backend such as mysql or postgres, the DATABASE_USER you create in your local_settings.py must
have permission to create tables under the database named by
DATABASE_NAME. DATABASE_USERRestart apache and you should see the graphite webapp on the main
page. If you encounter problems, you can increase the verbosity of
error by creating a local_settings file.
# DEBUG = True DEBUG = TrueAlso remember that the apache logs for the graphite webapp in the
graphite-example-vhost.conf are in /opt/graphite/storage/logs/
ErrorLog /opt/graphite/storage/log/webapp/error.log
CustomLog /opt/graphite/storage/log/webapp/access.log common
5 start carbon-cache
cd /opt/graphite/
./bin/carbon-cache.py start
6 test graphite-web
Now you have finished installing graphite, the next thing to do is put
some real data into it. This is accomplished by sending it some data
as demonstrated in the included ./examples/example-client.py
cd /opt/graphite/
python examples/example-client.py
http://monitor1:61080
更新20150320:
这里看看 graphite对metric的定制功能:
graphite-web默认以树形结构组织metrics,然后选择要查看的metric,就可以展示
graphite也支持自定义dashboard,选择需要展示的一些metrics,进行组合操作,访问dashboard可以展示定制的任何metrics graph
7 configure spark to send metrics to graphite
spark on yarn how to send metrics to graphite sink?
vi conf/metrics.properties
*.source.jvm.class=org.apache.spark.metrics.source.JvmSource
#master.source.jvm.class=org.apache.spark.metrics.source.JvmSource
#worker.source.jvm.class=org.apache.spark.metrics.source.JvmSource
#driver.source.jvm.class=org.apache.spark.metrics.source.JvmSource
#executor.source.jvm.class=org.apache.spark.metrics.source.JvmSource
*.sink.Graphite.class=org.apache.spark.metrics.sink.GraphiteSink
*.sink.Graphite.host=monitor1
*.sink.Graphite.port=2003
分发metrics.properties 后
启动 spark standalone
或
采用spark on yarn提交 spark-app
–files=/path/to/metrics.properties –conf spark.metrics.conf=metrics.properties