低硬件环境下的Tomcat集群如何搭建
1个回答
2018-09-11 · 百度知道合伙人官方认证企业
关注
展开全部
搭建apache+tomcat集群的方法:
1、安装tomcat+apache+mysql。
2、修改tomcat的端口,即修改server.xml中的配置,并修改 <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat_8084">
3、修改httpd.conf,解注释Include conf.d/*.conf
4、在conf.d文件夹中加入xxx.conf文件,在该文件中添加如下配置:
#LoadModule proxy_http_module modules/mod_proxy_http.so
ProxyRequests Off
ProxyPass / balancer://chinatrial-cluster/ stickysession=JSESSIONID nofailover=Off
ProxyPassReverse / http://127.0.0.1:8084/
ProxyPassReverse / http://127.0.0.1:8184/
#ProxyPassReverse / http://127.0.0.1:8380/
<Proxy balancer://chinatrial-cluster>
BalancerMember http://127.0.0.1:8084/ max=800 loadfactor=10 route=tomcat_8084
BalancerMember http://127.0.0.1:8184/ max=800 loadfactor=10 route=tomcat_8184
# BalancerMember http://127.0.0.1:8380/ max=800 loadfactor=10 route=chinatrial_8080
</Proxy>
其中route后面的值是和tomcat的server.xml中的<Engine>中的jvmRoute相对应
5、实现session共享
在数据库中建session共享表:
CREATE DATABASE `session`
USE `session`;
DROP TABLE IF EXISTS `session`.`tomcat_sessions`;
CREATE TABLE `session`.`tomcat_sessions` (
`session_id` varchar(100) NOT NULL,
`valid_session` char(1) NOT NULL,
`max_inactive` int(11) NOT NULL,
`last_access` bigint(20) NOT NULL,
`app_context` varchar(255) default NULL,
`session_data` mediumblob,
PRIMARY KEY (`session_id`),
KEY `kapp_context` (`app_context`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
6、在项目的context.xml中进行Manager的配置:
<Manager className="org.apache.catalina.session.PersistentManager"
debug="99" saveOnRestart="true" maxActiveSessions="-1"
minIdleSwap="30" maxIdleSwap="600" maxIdleBackup="0">
<Store className="org.apache.catalina.session.JDBCStore"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://172.16.100.229/session?user=root&password=nazca123&useUnicode=true&characterEncodeing=utf-8"
sessionTable="tomcat_sessions" sessionIdCol="session_id"
sessionDataCol="session_data" sessionValidCol="valid_session"
sessionMaxInactiveCol="max_inactive"
sessionLastAccessedCol="last_access" sessionAppCol='app_context'
checkInterval="60" debug="0" />
</Manager>
1、安装tomcat+apache+mysql。
2、修改tomcat的端口,即修改server.xml中的配置,并修改 <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat_8084">
3、修改httpd.conf,解注释Include conf.d/*.conf
4、在conf.d文件夹中加入xxx.conf文件,在该文件中添加如下配置:
#LoadModule proxy_http_module modules/mod_proxy_http.so
ProxyRequests Off
ProxyPass / balancer://chinatrial-cluster/ stickysession=JSESSIONID nofailover=Off
ProxyPassReverse / http://127.0.0.1:8084/
ProxyPassReverse / http://127.0.0.1:8184/
#ProxyPassReverse / http://127.0.0.1:8380/
<Proxy balancer://chinatrial-cluster>
BalancerMember http://127.0.0.1:8084/ max=800 loadfactor=10 route=tomcat_8084
BalancerMember http://127.0.0.1:8184/ max=800 loadfactor=10 route=tomcat_8184
# BalancerMember http://127.0.0.1:8380/ max=800 loadfactor=10 route=chinatrial_8080
</Proxy>
其中route后面的值是和tomcat的server.xml中的<Engine>中的jvmRoute相对应
5、实现session共享
在数据库中建session共享表:
CREATE DATABASE `session`
USE `session`;
DROP TABLE IF EXISTS `session`.`tomcat_sessions`;
CREATE TABLE `session`.`tomcat_sessions` (
`session_id` varchar(100) NOT NULL,
`valid_session` char(1) NOT NULL,
`max_inactive` int(11) NOT NULL,
`last_access` bigint(20) NOT NULL,
`app_context` varchar(255) default NULL,
`session_data` mediumblob,
PRIMARY KEY (`session_id`),
KEY `kapp_context` (`app_context`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
6、在项目的context.xml中进行Manager的配置:
<Manager className="org.apache.catalina.session.PersistentManager"
debug="99" saveOnRestart="true" maxActiveSessions="-1"
minIdleSwap="30" maxIdleSwap="600" maxIdleBackup="0">
<Store className="org.apache.catalina.session.JDBCStore"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://172.16.100.229/session?user=root&password=nazca123&useUnicode=true&characterEncodeing=utf-8"
sessionTable="tomcat_sessions" sessionIdCol="session_id"
sessionDataCol="session_data" sessionValidCol="valid_session"
sessionMaxInactiveCol="max_inactive"
sessionLastAccessedCol="last_access" sessionAppCol='app_context'
checkInterval="60" debug="0" />
</Manager>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |