在本文档中,我们会尽量将相关文件安装在/opt/graphite目录
因此,在/opt路径下创建一个文件夹graphite
#mkdir-p graphite
1.查看python版本。
#python --version
Python2.7.12
2.创建Python2.7的virtualenv环境
# pipinstall virtualenv
# pipinstall --upgrade pip
# sudopip install --upgrade virtualenv
100%|████████████████████████████████| 1.9MB 4.5MB/s
Installing collected packages: virtualenv
Successfullyinstalled virtualenv-16.0.0
创建虚拟环境目录:
#mkdir myproject
#cd myproject
#virtualenv /opt/graphite --python=/usr/bin/python
/opt/graphite:生成的虚拟环境的路径
3.加载virtualenv环境
#source/opt/graphite/bin/activate
[if !vml]
[endif]
在虚拟环境中,用pip安装的包都被安装到graphite这个环境下,系统Python环境不受任何影响。也就是说,graphite环境是专门针对myproject这个应用创建的。用deactivate命令可以退出该虚拟环境。
[if !vml]
[endif]
4.安装Carbon+Whisper
#pipinstall carbon --install-option="--prefix=/opt/graphite"--install-option=
"--install-lib=/opt/graphite/lib"
运行结果:
Successfullybuilt carbon Twisted txAMQP
Installingcollected packages: zope.interface, constantly, incremental, six, attrs,Automat, idna, hyperlink, PyHamcrest, Twisted, txAMQP, cachetools, urllib3,carbon
Successfullyinstalled Automat-0.7.0 PyHamcrest-1.9.0 Twisted-18.9.0 attrs-18.2.0cachetools-2.1.0 carbon-1.1.4 constantly-15.1.0 hyperlink-18.0.0 idna-2.7incremental-17.5.0 six-1.11.0 txAMQP-0.8.2 urllib3-1.24 zope.interface-4.5.0
#pipinstall whisper
运行结果:
Successfullybuilt whisper
Installingcollected packages: whisper
Successfullyinstalled whisper-1.1.4
5.使用默认的配置文件:
#cp/opt/graphite/conf/storage-schemas.conf.example/opt/graphite/conf/storage-schemas.conf
#cp/opt/graphite/conf/carbon.conf.example /opt/graphite/conf/carbon.conf
6.更改Carbon配置
#vi/opt/graphite/conf/carbon.conf
找到LOCAL_DATA_DIR =/opt/graphite/storage/whisper/ 去掉注释#,写入路径
7.启动Carbon
#/opt/graphite/bin/carbon-cache.pystart
Startingcarbon-cache (instance a)
问题:端口占用
#netstat–nlpt |grep XXXX
#killXXXX
再重新起进程。
8.安装graphite-api
#sudoapt-get install libffi-dev
(Readingdatabase ... 61775 files and directories currently installed.)
Preparingto unpack .../libffi-dev_3.2.1-4_amd64.deb ...
Unpackinglibffi-dev:amd64 (3.2.1-4) ...
Processingtriggers for man-db (2.7.5-1) ...
Settingup libffi-dev:amd64 (3.2.1-4) ...
#pipinstall graphite-api
Successfullybuilt PyYAML cairocffi tzlocal itsdangerous pycparser MarkupSafe
Installingcollected packages: PyYAML, pytz, structlog, pycparser, cffi, cairocffi, click,Werkzeug, itsdangerous, MarkupSafe, Jinja2, Flask, tzlocal, pyparsing,graphite-api
Successfullyinstalled Flask-1.0.2 Jinja2-2.10 MarkupSafe-1.0 PyYAML-3.13 Werkzeug-0.14.1cairocffi-0.9.0 cffi-1.11.5 click-7.0 graphite-api-1.1.3 itsdangerous-0.24pycparser-2.19 pyparsing-2.2.2 pytz-2018.5 structlog-18.2.0 tzlocal-1.5.1
9.安装graphite-web
#pipinstall --no-binary=:all: https://github.com/graphite-project/graphite-web/tarball/master
Installingcollected packages: Django, django-tagging, scandir, graphite-web
Running setup.py install for Django ... done
Running setup.py install for django-tagging... done
Running setup.py install for scandir ... done
Running setup.py install for graphite-web ...done
Successfullyinstalled Django-1.11.16 django-tagging-0.4.3 graphite-web scandir-1.9.0
10.修改配置文件
把/opt/graphite/conf 下的.example结尾的文件 重命名或者拷贝命名(去掉.example)
11.设置graphite local_settings.py文件
/opt/graphite/webapp/graphite/local_settings.py
修改内容:
DEBUG= True #不设置 页面不能正常显示
TIME_ZONE= 'Asia/Shanghai' #设置时区
添加sqlite数据库:用户名和密码不需要
[if !vml]
[endif]
12. 启动web服务
/opt/graphite/bin/run-graphite-devel-server.py--port=8085 --libs=/opt/graphite/webapp /opt/graphite
采用后台运行的方式:
nohup/opt/graphite/bin/run-graphite-devel-server.py --port=8085--libs=/opt/graphite/webapp /opt/graphite &
14.安装依赖包
#sudoapt-get install libcairo2-dev
#apt-getupdate
#sudoapt-get install libcairo2-dev
15.启动django,即整个Graphite的web应用
在/opt/graphite/webapp下新建一个manage.py 加执行权限,写入内容:
#!/usr/bin/envpython
importos
importsys
if__name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE","graphite.settings")
os.environ.setdefault('GRAPHITE_SETTINGS_MODULE','graphite.local_settings')
from django.core.management importexecute_from_command_line
execute_from_command_line(sys.argv)
:wq
#pythonmanage.py migrate --run-syncdb
启动之后对数据库进行同步可能会出现报错:no suchtable:account_profile
解决办法:
使用 python manage.py
migrate --run-syncdb 命令进行同步
之后用浏览器访问将看到一下界面
16.访问
http://***.**.**.**:8085/
17.安装grafana
在/etc/apt/sources.list中,最末端写入:
debhttps://packagecloud.io/grafana/stable/debian/ stretch main
18. 添加Package Cloud密钥,这允许你安装签名包
curlhttps://packagecloud.io/gpg.key | sudo apt-key add -
19. 更新你的Apt存储库并安装Grafana:
sudoapt-get update
问题:
/etc/apt#sudo apt-get update
Hit:1http://mirrors.aliyun.com/ubuntu xenial InRelease
Hit:2http://mirrors.aliyun.com/ubuntu xenial-security InRelease
Hit:3http://mirrors.aliyun.com/ubuntu xenial-updates InRelease
Hit:4http://mirrors.aliyun.com/ubuntu xenial-proposed InRelease
Hit:5http://mirrors.aliyun.com/ubuntu xenial-backports InRelease
Readingpackage lists... Done
E:The method driver /usr/lib/apt/methods/https could not be found.
N:Is the package apt-transport-https installed?
E:Failed to fetchhttps://packagecloud.io/grafana/stable/debian/dists/stretch/InRelease
E:Some index files failed to download. They have been ignored, or old ones usedinstead.
需要安装apt-transport-https软件包,这是通过HTTPS获取软件包所必需的。
#sudoapt-get install -y apt-transport-https ? # apt install apt-transport-https
#sudoapt-get install grafana
20.启动服务
# sudoservice grafana-server start
21.访问http://***.**.**.**:3000
echo"local.random.xxx 100 `date +%S`" | nc ***.**.**.** 2003
网友评论