使用DOCKER安装ES

在网站查找es镜像文件
https://hub.docker.com/_/elasticsearch

拉镜像

docker pull elasticsearch:7.7.0

创建配置和数据用文件夹

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/

启动

docker run --name elasticsearch -p 9200:9200 \
 -p 9300:9300 \
 -e "discovery.type=single-node" \
 -e ES_JAVA_OPTS="-Xms64m -Xmx128m" \
  -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 \
 -itd elasticsearch:7.7.0

设置自起
docker update elasticsearch --restart=always

验证是否成功

curl http://192.168.0.50:9200/

成功如下
 

{
  "name" : "550eca5cf3b2",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "1mP9IJU3TUy_C2DZMfKGBg",
  "version" : {
    "number" : "7.7.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "81a1e9eda8e6183f5237786246f6dced26a10eaf",
    "build_date" : "2020-05-12T02:01:37.602180Z",
    "build_snapshot" : false,
    "lucene_version" : "8.5.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

增加密码控制

在配置文件中增加
 

xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true

重新启动镜像
docker restart <容器ID>
直接访问会报错401

{
	"error": {
		"root_cause": [{
			"type": "security_exception",
			"reason": "missing authentication credentials for REST request [/]",
			"header": {
				"WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
			}
		}],
		"type": "security_exception",
		"reason": "missing authentication credentials for REST request [/]",
		"header": {
			"WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
		}
	},
	"status": 401
}

进入容器
docker exec -it <容器ID> bash

在bin中执行
 

bin/elasticsearch-setup-passwords interactive

设置密码
 

Initiating the setup of passwords for reserved users elastic,kibana,logstash_system,beats_system.
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]: 
passwords must be at least [6] characters long
Try again.
Enter password for [elastic]: 
Reenter password for [elastic]: 
Passwords do not match.
Try again.
Enter password for [elastic]: 
Reenter password for [elastic]: 
Enter password for [kibana]: 
Reenter password for [kibana]: 
Enter password for [logstash_system]: 
Reenter password for [logstash_system]: 
Enter password for [beats_system]: 
Reenter password for [beats_system]: 
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [elastic]

 开通跨域

http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization

重启后在浏览器直接访问 输入用户名密码 
http://127.0.0.1:9200/?auth_user=elastic&auth_password=changeme

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值