CentOS 7 安裝Graphite

編程語言 CentOS WebApp Python 達人科技 2017-05-21

Graphite簡介

Graphite是一個Python編寫的企業級開源監控工具,採用django框架,用來收集服務器所有的即時狀態,用戶請求信息,Memcached命中率,RabbitMQ消息服務器的狀態,操作系統的負載狀態。Graphite服務器大約每分鐘需要有4800次的跟新操作,它採用簡單的文本協議和繪圖功能,可以方便的使用在任何操作系統上。Graphite 自己本身並不收集具體的數據,這些數據收集的具體工作通常由第三方工具或插件完成(如 Ganglia, collectd, statsd, Collectl 等)。

簡單來說,Graphite主要做兩件事情:

  • 實時監控第三方工具傳來的數據
  • 根據數據繪製圖形

Graphite包含3個組件,carbon,whisper,graphite webapp其中:

  • carbon - 用於監控數據的 Twisted 守護進程
  • whisper - 用於存放和操作數據的庫
  • graphite webapp - 用於繪製圖形的Django webapp

關於Graphite的詳細官方文檔可以參考Graphite Documentation。

Graphite安裝

我安裝的環境是CentOS 7、python 2.7.5

1、修改yum源配置:

yum install wget

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

cd /etc/yum.repos.d/

wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

yum makecache

yum -y update

2、安裝pip、carbon 和whisper

yum -y install epel-release   #安裝epel擴展源pip才能安裝
yum -y install python-pip
yum -y install python-devel
yum -y install gcc
yum -y install unzip pip install carbon pip install whisper

3、安裝graphite-web

yum -y install libffi-devel zlib-devel openssl-devel install uwsgi-plugin-python
pip install graphite-web
pip uninstall django
pip install django==1.8

4、修改配置文件

cd /opt/graphite/conf/
ls #查看所有文件,拷貝去除example
cp aggregation-rules.conf.example aggregation-rules.conf
cp blacklist.conf.example blacklist.conf
cp carbon.amqp.conf.example carbon.amqp.conf 
cp carbon.conf.example carbon.conf
cp dashboard.conf.example dashboard.conf 
cp graphite.wsgi.example graphite.wsgi
cp graphTemplates.conf.example graphTemplates.conf
cp relay-rules.conf.example relay-rules.conf
cp rewrite-rules.conf.example rewrite-rules.conf
cp storage-aggregation.conf.example storage-aggregation.conf
cp storage-schemas.conf.example storage-schemas.conf
cp whitelist.conf.example whitelist.conf
cd /opt/graphite/webapp/graphite
cp local_settings.py.example local_settings.py
cd ../
mv content static vi uwsgi.ini

拷貝如下代碼進去,保存退出

[uwsgi]
# Django-related settings

socket = :8000

buffer-size = 40000

plugins=python
# the base directory (full path)

chdir = /opt/graphite/webapp

# Django s wsgi file

module = graphite.wsgi

# process-related settings

# master

master = true

# maximum number of worker processes

processes = 1

# ... with appropriate permissions - may be needed

# chmod-socket = 664

# clear environment on exit

vacuum = true

5、安裝uwsgi和nginx

yum -y install uwsgi
cd /home/admin/
wget http://nginx.org/download/nginx-1.4.7.tar.gz
tar zxvf nginx-1.4.7.tar.gz
cd nginx-1.4.7
./configure --with-openssl=/usr/include/openssl
vi objs/Makefile   #把第3行的“ -Werror ” 刪除,保存,關閉
make
make install 
vi /usr/local/nginx/conf/nginx.conf

拷貝如下代碼進去,保存退出

user  root;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

    worker_connections  1024;

}



http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {

        listen       8001;

        server_name  localhost;

        charset     utf-8;

        #access_log  logs/host.access.log  main;

        location / {

 include uwsgi_params;

 uwsgi_pass 127.0.0.1:8000;

 uwsgi_read_timeout 2;

        }

        location /static {

 root  /opt/graphite/webapp;

        }

    }

}

6、在網站上找到項目,創建manage.py,好進行數據庫的操作,和測試顯示項目中的問題

cd /opt/graphite/webapp/
vi manage.py 

拷貝如下代碼進去,保存退出

 1 #!/usr/bin/env python
 2 import os
 3 import sys
 4 
 5 
 6 if __name__ == "__main__":
 7     os.environ.setdefault("DJANGO_SETTINGS_MODULE", "graphite.settings")
 8 
 9     from django.core.management import execute_from_command_line
10 
11     execute_from_command_line(sys.argv)
pip install scandir
python manage.py migrate
vi /opt/graphite/webapp/graphite/local_settings.py
#取消SECRET_KEY、TIME_ZONE註釋,並且修改值:
SECRET_KEY = '@2o8&38gcsb(p*o*dy(fmh!_3-30a1qwq$sadb+6vk243%wj0#'
TIME_ZONE = 'Asia/Shanghai'
#保存退出

7、通過manage.py shell修改網站登錄的用戶名和密碼

python manage.py shell
>>> from django.contrib.auth.models import User
>>> user_list=[x for x in User.objects.all()]
>>> print user_list
#如果user_list不為空
>>>user=user_list[0]
>>>user.username='admin'
>>>user.set_password='123123'
>>>user.save
#如果user_list為空
>>>quit
python manage.py createsuperuser
#根據提示創建你的用戶
Username (leave blank to use 'root'): admin
Email address: [email protected]
Password:     #輸入後不會顯示,我輸的123123
Password (again):     #輸入後不會顯示

8、啟動carbon,carbon會在默認的2003端口接收數據。

python /opt/graphite/bin/carbon-cache.py start
uwsgi --ini /opt/graphite/webapp/uwsgi.ini 
#再新建一個窗口,啟動nginx,或者讓uwsgi後臺運行,建議測試的時候新建窗口,錯誤好捕獲。啟動nginx之前,先關閉防火牆或者開啟8001端口。我做測試,就關閉防火牆了。
systemctl disable firewalld #停用防火牆
systemctl stop firewalld    #禁止防火牆
/usr/local/nginx/sbin/nginx #啟動nginx
/usr/local/nginx/sbin/nginx -s reload   #重啟nginx

9、瀏覽網址http://127.0.0.1:8001,出現如下畫面,安裝成功,如果失敗,注意查看nginx的錯誤日誌和uwsgi的提示

CentOS 7 安裝Graphite

參考:http://tripleday.cn/2016/10/06/graphite/

相關推薦

推薦中...