摘要:在上安裝標簽空格分隔監控首先說一句,在上安裝真的很坑爹。。。或如果上面這個方法無法安裝那就用源碼安裝的方法。安裝開始好幾次就死在安裝這個上面,版本的通過命令安裝的不行,對應版本的包的名字叫做。
在 CentOS 5.8 上安裝 Graphite
標簽(空格分隔): 監控 monitor CentOS 5.8 Graphite
首先說一句,在 CentOS 5.8 上安裝真的很坑爹。。。
基礎環境操作系統內核
uname -a Linux cloud-test-slave-001 2.6.18-308.el5 #1 SMP Tue Feb 21 20:06:06 EST 2012 x86_64 x86_64 x86_64 GNU/Linux
操作系統版本
[root@cloud-test-slave-001 ~]# cat /etc/redhat-release CentOS release 5.8 (Final)
Python 版本
[root@cloud-test-slave-001 ~]# python --version Python 2.7必備軟件
按照 Graphite 官方文檔的要求,需要如下軟件:
python2.4 或者更高版本(必選)【建議 2.6 或 2.7 版本】 pycairo (需要 PNG 包支持,即 libpng)(必選) mod_python(必選) django(必選,需要 django 1.4 版本,為什么必須 django 1.4 在后面會說明) python-ldap (可選 - needed for ldap-based webapp authentication) python-memcached (可選 - needed for webapp caching, big performance boost) python-sqlite2 (可選 - a django-supported database module is required) bitmap and bitmap-fonts required on some systems, 尤其是在 Red Hat 系統上
下面是我目前安裝的一些涉及到的軟件的版本(可能有多余的,是因為我在虛擬環境安裝,沒有安裝好,只好混裝,所以拉出來的有點多)
執行命令 pip freeze 拉出如下清單:
Django==1.4 Dozer==0.4 Jinja2==2.7.3 MarkupSafe==0.23 PyYAML==3.10 SQLAlchemy==0.9.7 Twisted==14.0.2 WebOb==1.4 Werkzeug==0.9.6 alembic==0.6.5 configobj==5.0.6 croniter==0.3.3 cssselect==0.9.1 daemonize==2.3.1 dagobah==0.2.3 distribute==0.6.49 django-filter==0.7 django-tagging==0.3.1 lxml==3.3.5 micawber==0.3.0 paramiko==1.11.0 peewee==2.2.5 premailer==1.13 pycrypto==2.6.1 pysqlite==2.6.3 python-dateutil==2.2 python-memcached==1.53 txAMQP==0.6.2 uWSGI==2.0.7 virtualenv==1.11.6 whisper==0.9.12 wsgiref==0.1.2 zope.interface==4.1.1開始安裝
安裝 yum EPEL 源
wget "http://mirrors.ustc.edu.cn/fedora/epel/5/i386/epel-release-5-4.noarch.rpm" rpm -Uvh epel-release-5-4.noarch.rpm
安裝依賴包
yum install gcc bitmap bitmap-fonts zope
yum install openldap openldap24-libs openldap-clients openldap-devel openssl-devel
pip install pyOpenSSL python-memcached pycrypto python-ldap pysqlite uwsgi nginx
注:因為我這個目前是測試,所以 nginx 就直接 yum 安裝了,版本比較低,只有 0.8,如果是生產,建議源碼安裝最新的穩定版本。
pip install django==1.4
安裝 django-tagging ,默認的 pip install tagging 的這個不行,版本是 0.2.1 ,會報錯。
pip install django-tagging==0.3.1 或 pip install tagging==0.3.1
如果上面這個方法無法安裝 django-tagging=0.3.1 那就用源碼安裝的方法。
wget https://pypi.python.org/packages/source/d/django-tagging/django-tagging-0.3.1.tar.gz --no-check-certificate tar -zxvf django-tagging-0.3.1.tar.gz cd django-tagging-0.3.1 python setup.py install
安裝 pycairo
開始好幾次就死在安裝 pycairo 這個上面,python 2.7 版本的通過 pip install pycairo 命令安裝的不行,對應 python 2.7 版本的 pycairo 包的名字叫做 py2cairo。
安裝 py2cairo 包的方法如下:
1)下載 py2cairo 包:
wget http://www.cairographics.org/releases/py2cairo-1.10.0.tar.bz2 tar -xvf py2cairo-1.10.0.tar.bz2
如果上面的版本不行就用下面的方式獲取源碼包:
git clone git://git.cairographics.org/git/py2cairo
要安裝 py2cairo 必須要 cairo 包,而且這個包的版本有規定,我這邊下載的是 cairo-1.12.2。
wget http://cairographics.org/releases/cairo-1.12.2.tar.xz
cairo 依賴 libpng 和 pixman,所以需要安裝這兩個
yum -y install libpng* pixman*
注,有可能這樣安裝的 pixman 的版本不對,需要需要源碼安裝
源碼安裝 pixman:
wget http://cairographics.org/releases/pixman-0.22.0.tar.gz tar -zxvf pixman-0.22.0.tar.gz ./configure --prefix=/usr/local make && make install
注:這里 pixman 的安裝必需要加個 prefix=/usr/local,不然的話,cairo 會找不到再次表示蛋疼。
安裝 cairo 的正確姿勢:
tar -zxvf cairo-1.12.2.tar.xz cd cairo-1.12.2 ./configure make && make install
安裝 py2cairo 的正確姿勢:
安裝的時候需要明確下 pkgconfig 的位置和 Python 的包路徑:
cd py2cairo export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH PYTHONPATH="/usr/local/lib/python2.7/site-packages/:$PYTHONPATH" LDFLAGS="-lm -ldl -lutil" ./waf configure --prefix=/usr/local ./waf build ./waf install
經歷九九八十一難,終于安裝完成。
注:真的是最麻煩的就是 py2cairo 這個家伙,開始折騰了我一天沒有安裝好,沒有安裝好就無法出圖。。。
安裝 Graphite 三大件
pip install whisper carbon graphite-web
安裝數據采集工具 Diamond
git clone https://github.com/BrightcoveOS/Diamond cd Diamond
修改 Diamond 的配置文件:
cd Diamond cp conf/diamond.conf.example conf/diamond.conf
diamond.conf 配置文件如下:
# #Diamond Configuration File ### Options for the server [server] # Handlers for published metrics. handlers = diamond.handler.graphite.GraphiteHandler, diamond.handler.archive.ArchiveHandler # User diamond will run as # Leave empty to use the current user user = # Group diamond will run as # Leave empty to use the current group group = # Pid file pid_file = /var/run/diamond.pid # Directory to load collector modules from # 這個和你的 Diamond 安裝路徑有關 collectors_path = /root/Diamond/src/collectors/ # Directory to load collector configs from # 這個和你的 Diamond 安裝路徑有關 collectors_config_path = /root/Diamond/src/collectors/ # Directory to load handler configs from # 這個和你的 Diamond 安裝路徑有關 handlers_config_path = /root/Diamond/src/diamond/handler handlers_path = /root/Diamond/src/diamond/handler # Interval to reload collectors collectors_reload_interval = 3600 ### Options for handlers [handlers] # daemon logging handler(s) keys = rotated_file ### Defaults options for all Handlers [[default]] [[ArchiveHandler]] # File to write archive log files #需要創建 /var/log/diamond/ 目錄 log_file = /var/log/diamond/archive.log # Number of days to keep archive log files days = 7 [[GraphiteHandler]] ### Options for GraphiteHandler # Graphite server host host = 127.0.0.1 # Port to send metrics to port = 2003 # Socket timeout (seconds) timeout = 15 # Batch size for metrics batch = 1 [[GraphitePickleHandler]] ## Options for GraphitePickleHandler # Graphite server host host = 127.0.0.1 # Port to send metrics to port = 2004 # Socket timeout (seconds) timeout = 15 # Batch size for pickled metrics batch = 256 [[MySQLHandler]] ### Options for MySQLHandler # MySQL Connection Info hostname = 127.0.0.1 port = 3306 username = root password = database = diamond table = metrics # INT UNSIGNED NOT NULL col_time = timestamp # VARCHAR(255) NOT NULL col_metric = metric # VARCHAR(255) NOT NULL col_value = value [[StatsdHandler]] host = 127.0.0.1 port = 8125 [[TSDBHandler]] host = 127.0.0.1 port = 4242 timeout = 15 [[LibratoHandler]] user = user@example.com apikey = abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01 [[HostedGraphiteHandler]] apikey = abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01 timeout = 15 batch = 1 # And any other config settings from GraphiteHandler are valid here [[HttpPostHandler]] ### Urp to post the metrics url = http://localhost:8888/ ### Metrics batch size batch = 100 ### Options for collectors [collectors] [[default]] ### Defaults options for all Collectors # Uncomment and set to hardcode a hostname for the collector path # Keep in mind, periods are seperators in graphite # hostname = my_custom_hostname # If you prefer to just use a different way of calculating the hostname # Uncomment and set this to one of these values: # smart = Default. Tries fqdn_short. If that"s localhost, uses hostname_short # fqdn_short = Default. Similar to hostname -s # fqdn = hostname output # fqdn_rev = hostname in reverse (com.example.www) # uname_short = Similar to uname -n, but only the first part # uname_rev = uname -r in reverse (com.example.www) # hostname_short = `hostname -s` # hostname = `hostname` # hostname_rev = `hostname` in reverse (com.example.www) # shell = Run the string set in hostname as a shell command and use its # output(with spaces trimmed off from both ends) as the hostname. # hostname_method = smart # Path Prefix and Suffix # you can use one or both to craft the path where you want to put metrics # such as: %(path_prefix)s.$(hostname)s.$(path_suffix)s.$(metric)s # path_prefix = servers # path_suffix = # Path Prefix for Virtual Machines # If the host supports virtual machines, collectors may report per # VM metrics. Following OpenStack nomenclature, the prefix for # reporting per VM metrics is "instances", and metric foo for VM # bar will be reported as: instances.bar.foo... # instance_prefix = instances # Default Poll Interval (seconds) # interval = 300 ### Options for logging # for more information on file format syntax: # http://docs.python.org/library/logging.config.html#configuration-file-format [loggers] keys = root # handlers are higher in this config file, in: # [handlers] # keys = ... [formatters] keys = default [logger_root] # to increase verbosity, set DEBUG level = INFO handlers = rotated_file propagate = 1 [handler_rotated_file] class = handlers.TimedRotatingFileHandler level = DEBUG formatter = default # rotate at midnight, each day and keep 7 days args = ("/var/log/diamond/diamond.log", "midnight", 1, 7) [formatter_default] format = [%(asctime)s] [%(threadName)s] %(message)s datefmt = ### Options for config merging # [configs] # path = "/etc/diamond/configs/" # extension = ".conf" #Example: # /etc/diamond/configs/net.conf # [collectors] # # [[NetworkCollector]] # enabled = True
啟動 Diamond:
python diamond -c ../conf/diamond.conf啟動 Grapgite 三大件
初始化 Graphite 數據庫:
cd /opt/graphite/webapp/graphite mv local_settings.py.example local_settings.py
修改 local_settings.py 里面的數據庫配置,把下面一段的注釋取消:
DATABASES = { "default": { "NAME": "/opt/graphite/storage/graphite.db", "ENGINE": "django.db.backends.sqlite3", "USER": "root", "PASSWORD": "123456", "HOST": "", "PORT": "" } }
初始化 Graphite 數據庫:
python manage.py syncdb
注:在這個初始化的過程中就可能遇到的錯誤是 tagging 版本太低,或者是 django 的版本問題,所以才有前面的 django 的版本必須為 1.4,tagging 的版本必須為 0.3.1
啟動 carbon-cache:
cd /opt/graphite/bin ./carbon-cache.py start
注:這個在啟動過程中,可能遇到如下錯誤:
from carbon.util import run_twistd_plugin File “/opt/graphite/lib/carbon/util.py”, line 19, infrom twisted.scripts._twistd_unix import daemonize ImportError: cannot import name daemonize
解決方法是修改 /opt/graphite/lib/carbon/util.py 文件,把其 from twisted.scripts._twistd_unix import daemonize 替換成 import daemonize
注:需要安裝 daemonize,pip install daemonize
然后再次啟動即可
啟動 graphite,使用 wsgi 啟動,在 /opt/graphite/webapp 下新建一個文件 wsgi.py 和一個配置文件 django.xml:
wsgi.py
import os,sys if not os.path.dirname(__file__) in sys.path[:1]: sys.path.insert(0, os.path.dirname(__file__)) os.environ["DJANGO_SETTINGS_MODULE"] = "settings" from django.core.handlers.wsgi import WSGIHandler application = WSGIHandler()
django.xml
ip:port /opt/graphite/webapp/graphite .. wsgi
啟動:
uwsgi -x django.xml
現在可以愉快的訪問了 http://ip:port
建議:不作死就不會死,要安裝這個還是不要用 CentOS 5.8 了,太痛苦。。使用 Python 的 virtualenv 環境也會遇到很多問題。
比如使用 virtualenv 最新版本的時候,會遇到這個錯誤:
OSError: Command /Users/bgbb/Developer/django/vnv/bin/python -c "import sys, pip; sys...d"] + sys.argv[1:]))" setuptools pip failed with error code 2
解決辦法是降級到 virtualenv 1.10.1 版本:
pip uninstall virtualenv wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.10.1.tar.gz --no-check-certificate python setup.py install
如果大家安裝過程中遇到問題,歡迎交流!
參考資料注:該安裝方法適用于 CentOS 5.8,其他的版本應該不會遇到我這么多問題。
http://blog.chinaunix.net/uid-28769783-id-3652037.html
http://www.dongwm.com/archives/shi-yong-grafanahe-diamondgou-jian-graphitejian-kong-xi-tong/
http://www.linuxsysadmintutorials.com/install-graphite-on-a-centosrhel-server
http://blog.csdn.net/crazyhacking/article/details/8464235
http://viewsby.wordpress.com/2014/05/13/carbon-cache-py-cannot-import-name-daemonize
http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/
http://graphite.wikidot.com/
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/17354.html
摘要:最近為了分析公司的一個的應用性能,正好需要用到春神的那套的分析腳本,因此就立馬去搭建下環境依賴項依賴于注上面安裝的時候,的版本不能太高,不然會報錯,安裝失敗,目前使用的版本是該文的前提是你已經編譯安裝好了支持的版本,以及你已經 最近為了分析公司的一個 nginx + lua 的應用性能,正好需要用到春神的那套 nginx-lua 的分析腳本,因此就立馬去搭建下 環境: CentO...
摘要:最近為了分析公司的一個的應用性能,正好需要用到春神的那套的分析腳本,因此就立馬去搭建下環境依賴項依賴于注上面安裝的時候,的版本不能太高,不然會報錯,安裝失敗,目前使用的版本是該文的前提是你已經編譯安裝好了支持的版本,以及你已經 最近為了分析公司的一個 nginx + lua 的應用性能,正好需要用到春神的那套 nginx-lua 的分析腳本,因此就立馬去搭建下 環境: CentO...
摘要:為了發布以上列出的示例數據點,運行以下命令日志文件將包含關于新的被接收到的度量值的信息,信息被存儲在與交互來存儲時間序列數據到文件系統。 標簽(空格分隔): Graphite Carbon Whisper 監控 注:該系列文章絕對是學習 Graphite 的好文章,是我見過的將的最全面,最清晰,最簡單明了的系列文章。我會把該系列的所有文章全部翻譯完成,但是還是推薦各位讀讀原文...
摘要:的展示非常炫酷,絕對是運維提升逼格的一大利器。另外的可視化功能比強得多,而且以上版本將集成報警功能。它由寫成,著力于高性能地查詢與存儲時序型數據。被廣泛應用于存儲系統的監控數據,行業的實時數據等場景。 原有監控系統 showImg(https://segmentfault.com/img/remote/1460000011082384); 整個系統以 Graphite (carbon ...
閱讀 3576·2021-11-24 10:19
閱讀 3710·2021-09-30 09:47
閱讀 1282·2019-08-30 15:56
閱讀 780·2019-08-29 15:11
閱讀 893·2019-08-29 13:43
閱讀 3557·2019-08-28 18:25
閱讀 2149·2019-08-26 13:27
閱讀 1427·2019-08-26 11:44