从Synthesize安装Graphite步骤

版权声明:本文为博主原创文章,未经博主允许不得转载。更多文章www.ampliooo.com https://blog.csdn.net/m0_37904728/article/details/82785165

问题

按照Graphite官网上用Synthesize安装Graphite的步骤(或Synthesize Github上的安装步骤)安装后,Graphite的Web UI不能正常工作,经过尝试,发现需要一些额外配置

错误详情及解决方法:

1. 从synthesize安装,github地址: https://github.com/obfuscurity/synthesize/

➜  ~ git clone https://github.com/obfuscurity/synthesize.git
➜  ~ cd synthesize
➜  synthesize git:(master) vagrant plugin install vagrant-vbguest
➜  synthesize git:(master) vagrant up

2. 查看虚机端口映射关系,可知host的8443端口对应虚机的443端口

➜ synthesize git:(master) vagrant port

The forwarded ports for the machine are listed below. Please note that
these values may differ from values configured in the Vagrantfile if the
provider supports automatic port collision detection and resolution.

    22 (guest) => 2222 (host)
  2003 (guest) => 22003 (host)
  2004 (guest) => 22004 (host)
  3000 (guest) => 3030 (host)
  8125 (guest) => 8125 (host)
   443 (guest) => 8443 (host)

3. 尝试访问 https://localhost:8443, 如果无法访问网页,ssh到vagrant虚机启动apache2服务:

➜  synthesize git:(master) vagrant ssh
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.19.0-25-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
New release '16.04.5 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Last login: Wed Sep 19 10:23:41 2018 from 10.0.2.2
vagrant@vagrant:~$ sudo /etc/init.d/apache2 status

 * apache2 is not running

vagrant@vagrant:~$ sudo /etc/init.d/apache2 start

 * Starting web server apache2                                                                                                                                 *

4. 再次访问 https://localhost:8443, 网页会显示如下错误信息:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.


Apache/2.4.7 (Ubuntu) Server at localhost Port 8443

5. 进入虚机查看django中apache2的日志,会有如下报错信息:

vagrant@vagrant:~$ cat /opt/graphite/storage/log/apache2/error.log

[Wed Sep 19 09:04:53.432582 2018] [:error] [pid 18237:tid 139954644641664] mod_wsgi (pid=18237): Target WSGI script '/opt/graphite/conf/graphite.wsgi' cannot be loaded as Python module.

[Wed Sep 19 09:04:53.432611 2018] [:error] [pid 18237:tid 139954644641664] mod_wsgi (pid=18237): Exception occurred processing WSGI script '/opt/graphite/conf/graphite.wsgi'.

[Wed Sep 19 09:04:53.432615 2018] [:error] [pid 18234:tid 139954644641664] mod_wsgi (pid=18234): Target WSGI script '/opt/graphite/conf/graphite.wsgi' cannot be loaded as Python module.
…
…

经过研究,发现这是由于wsgi/django/whitenoise 的兼容性问题导致的(参考资料链接),打开/opt/graphite/conf/graphite.wsgi文件,将whitenoise相关的内容注释掉,修改后的文件如下: 

vi /opt/graphite/conf/graphite.wsgi

import os
import sys
try:
    from importlib import import_module
except ImportError:
    from django.utils.importlib import import_module
 
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'graphite.settings')  # noqa
 
from django.conf import settings
from django.core.wsgi import get_wsgi_application
 
application = get_wsgi_application()
'''
try:
    import whitenoise
except ImportError:
    whitenoise = False
else:
    # WhiteNoise < 2.0.1 does not support Python 2.6
    if sys.version_info[:2] < (2, 7):
        whitenoise_version = tuple(map(
                int, getattr(whitenoise, '__version__', '0').split('.')))
        if whitenoise_version < (2, 0, 1):
            whitenoise = False
 
if whitenoise:
    from whitenoise.django import DjangoWhiteNoise
    application = DjangoWhiteNoise(application)
    prefix = "/".join((settings.URL_PREFIX.strip('/'), 'static'))
    for directory in settings.STATICFILES_DIRS:
        application.add_files(directory, prefix=prefix)
    for app_path in settings.INSTALLED_APPS:
        module = import_module(app_path)
        directory = os.path.join(os.path.dirname(module.__file__), 'static')
        if os.path.isdir(directory):
            application.add_files(directory, prefix=prefix)
'''

 

6. 此时再访问 https://localhost:8443, 只显示页眉,静态文件未加载,错误码404.

404

 

这是由于Apache2的配置文件有问题,需要添加静态文件配置。打开文件/etc/apache2/sites-available/graphite.conf,在<VirtualHost *:443></Virtualhost>内添加如下内容:

Alias /static/ "/opt/graphite/webapp/content/"

然后重启apache2服务:

ranvagrant@vagrant:~$ sudo /etc/init.d/apache2 stop
 * Stopping web server apache2                                                                                                                                 *
vagrant@vagrant:~$ sudo /etc/init.d/apache2 start
 * Starting web server apache2                     

7. 此时再访问 https://localhost:8443, 静态文件仍然无法加载,错误码403,显然是权限问题。

解决方法: 打开文件/etc/apache2/sites-available/graphite.conf,在<VirtualHost *:443></Virtualhost>内添加如下内容:

<Location /static>
  Require all granted
</Location>

重新启动apache2服务

vagrant@vagrant:~$ sudo /etc/init.d/apache2 stop
 * Stopping web server apache2                                                                                                                                 *
vagrant@vagrant:~$ sudo /etc/init.d/apache2 start
 * Starting web server apache2

8. 再次尝试访问https://localhost:8443, 此时网页可以正常显示了。

展开阅读全文

没有更多推荐了,返回首页