Kotlin:runBlocking导致App应用出现ANR问题实例
     
 
文章目录
 
  
 
 
Tomcat会话保持
 
1、代理服务器配置
 
- 安装nginx服务(地址:192.168.10.11)
systemctl stop firewalld
setenforce 0
#关闭防火墙和防护中心
yum install -y epel-release.noarch
#安装yum额外源
yum install -y nginx
#安装nginx
systemctl start nginx
#开启nginx服务
systemctl status nginx
#查看nginx服务状态
#修改配置文件
vim /etc/nginx/nginx.conf
 upstream tomcat {
    server 192.168.10.12:8080;
    server 192.168.10.13:8080;
    }
#在http模块下添加upstream,负载均衡
location ~* \.jsp$ {
        proxy_pass http://tomcat;
        }
#在server模块下添加location,反向代理
nginx -t
#检查语法
nginx -s reload
#重新加载配置文件
 

 

 
2、web服务器配置
 
- 安装tomcat(web1地址:192.168.10.12)
- 安装tomcat(web2地址:192.168.10.13)
web1和web2相同配置
systemctl stop firewalld
setenforce 0
(1)部署jdk
tar xf jdk-8u291-linux-x64.tar.gz -C /usr/local
cd /usr/local/
ln -s jdk1.8.0_291/ jdk
vim /etc/profile.d/jdk.sh
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
export JRE_HOME=$JAVA_HOME/jre   
export CLASSPATH=$JAVA_HOME/lib/:$JRE_HOME/lib/
. /etc/profile.d/jdk.sh
java -version
(2)安装tomcat
tar xf apache-tomcat-9.0.16.tar.gz 
cp -r apache-tomcat-9.0.16 /usr/local/
cd /usr/local
ln -s apache-tomcat-9.0.16/ tomcat
useradd -M -s /sbin/nologin tomcat
chown tomcat:tomcat /usr/local/tomcat/ -R
vim /usr/lib/systemd/system/tomcat.service
[Unit]
Description=Tomcat
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
RestartSec=3
PrivateTmp=true
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target
   
systemctl daemon-reload
systemctl start tomcat
systemctl status tomcat
cd /usr/local/tomcat/webapps/ROOT
mv index.jsp index.jsp.bak
cat index.jsp
<%@ page import="java.util.*" %>
<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <title>tomcat test</title>
</head>
<body>
<div>On <%=request.getServerName() %></div>
<div><%=request.getLocalAddr() + ":" + request.getLocalPort() %></div>
<div>SessionID = <span style="color:blue"><%=session.getId() %></span></div>
<%=new Date()%>
</body>
</html>
 
- web1服务器配置(地址:192.168.10.12)

 

 

 

 
- web2服务器配置(地址:192.168.10.13)

 

 

 

 
 
192.168.10.11/index.jsp
 

 
3、会话保持
 
3.1 方法一:修改代理服务器配置(nginx)
 
vim /etc/nginx/nginx.conf
hash $remote_addr;
nginx -t
nginx -s reload
 

 
 
192.168.10.11/index.jsp
 

 
3.2 方法二:修改web服务器配置(tomcat)
 
 
访问官方文档,查看需要添加的配置文件
 
https://tomcat.apache.org/tomcat-9.0-doc/cluster-howto.html
For the impatient
The following is the default cluster configuration: 
<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.0.4"
                        port="45564"
                        frequency="500"
                        dropTime="3000"/>
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                      address="auto"
                      
                      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.MessageDispatchInterceptor"/>
          </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>
Cluster Basics
Make sure your web.xml has the <distributable/> element
 
 

 

 
修改tomcat服务配置
 
cd /usr/local/tomcat/conf
vim server.xml
        <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.0.4"
                        port="45564"
                        frequency="500"
                        dropTime="3000"/>
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                      address="192.168.10.12"
                      
                      
                      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.MessageDispatchInterceptor"/>
          </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>
cd /usr/local/tomcat/webapps/ROOT/WEB-INF
vim web.xml
  </description>
<distributable/>
</web-app>
systemctl restart tomcat
 
- web1服务器配置(地址:192.168.10.12)

 

 

 

 
- web2服务器配置(地址:192.168.10.13)

 

 

 

 
 
192.168.10.11/index.jsp
 
