라즈베리파이 Apache2 + Tomcat8 설치 (MOD_JK)

https://ryans-log.tistory.com/entry/install-apache-tomcat-and-modejk



절차를 미리 정리 하면...

-. 관련 패키지 일괄 설치

-. 설치된 Apache, Tomcat 동작 확인

.- Apache와 Tomcat 연결 (mod-jk 설정)

.- 잘 연결 했는가?



무엇보다 먼저 패키지 매니저를 업데이트 한다.

> sudo apt-get update



총 3개의 패키지(Apache2, Tomcat8, libapache2-mod-jk)를 설치한다.

참고로 libapache2-mod-jk는 Apache와 Tomcat을 연결하는 Apache의 모듈이다.

> sudo apt-get install apache2 tomcat8 libapache2-mod-jk

> sudo apt-get install apache2 tomcat9 libapache2-mod-jk


설치 후 브라우저에서 Apache와 Tomcat의 동작상태를 각각 확인한다.


Apache는 포트 80을 사용하므로 그냥 IP만

https://your-server-ip

Tomcat은 기본 포트 8080을 사용하므로 IP:8080

https://your-server-ip:8080

사실 여기까지는 뭐 apt-get 한방으로 끝났으나...

앞으로 진행될 mod-jk는 눈 똑바로 뜨고 진행해야 ~~



우선 Apache 설정에서 VirtualHost를 찾는다.

Apache보다 Tomcat과 친하게 지내느라 흐릿해진 내 기억속에 Apache 설정 파일은 분명 httpd.conf 였었는데 2.0부터 인가보다. apache2.conf 로 변경됬으며 Virtual Host 설정도 sites라는 이름으로 분리(파일도 분리)된 것이라 굳게 믿고

./sites-enabled 하위에 포트 80에 대한 Virtual Host를 정의한 파일을 찾아 JkMount 설정을 추가한다.

> sudo vi /etc/apache2/sites-enabled/000-default.conf


<VirtualHost> 태그 안에 아래 추가

JkMount /* ajp13_worker



?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com
 
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        JkMount /* ajp13_worker
 
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
 
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
 
        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
 
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet




위에 정의한 ajp13_worker의 정의는 workers.properties에서 찾을 수 있다.

> sudo vi /etc/libapache2-mod-jk/workers.properties

-> 이건 무시해도 됨


workers.properties에 대부분이 정상으로 작성되어 있으나 Java HOME은 없는 경로로 작성되어 있다.

아래를 /usr/lib/jvm 아래 있는 JDK로 올바르게 수정(여러 버전이 설치되어 있을 수 있으니...)

workers.java_home=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt

-> 라즈4에서 설치해보니까 알아서 잘 들어가 있음



마지막으로 Tomcat에 AJP프로토콜을 열어준다.

> sudo vi /etc/tomcat8/server.xml

-> nano가 편하다


아래라인 주석 해제하고, 겸사겸사 URIEncoding="UTF-8"도 추가

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>

<Connector protocol="AJP/1.3" address="::1" port="8009" redirectPort="8443" secretRequired="false" />

-> 기존거 뭐 지우란 소리가 아니라 새로 추가하면 된다


이제 두 서버를 사이좋게 재시작한다.

> sudo service tomcat8 restart

> sudo service apache2 restart


이제 포트 80을 호출해도 Tomcat의 It Works!가 열린다.

https://your-server-ip

Tomcat의 포트 8080을 막고자 할 때는 server.xml에서 다음 Connector를 삭제한다.

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />


JSP등 특정 URL 패턴만 Tomcat이 처리하도록 할 경우 (보통 정적파일은 Apache가 처리하는게 빠르니까) 000-default.conf의 JkMount 설정을 편집한다.

JkMount /*.jsp ajp13_worker





여기까지 잘 안된경우..

apache 설정에 mod-jk를 강제로 추가해본다.

> sudo vi /etc/apache2/apache2.conf


apache2.conf의 가장 마지막 라인 뒤에 Load Module 한다.

LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so


본래 mod_jk.so가 자동으로 얹혀저야 하나 잘 ㅇ ㄷ ㄴ ㅂ ㅈ ㅝ



아래는 내 파이의 workers.properties
?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

# workers.properties -
#
# This file is a simplified version of the workers.properties supplied
# with the upstream sources. The jni inprocess worker (not build in the
# debian package) section and the ajp12 (deprecated) section are removed.
#
# As a general note, the characters $( and ) are used internally to define
# macros. Do not use them in your own configuration!!!
#
# Whenever you see a set of lines such as:
# x=value
# y=$(x)\something
#
# the final value for y will be value\something
#
# Normaly all you will need to do is un-comment and modify the first three
# properties, i.e. workers.tomcat_home, workers.java_home and ps.
# Most of the configuration is derived from these.
#
# When you are done updating workers.tomcat_home, workers.java_home and ps
# you should have 3 workers configured:
#
# - An ajp13 worker that connects to localhost:8009
# - A load balancer worker
#
#
 
# OPTIONS ( very important for jni mode )
 
#
# workers.tomcat_home should point to the location where you
# installed tomcat. This is where you have your conf, webapps and lib
# directories.
#
workers.tomcat_home=/usr/share/tomcat8
 
#
# workers.java_home should point to your Java installation. Normally
# you should have a bin and lib directories beneath it.
#
workers.java_home=/usr/lib/jdk/jdk-8-oracle-arm32-vfp-hflt
 
#
# You should configure your environment slash... ps=\ on NT and / on UNIX
# and maybe something different elsewhere.
#
ps=/
 
#
#------ ADVANCED MODE ------------------------------------------------
#---------------------------------------------------------------------
#
 
#
#------ worker list ------------------------------------------
#---------------------------------------------------------------------
#
#
# The workers that your plugins should create and work with
#
worker.list=ajp13_worker
 
#
#------ ajp13_worker WORKER DEFINITION ------------------------------
#---------------------------------------------------------------------
#
 
#
# Defining a worker named ajp13_worker and of type ajp13
# Note that the name and the type do not have to match.
#
worker.ajp13_worker.port=8009
worker.ajp13_worker.host=localhost
worker.ajp13_worker.type=ajp13
#
# Specifies the load balance factor when used with
# a load balancing worker.
# Note:
#  ----> lbfactor must be > 0
#  ----> Low lbfactor means less work done by the worker.
worker.ajp13_worker.lbfactor=1
 
#
# Specify the size of the open connection cache.
#worker.ajp13_worker.cachesize
 
#
#------ DEFAULT LOAD BALANCER WORKER DEFINITION ----------------------
#---------------------------------------------------------------------
#
 
#
# The loadbalancer (type lb) workers perform wighted round-robin
# load balancing with sticky sessions.
# Note:
#  ----> If a worker dies, the load balancer will check its state
#        once in a while. Until then all work is redirected to peer
#        workers.
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=ajp13_worker




출처: https://ryans-log.tistory.com/entry/install-apache-tomcat-and-modejk [Ryan's Log]

Subscribe to X세대 신입사원

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe
774-86-01972 cinnabar.3d@gmail.com