Centos7使用docker搭建elasticsearch
安装docker
cat >/etc/yum.repos.d/docker.repo<<EOF
[docker-ce-edge]
name=Docker CE Edge - \$basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/\$basearch/edge
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
EOF
yum安装
yum -y install docker-ce
查看docker版本
docker --version
启动docker
systemctl enable docker
systemctl start docker
安装docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/v2.3.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
加速docker镜像
可登录阿里云
https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
然后获得
https://******.mirror.aliyuncs.com
页面中也有设置加速的代码
启动容器
创建对应文件夹目录
把下面文件保存成docker-compose.yml
文件
执行:
docker-compose up
(如果有报错自行百度)
version: '2.2'
services:
es790:
image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0
container_name: es790
environment:
- node.name=es790
- cluster.initial_master_nodes=es790
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./data:/usr/share/elasticsearch790/data
ports:
- 9202:9200
networks:
- elastic7
kib01:
image: docker.elastic.co/kibana/kibana:7.9.0
container_name: kib01
ports:
- 5601:5601
environment:
ELASTICSEARCH_URL: http://es790:9200
ELASTICSEARCH_HOSTS: '["http://es790:9200"]'
networks:
- elastic7
networks:
elastic7:
driver: bridge
如果报错
Native controller process has stopped - no new native processes can be started
可以将
- cluster.initial_master_nodes=es790
注释掉
然后添加
- discovery.type=single-node
安装ik分词
切换到docker项目根目录
docker-compose exec es790 /usr/share/elasticsearch/bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.9.0/elasticsearch-analysis-ik-7.9.0.zip
systemctl restart docker
验证
访问安装机器的
ip:9202 以及 5601是否正常访问
如果正常访问可以停止容器,然后使用
docker-compose up -d
挂在后台运行即可