Docker 安装elasticsearch-7.4.0(在线Docker版)
sudo
[root@localhost /]#
结尾之后,除此之外均为执行后的提示,阅读作者的所有文章雷同CentOS 7.5
,linux内核为3.10.0-862.el7.x86_64
24.0.6
yum
插件,命令:[root@localhost /]# yum update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.riken.jp
* extras: mirror.lzu.edu.cn
* updates: mirrors.bupt.edu.cn
No packages marked for update
jdk1.8以上即可
):[root@localhost /]# java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
已安装Java环境可忽略
):[root@localhost /]# yum install java-1.8.0-openjdk
Version: xx.x.x
表示安装成功):[root@localhost ~]# docker version
查询Docker中所有镜像,命令:
[root@localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
elasticsearch 7.4.0 dd156dd42341 4 years ago 859MB
备注:IMAGE ID
为镜像id,REPOSITORY
为镜像名称,TAG
为容器版本号,即表示elasticsearch xx.xx.xx
已拉取
查询Docker中正在运行的所有容器,命令:
[root@localhost /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a8d2e53ff244 elasticsearch:7.4.0 "/usr/local/bin/dock…" 8 seconds ago Restarting (1) 1 second ago elasticsearch
停止Docker中指定的容器,命令(公式:docker stop [NAMES]
):
[root@localhost /]# docker stop elasticsearch
Docker容器状态:
Restarting:运行中
Exited:已停止
删除Docker指定容器
,命令(公式:docker rm [NAMES]
):
[root@localhost /]# docker rm elasticsearch
删除Docker指定镜像
,命令(公式:docker rmi [IMAGE ID]
):
[root@localhost /]# docker rmi dd156dd42341
拉取elasticsearch:7.4.0
远程仓库镜像,命令(如下所示即为成功
):
[root@localhost /]# docker pull elasticsearch:7.4.0
7.4.0: Pulling from library/elasticsearch
d8d02d457314: Pull complete
a0fe4757966a: Pull complete
af323c430ce5: Pull complete
2a71ef3bd98b: Pull complete
c56e1e386724: Pull complete
1e56fdd350c5: Pull complete
16d320661b98: Pull complete
Digest: sha256:6765d5089eec04e1cc71c7020c15a553c6aa3845bed03c13aea59005ae011110
Status: Downloaded newer image for elasticsearch:7.4.0
docker.io/library/elasticsearch:7.4.0
创建需要挂载的文件目录与配置文件信息:
[root@localhost /]# mkdir -p /opt/elasticsearch/config
[root@localhost /]# mkdir -p /opt/elasticsearch/data
[root@localhost /]# echo "http.host: 0.0.0.0" >/opt/elasticsearch/config/elasticsearch.yml
[root@localhost /]# chmod -R 777 /opt/elasticsearch/
备注:echo "http.host: 0.0.0.0" >/opt/elasticsearch/config/elasticsearch.yml
为设置外网访问权限命令
启动elasticsearch:7.4.0容器,命令:
[root@localhost /]# docker run --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" -v /opt/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /opt/elasticsearch/data:/usr/share/elasticsearch/data -v /opt/elasticsearch/plugins:/usr/share/elasticsearch/plugins -d elasticsearch:7.4.0
2037a7aed2a1a121815faf73df0613df87761defbd7889d6e5a8e4f8c86ce619
[root@localhost /]#
备注1:启动命令 --name elasticsearch
处,名称可以自定义
备注2:命令开启了两个端口,9200:9200
中:
左边代表linux服务器对外暴露的端口,右边代表docker容器内端口,es默认端口9200
使用curl
命令访问elasticsearch网页,验证是否启动成功,以下为访问成功返回结果:
[root@localhost /]# curl http://192.168.11.40:9200/
{
"name" : "2037a7aed2a1",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "kRkYvQa9Q-GExIW4cYKdcg",
"version" : {
"number" : "7.4.0",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "22e1767283e61a198cb4db791ea66e3f11ab9910",
"build_date" : "2019-09-27T08:36:48.569419Z",
"build_snapshot" : false,
"lucene_version" : "8.2.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
[root@localhost /]# curl --location --request POST 'http://192.168.11.40:9200/_analyze' \
> --header 'Content-Type: application/json' \
> --data-raw '{
> "analyzer":"standard",
> "text":"ES hello world"
> }'
{
"tokens":[
{
"token":"es",
"start_offset":0,
"end_offset":2,
"type":"" ,
"position":0
},
{
"token":"hello",
"start_offset":3,
"end_offset":8,
"type":"" ,
"position":1
},
{
"token":"world",
"start_offset":9,
"end_offset":14,
"type":"" ,
"position":2
}
]
}
备注:执行以上curl
请求,如果报错提示没有--data-raw
方法,将--data-raw
换成--data
即可,这是由于curl版本过低导致