Jetty 9.4.12 Installation and Configuration
1 OS Configuration :
# TCP buffers
sysctl -w net.core.rmem_max=16777216
sysctl -w net.core.wmem_max=16777216
sysctl -w net.ipv4.tcp_rmem=
"4096 87380 16777216"
sysctl -w net.ipv4.tcp_wmem=
"4096 16384 16777216"
#queue sizes
sysctl -w net.core.somaxconn=4096
sysctl -w net.core.netdev_max_backlog=16384
sysctl -w net.ipv4.tcp_max_syn_backlog=8192
sysctl -w net.ipv4.tcp_syncookies=1
#Ports
sysctl -w net.ipv4.ip_local_port_range=
"1024 65535"
sysctl -w net.ipv4.tcp_tw_recycle=1
#File Descriptors, edit /etc/security/limits.conf
theusername hard nofile 40000
theusername soft nofile 40000
#Congestion Control
sysctl net.ipv4.tcp_available_congestion_control
sysctl -w net.ipv4.tcp_congestion_control=cubic
|
2 Download Jetty Package:
You need to download it and put it to the OS Image.
wget https:
//repo1
.maven.org
/maven2/org/eclipse/jetty/jetty-distribution/9
.4.12.v20180830
/jetty-distribution-9
.4.12.v20180830.
tar
.gz
wget https:
//repo1
.maven.org
/maven2/org/eclipse/jetty/jetty-distribution/9
.4.12.v20180830
/jetty-distribution-9
.4.12.v20180830.zip.md5
|
3 Prerequsite
JDK installed.
4 Create service account for Jetty
useradd
-m jetty
echo
"umask 002"
>>
/home/jetty/
.bash_profile
|
5 Unzip the Jetty packet to /opt/jetty
6 Create necessary directories.
mkdir
-p
/opt/apps_backup
#for CICD pipeline backup previous war packages
mkdir
-p
/opt/jetty/apps/work
#Jetty used internally
mkdir
-p
/opt/jetty/apps/union
#for key files which applications use
mkdir
-p
/app/appLogs/
#Applicatin logs
mkdir
/var/run/jetty
|
7 Add Jetty to system service
chown
-R jetty:jetty
/opt/jetty/
ln
-s
/opt/jetty/bin/jetty
.sh
/etc/init
.d
/jetty
chkconfig --add jetty
systemctl
enable
jetty
|
8 Configure Jetty
cd
/opt/jetty/apps
java -jar
/opt/jetty/start
.jar --add-to-start=http,deploy,jvm,threadpool,threadlimit,jmx,jsp,servlet,websocket,jstl,server,resources,ext,home-base-warning,console-capture
chown
-R jetty:jetty
/opt/jetty/apps
chown
-R jetty:jetty
/opt/jetty/
chown
-R jetty:jetty
/app/appLogs
chown
-R jetty:jetty
/opt/apps_backup
#modify the port you want in /opt/jetty/apps/start.init
#Tune the JVM memory and add -server option, thread_pool setting in /opt/jetty/apps/start.ini (uncomment --exec and -Xmx,-Xms set proper size and the GC section)
#1)usually set Xmx to 50%+ of Physical memory
#2)Be caution when set threadpool:MaxThreads, don't set it too high (memory overflow) as the default thread stack size(-Xss) is 1024K after JDK 5.
#Configure the number of threads according to the webapp. That is, how many threads it needs in order to achieve the best performance. Configure with mind to limiting memory usage maximum available. Typically >50 and <500.
Modify the character setting
for
jetty
open
the
file
/opt/jetty/etc/webdefault
.xml
change
"<encoding>ISO-8859-1</encoding>"
to
"<encoding>UTF-8</encoding>"
|
9 Add environment variables
vi
/etc/default/jetty
and put
in
################################
JETTY_HOME=
/opt/jetty
JETTY_BASE=
/opt/jetty/apps
JETTY_USER=jetty
JETTY_RUN=
/opt/jetty/apps
################################
vi
/etc/profile
and add
################################
JETTY_HOME=
/opt/jetty
JETTY_BASE=
/opt/jetty/apps
JAVA_HOME=
/usr/lib/jvm/java-1
.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64
APP_LOGS_PATH=
/app/appLogs/
################################
source
/etc/profile
|
10 add OS users for Jetty
useradd
appuser
# this user can be added to bastion host, it has read only privileges to view the logs.
useradd
-g jetty appowner
# this usre can be added to bastion host, it can control the jetty service by issuing service jetty start/stop/status
useradd
-g jetty appdeploy
# this user is to deploy WAR packages for pipeline.
echo
"umask 002"
>>
/home/appdeploy/
.bash_profile
chmod
771
/opt/jetty/apps/union
chmod
771
/opt/jetty/apps/logs
chmod
771
/opt/jetty/apps/webapps
chmod
771
/opt/apps_backup
chmod
771
/opt/jetty/apps/work
echo
"<your password>"
|
passwd
appuser --stdin &>
/dev/null
echo
"<your password>"
|
passwd
appowner --stdin &>
/dev/null
echo
"<your password>"
|
passwd
appdeploy --stdin &>
/dev/null
id
appuser
id
appowner
echo
"appowner ALL=(root) NOPASSWD: /sbin/service jetty stop,/sbin/service jetty start, /sbin/service jetty status"
>>
/etc/sudoers
echo
"appdeploy ALL=(root) NOPASSWD: /sbin/service jetty stop,/sbin/service jetty start, /sbin/service jetty status"
>>
/etc/sudoers
|
11 add jetty setup script on boot
#!/bin/bash
set
-x
JETTY_INI=
/opt/jetty/apps/start
.ini
#get current physical memory setting
mem_size=`
free
-m |
grep
Mem |
awk
'{print $2}'
`
#set jetty JVM xmx to 50% of mem
jmem=$(($mem_size
/2
))
jmem=
"-Xmx"
$jmem
"m"
#replace 166
sed
-i
"166c $jmem"
$JETTY_INI
sed
-i
'165,172s/#//g'
$JETTY_INI
sed
-i
'174,179s/#//g'
$JETTY_INI
|