Jetty installation learning and demonstration

Source: Internet
Author: User

Jetty's basic architecture

Jetty is currently a promising Servlet engine with a simple architecture and a scalable and flexible application server. It has a basic data model, this data model is Handler, and all the components that can be extended can be added to the Server as a Handler. Jetty helps you manage these Handler.

It is the basic architecture of Jetty. The core component of Jetty is composed of two components: Server and Connector. The whole Server component works based on the Handler Container, which is similar to the Tomcat Container, the Comparison Between Jetty and Tomcat is described in detail later. Another indispensable component in Jetty is Connector, which is responsible for accepting client connection requests and allocating requests to a processing queue for execution.

Figure 1. Jetty's basic architecture

Start deployment and installation:

1 Jetty:
Http://wiki.eclipse.org/Jetty/Howto/Install_Jetty

2. Add the account for running jetty.
Useradd-m jetty

3. Extract (decompress)
You can directly decompress the package without using configre or make.

Readme.txt

I need to start three jetty services, one service corresponds to one web application, so I directly copy3 decompression packages
Start three applications with the jetty. port:

The problem is that there is no way to stop using this method;
For example, java-jar/usr/local/jetty_7.6.15_8200/start. jar-DSTOP. PORT = 8200-DSTOP. KEY = magic -- the stop method fails to shut down the jetty process. You can only manually kill the ID. This is not too safe.

vim /usr/local/jetty_7.6.15_8100/etc/jetty.xml    <Call name="addConnector">      <Arg>          <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">            <Set name="host"><Property name="jetty.host" /></Set>            <Set name="port"><Property name="jetty.port" default="8100"/></Set>            <Set name="maxIdleTime">300000</Set>            <Set name="Acceptors">2</Set>            <Set name="statsOn">false</Set>            <Set name="confidentialPort">8443</Set>            <Set name="lowResourcesConnections">20000</Set>            <Set name="lowResourcesMaxIdleTime">5000</Set>          </New>      </Arg>    </Call>

5. Go to the/bin/directory and find that the jetty. sh script can be started.
/Usr/local/jetty_7.6.15_8100/bin/jetty. sh start
Stop:
/Usr/local/jetty_7.6.15_8100/bin/jetty. sh stop

[Root @ localhost etc] #/usr/local/jetty_7.6.15_8100/bin/jetty. sh stopStopping Jetty: OK [root @ localhost etc] #/usr/local/jetty_7.6.15_8100/bin/jetty. sh startStarting Jetty: 15:53:05. 744: INFO: Redirecting stderr/stdout to/usr/local/jetty_7.6.15_8100/logs/May 13, 2014 15:53:09 CST [root @ localhost etc] #


The following error is reported:

Modify the port as follows:

vim /usr/local/jetty_7.6.15_8200/etc/jetty.xml    <Call name="addConnector">      <Arg>          <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">            <Set name="host"><Property name="jetty.host" /></Set>            <Set name="port"><Property name="jetty.port" default="8200"/></Set>            <Set name="maxIdleTime">300000</Set>            <Set name="Acceptors">2</Set>            <Set name="statsOn">false</Set>            <Set name="confidentialPort">8443</Set>            <Set name="lowResourcesConnections">20000</Set>            <Set name="lowResourcesMaxIdleTime">5000</Set>          </New>      </Arg>    </Call>

Change to 8100,8200, 8300, and then list the stop startup commands as follows:

/Usr/local/jetty_7.6.15_8300/bin/jetty. sh start

When 8100 is started, the same error is reported again when 8200 is started.

Starting Jetty: Already Running !!

Java-jar/usr/local/jetty_7.6.15_8300/start. jar -- pre = etc/jetty-logging.xml -- pre = etc/jetty-jmx.xml -- stop STOP. PORT = 8300 STOP. KEY = 1

Nohup java-jar/usr/local/jetty_7.6.15_8100/start. jar -- pre = etc/jetty-logging.xml -- pre = etc/jetty-jmx.xml jetty. port = 8100 &

6. Try again in java-jar mode.
Nohup java-jar/usr/local/jetty_7.6.15_8200/start. jar jetty. port = 8200 &

In the following method, three jetty instances can be started, but the stop operation fails. The -- stop parameter is not successful. The jetty process is still running in the background and can only be killed to forcibly stop the process:

nohup java -jar /usr/local/jetty_7.6.15_8100/start.jar --pre=etc/jetty-logging.xml --pre=etc/jetty-jmx.xml jetty.port=8100 &nohup java -jar /usr/local/jetty_7.6.15_8200/start.jar --pre=etc/jetty-logging.xml --pre=etc/jetty-jmx.xml jetty.port=8200 &nohup java -jar /usr/local/jetty_7.6.15_8300/start.jar --pre=etc/jetty-logging.xml --pre=etc/jetty-jmx.xml jetty.port=8300 &


7. check the jetty. sh script.
[Root @ localhost bin] #/usr/local/jetty_7.6.15_8100/bin/jetty. sh check

JETTY_PID =/var/run/jetty. pid, and suddenly realized that if 8200 is started, JETTY_PID =/var/run/jetty. if pid is a pid, it must conflict with 8100. It is no wonder that only one jetty can be started at a time. sh. Check jetty. where to set/var/run/jetty in the sh script. pid, find the suffix number under the modification.

if [ -z "$JETTY_PID" ]then JETTY_PID="$JETTY_RUN/jetty_8200.pid"fiif [ -z "$JETTY_STATE" ]then JETTY_STATE=$JETTY_HOME/jetty.state
[Root @ localhost bin] # pwd/usr/local/jetty_7.6.15_8200/bin [root @ localhost bin] #/usr/local/jetty_7.6.15_8100/bin/jetty. sh stopStopping Jetty: OK [root @ localhost bin] #/usr/local/jetty_7.6.15_8200/bin/jetty. sh stopStopping Jetty: OK [root @ localhost bin] #/usr/local/jetty_7.6.15_8300/bin/jetty. sh stopStopping Jetty: OK [root @ localhost bin] # ps-eaf | grep jettyroot 20205 11980 0 00:00:00 pts/2 grep jetty [root @ localhost bin] #/usr/local/jetty_7.6.15_8300/bin/ jetty. sh startStarting Jetty: 20:28:32. 146: INFO :: redirecting stderr/stdout to/usr/local/jetty_7.6.15_8300/logs Tuesday 1, May 13, 2014 20:28:33 CST [root @ localhost bin] #/usr/local/jetty_7.6.15_8200/bin/jetty. sh startStarting Jetty: 20:28:34. 416: INFO :: redirecting stderr/stdout to/usr/local/jetty_7.6.15_8200/logs/Hangzhou Tuesday, September 12 20:28:37 CST [root @ localhost bin] #/usr/local/jetty_7.6.15_8100/bin/jetty. sh startStarting Jetty: 20:28:38. 527: INFO: Redirecting stderr/stdout to/usr/local/jetty_7.6.15_8100/logs/May 13, 2014 20:28:41 CST [root @ localhost bin] #

9. OpenHttp://192.xxx.xxx.xx: 8100/cargo-jetty-deployer/,The following error is reported::

Http error 400

Problem accessing/cargo-jetty-deployer/. Reason:

Command/is unknown

10. Deploy a simple jetty application:
[Root @ localhost webapps] # mkdir test1

[Root @ localhost test1] # cd test1

Restart jetty
[Root @ localhost test1] #/usr/local/jetty_7.6.15_8100/bin/jetty. sh restart

11. view the result: Enter the URL in the browser:Http://192.xxx.xxx.xx: 8100/test1/hello. jsp

Hello World, The first jetty demo page of timman in pl, such:

Additional summary:

(1): Simply comparing the performance of Tomcat and Jetty is not of great significance. It can only be said that in some use cases, its performance varies. Because they are used in different scenarios.

In terms of architecture, Tomcat is more advantageous in handling a few very busy connections. That is to say, if the connection life cycle is short, Tomcat has a higher overall performance.

(2) In addition, because Jetty's architecture is very simple, as a server, it can load components as needed, so that unwanted components can be removed, which can reduce the memory overhead of the server itself, processing a request can also reduce the number of generated temporary objects, which improves the performance. In addition, Jetty uses NIO technology by default to process I/O requests, while Tomcat uses BIO by default. In static resources processing, Tomcat is inferior to Jetty in performance.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.