jetty在Linux下的配置

jetty官网:http://www.eclipse.org/jetty/

具体配置流程如下1, 2:

1. Nginx 添加监听域名和路由端口.

#当前应用的可用流(可无限添加)

upstream pisaTbt0 {

server  10.221.12.182:8051 weight=1;

server  10.221.12.182:8052 weight=1;

keepalive 256;

}

upstream pisaTbt1 {

server  10.221.12.182:8061 weight=1;

server  10.221.12.182:8062 weight=1;

keepalive 256;

}

#监听域名,此处可配置监听多个端口

server {

listen  80;

server_name  203.195.182.194;

location ^~ /pisa-tbt/ {

proxy_pass        http://pisaTbt0;

proxy_set_header   Host             $host;

proxy_set_header   X-Real-IP        $remote_addr;

proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

}

}

server {

listen  8080;

server_name  203.195.182.194;

location ^~ /pisa-tbt/ {

proxy_pass        http://pisaTbt1;

proxy_set_header   Host             $host:8080;

proxy_set_header   X-Real-IP        $remote_addr;

proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

}

}

2. 配置和启动Jetty独立服务

1) 拷贝davinciDev或WukongDev为自己的应用目录(除了配置文件和日志目录其余全部为软连接, 不用担心版本问题)

3) 进入{Jetty目录}/standalone/{自己的应用地址}

4) 修改server.conf, 指定当前服务的两个端口号, 和上方的Nginx流内的端口号对应.

5) 修改etc/jetty-http.xml中的jetty.host为要启动的host

6) 执行   server.sh start   启动服务, 启动后将自动在两个端口号内选择一个执行.

7) 如果需要热重启服务时则执行   server.sh switch   进行切换, 脚本会启动新服务并保证可用的情况下关闭老服务.  Nginx则会自动路由请求到新服务.

Jetty独立服务介绍:

目录结构:

./data                  存储PID和启动进度信息.

./etc                    应用目录配置, 启动监听配置.(设置项会自动配置, 所以无需更改),此目录中主要包括jetty-deploy.xml和jetty-started.xml,这两个文件会替代全局配置

./log                    jetty的启动日志(针对当前独立应用)

./server.conf       启动端口号配置

./server.sh           独立服务执行脚本(包括三个命令, server.sh start:启动服务, server.sh stop:关闭服务, server.sh switch:切换服务)

./webapps           应用存放位置

jetty-deploy.xml样例

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">

<!-- =============================================================== -->
<!-- Create the deployment manager -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- The deplyment manager handles the lifecycle of deploying web -->
<!-- applications. Apps are provided by instances of the -->
<!-- AppProvider interface. -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">

<Call name="addBean">
<Arg>
<New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
<Set name="contexts">
<Ref refid="Contexts" />
</Set>
<Call name="setContextAttribute">
<Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
<Arg>.*/servlet-api-[^/]*\.jar$</Arg>
</Call>

<!-- Add a customize step to the deployment lifecycle -->
<!-- uncomment and replace DebugBinding with your extended AppLifeCycle.Binding class
<Call name="insertLifeCycleNode">
<Arg>deployed</Arg>
<Arg>starting</Arg>
<Arg>customise</Arg>
</Call>
<Call name="addLifeCycleBinding">
<Arg>
<New class="org.eclipse.jetty.deploy.bindings.DebugBinding">
<Arg>customise</Arg>
</New>
</Arg>
</Call> -->

<Call id="webappprovider" name="addAppProvider">
<Arg>
<New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
<Set name="monitoredDirName"><Property name="jetty.webapps"/></Set>
<Set name="defaultsDescriptor"><Property name="jetty.home" default="." />/etc/webdefault.xml</Set>
<Set name="scanInterval">0</Set>
<Set name="extractWars">true</Set>
<Set name="configurationManager">
<New class="org.eclipse.jetty.deploy.PropertiesConfigurationManager"></New>
</Set>
</New>
</Arg>
</Call>
</New>
</Arg>
</Call>

</Configure>

jetty-started.xml样例

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">

<!-- =============================================================== -->
<!-- Mixin the Start FileNoticeLifeCycleListener -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="addLifeCycleListener">
<Arg>
<New class="org.eclipse.jetty.util.component.FileNoticeLifeCycleListener">
<Arg><Property name="jetty.state"/></Arg>
</New>
</Arg>
</Call>
</Configure>

server.sh样例

#!/usr/bin/env bash
#Author Simon
# set profile
source ~/.bash_profile

# set project directory
if [ -z "$PROJECT_HOME" ]
then
START_SH=$0
case "$START_SH" in
/*) PROJECT_HOME=${START_SH%/*} ;;
./*/*/*) PROJECT_HOME=${START_SH%/*} ;;
./*) PROJECT_HOME=. ;;
esac
fi

cd "$PROJECT_HOME"
PROJECT_HOME=$PWD

# set jetty home directory
JETTY_HOME=${PROJECT_HOME%/*/*}
cd "$JETTY_HOME"

# create project log directory
logDir="$PROJECT_HOME/log"
if [ ! -d ${logDir} ]
then
$(mkdir -p ${logDir})
fi

# create project data directory
dataDir="$PROJECT_HOME/data"
if [ ! -d ${dataDir} ]
then
$(mkdir -p ${dataDir})
fi

source "$PROJECT_HOME/server.conf"

# jetty status
if [ -z "$JETTY_STATE" ]
then
JETTY_STATE=$dataDir/jetty.state
fi
rm -f $JETTY_STATE

if [ -z "$JAVA" ]
then
JAVA=$(which java)
fi

# Add jetty properties to Java VM options.
TMPDIR=${TMPDIR:-/tmp}
JAVA_OPTIONS+=("-Djetty.home=$JETTY_HOME" "-Djava.io.tmpdir=$TMPDIR")

# This is how the Jetty server will be started
JETTY_START=$JETTY_HOME/start.jar
[ ! -f "$JETTY_START" ] && JETTY_START=$JETTY_HOME/lib/start.jar

START_INI=$(dirname $JETTY_START)/start.ini
[ -r "$START_INI" ] || START_INI=""

CONFIGS=(
${JETTY_HOME}/etc/jetty-logging.xml
${PROJECT_HOME}/etc/jetty-deploy.xml
${PROJECT_HOME}/etc/jetty-started.xml
)
JETTY_ARGS=(
"jetty.logs"=${PROJECT_HOME}/log
"jetty.webapps"=${PROJECT_HOME}/webapps
"jetty.state"=${JETTY_STATE}
)

