Cleaning up Jetty - Removing 'unnecessaries' things

前端 未结 3 1456
刺人心
刺人心 2021-02-20 02:58

I\'m used to use Jetty as my web container.

What I did on my install steps is get the original tar ball and cleanup some directories and files<

相关标签:
3条回答
  • 2021-02-20 03:32

    In the past I used to trim Jetty down a lot by cutting out all the frameworks I don't use. That also let me trim down all the dependency jars. Once I got it trimmed down to the bare essentials I used it was very tiny. Then I repackaged it with onejar so it was a single file transfer that is ready to execute. Its been a long time since I managed any large scale application clusters so there are probably better ways to accomplish the same ends. Cloud computing comes to mind, but I haven't done much there, but that is where I'd look first if I were facing the same challenges today.

    Plus bandwidth and disk are a lot cheaper these days so the problems have gotten smaller with time in my opinion.

    0 讨论(0)
  • 2021-02-20 03:41

    I'm not breaking any license right?

    Correct.

    Can I bring any drawback for my system (performance/stability) doing that?

    The only drawback is that the Log4J properties file is useful for controlling how much (or how little) logging is performed. Disabling logging altogether results in smaller log files, conserving disk space. (Shouldn't be an issue with TB drives.) If the logging properties file cannot be found, an application might default to DEBUG or INFO levels, rather than ERROR levels. So, Log4J is useful to tell all applications to only log critical information.

    Eliminating extraneous examples (the test suite) tightens security by exposing less system information. It can also save a bit of memory because the test webapps cannot get loaded into memory.

    Does anyone customize more than this on jetty?

    You can clean the webapps directory as follows:

    cd /opt/jetty
    rm -rf webapps
    mkdir -p webapps/root
    echo "<html><body></body></html>" > webapps/root/index.html
    

    Restart Jetty.

    0 讨论(0)
  • 2021-02-20 03:41

    Here's one way of cleaning up Jetty (9.1.5).

    tar -xzvf jetty-distribution-9.1.5.v20140505.tar.gz
    # can rename 'jetty-distribution-9.1.5.v20140505' to 'jetty-9.1.5' or similar
    cd jetty-distribution-9.1.5.v20140505
    rm -rf VERSION.txt license-eplv10-aslv20.html notice.html start.d/jsp.ini resources/log4j.properties demo-base/
    find -name README.TXT | xargs rm -fv
    
    mv etc etc.bak              # keep a backup of etc/ and modules/, take whats necessary
    mv modules modules.bak
    mkdir etc modules work
    mv modules.bak/.donotdelete modules.bak/deploy.mod modules.bak/ext.mod modules.bak/http.mod \
        modules.bak/logging.mod modules.bak/resources.mod modules.bak/security.mod modules.bak/server.mod modules.bak/servlet* \
        modules.bak/webapp.mod modules/
    mv $(grep -h --color=none "etc.*.xml" modules/* | sed 's/etc/etc\.bak/g') etc/
    mv etc.bak/jetty-started.xml etc.bak/jetty.conf etc/        # required for bin/jetty.sh
    mv etc.bak/webdefault.xml etc/                              # required for web applications
                                                                # provides default deployment descriptor config for all apps
    # rm -rf modules.bak/ etc.bak/                              # remove if not needed
    
    sed -i '/^#/d; /^\s*$/d' start.ini start.d/http.ini         # clean if needed
    
    vi start.ini start.d/http.ini                               # check and modify if needed
        start.ini: 'jetty.send.server.version=false', remove '--module=websocket'
        http.ini: 'jetty.port=9999'
    vi modules/<whatever.mod>                                   # check and modify if needed
    vi etc/jetty.xml # to prevent Jetty from showing context related information
        remove
            <Item>
                <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
            </Item>
    vi etc/jetty-logging.xml # suffix date with '-', instead of prefixing with '_'
        change
            <Arg><Property name="jetty.logs" default="./logs"/>/yyyy_mm_dd.stderrout.log</Arg>
            ...
            <Get id="ServerLogName" name="datedFilename"/>
        to
            <Arg><Property name="jetty.logs" default="./logs"/>/stderrout.log.yyyy_mm_dd</Arg>
            ...
            <Arg type="java.lang.String">yyyy-MM-dd</Arg>
            <Arg type="java.lang.String">HHmmssSSS</Arg>
            <Get id="ServerLogName" name="datedFilename"/>
    vi etc/webdefault.xml # disable jsp support and modify other default settings
        remove or comment out <servlet> and <servlet-mapping> of JSP Servlet
        remove or comment out index.jsp from <welcome-file-list>
        set dirAllowed to false in default servlet
    vi bin/jetty.sh # use $JETTY_BASE/logs instead of $JETTY_BASE as working directory
        change
            JETTY_RUN=$(findDirectory -w /var/run /usr/var/run $JETTY_BASE /tmp)
            JETTY_STATE=$JETTY_BASE/${NAME}.state
        to
            JETTY_RUN=$(findDirectory -w /var/run /usr/var/run $JETTY_BASE/logs $JETTY_BASE /tmp)
            JETTY_STATE=$JETTY_RUN/${NAME}.state
    vi bin/jetty.sh # use $JETTY_HOME/work as default TMPDIR
        move following 
            TMPDIR=${TMPDIR:-/tmp}
        below 'JETTY_HOME=$PWD' and change
            TMPDIR=${TMPDIR:-"$JETTY_HOME"/work}
    

    And the resulting structure.

    jetty-distribution-9.1.5.v20140505
    ├── bin
    │   └── jetty.sh
    ├── etc
    │   ├── jetty-deploy.xml
    │   ├── jetty-http.xml
    │   ├── jetty-logging.xml
    │   ├── jetty-started.xml
    │   ├── jetty.conf
    │   ├── jetty.xml
    │   └── webdefault.xml
    ├── lib
    │   └── <no change or keep only relevant>
    ├── logs
    ├── modules
    │   ├── deploy.mod
    │   ├── ext.mod
    │   ├── http.mod
    │   ├── logging.mod
    │   ├── resources.mod
    │   ├── security.mod
    │   ├── server.mod
    │   ├── servlet.mod
    │   ├── servlets.mod
    │   └── webapp.mod
    ├── resources
    ├── start.d
    │   └── http.ini
    ├── start.ini
    ├── start.jar
    ├── webapps
    └── work
    
    0 讨论(0)
提交回复
热议问题