docker pull elasticsearch
mkdir /mnt/data/elasticsearch/config
mkdir /mnt/data/elasticsearch/data
mkdir /mnt/data/elasticsearch/plugins
其中config为配置文件,data为数据,plugins为相关插件。创建这些是为了之后启动容器时作为挂载目录。
运行容器前,写入elasticsearch.yml配置文件到config目录下:
echo "http.host: 0.0.0.0" >> /mnt/data/elasticsearch/config/elasticsearch.yml
数据挂载需要权限,需要设置data文件的权限为可读写:
chmod -R 777 /mnt/data/elasticsearch/data
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -v /mnt/data/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /mnt/data/elasticsearch/data:/usr/share/elasticsearch/data -v /mnt/data/elasticsearch/plugins:/usr/share/elasticsearch/plugins -d elasticsearch
-e "discovery.type=single-node" 设置为单节点
特别注意:
-e ES_JAVA_OPTS="-Xms512m -Xmx512m" \ 测试环境下,设置ES的初始内存和最大内存,否则导致过大启动不了ES
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
sysctl.conf
配置文件 vim /etc/sysctl.conf
结尾添加:
vm.max_map_count=262144
保存后执行如下指令 立即生效
/sbin/sysctl -p
initial heap size [67108864] not equal to maximum heap size [134217728]; this can cause resize pauses
解决方式:将-e ES_JAVA_OPTS="-Xms512m -Xmx512m"
里的**-Xms和-Xmx**设置相等
the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
解决方式:指定默认模式-e "discovery.type=single-node"
登录ip:9200后显示类似下面的信息即为启动成功:
{
"name" : "53e0c480dfad",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "xLlN6WtLT5yhK9GGS11ZtA",
"version" : {
"number" : "7.17.6",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "f65e9d338dc1d07b642e14a27f338990148ee5b6",
"build_date" : "2022-08-23T11:08:48.893373482Z",
"build_snapshot" : false,
"lucene_version" : "8.11.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
docker pull kibana:7.17.6
docker run --name kibana -e ELASTICSEARCH_HOSTS=http://自己的IP地址:9200 -p 5601:5601 -d kibana:7.17.6
//docker run --name kibana -e ELASTICSEARCH_URL=http://自己的IP地址:9200 -p 5601:5601 -d kibana:7.17.6
进入容器修改相应内容
server.port: 5601
server.host: 0.0.0.0
elasticsearch.hosts: [ "http://自己的IP地址:9200" ]
i18n.locale: "Zh-CN"
然后访问页面
http://自己的IP地址:5601
docker run --name=elasticsearch-head -d -p 9100:9100 docker.io/mobz/elasticsearch-head:5
成功后通过9100端口访问
elasticsearch使用docker运行实例,至此就搭建完了。