docker安装Elasticsearch7.6集群并设置密码的方法步骤
目录
- 一些基础配置
- 关于版本和docker镜像
- 开始
- 关于elasticsearch.yml
- 关于证书elastic-certificates.p12
- 生成密码
- 使用密码
- 忘记密码
为了简化物理安装过程,我们将使用docker安装我们的服务。
一些基础配置 es需要修改linux的一些参数。
设置
vm.max_map_count=262144
sudo vim /etc/sysctl.confvm.max_map_count=262144
不重启, 直接生效当前的命令
sysctl -w vm.max_map_count=262144
es的data和logs目录需要给1000的用户授权, 我们假设安装3个实力的es集群,先创建对应的数据存储文件
mkdir -p es01/datamkdir -p es01/logsmkdir -p es02/datamkdir -p es02/logsmkdir -p es03/datamkdir -p es03/logs## es的用户id为1000,这里暂且授权给所有人好了sudo chmod 777 es* -R
关于版本和docker镜像 Elasticsearch分几种licenses,其中Open Source和Basic是免费的, 而在6.8之后安全功能才开始集成在es的Basic授权上。
文章图片
Basic对应docker镜像为
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.6.2
同时dockerhub同步为elasticsearch. 我们直接拉取
elasticsearch:7.6.2
就好。开始 首先,创建docker-compose.yml
version: '2.2'services:es01:image: elasticsearch:7.6.2container_name: es01environment:- node.name=es01- cluster.name=es-docker-cluster- discovery.seed_hosts=es02,es03- cluster.initial_master_nodes=es01,es02,es03- bootstrap.memory_lock=true- "ES_JAVA_OPTS=-Xms512m -Xmx512m"ulimits:memlock:soft: -1hard: -1volumes:- ./es01/data:/usr/share/elasticsearch/data- ./es01/logs:/usr/share/elasticsearch/logs- ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml- ./elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12ports:- 9200:9200networks:- elastices02:image: elasticsearch:7.6.2container_name: es02environment:- node.name=es02- cluster.name=es-docker-cluster- discovery.seed_hosts=es01,es03- cluster.initial_master_nodes=es01,es02,es03- bootstrap.memory_lock=true- "ES_JAVA_OPTS=-Xms512m -Xmx512m"ulimits:memlock:soft: -1hard: -1volumes:- ./es02/data:/usr/share/elasticsearch/data- ./es02/logs:/usr/share/elasticsearch/logs- ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml- ./elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12ports:- 9201:9200networks:- elastices03:image: elasticsearch:7.6.2container_name: es03environment:- node.name=es03- cluster.name=es-docker-cluster- discovery.seed_hosts=es01,es02- cluster.initial_master_nodes=es01,es02,es03- bootstrap.memory_lock=true- "ES_JAVA_OPTS=-Xms512m -Xmx512m"ulimits:memlock:soft: -1hard: -1volumes:- ./es03/data:/usr/share/elasticsearch/data- ./es03/logs:/usr/share/elasticsearch/logs- ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml- ./elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12ports:- 9202:9200networks:- elastickib01:depends_on: - es01image: kibana:7.6.2container_name: kib01ports:- 5601:5601environment:ELASTICSEARCH_URL: http://es01:9200ELASTICSEARCH_HOSTS: http://es01:9200volumes:- ./kibana.yml:/usr/share/kibana/config/kibana.ymlnetworks:- elasticnetworks:elastic:driver: bridge
关于elasticsearch.yml 内容如下
network.host: 0.0.0.0xpack.security.enabled: truexpack.security.transport.ssl.enabled: truexpack.security.transport.ssl.keystore.type: PKCS12xpack.security.transport.ssl.verification_mode: certificatexpack.security.transport.ssl.keystore.path: elastic-certificates.p12xpack.security.transport.ssl.truststore.path: elastic-certificates.p12xpack.security.transport.ssl.truststore.type: PKCS12xpack.security.audit.enabled: true
- network.host 设置允许其他ip访问,解除ip绑定
- xpack.security 则是安全相关配置,其中ssl的证书需要自己生成
关于证书elastic-certificates.p12 es提供了生成证书的工具
elasticsearch-certutil
,我们可以在docker实例中生成它,然后复制出来,后面统一使用。首先运行es实例
sudo docker run -dit --name=es elasticsearch:7.6.2 /bin/bash
进入实例内部
sudo docker exec -it es /bin/bash
生成ca: elastic-stack-ca.p12
[root@25dee1848942 elasticsearch]# ./bin/elasticsearch-certutil caThis tool assists you in the generation of X.509 certificates and certificatesigning requests for use with SSL/TLS in the Elastic stack.The 'ca' mode generates a new 'certificate authority'This will create a new X.509 certificate and private key that can be usedto sign certificate when running in 'cert' mode.Use the 'ca-dn' option if you wish to configure the 'distinguished name'of the certificate authorityBy default the 'ca' mode produces a single PKCS#12 output file which holds:* The CA certificate* The CA's private keyIf you elect to generate PEM format certificates (the -pem option), then the output willbe a zip file containing individual files for the CA certificate and private keyPlease enter the desired output file [elastic-stack-ca.p12]: Enter password for elastic-stack-ca.p12 :
再生成cert: elastic-certificates.p12
[root@25dee1848942 elasticsearch]# ./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12This tool assists you in the generation of X.509 certificates and certificatesigning requests for use with SSL/TLS in the Elastic stack.The 'cert' mode generates X.509 certificate and private keys.
这个生成elastic-certificates.p12 就是我们需要使用的。
复制出证书, ctrl+d退出容器内部
sudo docker cp es:/usr/share/elasticsearch/elastic-certificates.p12 .# 关闭这个容器sudo docker kill essudo docker rm es
如此获取了证书。
生成密码 我们首先要启动es集群,去里面生成密码。
sudo docker-compose up
然后进入其中一台
sudo docker exec -it es01 /bin/bash
生成密码用auto, 自己设置用
interactive
[root@cfeeab4bb0eb elasticsearch]# ./bin/elasticsearch-setup-passwords -hSets the passwords for reserved usersCommands--------auto - Uses randomly generated passwordsinteractive - Uses passwords entered by a userNon-option arguments:commandOptionDescription------------------EConfigure a setting-h, --helpShow help-s, --silentShow minimal output-v, --verboseShow verbose output[root@cfeeab4bb0eb elasticsearch]# ./bin/elasticsearch-setup-passwords autoInitiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.The passwords will be randomly generated and printed to the console.Please confirm that you would like to continue [y/N]yChanged password for user apm_systemPASSWORD apm_system = YxVzeT9B2jEDUjYp66WsChanged password for user kibanaPASSWORD kibana = 8NnThbj0N02iDaTGhidUChanged password for user logstash_systemPASSWORD logstash_system = 9nIDGe7KSV8SQidSk8DjChanged password for user beats_systemPASSWORD beats_system = qeuVaf1VEALpJHfEUOjJChanged password for user remote_monitoring_userPASSWORD remote_monitoring_user = DtZCrCkVTZsinRn3tW3DChanged password for user elasticPASSWORD elastic = q5f2qNfUJQyvZPIz57MZ
使用密码 浏览器访问localhost:9200/9201/9202 需要输入账号
输入对应的elastic/password就好
浏览器访问localhost:5601
文章图片
忘记密码 如果生成后忘记密码了怎么办, 可以进入机器去修改。
【docker安装Elasticsearch7.6集群并设置密码的方法步骤】进入es的机器
sudo docker exec -it es01 /bin/bash
创建一个临时的超级用户RyanMiao
./bin/elasticsearch-users useradd ryan -r superuserEnter new password: ERROR: Invalid password...passwords must be at least [6] characters long[root@cfeeab4bb0eb elasticsearch]# ./bin/elasticsearch-users useradd ryan -r superuserEnter new password: Retype new password:
用这个用户去修改elastic的密码:
curl -XPUT -u ryan:ryan123 http://localhost:9200/_xpack/security/user/elastic/_password -H "Content-Type: application/json" -d '{"password": "q5f2qNfUJQyvZPIz57MZ"}'
参考 http://codingfundas.com/setting-up-elasticsearch-6-8-with-kibana-and-x-pack-security-enabled/index.html
到此这篇关于docker安装Elasticsearch7.6集群并设置密码的方法步骤的文章就介绍到这了,更多相关docker安装Elasticsearch7.6集群 内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
推荐阅读
- Docker应用:容器间通信与Mariadb数据库主从复制
- Mac安装Chromedriver
- MongoDB,Wondows下免安装版|MongoDB,Wondows下免安装版 (简化版操作)
- MAC安装Mongo
- 【Hadoop踩雷】Mac下安装Hadoop3以及Java版本问题
- react|react 安装
- VueX--VUE核心插件
- python-安装sublime遇到异常
- typeScript入门基础介绍
- docker镜像探索----dive工具