To install the JDK:
Enter the/usr directory, create a Java folder, mkdir Java, will be
Use the RZ command to upload to the Java directory, and assign permissions chmod 755 Jdk-6u45-linux-i586.bin
./jdk-6u45-linux-i586.bin (Note that this step must be in the directory of Jdk-6u45-linux-i586.bin, which is the Java directory)
Generated in Java directory after decompression
To configure environment variables:
Vi/etc/profile, add the following:
Language=cn
Export language
Java_home=/usr/java/jdk1.6.0_45
Export Java_home
Export path= $JAVA _home/bin: $PATH
Save and exit when add is complete. To make the/etc/profile file effective immediately after modification, you can use the following command: Source/etc/profile
Java-version, look at the output version, if you can see the version number proves that the JDK installation was successful
Install Apache, after compiling, through virtual machine IP: port on line access, if return "it works" prove Apache boot success (note that the Apache engineering path to correct), no port number is OK, I tried.
Upload
to the root directory, this file is 32-bit, be sure to match your operating system, and then renamed to Mod_jk.so, using the following command: MV mod_jk-1.2.23-apache-2.2.x-linux-i686.so mod_jk.so
and assign a value of 777 permissions, Chmod-r 777 mod_jk.so
Copy the mod_jk.so to the Apache2/modules: CP mod_jk.so/usr/local/apache2/modules/
Add the following in the httpd.conf:
httpd.conf Path, under/usr/local/apache2/conf, vi httpd.conf, add include "/usr/local/apache2/conf/mod_jk.conf", save and exit, if present, do not add
To create a new mod_jk.conf file under the/usr/local/apache2/conf path, the command for creating the file is: Touch mod_jk.conf, then Add the following content:
#加载mod_jk Module
LoadModule Jk_module modules/mod_jk.so
#指定 workers.properties file path
Jkworkersfile conf/workers.properties
#指定哪些请求交给tomcat处理, "LoadBalancer" is the name of the load assignment controller specified in the Workers.properties
Jklogfile Logs/mod_jk.log
#JkLogLevel Debug
Jkmount/*.do LoadBalancer
Jkmount/*.jsp LoadBalancer
Create a new workers.properties file under/usr/local/apache2/conf: Touch Workers.properties, and add the following content:
Worker.list=loadbalancer # Here is consistent with mod_jk.conf
worker.worker2.port=8009 #t omcat2 ajp13 port number, corresponding to Tomcat profile Server.xml # Connector port= "8009", default 8009
worker.worker2.host=127.0.0.1 (changed to virtual machine IP, changed) # Worker2 address, native Loaclhost or 127.0.0.1, remote direct write IP
worker.worker2.type=ajp13 # Consistent with the protocol of Server.xml in Worker2
worker.worker2.lbfactor=1 # Weight value of load, higher indicates greater load
worker.worker3.port=9009
worker.worker3.host=127.0.0.1 (changed to virtual machine IP, changed)
Worker.worker3.type=ajp13
Worker.worker3.lbfactor=1
Worker.loadbalancer.type=lb
Worker.loadbalancer.balance_workers=worker2,worker3 # Specify the list of workers for the payload, separated by commas
Worker.loadbalancer. Sticky_session=false # Configuring whether session sessions are sticky
Worker.loadbalancer.sticky_session=1 #这样负载均衡器lb就会尽量保持一个session, that is, to enable users to interact with the same tomcat in a single session
Worker.loadbalancer. Sticky_session_force=false # Whether session sharing is enabled
To install Tomcat:
Will
Use the RZ command to upload to the root directory
Unzip: TAR-ZXVF apache-tomcat-7.0.41.tar.gz
Rename the folder that was created after decompression to Worker2: MV apache-tomcat-7.0.41 Worker2
Copy two tomcat at a time, named Worker2 and Worker3
MV apache-tomcat-7.0.41 Worker2
CP Worker2 Worker3-r
is the installation of 2 Tomcat,worker2 and Worker3
Modify the 2 Tomcat Server.xml to ensure that the port number of the 2 Tomcat is inconsistent, two server.xml locations in the worker2/conf, worker3/conf directories
The WORKER2 is configured as follows:
The four red boxes in the picture need to be modified, but the first three and Uncle Ann Blog requirements are the same, so stay the same, the last one changed to Worker2
The WORKER3 is configured as follows:
The four red boxes in the diagram need to be modified.
First red box 8005 changed to 8006 (changed)
The second red box 8080 is changed to 8081 (changed)
Third red box 8009 changed to 9009 (changed)
The last jvm1 changed to Worker3 (changed)
To upload an application war package:
With the RZ command will be uploaded to/root/worker2/webapps and/root/worker3/webapps, and then under WebApps (Project path) will automatically generate a Test1 folder (not previously, exit WebApps directory , you will see the Test1 folder when you enter the WebApps directory)
CD Test1
See the previously uploaded Test1.war files extracted in the Test1 directory into the test.jsp format, respectively editing/root/worker2/webapps/test1 and /root/worker3/webapps/test1 test.jsp Content, edited content into Test_worker2 (previous content is test), Test_worker3 (previous content is test)
The Enable Tomcat command is: Enter in the/root/worker2/bin directory./startup.sh
The Stop Tomcat command is: Enter in the/root/worker2/bin directory./shutdown.sh
Similarly, the same operation in Worker3
Launch Apache Worker2,worker3 separately, with different browsers to access
First case:
http://192.168.2.199:8080 (IE9 browser)
Output Result:
Second case:
192.168.2.199:8081 (Firefox browser)
Output Result:
The third case:
(Google Chrome) can be accessed successfully, such as
Refresh page Display
Repeated refreshes can see two page polling access to two Tomcat, this way to achieve load balancing
PS: If reported 404 error, it is necessary to check the problem where, I have been countless judgments finally locked Apache in mischief, so use ps-ef |grep httpd This command, the process of all killed, only keep the following process
then follow the steps below to restart the Apache service, The red box does not seem to be executed (this has not been tried), you will see the results you want to see, it is not easy
Fourth case:
When you stop TOMCAT1 (worker2)
192.168.2.199/test1/test.jsp can access the success (Firefox browser), such as, repeated refresh can only access Tomcat2 (WORKER3)
Fifth case:
Stop Tomcat2 (WORKER3)
Http://192.168.2.199/test1/test.jsp can access the success (IE9 browser), such as, repeated refresh can only access Tomcat1 (WORKER2)
Proven Apache + Tomcat Load Balancer Build success
Apache + Tomcat Load Balancer Setup