【问题标题】:How to deploy CKAN using lighttpd?如何使用 lighttpd 部署 CKAN?
【发布时间】:2016-09-21 17:29:02
【问题描述】:

我想知道如何使用 lighttpd 运行和部署 CKAN。

实际上,我正在使用 mod_proxy 将 lighttpd 重定向到 httpd 替代端口(正在运行 ckan):

$HTTP["host"] == "ckan.example.com"{    
    proxy.server = ( "" =>
    ( "" => 
    ("host" => "127.0.0.1", "port" => 81)
    )
    )
}

但肯定会降低性能。

apache配置如下:

WSGISocketPrefix /var/run/wsgi
<VirtualHost 0.0.0.0:81>
    ServerName localhost
    ServerAlias localhost
    WSGIScriptAlias / /etc/ckan/default/apache.wsgi

    # Pass authorization info on (needed for rest api).
    WSGIPassAuthorization On

    # Deploy as a daemon (avoids conflicts between CKAN instances).
    WSGIDaemonProcess ckan_default display-name=ckan_default processes=2 threads=15

    WSGIProcessGroup ckan_default

    # Add this to avoid Apache show error: 
    # "AH01630: client denied by server configuration: /etc/ckan/default/apache.wsgi" 
    <Directory /etc/ckan/default>
    Options All
    AllowOverride All
    Require all granted
    </Directory>

    ErrorLog /var/log/httpd/ckan_default.error.log
    CustomLog /var/log/httpd/ckan_default.custom.log combined
</VirtualHost>

/etc/ckan/default/apache.wsgi 是:

import os
activate_this = os.path.join('/usr/lib/ckan/default/bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))

from paste.deploy import loadapp
config_filepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'development.ini')
from paste.script.util.logging_config import fileConfig
fileConfig(config_filepath)
application = loadapp('config:%s' % config_filepath)

作为 FastCGI 的一种方法是完美的。

【问题讨论】:

    标签: python-2.7 wsgi lighttpd ckan


    【解决方案1】:

    尝试使用 uWSGI。在你最喜欢的发行版上安装 uwsgi 和 uwsgi-plugin-python 包。然后,uwsgi --plugin python --ini-paste /path/to/development.ini ...。 uWSGI 可以配置为 SCGI 服务器或 FastCGI 服务器或 HTTP 服务器(以及其他网关),因此可以作为 lighttpd mod_scgi (SCGI)、mod_fastcgi (FastCGI)、mod_proxy (HTTP) 的后端。

    http://uwsgi-docs.readthedocs.io/en/latest/Python.html#paste-support

    仅供参考:lighttpd mod_scgi 还将在即将推出的 lighttpd 1.4.42 中支持 uwsgi 协议

    【讨论】:

    • 所以,我认为需要对 ini 进行更多更改才能使用它:pastebin.com/raw/K1FfhW4F
    • github.com/ckan/ckan/wiki/… 并搜索“WSGI”。 WSGI 的文档中有多个部分。请通读,特别是“Step 3 Install python package”和“9. Create a WSGI file”
    【解决方案2】:

    无需安装其他任何东西,可以将 CKAN 作为守护程序运行并使用代理通过 lighttpd 在端口 80 上服务 ckan。

    因此,有必要在 CentOS7 上将其作为服务:

    创建一个服务来运行 ckan 守护进程:

    使用 CentOS7(和所有 RHEL7 系列)很容易创建服务。 您只需要创建一个 ckand.service 并将 CKAN 作为守护程序运行。

    创建日志并运行目录:

    mkdir -p /var/run/ckan && chown ckan:ckan /var/run/ckan -R
    mkdir -p /var/log/ckan && chown ckan:ckan /var/log/ckan -R
    

    所以创建一个 ckand.service unit file 用于具有以下内容的服务:

    您可能需要更改配置文件路径。

    [Unit]
    Description=CKAN Daemon Service
    Requires=solr.service postgresql.service
    After=solr.service postgresql.service
    
    [Service]
    User=ckan
    Group=ckan
    Type=forking
    TimeoutSec=0
    PermissionsStartOnly=true
    
    PIDFile=/var/run/ckan/ckan.pid
    
    Restart=on-failure
    
    RestartPreventExitStatus=1
    
    PrivateTmp=false
    
    ExecStart=/usr/lib/ckan/default/bin/paster serve /etc/ckan/default/development.ini --daemon  --pid-file=/var/run/ckan/ckan.pid  --log-file=/var/log/ckan/ckan.log
    ExecStop=/usr/lib/ckan/default/bin/paster serve /etc/ckan/default/development.ini --stop-daemon --pid-file=/var/run/ckan/ckan.pid
    ExecReload=/bin/kill -HUP $MAINPID
    KillMode=process
    
    Restart=on-failure
    RestartSec=42s
    
    [Install]
    WantedBy=default.target
    

    然后在 lighttpd 上创建一个 vhost:

    首先,您必须确保已激活代理模块,然后 在 /etc/lighttpd/vhost.d/ 上,您必须像这样创建一个 .conf:

    $HTTP["host"] == "ckan.example.com" {
      proxy.server = ( "" =>
            ( "" => 
                ("host" => "127.0.0.1", "port" => 5000) # if you're running ckan on a different port please change here
            )
        )
    }
    

    恢复方式:

    cd /etc/ckan/default
    wget https://gist.githubusercontent.com/LeonanCarvalho/a7bd73fe9632873c1bd7898c73d4b218/raw/637db259f4e1ac8980ea3377259bd65042cd1a8b/ckand.service
    #It can't be a symbolic link
    ln -P /etc/ckan/default/ckand.service /etc/systemd/system/ckand.service 
    systemctl enable ckand
    systemctl start ckand
    systemctl status ckand -l
    cd /etc/lighttpd/vhost.d
    wget https://gist.githubusercontent.com/LeonanCarvalho/a7bd73fe9632873c1bd7898c73d4b218/raw/637db259f4e1ac8980ea3377259bd65042cd1a8b/ckan_lighttpd_vhost.conf
    systemctl restart lighttpd
    

    wget前请检查链接内容,下载后可以更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-28
      • 2015-06-22
      • 2023-02-12
      • 1970-01-01
      • 2022-07-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多