TOMCAT 配置主机均衡负载
两台主机相同配置 java环境变量 和配置tomcat
[root@server1 ~]# ls
apache-tomcat-7.0.37.tar.gz jdk-7u79-linux-x64.tar.gz memcached-session-manager-tc6-1.6.3.jar
[root@server1 ~]# tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/
[root@server1 ~]# cd /usr/local/
[root@server1 local]# ln -s jdk1.7.0_79/ java
[root@server1 local]# vim /etc/profile
[root@server1 local]# source /etc/profile
[root@server1 local]# . /etc/profile
[root@server1 local]# sh /etc/profile
[root@server1 local]# echo $JAVA_HOME
/usr/local/java
[root@server1 local]# echo $CLASSPATH
.:/usr/local/java/lib:/usr/local/java/jre/lib
[root@server1 local]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/java/bin:/usr/local/java/bin
[root@server1 local]# cd
[root@server1 ~]# vim test.java
[root@server1 ~]# javac test.java
[root@server1 ~]# java test
Hello World!
[root@server1 ~]#
[root@server1 ~]# ls
apache-tomcat-7.0.37.tar.gz jdk-7u79-linux-x64.tar.gz memcached-session-manager-tc6-1.6.3.jar test.class test.java
[root@server1 ~]# tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/
[root@server1 ~]# ln -s apache-tomcat-7.0.37/ tomcat
[root@server1 ~]# cd /usr/local/
[root@server1 local]# ls
apache-tomcat-7.0.37 bin etc games include java jdk1.7.0_79 lib lib64 libexec sbin share src
[root@server1 local]# cd apache-tomcat-7.0.37/
[root@server1 apache-tomcat-7.0.37]# ls
bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work
[root@server1 apache-tomcat-7.0.37]# cd bin/
[root@server1 bin]# ls
bootstrap.jar catalina-tasks.xml configtest.bat daemon.sh setclasspath.bat shutdown.sh tomcat-juli.jar tool-wrapper.sh
catalina.bat commons-daemon.jar configtest.sh digest.bat setclasspath.sh startup.bat tomcat-native.tar.gz version.bat
catalina.sh commons-daemon-native.tar.gz cpappend.bat digest.sh shutdown.bat startup.sh tool-wrapper.bat version.sh
[root@server1 bin]# ./startup.sh
Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.37
Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.37
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.37/temp
Using JRE_HOME: /usr/local/java
Using CLASSPATH: /usr/local/apache-tomcat-7.0.37/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.37/bin/tomcat-juli.jar
[root@server1 bin]# cd /usr/local/apache-tomcat-7.0.37/
[root@server1 apache-tomcat-7.0.37]# ls
bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work
[root@server1 apache-tomcat-7.0.37]# cd webapps/ROOT/
[root@server1 ROOT]# ls
asf-logo.png bg-button.png bg-nav-item.png bg-upper.png favicon.ico RELEASE-NOTES.txt tomcat.gif tomcat-power.gif WEB-INF
asf-logo-wide.gif bg-middle.png bg-nav.png build.xml index.jsp tomcat.css tomcat.png tomcat.svg
[root@server1 ROOT]# vim test.jsp
[root@server1 ROOT]# cat test.jsp
Server1 the time is: <%=new java.util.Date() %>
[root@server1 ROOT]# vim /usr/local/nginx/conf/nginx.conf
21 upstream tomcat {
22 server 172.25.77.1:8080;
23 server 172.25.77.2:8080;
24 }
47 location / {
48 # root html;
49 index index.html index.htm index.php;
50 root /usr/local/tomcat/webapps/ROOT;
51 }
64 location ~ \.jsp$ {
65 proxy_pass http://tomcat;
66 }
[root@server1 ROOT]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server1 ROOT]# nginx
[root@server1 ROOT]# nginx -s reload
##访问 172.25.77.1/test.jsp 出现负载均衡
Server1 the time is: Tue Aug 07 01:53:32 CST 2018
Server2 the time is: Tue Aug 07 01:47:30 CST 2018