usage()
{
echo "Usage: ${0##*/} {start|stop|switch}"
exit 1
}
[ $# -gt 0 ] || usage

isRun()
{
kill -0 "$1" 2>/dev/null
}

getPid()
{
echo $(cut -d\| -f 1 ${dataDir}/project_$1.pid 2>/dev/null)
}

#引用自jetty.sh
started()
{
# wait for 60s to see "STARTED" in PID file, needs jetty-started.xml as argument
for T in 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
do
sleep 4
[ -z "$(grep STARTED $1 2>/dev/null)" ] || return 0
[ -z "$(grep STOPPED $1 2>/dev/null)" ] || return 1
[ -z "$(grep FAILED $1 2>/dev/null)" ] || return 1
local PID=$2 || return 1
kill -0 "$PID" 2>/dev/null || return 1
echo -n "."
done

return 1
}

shutdownServer()
{
PID=$1
if isRun $PID
then
kill "$PID" 2>/dev/null

TIMEOUT=30
while isRun $PID; do
if (( TIMEOUT-- == 0 )); then
kill -KILL "$PID" 2>/dev/null
fi

sleep 1
done

if! isRun $PID
then
return0
else
return1
fi
fi
return0
}

start()
{
local currentPort
local port=$1

if[ $port >0]
then
currentPort=$port
else
currentPort=${PORT[0]}
fi

pidFilePath=${dataDir}/project_${currentPort}.pid

PID=$(getPid $currentPort)
if isRun $PID
then
echo "jetty already running!"
exit
fi

#此处限制访问IP为内网
RUN_ARGS=(${JAVA_OPTIONS[@]}-jar "$JETTY_START" ${JETTY_ARGS[@]} jetty.host="10.207.169.50" jetty.port=${currentPort}"${CONFIGS[@]}")
RUN_CMD=("$JAVA" ${RUN_ARGS[@]})

#start jetty
echo "${RUN_CMD[@]}"
"${RUN_CMD[@]}">/dev/null&
JETTY_PID=$!
disown $!

if started "$JETTY_STATE""$JETTY_PID"
then
echo ""
echo "OK `date`"
else
echo ""
echo "FAILED `date`"
fi

if! isRun $JETTY_PID
then
echo "jetty run fail!"
exit
fi
echo "Ok! new server startup, PID:[$JETTY_PID], PORT:[$currentPort]"
echo "$JETTY_PID|$currentPort"> $pidFilePath
}

stop()
{
for port in ${PORT[@]}
do
PID=$(getPid $port)
if isRun $PID
then
shutdownServer $PID

if! isRun $PID
then
closeFlag=1
echo "Ok! PORT:[$port]"
fi
fi
done

if[! $closeFlag ]
then
echo "stop fail(not pid file | not start)"
fi
}

switch()
{
for port in ${PORT[@]}
do
local pid=$(getPid $port)
if isRun $pid
then
alreadyStartPort=$port
fi
done

if[! $alreadyStartPort ]
then
echo "jetty not start!"
exit
fi

local pid=$(getPid $alreadyStartPort)

echo "current running PID:[$pid], PORT:[$alreadyStartPort]"

for item in ${PORT[@]}
do
if((item != $alreadyStartPort))
then
#启动此端口的服务
echo "start another jetty PORT:[$item]"
start $item

sleep 2

if shutdownServer $pid
then
echo "Ok! old server shutdown, PID:[$pid], PORT:[$alreadyStartPort]"
else
echo "fail! server shutdown, PID:[$pid], PORT:[$alreadyStartPort]"
fi
fi
done
}

case"$1"in
start)
echo "Starting Jetty..."
start
echo "End"
;;

stop)
echo "Stopping Jetty..."
stop
echo "End"
;;

switch)
echo "Switching Jetty..."
switch
echo "End"
;;
esac

exit0

jetty war包解压设置

自定义的解压路径设置比较复杂,最简的就是在jetty根目录下增加一work目录,jetty就会把war包解压路径放在work下面

jetty根目录下的start.ini可以配置jvm的一些参数,简要示例如下,在末尾添加以下参数:

--exec
-Xmx1024m
-Xms1024m
-Xmn512m
-XX:PermSize=128m
-XX:MaxPermSize=128m
-XX:MaxTenuringThreshold=7
-XX:GCTimeRatio=19
-XX:+UseConcMarkSweepGC
-XX:ParallelGCThreads=8
-XX:+CMSClassUnloadingEnabled
-XX:+UseCMSCompactAtFullCollection
-XX:CMSFullGCsBeforeCompaction=5
-XX:-CMSParallelRemarkEnabled
-XX:+DisableExplicitGC
-XX:CMSInitiatingOccupancyFraction=70
-XX:SoftRefLRUPolicyMSPerMB=0

jetty根目录下的start.d下的http.ini可以配置使用start.jar启动时使用的端口,此处如果使用了第二步standalone方式的启动形式,则最好把jetty.port注掉,否则有可能会有冲突

etc/jetty-http.xml可配置jetty总的监听端口

时间: 2024-08-02 10:44:44

jetty在Linux下的配置的相关文章

Linux下安装配置Apache服务器

Linux下安装配置Apache服务器 1. 安装Apache [[email protected] ~]# yum –y install httpd 2. 启动Apache [[email protected] ~]# systemctl start httpd 3. 查看进程 [[email protected] ~]# systemctl status httpd httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib

