准备6台redis服务器
1、修改配置文件redis.windows.conf
-
修改redis.windows.conf,端口号分别对应:
6379、6380、6381、6382、6383、6384。
-
开启cluster-enabled :
cluster-enabled yes
-
指定集群配置文件:
cluster-config-file nodes-6379.conf
,cluster-config-file nodes-6379.conf 是为该节点的配置信息,这里使用 nodes-端口.conf命名方法。服务启动后会在目录生成该文件。 -
指定超时:
cluster-node-timeout 15000
-
开启持久:
appendonly yes
2、安装Ruby
3、安装Ruby驱动
解压Ruby驱动(rubygems-2.7.7) , 进入根目录,执行
ruby setup.rb
4、切入到Redis目录执行(6379的Redis目录)
gem install redis
5、执行集群构建脚本
-
启动6个Redis
-
拷贝redis-trib.rb到Redis目录(6379的Redis目录)
-
在6379根目录执行构建脚本:
redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384
- 在出现 Can I set the above configuration? (type ‘yes’ to accept): 请确定并输入 yes 。成功后的结果如下:
6、测试集群命令
-
启动客户端:redis-cli –c –h 127.0.0.1 –p 6379 , 可以跟任何节点的端口
-
查看整个集群:cluster info
-
查看当前Redis:info replication
-
查看槽位:cluster nodes
7、集群代码测试
- 使用JedisCluster链接集群
@Test
public void testCluster() throws IOException, InterruptedException {
Set<HostAndPort nodes = new HashSet<();
nodes.add(new HostAndPort("127.0.0.1", 6379));
nodes.add(new HostAndPort("127.0.0.1", 6380));
nodes.add(new HostAndPort("127.0.0.1", 6381));
nodes.add(new HostAndPort("127.0.0.1", 6382));
nodes.add(new HostAndPort("127.0.0.1", 6383));
nodes.add(new HostAndPort("127.0.0.1", 6384));
JedisCluster cluster = new JedisCluster(nodes);
try {
String res = cluster.get("name");
System.out.println(res);
//cluster.quit();
} catch (Exception e) {
e.printStackTrace();
//cluster.quit();
}
}
ElasticSeacher
1、解压elasticsearch-5.2.2
2、解压kibana-5.2.2-windows-x86
3、分词器:解压elasticsearch-analysis-ik-5.2.2,然后将插件放入E:\opensource\es\elasticsearch-5.2.2\plugins中
如果ES启动占用的内存比较大可以通过修改 jvm.options 文件来修改内存
GET _search
{
"query": {
"match_all": {}
}
}
#创建索引#
PUT shopping
{
"settings":{
"number_of_shards":5,
"number_of_replicas":1
}
}
#查询索引库#
GET _cat/indices?v
#查看指定索引库#
GET _cat/indices/shopping
#删除索引库#
DELETE shopping
#添加员工:直接创建了crm索引库#
PUT /crm/employee/7
{
"id":7,
"name":"zs zhang",
"age":32,
"sex":1
}
#自动创建文档id#
POST /crm/employee
{
"id":2,
"name":"zangsan",
"age":18
}
#查询#
GET crm/employee/1/_source
#修改#
POST /crm/employee/1/_update
{
"doc":{
"id" : 1,
"name": "lisi",
"age":28
}
}
#查询指定库#
GET crm/employee/_search
#批量查询#
GET crm/employee/_mget
{
"ids":["1","AXJ-N5mGzuyNLneBtZCU"]
}
#################DSL查询####################
GET crm/employee/_search
{
"query": {
"match": {
"sex": "1"
}
},
"from": 0,
"size": 10,
"_source":["id","name","age","sex"],
"sort":[{"age":"desc"}]
}
#######################过滤#######################
GET crm/employee/_search
{
"query": {
"bool": {
"must": [{
"match": {
"name": "yin"
}
}],
"filter": [
{
"range":{
"age":{
"gte":20,
"lte":50
}
}
},
{
"term": {
"sex": 1
}
}
]
}
}
},
"from": 0,
"size": 10,
"sort": [{"age":"desc"}]
}
POST _analyze
{
"analyzer":"ik_smart",
"text":"中国驻洛杉矶领事馆遭亚裔男子枪击嫌犯已自首"
}