[Ubuntu 20.04] Tomcat8 ์„ค์น˜

2021. 1. 22. 01:19ใ†System ์ž‘์—…์‹ค/LINUX

728x90
๋ฐ˜์‘ํ˜•

์•ˆ๋…•ํ•˜์„ธ์š”? ์ฃผ๋‹ˆํ•˜๋ž‘ ์ž…๋‹ˆ๋‹ค.

์˜ค๋Š˜์€ Synology NAS์— ์„ค์น˜ํ•œ Docker ์•ˆ Ubuntu 20.04์— Tomcat8๋ฅผ ์„ค์น˜๋ฅผ ํ•ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

Ubuntu์— ๊ธฐ๋ณธ ์„ค์ •์— ๋Œ€ํ•ด์„œ๋Š” '[Ubuntu 20.04] Apache2 ์„ค์น˜' ํฌ์ŠคํŒ… ์—ด์–ด ๋‘๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

 

์•„ํŒŒ์น˜ ํ†ฐ์บฃ 7 ๋”ฐ๋ผ์žก๊ธฐ

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 


 

 

๐Ÿ“Œ JDK ์„ค์น˜


๋”๋ณด๊ธฐ

          ๐Ÿ‘‰ apt๋กœ ์ง€์ •๋œ Site(/etc/apt/source.list)์— openjdk-8์ด ์žˆ๋Š”์ง€ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค.

 

          ๐Ÿ‘‰JDK๊ฐ€ ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธ ํ•˜์˜€์œผ๋‹ˆ ์„ค์น˜ ํ•ด ์ฃผ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

          ๐Ÿ‘‰ ์ •์ƒ์ ์œผ๋กœ ์„ค์น˜๊ฐ€ ์™„๋ฃŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

         

          ๐Ÿ‘‰์ž๋ฐ”๊ฐ€ ์„ค์น˜๋œ ์œ„์น˜๋ฅผ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

          ๐Ÿ‘‰ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๊ฑธ์–ด ์ฃผ๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

 

 

๐Ÿ“Œ Tomcat8 ์„ค์น˜


๋”๋ณด๊ธฐ

          ๐Ÿ‘‰ OS์— Apache2 ํŒจํ‚ค์ง€๊ฐ€ ์ด๋ฏธ ์„ค์น˜๋˜์—ˆ๋Š”์ง€ ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

         

          ๐Ÿ‘‰ ๋งŒ์•ฝ ์„ค์น˜๊ฐ€ ๋˜์ง€ ์•Š์•˜๋‹ค๋ฉด Listing Line๋’ค์— ์•„๋ฌด๊ฒƒ๋„ ๋‚˜์˜ค์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

 

์ฃผ๋‹ˆํ•˜๋ž‘์˜ Ubuntu๋Š” Tomcat์ด ์„ค์น˜๋˜์–ด ์žˆ์ง€ ์•Š๋‚˜ ๋ณด๋„ค์š”!

 

 

           ๐Ÿ‘‰ wget๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•ด์„œ ์„ค์น˜ ํ•ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. (/usr ๋ฐ‘์— ๋ฐ›์•„์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.)

 

 

 

 

         ๐Ÿ‘‰ ๋‚ด๋ ค๋ฐ›๊ธฐ๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด ์••์ถ•์„ ํ•ด์ œํ•˜์—ฌ ์ฃผ์„ธ์š”!

 

         ๐Ÿ‘‰ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๊ฑธ์–ด์ฃผ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

       

         ๐Ÿ‘‰ wget๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•ด์„œ ์„ค์น˜ ํ•ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. (/usr ๋ฐ‘์— ๋ฐ›์•„์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.)

         ๐Ÿ‘‰ ๋ฒ„์ „ ํ™•์ธ์„ ํ†ตํ•ด ์ •์ƒ์ ์œผ๋กœ ์„ค์น˜๋œ ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

 

๐Ÿ“Œ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ •


๋”๋ณด๊ธฐ

         ๐Ÿ‘‰ ๋ฐฉํ™”๋ฒฝ ์˜คํ”ˆ

                  ufw allow 8080

 

 

         ๐Ÿ‘‰ ํ™˜๊ฒฝ ๋ณ€์ˆ˜ (etc/profile)

vim /etc/profile

 

         ๐Ÿ‘‰ ์œ„์™€ ๊ฐ™์ด JAVA์™€ Tomcat ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ•˜์—ฌ ์ค๋‹ˆ๋‹ค.

 

 

         ๐Ÿ‘‰ Tomcat ๊ธฐ๋™

         ๐Ÿ‘‰ tomcat์ด ์„ค์น˜๋œ ๊ณณ bin ๋””๋ ‰ํ„ฐ๋ฆฌ์—์„œ ./startup.sh๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ธฐ๋™ ์‹œ์ผœ ์ค๋‹ˆ๋‹ค.

 

         ๐Ÿ‘‰ Tomcat ์ •์ƒ ๊ธฐ๋™ ๋ชจ์Šต

