1 下载镜像
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.1.3
2 创建挂载目录,将数据盘挂载出来
mkdir -p /docker/elasticsearch/usr/share/elasticsearch/data
chmod 777 -R /docker/elasticsearch
3 创建docker启动Elasticsearch服务
docker run -d --name elasticsearch -p 10013:9200 -p 10014:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms512m -Xmx1024m" -e "http.host=0.0.0.0" --privileged --restart=always -v /docker/elasticsearch/usr/share/elasticsearch/data:/usr/share/elasticsearch/data docker.elastic.co/elasticsearch/elasticsearch:8.1.3
4 Elasticsearch从8开始不再提供默认密码,这里需要重置密码
使用如下命令一次性将 elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user 等用户密码都重新设置
docker exec -it elasticsearch /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
如下依次输入各个用户的密码,当然也可以设置为一个,自己需要记住:
[root@redrose2100 ~]# docker exec -it elasticsearch /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
******************************************************************************
Note: The 'elasticsearch-setup-passwords' tool has been deprecated. This command will be removed in a future release.
******************************************************************************
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y
Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana_system]:
Reenter password for [kibana_system]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
[root@redrose2100 ~]#
5 由于Elasticsearch从8开始启用了安全证书机制,将证书拷贝到宿主机
mkdir -p /docker/elasticsearch/usr/share/elasticsearch/config/certs
docker cp elasticsearch:/usr/share/elasticsearch/config/certs/http_ca.crt /docker/elasticsearch/usr/share/elasticsearch/config/certs/
6 在命令行使用如下命令验证Elasticsearch是否安装成功
使用如下命令,然后在交互环境根据提示输入上面重置后的密码
curl --cacert /docker/elasticsearch/usr/share/elasticsearch/config/certs/http_ca.crt -u elastic https://127.0.0.1:10013
过程如下:
[root@redrose2100 ~]# curl --cacert /docker/elasticsearch/usr/share/elasticsearch/config/certs/http_ca.crt -u elastic https://127.0.0.1:10013
Enter host password for user 'elastic':
{
"name" : "994bcface178",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "xOFaXy78QxWuJ8b-qcUF1g",
"version" : {
"number" : "8.1.3",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "39afaa3c0fe7db4869a161985e240bd7182d7a07",
"build_date" : "2022-04-19T08:13:25.444693396Z",
"build_snapshot" : false,
"lucene_version" : "9.0.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
[root@redrose2100 ~]#
7 至此,Elasticsearch 8.1.3版本的安装就已经成功完成了
8 若后期想单独修改某个用户的密码时,使用如下命令即可
如下为修改用户elastic的密码
docker exec -it elasticsearch /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
9 为了简单使用,也可以将使用认证的开关关掉,首先将ElasticSearch中的配置文件拷贝出来
docker cp elasticsearch:/usr/share/elasticsearch/config/elasticsearch.yml /docker/elasticsearch/usr/share/elasticsearch/config/
10 编辑配置文件,
vi /docker/elasticsearch/usr/share/elasticsearch/config/elasticsearch.yml
将如下位置的配置的true修改为false
11 然后使用如下命令将修改后的配置重新拷贝到docker容器中
docker cp /docker/elasticsearch/usr/share/elasticsearch/config/elasticsearch.yml elasticsearch:/usr/share/elasticsearch/config/elasticsearch.yml
12 重启docker
docker restart elasticsearch
13 此时,直接使用如下命令再次请求Elasticsearch,即不适用证书直接请求
curl http://127.0.0.1:10013 -u elastic
结果如下:
Enter host password for user 'elastic':
{
"name" : "994bcface178",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "xOFaXy78QxWuJ8b-qcUF1g",
"version" : {
"number" : "8.1.3",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "39afaa3c0fe7db4869a161985e240bd7182d7a07",
"build_date" : "2022-04-19T08:13:25.444693396Z",
"build_snapshot" : false,
"lucene_version" : "9.0.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
[root@redrose2100 elasticsearch]#