resin 专业版具备http负载均衡的能力,我们这里采用nginx来负载均衡resin的http请求,同时使用jvm做到session共享的效果.
 
mysql
 
二.安装及初始化
1.安装jdk
cp jdk-6u20-linux-x64-rpm.bin /usr/java
cd /usr/java
./jdk-6u20-linux-x64-rpm.bin ###时间有点长
rpm -ivh jdk-6u20-linux-amd64.rpm
##设置环境变量,
echo -en "export JAVA_HOME = /usr/java/jdk1.6
export PATH = $PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
exportCLASSPATH=.:/usr/java/jdk1.6/lib:/usr/java/jdk1.6/jre/lib:$CLASSPATH"
>> /etc/profile
source  /etc/profile
java --version
##出现java版本说明安装jdk成功
cd
2.安装jvm&&nginx
tar zxvf pcre-8.02.tar.gz
cd pcre 8.02
./configure
make;make install
cd ..
tar zxvf nginx-0.8.34.tzr.gz
cd ..
tar zxvf  nginx-upstram*
mv nginx-upstram-jvm-route nginx0.8.34
cd nginx-0.8.34
##打补丁
patch -p0 < nginx-upstram-jvm-route/jvm_route.patch
##编译
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=nginx_upstream_jvm_route
cd ..
3.安装resin
tar zxvf  resin*
cd resin3.1.10
./configure --prefix=/usr/local/resin
make;make install
## 环境变量
echo "export RESIN_HOME=/usr/local/resiin " >> /etc/profile
source /etc/export
 
三.整合
1.配置及启动resin
cd /usr/localresin
vi conf/resin.comf
###查找
<http address="*" port="8080"/>
###注释掉
<!--http address="*" port="8080"/-->
###查找
<server id="" address="127.0.0.1" port="6800">
###替换成(3.1版本这个地方进行了改动)
<server id="1" address="127.0.0.1" port="6800">
<http id="" port="8080"/>
<server id="2" address="127.0.0.1" port="6801">
<http id="" port="8080"/>
<server id="3" address="127.0.0.1" port="6802">
<http id="" port="8080"/>
</server>
echo "rest" > webapp/ROOT/test.jsp
cp webapp/ROOT/index.jsp /webapp/ROOT/index.jsp_bak
echo > webapp/ROOT/index.jsp
vi webapp/ROOT/index.jsp
###add;( 测试代码来源于互联网)
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
%>
<html>
  <head>
    </head>
      <body>
        this is a page
        <br />
       <%out.print(request.getSession()) ;%>
       <!--输出session-->
        <br />
        <%out.println(request.getHeader("Cookie")); %>
      <!--输出Cookie-->
      </body>
 </html
###启动resin
启动server 1:bin/httpd.sh -server 1 start
启动server 2:bin/httpd.sh -server 2 start
启动server 3:bin/httpd.sh -server 3 start
###整合nginx与resin
vi  /usr/local/nginx/conf/nginx.conf
 ###增加如下两段(访问jsp文件则proxy_pass到webgroup群集)
http{
......
   upstream webgroup {
    server 127.0.0.1:8080 srun_id=1; ## 注意与resin server id对应
    server 127.0.0.1:8080 srun_id=2;
    server 127.0.0.1:8080 srun_id=3;
   
    jvm_route $cookie_JSESSIONID|sessionid;
 }
  .....................
server{
   listen       80;
   server_name  127.0.0.1 localhost;
   index index.html index.htm index.jsp;
   root  /usr/local/www;
   location ~ .*\.jsp$
   {
     proxy_pass http://webgroup;
     proxy_redirect    off;
     proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
     proxy_set_header  X-Real-IP  $remote_addr;
     proxy_set_header  Host $http_host;
   }
..........................
}
}
 
###启动nginx
/usr/local/nginx/sbin/nginx
 
四.测试
links 127.0.0.1/test.jsp ###测试resin是否正常
links 127.0.0.1/index.jsp###测试session是否共享
可以使用不同的浏览器进行测试
同一个浏览器数次刷新后看看session id是否变化,如果不变化,说明jvm模块是起了作用的
the end
 
五. 安装mysql
我这里使用rpm包安装,源码编译安装也可,主要就是mysql的jdbc驱动需要设置配置一下
rpm -ivh MySQL-client*
rpm -ivh MySQL-server*
tar zxvf mysql*
cp mysql-connector* /usr/local/resin
cp mysql-connector-java-5.1.12-bin.jar /usr/local/resin/lib
echo "JDBC_HOME=/usr/local/resin/mysql-connector-java-5.1.12" >> /etc/profile
source /etc/profile
###给root授权,注意这里面不能是@localhost,resin调用jdbc类似于远程读取
mysql
GRANT ALL ON *.* TO root@'%';
use test;
create table test(age int not null primary key,name char(20));
INSERT INTO test (age,name) values ('20'','admin');
exit
###建立测试页面,读取name数值(测试代码来源于互联网)
 vi  /usr/local/resin/webapps/ROOT/test.jsp
###add;
<%@ page contentType="text/html;charset=GBK" %>
<%@ page language="java" import="java.sql.*"%>
<%
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
if(conn==null){
System.out.println("get Conn Error");
}
Statement stmt=conn.createStatement();
ResultSet RS_result=null;
%>
<html>
<head>
<title>虏芒</title></head>
<body>
<%
RS_result=stmt.executeQuery("select * from test");
String Name;
while(RS_result.next())
{
Name=RS_result.getString("username");
%>
<%=Name%>
<%
}
RS_result.close();
stmt.close();
conn.close();
%>
</body>
</html>
 
测试结果:
links 127.0.0.1/test.jsp
出现admin即表明测试成功
 
the end