一、安装elasticsearch
- 环境
名称 | 版本 | 备注 | |
---|---|---|---|
虚拟机 | VMware® Workstation 15 Pro | ||
centos7 | 1810 | ||
docker | 19.03.1 | ||
Elasticsearch | 7.4.3 |
- 安装docker
- 拉取elasticsearch
打开docker官方仓库,搜索elasticsearch以查看需要下载的版本,拉取镜像的时候,官方推荐要指定版本号
https://hub.docker.com
[root@master ~]# docker pull elasticsearch:7.4.2
7.4.2: Pulling from library/elasticsearch
d8d02d457314: Pull complete
f26fec8fc1eb: Pull complete
8177ad1fe56d: Pull complete
d8fdf75b73c1: Pull complete
47ac89c1da81: Pull complete
fc8e09b48887: Pull complete
367b97f47d5c: Pull complete
Digest: sha256:543bf7a3d61781bad337d31e6cc5895f16b55aed4da48f40c346352420927f74
Status: Downloaded newer image for elasticsearch:7.4.2
docker.io/library/elasticsearch:7.4.2
- 查看镜像
[root@master ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
elasticsearch 7.4.2 b1179d41a7b4 2 weeks ago 855MB
- 创建容器
[root@master ~]# docker run -d -p 9200:9200 -p 9300:9300 --name elasticsearch elasticsearch:7.4.2
28e360177e4a45a0ae0ed6e5f8e3eefc385bc71718b4293e65bc78efb59e6e93
[root@master ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
28e360177e4a elasticsearch:7.4.2 "/usr/local/bin/dock…" 10 seconds ago Up 9 seconds 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch
--name 名称 给容器起个名字
-p 外部访问端口:容器端口 9200是供htpp访问端口,9300是供tcp访问的端口,如果不做端口映射,浏览器就不能访问elasticsearch的服务
- 修改配置
# 启动容器
[root@master ~]# docker start c85dca5150d8
# 进入容器
[root@master ~]# docker exec -it c85dca5150d8 /bin/bash
- 访问测试
[root@master ~]# curl http://192.168.56.101:9200
{
"name" : "I7hHCsK",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "3sH4lSgDSjeSiJClo-wZBg",
"version" : {
"number" : "6.7.2",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "56c6e48",
"build_date" : "2019-04-29T09:05:50.290371Z",
"build_snapshot" : false,
"lucene_version" : "7.7.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
常见问题:
- curl: (7) Failed connect to 192.168.56.101:9200; Connection refused
# 查看日志
[root@master ~]# docker logs -f c85dca5150d8
# 发现错误
ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
显示max_map_count的值太小了,需要设大到262144
修改:
# 设置max_map_count:
[root@master ~]# sysctl -w vm.max_map_count=262144
vm.max_map_count = 262144
# 重启容器
[root@master ~]# systemctl restart docker