CentOS 7 安裝Graphite
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: 123123@qq.com
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的提示
參考:http://tripleday.cn/2016/10/06/graphite/


※js實用方法記錄-簡單cookie操作
※selenium+python環境的搭建的自動化測試
※C超簡單方法實現兩個richtextbox控制項滾動條同步滾動
※初次嘗試Linux並記錄一二
TAG:達人科技 |
※CentOS7全局安裝composer
※基於Vmware workstation CentOS7.4的安裝
※Centos7 安裝python3
※CentOS Docker 安裝
※CentOS 7 Deployment and Installation CMDBuild
※HBase初識、CentOS6.6中HBase安裝與HBase Shell簡單使用
※使用Centos7.5+Nginx+Gunicorn+Django+Python3部署blog項目
※Caffe安裝及配置Python介面(CentOS7)
※在Red Hat和Centos上安裝MongoDB
※圖解oracle 12C在CentOS7 上的安裝
※Install VMware Tools in CentOS 7 command line mode
※CentOS7安裝MongoDB4
※MongoDB系統CentOS 7.1 crash的排障過程
※Centos7/RHEL7-firewalld設置訪問規則
※GIS on CentOS 7之PostgreSQL&PostGIS
※Centos7 Install and Configuration Redis
※CentOS6.6下搭建jdk、tomcat、MySQL、Nginx
※Centos 7 backup and restore Redis data
※Centos下安裝配置WordPress與nginx教程
※Centos7安裝ffmpeg和使用youtube-dl下載Youtube視頻