1.到github搜索docker compose, 选中合适的版本下载下来
wget 'https://github.com/docker/compose/releases/download/1.27.4/docker-compose-Linux-x86_64'
2.移动重命名并赋予执行权限
mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
chmod 777 /usr/local/bin/docker-compose
3.配置环境变量
vim /etc/profile
# 在 PATH 中添加路径/usr/local/bin 后保存退出
# 使环境变量生效
source /etc/profile
4.测试
docker-compose
sudo mkdir -p /opt/docker/elk /opt/docker/es /opt/docker/kibana
chmod 777 /opt/docker/elk /opt/docker/es /opt/docker/kibana
cd /opt/docker/es && mkdir dic && cd /opt/docker/es/dic
# 自定义词典
sudo vim custom_dict.dic
# 创建目录
sudo mkdir -p /opt/docker/es/plugins/ik
cd /opt/docker/es/plugins/ik
# github搜索ik下载跟es、kibana一样的版本
wget "https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.2/elasticsearch-analysis-ik-6.4.2.zip"
# 解压
unzip elasticsearch-analysis-ik-6.4.2.zip
# 配置(docker es)内自定义词典的路径
sudo vim /opt/docker/es/plugins/ik/config/IKAnalyzer.cfg.xml
<entry key="ext_dict">/usr/share/elasticsearch/dic/custom_dict.dicentry>
# 启动一个临时的es容器
docker run -d --name es_temp -p 9200:9200 -p 9300:9300 elasticsearch:6.4.2
# 查看容器的状态,和容器id
docker ps
# 将es容器内的config文件夹复制到宿主机
sudo docker cp 容器id:/usr/share/elasticsearch/config /opt/docker/es/
# 复制完将停掉临时容器、删掉容器、删掉镜像
docker stop es_temp
docker rm es_temp
docker rmi elasticsearch:6.4.2
如果容器启动失败,使用docker logs es_temp -f 查看日志
我遇到的一个报错
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]分配的虚拟内存max_map_count过低
临时更改
sudo sysctl -w vm.max_map_count=262144
永久更改
sudo vim /etc/sysctl.conf
加上一句
vm.max_map_count=262144
保存退出,然后用sudo sysctl -p 使其生效
sudo vim /opt/docker/es/Dockerfile
from elasticsearch:6.4.2
# 容器启动时将ik分词器复制到容器内部
copy ./plugins/ /usr/share/elasticsearch/plugins/
sudo mkdir -p /opt/docker/kibana/config && cd /opt/docker/kibana/config/
sudo vim /opt/docker/kibana/config/kibana.yml
# Default Kibana configuration for docker target
server.name: kibana
server.host: "0"
# 这里的ip要配成es容器的ip,而不是宿主机的ip
elasticsearch.url: "http://172.20.0.5:9200"
xpack.monitoring.ui.container.elasticsearch.enabled: false
elasticsearch.ssl.verificationMode: none
sudo vim /opt/docker/elk/docker-compose.yml
version: '3.7'
services:
kibana:
restart: always
logging:
driver: "json-file"
options:
max-size: "100m"
max-file: "2"
image: kibana:6.4.2
container_name: kibana6
networks:
elk_net: # 使用我们自定义的网络
ports:
- 5601:5601
volumes:
- /opt/docker/kibana/config:/usr/share/kibana/config/ # 映射kibana的配置文件
es:
restart: always
build:
context: ../es/ # Dockerfile所在的目录
dockerfile: Dockerfile # Dockerfile的文件名
container_name: es6
networks:
elk_net: # 使用我们自定义的网络
ipv4_address: "172.20.0.5" # 固定容器内部ip
ports:
- 9300:9300
- 9200:9200
volumes:
- /opt/docker/es/config/:/usr/share/elasticsearch/config/ # 映射es的配置文件
- /opt/docker/es/dic/:/usr/share/elasticsearch/dic/ # 映射自定义词典文件
- /opt/docker/es/plugins/ik/config/IKAnalyzer.cfg.xml:/usr/share/elasticsearch/plugins/ik/config/IKAnalyzer.cfg.xml # 映射ik分词器的配置文件
networks: # 创建我们自定义的网络
elk_net:
ipam:
config:
- subnet: 172.20.0.0/16
gateway: 172.20.0.1
保存退出
cd /opt/docker/elk
sudo docker-compose up -d
查看容器状态
docker ps -a
访问kibana: http://127.0.0.1:5601