docker安装elasticsearch
简单操作
(1) 查看本机images镜像
docker images
(2) 查看本机正在运行的容器
docker ps
(3) 从dockerhub上 pull 镜像
docker pull 镜像名称
安装及配置
-
docker search es 搜索dockerhub上所有elasticsearch版本
-
docker pull es:7.5.1 选择下载7.5.1版本
-
单节点运行es命令 docker run -d --name es -p 9200:9200 -p 9300:9300 -e “discovery.type=single-node” docker.io/elasticsearch、
-
下载kibana,需与es版本相对应
- docker启动kibana
docker run --name my-kibana -e ELASTICSEARCH_URL=http://192.168.99.100:9200 -p 5601:5601 -d kibana:7.5.1
- docker启动kibana
docker run 简单参数说明
参数 | 说明 |
---|---|
–name | 指定容器的名字 |
-d | 指定容器运行于前台还是后台,默认为false |
-p | 指定容器暴露的端口 |
-e | 指定容器的环境变量 |
修改配置文件
-
进入容器
- docker exec -it es /bin/bash
- windows powerShell 需将 /bin/sh 或 /bin/bash 改成 sh 以及 bash
- Gitbash进docker容器 加入前缀 winpty docker exec -it es bash
-
vi elasticsearch.yml
加入跨域配置
http.cors.enabled: true
http.cors.allow-origin: "*"
- ps: windows外部如需访问docker中的elasticsearch服务,需访问docker所分配的ip地址加上端口号,如:(192.168.99.100:9200),不能直接访问localhost
遇到的问题及解决
bash: vi: command not found问题:
- 原因是未安装vim及vi
执行apt-get install vim提示:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package vim
-
这时候需要执行:
apt-get update
命令的作用是:
- 同步 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的索引,这样才能获取到最新的软件包。
-
等命令更新完毕以后再执行:apt-get install vim命令即可安装成功。
apt-get命令无法使用的情况
- 首先我们拉取一个ubuntu镜像
docker pull ubuntu
- 然后运行
docker run -it ubuntu /bin/bash
- 重要 - 设置ubuntu apt-get 源 (ubuntu官方跟阿里云的) 执行以下命令
sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
apt-get clean
apt-get update
apt-get upgrade
国内因网络问题安装vim不成功,直接设置sources镜像
echo "">sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse">>sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse">>sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse">>sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse">>sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse">>sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse">>sources.list
vim方向键不可用
vim ~/.vimrc
添加
:set term=builtin_ansi 保存退出