Docker 安装 ES eslasticsearch
1.下载镜像
我这里下载的是 6.8.14 如果你不知道有哪些版本 可以查看 https://hub.docker.com/_/elasticsearch
[root@localhost jzj]# docker pull elasticsearch:6.8.14
6.8.14: Pulling from library/elasticsearch
2d473b07cdd5: Pull complete
6dbda2abf11b: Pull complete
0f83f8218f21: Pull complete
ef09830e6673: Pull complete
2fe03456d8dd: Pull complete
b637754fc2dc: Pull complete
1fae7ca1e8cd: Pull complete
Digest: sha256:d073febacfafc2581545dde7eb56d139a87a0aa052110891beef29d863df938d
Status: Downloaded newer image for elasticsearch:6.8.14
docker.io/library/elasticsearch:6.8.14
[root@localhost jzj]#
2.启动ES
9200:Elasticsearch 对外提供的web端口
9300:Elasticsearch 自己使用的端口
查看docker 容器 docker ps -a
#直接后台加-d
[root@localhost jzj]# docker run -d --name jzj_es -p 9200:9200 -p 9300:9300 -v ~/es/data:/var/lib/elasticsearch/data -e ES_JAVA_OPTS="-Xms500m -Xmx500m" -e "discovery.type=single-node" elasticsearch:6.8.14
8dfd17d6110e92e86a8e1c01062f9439dd6f65d61afac91bb17d5409b07399a7
[root@localhost jzj]#
[root@localhost jzj]#
[root@localhost jzj]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8dfd17d6110e elasticsearch:6.8.16 "/usr/local/bin/dock…" 9 seconds ago Up 9 seconds 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp jzj_es_01
d999f96fcc19 mysql:5.6 "docker-entrypoint.s…" 56 minutes ago Up 23 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp jzj-mysql
[root@localhost jzj]#
3.安装IK分词器
一定要下 自己版本对应的,我的es版本是6.8.14
所以我下载了 6.8.14版本的 https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v6.8.14
#进入容器
[root@localhost jzj]# docker exec -it jzj_es bash
[root@8dfd17d6110e elasticsearch]#
#下载ik分词器,真的超级慢啊
[root@fde130c46e39 elasticsearch]# ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.8.14/elasticsearch-analysis-ik-6.8.14.zip
-> Downloading https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.8.14/elasticsearch-analysis-ik-6.8.14.zip
[=================================================] 100%??
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: plugin requires additional permissions @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.net.SocketPermission * connect,resolve
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.
Continue with installation? [y/N]y
-> Installed analysis-ik
[root@fde130c46e39 elasticsearch]#
4.重启容器、测试
可以看到,已经成功安装 es
#退出容器、重启容器
[root@fde130c46e39 elasticsearch]# exit;
exit
[root@localhost jzj]# docker restart jzj_es_01
jzj_es_01
[root@localhost jzj]#
#测试是否能连接:curl -X GET localhost:9200/
[root@localhost jzj]# curl -X GET localhost:9200/
{
"name" : "fOB7F_J",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "cDYlAOeCRD6IkW2IZAOKvA",
"version" : {
"number" : "6.8.14",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "dab5822",
"build_date" : "2021-02-02T19:58:04.182039Z",
"build_snapshot" : false,
"lucene_version" : "7.7.3",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
5.测试ES
5.1 基本概念
概念 | 数据库 | 表结构 | 一行数据 | 数据的每一列 |
---|---|---|---|---|
MYSQL | DB | Table | Row line | Column 每一列 |
ES | Index | Type | Document | Field字段 |
5.2 Postman放数据
先创建 索引Index(数据库) -account
再创建 类型Type(表结构)person
再创建 表列Field(Column列)user、title、desc
注意Body穿Json数据,Http请求方式用PUT
http://192.168.3.28:9200/accounts
Json数据
{
"mappings": {
"person": {
"properties": {
"user": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"desc": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}
}
}
创建成功,查看ES中数据
5.3 查看数据
GET
http://192.168.3.28:9200/accounts