Skip to content

Instantly share code, notes, and snippets.

@marcoberri
Last active November 26, 2019 13:05
Show Gist options
  • Save marcoberri/799d4ba7a82aef026f99 to your computer and use it in GitHub Desktop.
Save marcoberri/799d4ba7a82aef026f99 to your computer and use it in GitHub Desktop.
(WP) test balancer apache 2.4 with two tomcat on debian
#su una Ubuntu 15.04 server
##Install java 8
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default
##Verificare se è dispinibile la versione 2.4 di apache
sudo apt-get -s install apache2
##se disponibile
sudo apt-get install apache2
##start apache2
sudo /etc/init.d/apache2 start
##test via browser
http://192.168.1.13/
##Tomcat 8
##nuovo utente Tomcat
sudo adduser --system --shell /bin/bash --gecos 'Tomcat Java Servlet and JSP engine' --group --disabled-password --home /home/tomcat tomcat
##download tomcat 8
cd /opt/
sudo wget http://mirror.nohup.it/apache/tomcat/tomcat-8/v8.0.32/bin/apache-tomcat-8.0.32.zip
sudo unzip apache-tomcat-8.0.32.zip
sudo chown -R tomcat:tomcat apache-tomcat*
cd apache-tomcat-8.0.32/bin
sudo chmod +x *.sh
##edit file on conf/tomcat-user.xml
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="tomcat" password="tomcat" roles="manager-gui,manager-script,manager-jmx,manager-status"/>
##move folder to *_NODE1
mv apache-tomcat-8.0.32 apache-tomcat-8.0.32_NODE1
##create 2 tomcat node, clone folder
cp -a apache-tomcat-8.0.32_NODE1 apache-tomcat-8.0.32_NODE2
##edit apache-tomcat-8.0.32_NODE2/conf/server.xml
modify <Connector port="8080" protocol="HTTP/1.1"...
to <Connector port="8081" protocol="HTTP/1.1"
##test tomcat
#switch to tomat user
sudo chown -R tomcat:tomcat apache-tomcat*
sudo su - tomcat
/opt/apache-tomcat-8.0.32_NODE1/bin/startup.sh
/opt/apache-tomcat-8.0.32_NODE2/bin/startup.sh
##via browser
http://192.168.1.13:8080/
http://192.168.1.13:8081/
##tomcat manager
usr:tomcat
pwd: tomcat
http://192.168.1.13:8080/manager/html
http://192.168.1.13:8081/manager/html
##test page
http://192.168.1.13:8080/examples/jsp/jsp2/simpletag/hello.jsp
http://192.168.1.13:8081/examples/jsp/jsp2/simpletag/hello.jsp
##create sample page test
apache-tomcat-8.0.32_NODE2/webapps/examples/balancer.html
with:
<html>
<body>
<h1>NODE 2</h2>
</body>
</html>
##and
apache-tomcat-8.0.32_NODE1/webapps/examples/balancer.html
with:
<html>
<body>
<h1>NODE 1</h1>
</body>
</html>
##test it:
http://192.168.1.13:8081/examples/balancer.html
http://192.168.1.13:8080/examples/balancer.html
##edit apache2conf
edit /etc/apache2/sites-available/001-test-balance.conf
<VirtualHost *:80>
ServerName test.bal
<Proxy "balancer://mybal">
BalancerMember "http://127.0.0.1:8080"
BalancerMember "http://127.0.0.1:8081"
</Proxy>
ProxyPass "/" "balancer://mybal/examples/"
ProxyPassReverse "/" "balancer://mybal/examples/"
ErrorLog ${APACHE_LOG_DIR}/balancer_error.log
CustomLog ${APACHE_LOG_DIR}/balancer_access.log combined
</VirtualHost>
sudo a2ensite 001-test-balance.conf
sudo a2dissite 000-default.conf
sudo a2insmod proxy_http
sudo a2insmid lbmethod_byrequests
sudo a2insmid proxy_balancer
sudo apache2ctl restart
##edit server virtual hosts
sudo joe /etc/hosts
##add
127.0.0.1 test.bal
##edit local client virtual hosts
192.168.1.13 test.bal
test from browser
http://test.bal//balancer.html
or
http://192.168.1.13/balancer.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment