最近部署监控,看到一篇非常好的文章,转载过来。

原文地址:CentOS 5安装Graphite

如何在CentOS 5安装Graphite?历经一周的摸索,经历各种错误,终于在CentOS安装Graphite成功,看到Graphite的界面出现的那一刻是太高兴了。

CentOS 5安装Graphite - 浏览器界面

挺不错的吧,非常漂亮的图,而且自动实时更新。

系统信息

CentOS信息

[root@mail conf]# uname -a
Linux mail.domain.com 2.6.18-308.el5 #1 SMP Tue Feb 21 20:06:06 EST 2012 x86_64 x86_64 x86_64 GNU/Linux

Python信息

[root@mail conf]# python
Python 2.4.3 (#1, Feb 22 2012, 16:05:45)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

关闭selinux

setenforce 0
vim /etc/selinux/config
#SELINUX=enforcing
SELINUX=disabled

 CentOS 5安装Graphite

以下安装操作都是使用root用户。

 第一步:添加额外源

除了CentOS源base、updates、extra之外,再添加两个源:epel和rpmforge。

# 安装epel源
wget http://mirrors.sohu.com/fedora-epel/5/i386/epel-release-5-4.noarch.rpm
yum install epel-release-5-4.noarch.rpm
# 安装rpmforge源
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
yum install rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm

 第二步:安装依赖包

依赖包相当多,争取一次搞定。

yum -y install bitmap bitmap-fonts Django pycairo python-devel python-ldap python-memcached mod_wsgi python-sqlite2 glibc-devel gcc gcc-c++ git openssl-devel python-zope-interface httpd memcached python-hashlib  django-tagging python-twisted python-simplejson

这里还是做一下简单说明:

  • cairo是graphite的绘图库,是必须的软件。
  • bitmap-fonts字体也是需要的,否则可能图形显示不正常。
  •  python-twisted必须安装rpmforge源的python-twisted-core-8.2.0-1.el5.rf,这也是为什么添加rpmforge源的原因。
  • mod_wsgi是apache的模块

第三步:安装Graphite组件

Graphite组件包括三个部分:carbon、whisper和graphite-web。

# install graphite-web
tar zxvf graphite-web-0.9.10-pre4.tar.gz
cd graphite-web-0.9.10-pre4
python setup.py install
cd ..
# install whisper
tar zxvf whisper-0.9.10-pre3.tar.gz
cd whisper-0.9.10-pre3
python setup.py install
cd ..
# install carbon
tar zxvf carbon-0.9.10-pre3.tar.gz
cd carbon-0.9.10-pre3
python setup.py install

第四步:配置Apache服务

配置graphite虚拟主机

创建Graphite的虚拟主机配置:/etc/httpd/conf.d/graphite.conf,创建方法如下:

cat > /etc/httpd/conf.d/graphite.conf
Listen 8080

# You may need to manually edit this file to fit your needs.
# This configuration assumes the default installation prefix
# of /opt/graphite/, if you installed graphite somewhere else
# you will need to change all the occurances of /opt/graphite/
# in this file to your chosen install location.
<VirtualHost *:8080>
 ServerName graphite
 DocumentRoot "/opt/graphite/webapp"

 # I've found that an equal number of processes & threads tends
 # to show the best performance for Graphite (ymmv).
 WSGIDaemonProcess graphite processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120
 WSGIProcessGroup graphite

 # You will need to create this file! There is a graphite.wsgi.example
 # file in this directory that you can safely use, just copy it to graphite.wgsi
 WSGIScriptAlias / /opt/graphite/conf/graphite.wsgi

 Alias /content/ /opt/graphite/webapp/content/
 <Location "/content/">
 SetHandler None
 </Location>

 # NOTE: In order for the django admin site media to work you
 # must change @DJANGO_ROOT@ to be the path to your django
 # installation, which is probably something like:
 # /usr/lib/python2.6/site-packages/django
 Alias /media/ "/usr/lib/python2.4/site-packages/django/contrib/admin/media/"
 <Location "/media/">
 SetHandler None
 </Location>

 # The graphite.wsgi file has to be accessible by apache. It won't
 # be visible to clients because of the DocumentRoot though.
 <Directory /opt/graphite/conf/>
 Order deny,allow
 Allow from all
 </Directory>

</VirtualHost>

配置mod_wsgi模块

在 /etc/httpd/conf.d/wsgi.conf文件中添加以下两行:

LoadModule wsgi_module modules/mod_wsgi.so
WSGISocketPrefix /var/run/wsgi

配置Graphite

创建配置文件

运行以下命令创建配置文件:

cd /opt/graphite/conf/
for i in graphite.wsgi carbon.conf storage-schemas.conf ; do cp $i.example $i; done
cp /opt/graphite/webapp/graphite/local_settings.py{.example,}

 初始化数据库

运行以下命令创建数据库:

python /opt/graphite/webapp/graphite/manage.py syncdb
chown -R apache:apache /opt/graphite/storage/

apache是httpd服务运行的用户和组。

启动服务和程序

启动httpd服务:

service httpd start

启动carbon-cache程序:

/opt/graphite/bin/carbon-cache.py start

测试

安装已经完成。在浏览器中使用http://ip:8080,使用安装graphite的主机的ip代替。可以访问即可以肯定的告诉你CentOS 5安装Graphite成功了。

参考文章