Resin是一个常用的java中间件,对servlet和JSP提供了良好的支持,同时也支持HTTP。所以Resin可以独立部署成web服务器,处理所有的http静态与JSP动态请求。
更多时候会通过将Apache/IIS与Resin整合的方式,将动态请求与静态请求分开,让Apache/IIS处理静态请求,Resin专注处理JSP的动态请求,这样能够最大的发挥Apache与Resin的优势,有效调高服务器的处理效率。
本文作者: cubix 博客地址: http://cubix.blog.51cto.com/
文章参考:http://coolerfeng.blog.51cto.com/133059/54422/
一、基础环境说明与配置
本次使用Centos6.7,编译安装Apache2.4.20、Resin-3.1.14。
1.关闭SELINUX,配置yum源。
##关闭SeLinux setenforce 0 sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config ##下载CentOS6源 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo yum makecache
2.源码包下载。
##下载Apache2.4编译所需的apr、apr-util、pcre wget http://apache.fayea.com//apr/apr-1.5.2.tar.gz -O /usr/local/src/apr-1.5.2.tar.gz wget http://apache.fayea.com//apr/apr-util-1.5.4.tar.gz -O /usr/local/src/apr-util-1.5.4.tar.gz wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz -O /usr/local/src/pcre-8.40.tar.gz ##下载Apache-2.4.20 wget http://archive.apache.org/dist/httpd/httpd-2.4.20.tar.gz -O /usr/local/src/httpd-2.4.20.tar.gz ##下载Resin-3.1.14 wget http://www.caucho.com/download/resin-3.1.14.tar.gz -O /usr/local/src/resin-3.1.14.tar.gz ##jdk下载地址 http://www.oracle.com/technetwork/java/javase/archive-139210.html ##jdk下载需要先登录oracle账户,先下载好jdk,再放到服务器的/usr/local/src目录。 ##本文使用jdk-6u29-linux-x64.bin
二、编译安装Apache、Resin
1.安装依赖包
yum install -y gcc gcc-c++ openssl openssl-devel perl
2.编译安装Apache2.4所依赖的apr、apr-util、pcre
cd /usr/local/src/ ##解压所有压缩包 tar xf apr-1.5.2.tar.gz tar xf apr-util-1.5.4.tar.gz tar xf pcre-8.40.tar.gz tar xf httpd-2.4.20.tar.gz tar xf resin-3.1.14.tar.gz ##编译apr cd /usr/local/src/apr-1.5.2 ./configure --prefix=/usr/local/apr make && make install ##编译apr-util cd /usr/local/src/apr-util-1.5.4 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ make && make install ##编译pcre cd /usr/local/src/pcre-8.40 ./configure --prefix=/usr/local/pcre make && make install
3.编译安装Apache-2.4.20
cd /usr/local/src/httpd-2.4.20 ./configure \ --prefix=/usr/local/apache-2.4.20 \ --with-apr-util=/usr/local/apr-util/ \ --with-apr=/usr/local/apr/ \ --with-pcre=/usr/local/pcre/ \ --enable-mods-shared=most \ --enable-mpms-shared=all \ --enable-modules=most \ --enable-rewrite \ --enable-ssl \ --enable-so make && make install ##为apache添加软连接,方便版本切换 ln -s /usr/local/apache-2.4.20 /usr/local/apache ##配置apache开机自动启动 echo '/usr/local/apache/bin/apachectl start ' >> /etc/rc.local
4.配置JAVA环境
##安装JDK1.6 cd /usr/local/src/ ./jdk-6u29-linux-x64.bin mv /usr/local/src/jdk1.6.0_29 /usr/local/jdk1.6.0_29 ##为jdk添加软连接,方便版本切换 ln -s /usr/local/jdk1.6.0_29 /usr/local/jdk ##配置jdk到环境变量中 cat >> /etc/profile <
5.编译安装Resin-3.1.14
##将apr、apr-util、pcre的C语言头文件添加到apache中(作用请见下文) ln -s /usr/local/pcre/include/* /usr/local/apache/include/ ln -s /usr/local/apr/include/apr-1/* /usr/local/apache/include/ ln -s /usr/local/apr-util/include/apr-1/* /usr/local/apache/include/ ##修改mod_caucho.c中的api变量名(作用请见下文) sed -i 's/remote_ip/client_ip/g' /usr/local/src/resin-3.1.14/modules/c/src/apache2/mod_caucho.c sed -i 's/remote_addr/client_addr/g' /usr/local/src/resin-3.1.14/modules/c/src/apache2/mod_caucho.c ##编译Resin cd /usr/local/src/resin-3.1.14 ./configure \ --prefix=/usr/local/resin-3.1.14 \ --with-apxs=/usr/local/apache/bin/apxs make && make install ##为Resin添加软连接,方便版本切换 ln -s /usr/local/resin-3.1.14 /usr/local/resin ##配置apache开机自动启动 echo '/usr/local/resin/bin/httpd.sh start' >> /etc/rc.local ##检验Resin与Apache联配的模块是否成功编译 #1.检查模块是否生成 ls /usr/local/apache/modules/ |grep caucho mod_caucho.so ##modules目录中存在模块 #2.检查Apache主配置文件中是否已加载模块 tail /usr/local/apache/conf/httpd.conf # # mod_caucho Resin Configuration # LoadModule caucho_module /usr/local/apache-2.4.20/modules/mod_caucho.so ResinConfigServer localhost 6800 CauchoConfigCacheDirectory /tmp CauchoStatus yes #ResinConfigServer localhost 6800 #此配置作用是将JSP的请求转发到本地的6800端口,6800为Reisn默认的监控端口。如果在resin中修改了此端口,则该配置的端口也应该一起修改。
三、配置Apache与Resin
1.配置Apache
##备份配置文件。 cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.back ##创建一个conf.d目录。将apache的虚拟主机配置统一存放在此目录中,方便维护管理 mkdir -p /usr/local/apache/conf/conf.d/ ## 预配置Apache,关闭Apache的版本信息 cat >>/usr/local/apache/conf/httpd.conf <>/usr/local/apache/conf/httpd.conf < /usr/local/apache/conf/conf.d/$web.conf < DocumentRoot "/www/$web/" ServerName $web ErrorLog "|/usr/local/apache/bin/rotatelogs /usr/local/apache/logs/$web-%Y%m%d_error.log 86400 480" CustomLog "|/usr/local/apache/bin/rotatelogs /usr/local/apache/logs/$web-%Y%m%d_access.log 86400 480" common Options Indexes FollowSymLinks AllowOverride All Require all granted DirectoryIndex index.php index.Html index.html EOF
2.配置Resin,将Resin的web路径与Apache的web路径指向到同一个文件夹
cp /usr/local/resin/conf/resin.conf /usr/local/resin/conf/resin.conf.bak sed -i "s#webapps/ROOT#/www/$web/#g" /usr/local/resin/conf/resin.conf
3.放置测试页面
cat > /www/www.a.com/index.jsp <Jsp Page <%out.println("Hello 51cto! This is jsp Page.
");%>