使用apache和nginx部署graphite的相关配置

写在前面

咱们在测试的时候,能够使用下面的命令来启动graphitenginx

django-admin runserver 172.16.81.101:8000 --settings=graphite.settings

可是这种启动方式只可用于测试,生产环境下,启动graphite不能用这种方式。web

生产环境下须要使用apache或者nginx来部署graphite。apache

下面我就来介绍一下,要使用apache或者nginx来部署graphite,应该怎么对graphite和apache(nginx)进行配置。django

使用apache部署graphite的相关配置

1:修改/opt/graphite文件夹以及文件夹下全部文件的用户和组为apache浏览器

#chown apache:apache /opt/graphite

2:生成graphite.wsgi文件bash

#cp /opt/graphite/conf/graphite.wsgi.example /opt/graphite/conf/graphite.wsgi

3:生成graphite-vhost.conf文件服务器

#cp /opt/graphite/examples/example-graphite-vhost.conf /usr/local/apache2/conf/extra/ graphite-vhost.conf

4:修改apache的配置文件httpd.confapp

修改运行apache的用户和组为apache:webapp

在httpd.conf配置文件里面增长下面一条配置信息socket

5:修改/usr/local/apache2/conf/extra/ graphite-vhost.conf配置文件:

把下面这条配置放开

增长监听端口

修改graphite静态文件路径:

重启apache /usr/local/apache2/bin/apachectl restart

使用浏览器访问 http://ip:8080/就能够看到graphite-web的界面了,以下所示:

 

使用nginx部署graphite的相关配置

1:在/opt/graphite/webapp文件夹下建立graphite.ini文件,这个是uwsgi要使用的配置文件,内容以下:

[uwsgi]
post-buffering = 32768
buffer-size = 32768
chdir=/opt/graphite/webapp/
module=graphite.wsgi
master=true
pidfile=/var/run/graphite.pid
vacuum=true
max-requests=10000
daemonize=/opt/graphite/storage/log/webapp/access.log
processes=4
socket=172.16.81.101:9090
stats=127.0.0.1:1716
listen=1024

使用命令uwsgi -i graphite.ini启动uwsgi,而后浏览器访问http://ip:9090/,若是能够看到graphite-web的界面,说明这个配置文件是没问题的。

这个配置文件也能够是xml格式的,以下所示:

<uwsgi>
    <socket>:8077</socket>
    <chdir>/opt/graphite/webapp</chdir>
    <module>wsgi</module>
    <processes>4</processes> <!-- 进程数 --> 
    <daemonize>uwsgi.log</daemonize>
</uwsgi>

若是是xml格式的配置文件,那么启动uwsgi的命令是uwsgi -x graphite.xml

uwsgi其实也是一个web服务器,能够用来启动django项目。之因此还要使用nginx,主要是使用nginx来处理静态文件的请求。

2:配置nginx.conf文件,打开配置文件/usr/local/nginx/conf/nginx.conf,修改下面两处地方:

uwsgi_pass这项配置内容必须跟上面graphite.ini配置文件里面的socket配置项保持一致。静态文件请求nginx来处理,若是是非静态文件请求,会经过uwsgi_pass这个配置转给uwsgi来处理。

这个是配置graphite静态文件的路径。

重启nginx

使用浏览器访问 http://ip:80/就能够看到graphite-web的界面了。