# 安装
# ES单节点安装(针对1.7.2版本)
# 1、获取es
wget https://repo1.maven.org/maven2/org/elasticsearch/elasticsearch/1.7.2/elasticsearch-1.7.2.tar.gz
1
# 2、修改配置elasticsearch.yml文件
## 使用es默认配置文件启动后,只能本地可以访问。
## network.host: 0.0.0.0 允许外部网络访问
network.host: 0.0.0.0
1
2
3
2
3
# 3、启动es
## nohup 不挂起运行命令,将日志自动收集到当前目录下的`nohup.out`。
## & 后台运行。
nohup ./bin/elasticsearch &
1
2
3
2
3
# 4、查看是否启动成功
curl 'http://localhost:9200/?pretty'
1
若启动成功,控制台会打印如下内容:
{
"status" : 200,
"name" : "Dr. Otto Octavius",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "1.7.2",
"build_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec",
"build_timestamp" : "2015-09-14T09:49:53Z",
"build_snapshot" : false,
"lucene_version" : "4.10.4"
},
"tagline" : "You Know, for Search"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# 5、创建索引
curl -XPUT 'localhost:9200/test_index?pretty'
1
# 6、查看索引
## 查看单个索引
curl -XGET 'localhost:9200/test_index?pretty'
{
"test_index" : {
"aliases" : { },
"mappings" : {
"test_type" : {
"properties" : {
"name" : {
"type" : "string"
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1505527446868",
"uuid" : "bIdTOfZqQDeko5qWZ-SYFQ",
"number_of_replicas" : "1",
"number_of_shards" : "5",
"version" : {
"created" : "1070299"
}
}
},
"warmers" : { }
}
}
## 查看全部索引
curl 'localhost:9200/_cat/indices?v'
health status index pri rep docs.count docs.deleted store.size pri.store.size
yellow open test_index 5 1 0 0 575b 575b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 7、添加数据
curl -XPUT 'localhost:9200/test_index/test_type/id1?pretty' -d '
{
"name": "leichu"
}'
1
2
3
4
2
3
4
# 8、查看索引数据
curl -XGET 'localhost:9200/test_index/test_type/id1?pretty'
{
"_index" : "test_index",
"_type" : "test_type",
"_id" : "id1",
"_version" : 1,
"found" : true,
"_source":
{
"name": "leichu"
}
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 9、删除索引
curl -XDELETE 'localhost:9200/test_index?pretty'
1
# 10、关闭es
curl -XPOST 'http://localhost:9200/_shutdown'
1
# 11、安装head插件
./bin/plugin install mobz/elasticsearch-head
1
浏览器访问 http://localhost:9200/_plugin/head/
# ES集群
# 1、先安装单节点es,复制2份es安装包
cp -rf elasticsearch elasticsearch-1
cp -rf elasticsearch elasticsearch-2
1
2
2
# 2、修改每个es的配置文件elasticsearch.yml
elasticsearch/elasticsearch.yml
cluster.name: es-cluster-leichu
node.name: "es-c"
node.master: true
node.data: true
network.host: 0.0.0.0
transport.tcp.port: 9300
http.port: 9200
1
2
3
4
5
6
7
2
3
4
5
6
7
elasticsearch-1/elasticsearch.yml
cluster.name: es-cluster-leichu
node.name: "es1"
node.master: true
node.data: true
network.host: 0.0.0.0
transport.tcp.port: 9301
http.port: 9201
1
2
3
4
5
6
7
2
3
4
5
6
7
elasticsearch-2/elasticsearch.yml
cluster.name: es-cluster-leichu
node.name: "es2"
node.master: true
node.data: true
network.host: 0.0.0.0
transport.tcp.port: 9302
http.port: 9202
1
2
3
4
5
6
7
2
3
4
5
6
7
# 3、分别启动elasticsearch,elasticsearch-1,elasticsearch-2
IK分词器 →