Host PC Web Browser์—์„œ ์ •์ƒ ์ ‘์† ๋ชจ์Šต

๐Ÿ’ก ์งœ์ž”!

์ •์ƒ์ ์œผ๋กœ ๊ธฐ๋™์ด ์™„๋ฃŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!

 

์•„๋ž˜ ๋‚ด์šฉ์„ ์ง„ํ–‰ํ•˜์‹œ๊ธฐ ์ „ Tomcat์„ ์ข…๋ฃŒํ•˜์—ฌ ์ฃผ์„ธ์š”.

root@localhost: ./shutdown.sh

 


๐Ÿ“Œ์„œ๋น„์Šค ๋“ฑ๋ก

         ๐Ÿ‘‰ ๊ณ„์ • ์ƒ์„ฑ

 

         ๐Ÿ‘‰ ์„œ๋น„์Šค ๋“ฑ๋ก (/etc/systemd/system์— tomcat.service ์ƒˆ๋กœ ์ž‘์„ฑ)

# Systemd unit file for tomcat 
[Unit] 
Description=Apache Tomcat Web Application Container 
After=syslog.target network.target 

[Service] Type=forking 

Environment="JAVA_HOME=/usr/lib/java" 
Environment="CATALINA_PID=/usr/tomcat/temp/tomcat.pid"
Environment="CATALINA_HOME=/usr/tomcat"
Environment="CATALINA_BASE=/usr/tomcat" 
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC" 
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom" 

ExecStart=/usr/tomcat/bin/startup.sh 
ExecStop=/usr/tomcat/bin/shutdown.sh 

User=tomcat 
Group=tomcat 
UMask=0007 
RestartSec=10 
Restart=always 

[Install] 
WantedBy=multi-user.target

         ๐Ÿ‘‰ ์œ„์™€ ๊ฐ™์ด ํŒŒ์ผ์„ ์ž‘์„ฑํ•˜์—ฌ ์ฃผ์‹œ๊ณ  ์ €์žฅ์„ ํ•˜์‹  ๋’ค์—

root@localhost: systemctl daemon-reload

 

         ๐Ÿ‘‰ OS ๋ถ€ํŒ…์‹œ ์ž๋™์‹œ์ž‘ ์Šคํฌ๋ฆฝํŠธ

         ๐Ÿ‘‰ /etc/init.d ๋ฐ‘์— tomcat ํŒŒ์ผ์„ ํ•˜๋‚˜ ๋งŒ๋“œ์‹  ๋’ค ๊ถŒํ•œ์„ 755๋กœ ์„ค์ • ํ•ด ์ค๋‹ˆ๋‹ค.

root@localhost: chmod 755 tomcat

#!/bin/sh 
#
# /etc/init.d/tomcat -- startup script for the Tomcat 8 servlet engine 
# 
# Modified init-Script from Ubuntu Tomcat init-script 
# 
# ### BEGIN INIT INFO # Provides: tomcat 
# Required-Start: $local_fs $remote_fs $network 
# Required-Stop: $local_fs $remote_fs $network 
# Should-Start: $named # Should-Stop: $named 
# Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 
# Short-Description: Start Tomcat. 
# Description: Start the Tomcat servlet engine. 
### END INIT INFO 
set -e 

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/tomcat 
NAME=tomcat 
DESC="Tomcat servlet engine" 
DEFAULT=/etc/default/$NAME 
JVM_TMP=/tmp/tomcat-tmp 

if [ `id -u` -ne 0 ]; then 
	echo "You need root privileges to run this script" 
	exit 1 
fi 

# Make sure tomcat is started with system locale 
if [ -r /etc/default/locale ]; then 
	. /etc/default/locale 
    export LANG 
fi 

. /lib/lsb/init-functions 

if [ -r /etc/default/rcS ]; then 
	. /etc/default/rcS 
fi 

# The following variables can be overwritten in $DEFAULT 

# Run Tomcat 8 as this user ID and group ID 
TOMCAT_USER=tomcat 
TOMCAT_GROUP=tomcat 

# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not # defined in $DEFAULT) 
JDK_DIRS="/usr/lib/java"

# Look for the right JVM to use 
for jdir in $JDK_DIRS; do 
	if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then 
    	JAVA_HOME="$jdir" 
 	fi 
    done 
    
    export JAVA_HOME=/usr/lib/java 
    
    # Directory where the Tomcat binary distribution resides 
    CATALINA_HOME=/usr/$NAME 
    
    # Directory for per-instance configuration files and webapps 
    CATALINA_BASE=/usr/$NAME 
    
    # Use the Java security manager? (yes/no) 
    TOMCAT_SECURITY=no 
    
    # Default Java options 
    # Set java.awt.headless=true if JAVA_OPTS is not set so the 
    # Xalan XSL transformer can work without X11 display on JDK 1.4+ 
    # It also looks like the default heap size of 64M is not enough for most cases 
    # so the maximum heap size is set to 128M 
    if [ -z "$JAVA_OPTS" ]; then 
    	JAVA_OPTS="-Djava.awt.headless=true -Xmx128M" 
    fi 
    
    # End of variables that can be overwritten in $DEFAULT 
    
    # overwrite settings from default file 
 if [ -f "$DEFAULT" ]; then 
 	. "$DEFAULT" 
 fi 
 
 if [ ! -f "$CATALINA_HOME/bin/bootstrap.jar" ]; then 
 	log_failure_msg "$NAME is not installed" 
    exit 1 
 fi 
 
 POLICY_CACHE="$CATALINA_BASE/work/catalina.policy" 
 
 if [ -z "$CATALINA_TMPDIR" ]; then 
 	CATALINA_TMPDIR="$JVM_TMP" 
 fi 
 
 # Set the JSP compiler if set in the tomcat.default file 
 if [ -n "$JSP_COMPILER" ]; then 
 	JAVA_OPTS="$JAVA_OPTS -Dbuild.compiler=\"$JSP_COMPILER\"" 
 fi 
 
 SECURITY="" 
 
 if [ "$TOMCAT_SECURITY" = "yes" ]; then 
 	SECURITY="-security" 
 fi 
 
 # Define other required variables 
 CATALINA_PID="/var/run/$NAME.pid" 
 CATALINA_SH="$CATALINA_HOME/bin/catalina.sh" 
 
 # Look for Java Secure Sockets Extension (JSSE) JARs 
 if [ -z "${JSSE_HOME}" -a -r "${JAVA_HOME}/jre/lib/jsse.jar" ]; then 
 	JSSE_HOME="${JAVA_HOME}/jre/" 
 fi 
 
 catalina_sh() { 
	 # Escape any double quotes in the value of JAVA_OPTS 
 	 JAVA_OPTS="$(echo $JAVA_OPTS | sed 's/\"/\\\"/g')" 
     
     AUTHBIND_COMMAND="" 
     if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then 
     	JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true" 
        AUTHBIND_COMMAND="/usr/bin/authbind --deep /bin/bash -c " 
     fi 
     
     # Define the command to run Tomcat's catalina.sh as a daemon 
     # set -a tells sh to export assigned variables to spawned shells. 
     TOMCAT_SH="set -a; JAVA_HOME=\"$JAVA_HOME\"; source \"$DEFAULT\"; \ 
     	CATALINA_HOME=\"$CATALINA_HOME\"; \ 
        CATALINA_BASE=\"$CATALINA_BASE\"; \ 
        JAVA_OPTS=\"$JAVA_OPTS\"; \ 
        CATALINA_PID=\"$CATALINA_PID\"; \ 
        CATALINA_TMPDIR=\"$CATALINA_TMPDIR\"; \ 
        LANG=\"$LANG\"; JSSE_HOME=\"$JSSE_HOME\"; \ 
        cd \"$CATALINA_BASE\"; \ 
        \"$CATALINA_SH\" $@" 
        if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then 
        	TOMCAT_SH="'$TOMCAT_SH'" 
        fi 
        # Run the catalina.sh script as a daemon 
        set +e 
        touch "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out 
        chown $TOMCAT_USER "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out 
        start-stop-daemon --start -b -u "$TOMCAT_USER" -g "$TOMCAT_GROUP" \ 
        	-c "$TOMCAT_USER" -d "$CATALINA_TMPDIR" \ 
        	-x /bin/bash -- -c "$AUTHBIND_COMMAND $TOMCAT_SH" 
        status="$?" 
        set +a -e 
        return $status 
} 

case "$1" in 
	start) 
    	if [ -z "$JAVA_HOME" ]; then 
        	log_failure_msg "no JDK found - please set JAVA_HOME"
            exit 1 
        fi
        
        if [ ! -d "$CATALINA_BASE/conf" ]; then 
        	log_failure_msg "invalid CATALINA_BASE: $CATALINA_BASE" 
            exit 1 
        fi 
        
        log_daemon_msg "Starting $DESC" "$NAME" 
        if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ 
        	--user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \ 
            >/dev/null; then 
            
            # Regenerate POLICY_CACHE file 
            umask 022
            echo "// AUTO-GENERATED FILE from /opt/tomcat/" \ 
            		> "$POLICY_CACHE" 
            echo "" >> "$POLICY_CACHE" 
            cat $CATALINA_BASE/conf/*.policy \ 
            		>> "$POLICY_CACHE" 
                    
            # Remove / recreate JVM_TMP directory 
            rm -rf "$JVM_TMP" 
            mkdir -p "$JVM_TMP" || { 
            	log_failure_msg "could not create JVM temporary directory" 
                exit 1 
            } 
            chown $TOMCAT_USER "$JVM_TMP" 
            
            catalina_sh start $SECURITY 
            sleep 5 
            if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ 
            	--user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \ 
                >/dev/null; then if [ -f "$CATALINA_PID" ]; then 
                	rm -f "$CATALINA_PID" 
            fi 
            	log_end_msg 1 
            else 
            	log_end_msg 0 
            fi 
      else 
      		log_progress_msg "(already running)" 
            log_end_msg 0 
            
       fi 
       ;; 
  stop) 
  		log_daemon_msg "Stopping $DESC" "$NAME" 
        
        set +e 
        if [ -f "$CATALINA_PID" ]; then 
        	start-stop-daemon --stop --pidfile "$CATALINA_PID" \
            	--user "$TOMCAT_USER" \ 
                --retry=TERM/20/KILL/5 >/dev/null 
        if [ $? -eq 1 ]; then 
        		log_progress_msg "$DESC is not running but pid file exists, cleaning up" 
        elif [ $? -eq 3 ]; then 
        	PID="`cat $CATALINA_PID`" 
            log_failure_msg "Failed to stop $NAME (pid $PID)" 
            exit 1 
        fi 
        rm -f "$CATALINA_PID" 
        rm -rf "$JVM_TMP" 
   	else log_progress_msg "(not running)" 
   	fi 
    log_end_msg 0 
    set -e
    ;; 
status) 
	set +e 
    start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ 
    --user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \ 
    >/dev/null 2>&1 
    if [ "$?" = "0" ]; then 
    	
        if [ -f "$CATALINA_PID" ]; then 
        	log_success_msg "$DESC is not running, but pid file exists." 
           		exit 1 
        else log_success_msg "$DESC is not running." 
        		exit 3 
        fi 
     else 
     	log_success_msg "$DESC is running with pid `cat $CATALINA_PID`" 
     fi 
     set -e 
     ;;
restart|force-reload)
	if [ -f "$CATALINA_PID" ]; then 
    	$0 stop 
        sleep 1 
    fi 
    $0 start 
    ;; 
try-restart)
	if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ 
    	--user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \ 
        >/dev/null; then 
        $0 start 
    fi 
    ;; 
*) 
	log_success_msg "Usage: $0 {start|stop|restart|try-restart|force-reload|status}" 
    exit 1 
    ;; 
esac 

exit 0

 

         ๐Ÿ‘‰ JAVA_HOME, CATALINA_HOME, Tomcat ๊ณ„์ •,

              ๋””๋ ‰ํ„ฐ๋ฆฌ๋Š” ๊ฐ์ž์— ํ™˜๊ฒฝ์— ๋งž๊ฒŒ ์ž˜ ์„ค์ • ํ•ด์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

 

 

์—ฌ๊ธฐ๊นŒ์ง€ ์ž˜ ๋˜์…จ๋‹ค๋ฉด ์ถ•ํ•˜๋“œ๋ฆฝ๋‹ˆ๋‹ค! Tomcat์ด ์ •์ƒ ์„ค์น˜ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!

 


 

 

์•„ํŒŒ์น˜ ํ†ฐ์บฃ 7 ๋”ฐ๋ผ์žก๊ธฐ

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

์ฃผ๋‹ˆํ•˜๋ž‘์˜ ์ด๋ฒˆ ํฌ์ŠคํŒ…์ด ์–ด๋– ์…จ๋‚˜์š”? ๊ตฌ๋…, ๊ณต๊ฐ๊ณผ ๋Œ“๊ธ€์€ ์ฃผ๋‹ˆํ•˜๋ž‘์—๊ฒŒ ๋งค์šฐ ํฐ ํž˜์ด ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค!

728x90
๋ฐ˜์‘ํ˜•

'System ์ž‘์—…์‹ค > LINUX' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Ubuntu 20.04] JDK 14์™€ IDE ์„ค์น˜  (0) 2021.02.21
[Ubuntu 20.04] Vmware์— Ubuntu ์„ค์น˜  (0) 2021.02.20
[Ubuntu 20.04] Apache2 ์„ค์น˜  (0) 2021.01.20
[CentOS7] MariaDB ์„ค์น˜  (2) 2021.01.19
[CentOS7] Apache + PHP ์„ค์น˜  (2) 2021.01.19