步骤:
1.将2台机器的.erlang.cookie都设置一致,rabbitmq依赖它进行集群通讯(windows目录下C:\Users\Administrator和C:\Windows)
C:\Windows\System32\config\systemprofile
2.修改2台机器的host文件配置
10.0.0.151 computera
10.0.0.234 computerb
3.
在2台机器C:\Users\Administrator\AppData\Roaming\RabbitMQ目录下添加rabbitmq.config集群配置文件,注意以.符号结尾
例如:
[{rabbit,[{tcp_listeners, [5672]},{cluster_nodes,{['rabbit@computera','rabbit@computerb'],ram}}]}].
10.0.0.151机器在该目录下同时添加rabbitmq-env.conf配置文件
NODENAME=rabbit@computera
NODE_IP_ADDRESS=10.0.0.151
NODE_PORT=5672
RABBITMQ_MNESIA_BASE=C:\Users\Administrator\AppData\Roaming\RabbitMQ\db
RABBITMQ_LOG_BASE=C:\Users\Administrator\AppData\Roaming\RabbitMQ\log
10.0.0.234机器将ip修改为10.0.0.234、nodename修改为:rabbit@computerb
4.在10.0.0.234机器运行
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
在10.0.0.151机器运行
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster rabbit@computerb --ram
然后启动rabbit服务查看集群状态
rabbitmqctl start_app
rabbitmqctl cluster_status
搭建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>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)