wlanboy
Content Contributer
I really like Ruby but sometimes you need/want to run some Java apps on your vps. This is quite easy because you can strip down the Java VM to use quite a small amount of RAM.
But if you need to support servlets, websockets, JMX or JNDI lookups you need a container, or at least a servlet container.
You should not try to run the big application servers on a small vps - just by looking to the footprint of Jboss, Glassfish or Websphere.
But you can easily run Jetty on a small vps.
So let's install Jetty:
If you look to the footprint of Jetty:
PID User Command Swap USS PSS RSS
7358 jetty /usr/bin/java -Djetty.state 37456 40388 40492 41464
no one can say that Jetty is bloated.
Maybe enough to bring back some Java to your vps.
PS: One Jetty based project: Bombermine.
Configuration of Jetty
All config files are located in "/opt/jetty/etc"
/opt/jetty/etc# ls
README.spnego jetty-deploy.xml jetty-jmx.xml jetty-proxy.xml jetty-spdy.xml jetty.conf spnego.conf
jdbcRealm.properties jetty-http.xml jetty-logging.xml jetty-requestlog.xml jetty-ssl.xml jetty.xml spnego.properties
jetty-annotations.xml jetty-https.xml jetty-lowresources.xml jetty-rewrite.xml jetty-started.xml keystore test-realm.xml
jetty-debug.xml jetty-ipaccess.xml jetty-monitor.xml jetty-setuid.xml jetty-stats.xml krb5.ini webdefault.xml
jetty-demo.xml jetty-jaas.xml jetty-plus.xml jetty-spdy-proxy.xml jetty-xinetd.xml realm.properties
Best place to set the virtual hosts: Within the war file:
But if you need to support servlets, websockets, JMX or JNDI lookups you need a container, or at least a servlet container.
You should not try to run the big application servers on a small vps - just by looking to the footprint of Jboss, Glassfish or Websphere.
But you can easily run Jetty on a small vps.
So let's install Jetty:
- Install Java
apt-get install openjdk-7-jdk (wopping 363MB)
mkdir /usr/java
For 64bit:
ln -s /usr/lib/jvm/java-7-openjdk-amd64 /usr/java/default
For 32bit
ln -s /usr/lib/jvm/java-7-openjdk-i386/ /usr/java/default
- Download Jetty
http://download.eclipse.org/jetty/stable-9/dist/
Code:wget http://eclipse.org/downloads/download.php?file=/jetty/stable-9/dist/jetty-distribution-9.0.5.v20130815.tar.gz&r=1 tar -xzf *.tar.gz
- Prepare directories and users
Code:mkdir /opt mv jetty-distribution-9.0.5.v20130815 /opt/jetty useradd jetty -U -s /bin/false chown -R jetty:jetty /opt/jetty
- Configure Jetty defaults
Code:nano /etc/default/jetty
JAVA=/usr/bin/java # Path to Java
NO_START=0 # Start on boot
JETTY_HOST=127.0.0.1 # Listen to following ip
JETTY_ARGS=jetty.port=8085 # Web port of jetty
JETTY_USER=jetty # User to run under
- Configure Jetty as a service
Code:cp /opt/jetty/bin/jetty.sh /etc/init.d/jetty chmod +x /etc/init.d/jetty update-rc.d jetty defaults service jetty restart
- Remove demo apps (because they are not secure)
Code:cd /opt/jetty/webapps rm -rf test.d/ test.war test.xml async-rest.war rm -rf /opt/jetty/webapps.demo
If you look to the footprint of Jetty:
PID User Command Swap USS PSS RSS
7358 jetty /usr/bin/java -Djetty.state 37456 40388 40492 41464
no one can say that Jetty is bloated.
Maybe enough to bring back some Java to your vps.
PS: One Jetty based project: Bombermine.
Configuration of Jetty
All config files are located in "/opt/jetty/etc"
/opt/jetty/etc# ls
README.spnego jetty-deploy.xml jetty-jmx.xml jetty-proxy.xml jetty-spdy.xml jetty.conf spnego.conf
jdbcRealm.properties jetty-http.xml jetty-logging.xml jetty-requestlog.xml jetty-ssl.xml jetty.xml spnego.properties
jetty-annotations.xml jetty-https.xml jetty-lowresources.xml jetty-rewrite.xml jetty-started.xml keystore test-realm.xml
jetty-debug.xml jetty-ipaccess.xml jetty-monitor.xml jetty-setuid.xml jetty-stats.xml krb5.ini webdefault.xml
jetty-demo.xml jetty-jaas.xml jetty-plus.xml jetty-spdy-proxy.xml jetty-xinetd.xml realm.properties
- jetty-http.xml
Host and port of the http port - jetty-https.xml
Port and certs for SSL - jetty.xml
All major settings like:
- Thread pool
Code:<Get name="ThreadPool"> <Set name="minThreads" type="int"><Property name="threads.min" default="10"/></Set> <Set name="maxThreads" type="int"><Property name="threads.max" default="200"/></Set> <Set name="idleTimeout" type="int"><Property name="threads.timeout" default="60000"/></Set> <Set name="detailedDump">false</Set> </Get>
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<Set name="secureScheme">https</Set>
<Set name="securePort"><Property name="jetty.secure.port" default="8443" /></Set>
<Set name="outputBufferSize">32768</Set>
<Set name="requestHeaderSize">8192</Set>
<Set name="responseHeaderSize">8192</Set>
<Set name="sendServerVersion">true</Set>
<Set name="sendDateHeader">false</Set>
<Set name="headerCacheSize">512</Set>
<!-- Uncomment to enable handling of X-Forwarded- style headers-->
<Call name="addCustomizer">
<Arg><New class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg>
</Call>
</New>
Best place to set the virtual hosts: Within the war file:
Code:
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/ibadmin</Set>
<Set name="war"><Property name="jetty.webapps" default="."/>/ibadmin.war</Set>
<Set name="virtualHosts">
<Array type="String">
<Item>test.wlanboy.com</Item>
<Item>@ConnectorName</Item>
<Item>localhost</Item>
<Item>127.0.0.1</Item>
</Array>
</Set>
Last edited by a moderator: