【问题标题】:gzip compression not working in Solr 5.1gzip 压缩在 Solr 5.1 中不起作用
【发布时间】:2015-05-22 08:22:36
【问题描述】:

我正在尝试在 Solr 5.1 中应用 gzip 压缩。我知道 Solr 5.0 不再支持在 Tomcat 上运行 Solr,所以我尝试在 Solr 中实现它。

我已经下载了 jetty-servlets-9.3.0.RC0.jar 并将其放在我的 webapp\WEB-INF 文件夹中,并在 webapp\WEB-INF\web.xml 中添加了以下内容:

<filter>
   <filter-name>GzipFilter</filter-name>
   <filter-class>org.eclipse.jetty.servlets.GzipFilter</filter-class>
      <init-param>
         <param-name>methods</param-name>
         <param-value>GET,POST</param-value>
         <param-name>mimeTypes</param-name>
         <param-value>text/html,text/plain,text/xml,text/json,text/javascript,text/css,application/xhtml+xml,application/javascript,image/svg+xml,application/json,application/xml; charset=UTF-8</param-value>
      </init-param>
</filter>
<filter-mapping>
<filter-name>GzipFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

但是,当我启动 Solr 并检查浏览器时,没有 gzip 压缩,我只在 Response Headers 输出中得到以下信息: 内容类型:文本/纯文本;字符集=UTF-8 传输编码:分块

是否有任何我配置错误或可能遗漏的内容?我也在运行 zookeeper-3.4.6。

【问题讨论】:

    标签: solr compression jetty gzip apache-zookeeper


    【解决方案1】:

    下载与 Solr 中当前版本非常匹配的 Jetty 犹太洁食版本:http://www.eclipse.org/jetty/download.html

    将该 .zip 文件解压缩到您将丢弃的位置。 将这些文件复制到 Solr 中的 jetty 副本(位于 path-to-solr/server/ 中):

    • modules/gzip.mod
    • etc/gzip.xml

    修改modules/gzip.mod

    #
    # GZIP module
    # Applies GzipHandler to entire server
    #
    
    [depend]
    server
    
    [xml]
    etc/jetty-gzip.xml
    
    [ini-template]
    ## Minimum content length after which gzip is enabled
    jetty.gzip.minGzipSize=2048
    
    ## Check whether a file with *.gz extension exists
    jetty.gzip.checkGzExists=false
    
    ## Gzip compression level (-1 for default)
    jetty.gzip.compressionLevel=-1
    
    ## User agents for which gzip is disabled
    jetty.gzip.excludedUserAgent=.*MSIE.6\.0.*
    

    修改etc/gzip.xml

    <?xml version="1.0"?>
    <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
    <!-- =============================================================== -->
    <!-- Mixin the GZIP Handler                                          -->
    <!-- This applies the GZIP Handler to the entire server              -->
    <!-- If a GZIP handler is required for an individual context, then   -->
    <!-- use a context XML (see test.xml example in distribution)        -->
    <!-- =============================================================== -->
    <Configure id="Server" class="org.eclipse.jetty.server.Server">
        <Call name="insertHandler">
            <Arg>
                <New id="GzipHandler" class="org.eclipse.jetty.server.handler.gzip.GzipHandler">
                    <Set name="minGzipSize">
                        <Property name="jetty.gzip.minGzipSize" deprecated="gzip.minGzipSize" default="2048"/>
                    </Set>
                    <Set name="checkGzExists">
                        <Property name="jetty.gzip.checkGzExists" deprecated="gzip.checkGzExists" default="false"/>
                    </Set>
                    <Set name="compressionLevel">
                        <Property name="jetty.gzip.compressionLevel" deprecated="gzip.compressionLevel" default="-1"/>
                    </Set>
                    <Set name="excludedAgentPatterns">
                        <Array type="String">
                            <Item>
                                <Property name="jetty.gzip.excludedUserAgent" deprecated="gzip.excludedUserAgent" default=".*MSIE.6\.0.*"/>
                            </Item>
                        </Array>
                    </Set>
                    <Set name="includedMethods">
                        <Array type="String">
                            <Item>GET</Item>
                            <Item>POST</Item>
                        </Array>
                    </Set>
    
        <Set name="includedPaths"><Array type="String"><Item>/*</Item></Array></Set>
    
        <Set name="excludedPaths"><Array type="String"><Item>*.gz</Item></Array></Set>
    
        <Call name="addIncludedMimeTypes"><Arg><Array type="String">
            <Item>text/html</Item>
            <Item>text/plain</Item>
            <Item>text/xml</Item>
            <Item>application/xml</Item><!-- IMPORTANT - DO NOT FORGET THIS LINE -->
            <Item>application/xhtml+xml</Item>
            <Item>text/css</Item>
            <Item>application/javascript</Item>
            <Item>image/svg+xml</Item>
        </Array></Arg></Call>
                    <!--
        <Call name="addExcludedMimeTypes"><Arg><Array type="String"><Item>some/type</Item></Array></Arg></Call>
        -->
                </New>
            </Arg>
        </Call>
    </Configure>
    

    这是应该让你有点畏缩的部分。 修改bin\solr.cmd

    ...
    set "SOLR_JETTY_CONFIG=--module=http,gzip"
    ...
    set "SOLR_JETTY_CONFIG=--module=https,gzip"
    ...
    

    请注意--module=http 已经存在。只需添加 ",gzip" 使其与上面的行匹配。 我宁愿找到一种更好的方法来指定要加载的 gzip 模块,但我不知道如何。如果你知道怎么做,请回复这个答案并告诉我怎么做,因为我讨厌修改产品附带的脚本——这是维护的噩梦,而且,我想你明白了。

    在此之后,重新启动 solr 服务器,现在应该启用 gzip - 至少对于 &amp;wt=xml,它以 Content-Type: application/xml 发回。 您可以将所需内容添加到 etc/gzip.xml 并重新启动 solr 服务器以使其识别您的更改。

    我测试了压缩和不压缩 1000 个文档。对我来说,这就是 3.8 MB 和 637 KB 之间的差异。

    【讨论】:

    • 注意:我使用的是 solr 6.1.0,所以如果您需要进行一些调整,请记住这一点。我知道 .war 文件在 solr 5.4 或 5.5 的某个地方消失了。
    猜你喜欢
    • 2022-01-20
    • 1970-01-01
    • 2015-11-10
    • 1970-01-01
    • 2017-03-20
    • 2018-04-19
    • 2015-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多