1. pull 拉取镜像
docker pull elasticsearch:7.4.2 存储和检索
docker pull kibana:7.4.2 可视化检索数据
2. 配置
mkdir -p /mydata/elasticsearch/config
mkdir -p /mydata/elasticsearch/data
echo"http.host: 0.0.0.0">/mydata/elasticsearch/config/elasticsearch.yml #表示允许任意主机登录
chmod -R 777 /mydata/elasticsearch/ #不设置权限可能会启动失败
3. 启动
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-e"discovery.type=single-node" \ #单节点模式来测试
-e ES_JAVA_OPTS="-Xms64m -Xmx512m" \ #测试环境下设置过大可能卡死虚拟机;实际使用中再做调整
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.4.2
4. 设置开机启动
docker update elasticsearch --restart=always
5. 确认是否启动成功
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
df0b64ca4e94 elasticsearch:7.4.2 "/usr/local/bin/dock…" 3 minutes ago Up 3 minutes 0.0.0.0:9200- >9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch
6. 通过地址栏访问
虚拟机IP地址:9200
看到如下返回, 代表启动成功:
{
"name" : "df0b64ca4e94",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "28mdUfxVSKG6P3W6mM-4fQ",
"version" : {
"number" : "7.4.2",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
"build_date" : "2020-03-26T06:34:37.794943Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
7. 启动kibana并设置开机启动
docker run --name kibana -e ELASTICSEARCH_HOSTS=http://172.17.0.3:9200 -p 5601:5601 -d kibana:7.4.2
其中,ip地址一定要改成你自己的虚拟机地址,不然会链接不上
docker update kibana --restart=always
8. 启动完成后, 访问虚拟机的5601端口,看到Kibana的可视化界面后表示安装成功