Linux下的配置iptables防火墙增强服务器安全

Linux下的配置iptables防火墙增强服务器安全 实验要求 iptables常见概念 iptables服务器安装及相关配置文件 实战:iptables使用方法 例1:使用iptables防火墙保护公司web服务器 例2:使用iptables搭建路由器,通过SNAT使用内网机器上网 例3:限制某些IP地址访问服务器 例4:使用DNAT功能把内网web服务器端口映射到路由器外网 实验环境 iptables服务端:xuegod-63   IP:192.168.1.63 iptables客户端:x

Ubuntu Linux下如何配置Android开发环境

下载和安装Win7系统Android开发环境中讲了怎样在Win7系统中安装Android开发环境,那么怎样在Linux系统中配置Android开发环境呢?本篇文章就将演示如何使用Eclipse.Android SDK和PhoneGap在Ubuntu 11.04环境下配置Android开发环境. 以下是在Ubuntu linux系统中配置Android开发环境的几个步骤:        1.安装Eclipse和Android SDK/PhoneGap所需软件包: 打开终端,输入下面命令完成题目所述

linux下apache配置

Apache简介 Apache源于NCSAhttpd服务器,经过多次修改,成为世界上最流行的Web服务器软件之一.Apache取自"a patchy server"的读音,意思是充满补丁的服务器,因为它是自由软件,所以不断有人来为它开发新的功能.新的特性.修改原来的缺陷.Apache的特点是简单.速度快.性能稳定,并可做代理服务器来使用. 环境拓扑: LinuxClient ----------RHEL5.9(vmnet1)----------(vmnet1) Win7Client 前

LInux下iptables配置

linux下IPTABLES配置详解 如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 我们来配置一个filter表的防火墙. (1)查看本机关于IPTABLES的设置情况 [[email protected] ~]# iptables -L -nChain INPUT (policy ACCEPT)target       prot opt source                 destination Chain FORWARD (policy ACCEPT)targ

linux下eclipse配置jdk

今天在ubuntu12.04上安装了eclipse,本以为安装完eclipse后,还需要配置jdk,但没有想到eclipse自动已经配好了(但主要原因是我的linux中只安装了一个jdk,如果有两个以上的JDK版本可能就需要更改了).那么如果系统没有配置或者配置的jdk不是我们想要的jdk,那么我们如何做呢?我参考了这片博客:http://blog.csdn.net/clj198606061111/article/details/11881575,讲的很清晰.如下: window -> pref

linux下安装配置tomcat以及tomcat开机自启配置

Linux下Tomcat安装配置以及Windows不能连接服务器Tomcat解决方案 一.从官方网站上下载tomcat软件包. 官网地址: http://tomcat.apache.org/ 点击左侧的 download的一个版本,我选择的是 tomcat7.0,选择一个后缀名为.tar.gz文件直接下载到本地. 二.通过工具SSH Secure 上传至linux服务器中,进行解压 解压tomcat压缩文件: #tar zxvf apache-tomcat-7.0.53.tar.gz 将解压后的

Linux下安装配置Nexus

一.安装和运行nexus 1.下载nexus:http://www.sonatype.org/nexus/go 可选择tgz和zip格式,以及war,选择tgz或zip时不同版本可能在启动时存在一定问题,可能是因为jdk版本问题,若无法启动请选择2.5或更早的版本 注:nexus 2.6版本之后不再支持jdk1.6 2.安装nexus 若下载war,则将其放置tomcat下的webapp目录中,改名为nexus,运行tomcat服务,即可访问http://localhost:8081/nexus

linux下IPTABLES配置详解 (防火墙命令)

linux下IPTABLES配置详解 -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 24000 -j ACCEPT-A RH-Firewall-1-INPUT -s 121.10.120.24 -p tcp -m tcp --dport 18612 -j ACCEPT 如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 我们来配置一个filter表的防火墙. (1)查看本机关于IPTABLES的