Apache로 Tomcat 로드밸런싱 설정

Programming/Apache, PHP 2021. 4. 10. 13:04 Posted by 파란크리스마스

출처

필수 라이브러리 설치

bluesanta@bluesanta-desktop:~$ sudo apt install libexpat1-dev libssl-dev

PCRE 설치

bluesanta@bluesanta-desktop:~$ wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
bluesanta@bluesanta-desktop:~$ tar xvf pcre-8.44.tar.gz 
bluesanta@bluesanta-desktop:~$ cd pcre-8.44/
bluesanta@bluesanta-desktop:~/pcre-8.44$ ./configure --prefix=/usr/local/pcre-8.44
bluesanta@bluesanta-desktop:~/pcre-8.44$ make
bluesanta@bluesanta-desktop:~/pcre-8.44$ sudo make install

Apache 웹서버 설치

bluesanta@bluesanta-desktop:~$ wget https://archive.apache.org/dist/httpd/httpd-2.4.39.tar.gz
bluesanta@bluesanta-desktop:~$ tar xvf httpd-2.4.39.tar.gz 
bluesanta@bluesanta-desktop:~$ cd httpd-2.4.39/
bluesanta@bluesanta-desktop:~/httpd-2.4.39$ cd srclib
bluesanta@bluesanta-desktop:~/httpd-2.4.39/srclib$ wget https://archive.apache.org/dist/apr/apr-1.7.0.tar.gz
bluesanta@bluesanta-desktop:~/httpd-2.4.39/srclib$ tar xvfz apr-1.7.0.tar.gz
bluesanta@bluesanta-desktop:~/httpd-2.4.39/srclib$ mv apr-1.7.0 apr
bluesanta@bluesanta-desktop:~/httpd-2.4.39/srclib$ wget https://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz
bluesanta@bluesanta-desktop:~/httpd-2.4.39/srclib$ tar xvfz apr-util-1.6.1.tar.gz
bluesanta@bluesanta-desktop:~/httpd-2.4.39/srclib$ mv apr-util-1.6.1 apr-util
bluesanta@bluesanta-desktop:~/httpd-2.4.39/srclib$ wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
bluesanta@bluesanta-desktop:~/httpd-2.4.39/srclib$ tar xvfz pcre-8.44.tar.gz
bluesanta@bluesanta-desktop:~/httpd-2.4.39/srclib$ mv pcre-8.44 pcre
bluesanta@bluesanta-desktop:~/httpd-2.4.39/srclib$ cd ..
bluesanta@bluesanta-desktop:~/httpd-2.4.39$ ./configure --prefix=/opt/apache24 --with-pcre=/usr/local/pcre-8.44 --enable-cgi --enable-info --enable-deflate --enable-ssl --enable-proxy --enable-proxy-connect --enable-proxy-http --enable-proxy-ftp --enable-expires --enable-headers --enable-rewrite --enable-so --with-included-apr --with-included-apr-util --with-included-pcre
bluesanta@bluesanta-desktop:~/httpd-2.4.39$ make
bluesanta@bluesanta-desktop:~/httpd-2.4.39$ make install

mod_jk 설치

bluesanta@bluesanta-desktop:~$ wget https://archive.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.46-src.tar.gz
bluesanta@bluesanta-desktop:~$ tar xvf tomcat-connectors-1.2.46-src.tar.gz
bluesanta@bluesanta-desktop:~$ cd tomcat-connectors-1.2.46-src/native/
bluesanta@bluesanta-desktop:~$ ./configure --with-apxs=/opt/apache24//bin/apxs
bluesanta@bluesanta-desktop:~/tomcat-connectors-1.2.46-src/native$ make
bluesanta@bluesanta-desktop:~/tomcat-connectors-1.2.46-src/native$ make install

로드밸런싱 설정

bluesanta@bluesanta-desktop:~$ cd /opt/apache24/conf/
bluesanta@bluesanta-desktop:/opt/apache24/conf$ vi workers.properties

workers.properties

worker.list=load_balancer

worker.load_balancer.type=lb
worker.load_balancer.balance_workers=tomcat1,tomcat2
#worker.load_balancer.balance_workers=tomcat2

# tomcat/conf/server.xml - ajp 포트
worker.tomcat1.port=8009
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1

# tomcat/conf/server.xml - ajp 포트
worker.tomcat2.port=7009
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1

httpd.conf

bluesanta@bluesanta-desktop:/opt/apache24/conf$ vi httpd.conf

LoadModule jk_module modules/mod_jk.so

... 생략 ...

<IfModule jk_module>
    JkWorkersFile    conf/workers.properties
    JkLogFile        logs/mod_jk.log
    JkLogLevel       info
    JkMount /* 	load_balancer
</IfModule>

Apache 웹서버 환경 설정

bluesanta@bluesanta-desktop:~$ cd /opt/apache24/conf/
bluesanta@bluesanta-desktop:/opt/apache24/conf$ vi httpd.conf

ServerName 주석을 풀고 localhost로 설정

#ServerName www.example.com:80
ServerName localhost

서비스 등록 파일 apache2.service 생성

bluesanta@bluesanta-desktop:/opt/apache24/conf$ cd /opt/apache24/bin/
bluesanta@bluesanta-desktop:/opt/apache24/bin$ vi apache2.service

apache2.service 내용

[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=https://httpd.apache.org/docs/2.4/

[Service]
Type=forking
Environment=APACHE_STARTED_BY_SYSTEMD=true
ExecStart=/opt/apache24/bin/apachectl start
ExecStop=/opt/apache24/bin/apachectl stop
ExecReload=/opt/apache24/bin/apachectl graceful
PrivateTmp=true
Restart=on-abort

[Install]
WantedBy=multi-user.target

apache2.service 파일 /etc/systemd/system 디렉토리에 복사

bluesanta@bluesanta-desktop:/opt/apache24/bin$ sudo chmod +x apache2.service
bluesanta@bluesanta-desktop:/opt/apache24/bin$ sudo cp apache2.service /etc/systemd/system

Apache 서비스 등록

bluesanta@bluesanta-desktop:/opt/apache24/bin$ sudo systemctl enable apache2
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /etc/systemd/system/apache2.service.

Apache 서비스 실행

bluesanta@bluesanta-desktop:/opt/apache24/bin$ sudo systemctl start apache2

Apache 서비스 상태 확인

bluesanta@bluesanta-desktop:/opt/apache24/bin$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/etc/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2021-04-10 14:22:21 KST; 57s ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 284736 (httpd)
      Tasks: 82 (limit: 18898)
     Memory: 7.2M
     CGroup: /system.slice/apache2.service
             ├─284736 /opt/apache24/bin/httpd -k start
             ├─284737 /opt/apache24/bin/httpd -k start
             ├─284738 /opt/apache24/bin/httpd -k start
             └─284739 /opt/apache24/bin/httpd -k start
 
 4월 10 14:22:21 bluesanta-desktop systemd[1]: Starting The Apache HTTP Server...
 4월 10 14:22:21 bluesanta-desktop systemd[1]: Started The Apache HTTP Server.

댓글을 달아 주세요