目录
前言
本文请酌情观看,是本人整理的笔记,一搬来说只有我自己看的懂,所以酌情观看
这里会讲解常用产品的集群搭建
集群的介绍
也就是一个分布式的项目拆分成很多模块后,一个模块可能布置到多台机器
zookeeper集群
zookeeper基础 https://blog.csdn.net/yzj17025693/article/details/89927236
leader选举
leader选举是zookeeper的投票机制,成为leader的节点,一般要承受更高的并发量
所以一般是状态良好的节点(机器)会被选中成为leader
搭建伪集群
服务器之间通信端口,2881,而2181是客户端连接服务器的端口,tomcat需要连接的是2181
启动集群和查看状态
模拟集群异常
Dubbox连接zookeeper集群
protocol 是协议,,表示使用的是zookeeper集群
solr集群
solr基础 https://blog.csdn.net/yzj17025693/article/details/90442002
solr集群的搭建
修改tomcat的运行端口,需要的是修改tomcat的配置文件在tomcat的conf目录,server.xml里
修改3个端口
这个ip是zookeeper的ip和端口
tomcat的ip和http连接的端口,不是tomcat服务器之间通信的端口
spring data solr连接solr集群
原本的配置
分片配置
模拟集群异常
总共4个tomcat节点,具体的参数,可以参考上面的zookeeper集群
redis cluster(集群)
redis集群搭建
ruby脚本搭建redis集群
客户端连接redis集群
SpringDataRedis连接Redis集群
添加redis-cluster-config.properties配置文件
#cluster configuration
redis.host1=192.168.25.140
redis.port1=7001
redis.host2=192.168.25.140
redis.port2=7002
redis.host3=192.168.25.140
redis.port3=7003
redis.host4=192.168.25.140
redis.port4=7004
redis.host5=192.168.25.140
redis.port5=7005
redis.host6=192.168.25.140
redis.port6=7006
redis.maxRedirects=3
redis.maxIdle=100
redis.maxTotal=600
添加spring 配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 加载配置属性文件 -->
<context:property-placeholder ignore-unresolvable="true" location="classpath:properties/redis-cluster-config.properties" />
<bean id="redis-clusterConfiguration" class="org.springframework.data.redis.connection.redis-clusterConfiguration">
<property name="maxRedirects" value="${redis.maxRedirects}"></property>
<property name="clusterNodes">
<set>
<bean class="org.springframework.data.redis.connection.redis-clusterNode">
<constructor-arg name="host" value="${redis.host1}"></constructor-arg>
<constructor-arg name="port" value="${redis.port1}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.redis-clusterNode">
<constructor-arg name="host" value="${redis.host2}"></constructor-arg>
<constructor-arg name="port" value="${redis.port2}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.redis-clusterNode">
<constructor-arg name="host" value="${redis.host3}"></constructor-arg>
<constructor-arg name="port" value="${redis.port3}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.redis-clusterNode">
<constructor-arg name="host" value="${redis.host4}"></constructor-arg>
<constructor-arg name="port" value="${redis.port4}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.redis-clusterNode">
<constructor-arg name="host" value="${redis.host5}"></constructor-arg>
<constructor-arg name="port" value="${redis.port5}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.redis-clusterNode">
<constructor-arg name="host" value="${redis.host6}"></constructor-arg>
<constructor-arg name="port" value="${redis.port6}"></constructor-arg>
</bean>
</set>
</property>
</bean>
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxTotal" value="${redis.maxTotal}" />
</bean>
<bean id="jeidsConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" >
<constructor-arg ref="redis-clusterConfiguration" />
<constructor-arg ref="jedisPoolConfig" />
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jeidsConnectionFactory" />
</bean>
</beans>