安装ElasticSearch
sudo docker pull elasticsearch:7.8.0
sudo docker run -tid --name es7 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.8.0
9300是集群节点指点的tcp通讯端口
9200是http协议的web客户端RESTful端口
discovery.type=single-node 表示,如果你正在使用单个节点开发,那就要添加这句话避开引导检查
sudo docker start es7
sudo docker exec -ti es7 /bin/bash
sudo docker logs es7 # 查看某个容器的日志
现在就可以在浏览器输入 ip + 端口号 访问了。 如:http://localhost:9200/
如果sudo docker logs es7 发现内存不足
sudo find / -name jvm.options
sudo vi /var/lib/docker/overlay2/b926d7a38a6447554e36cab5da25d89b534f5ab3b95ed64954e19459abb49733/diff/usr/share/elasticsearch/config/jvm.options
-Xms1g
-Xmx1g
#-Xms700m
#-Xmx700m
sudo find / -name elasticsearch.yml
sudo vi /var/lib/docker/overlay2/198a62213a46b756e1a57cf011a75b5cc0192f731ec1b573d275f57eddb4efeb/diff/usr/share/elasticsearch/config/elasticsearch.yml
#减少内存暴增
index.store.type: niofs
#密码设置
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
保存后
重启后,重新进入容器,输入elasticsearch-setup-passwords interactive,按y确认后即可设置密码.
以我的试验会得到以下报错,大致意思是抱怨连接不上这个URL
Connection failure to: http://localhost:9200/_security/_authenticate?pretty failed: Connection refused
ERROR: Failed to connect to elasticsearch at http://localhost:9200/_security/_authenticate?pretty. Is the URL correct and elasticsearch running?
重新来就可以了:
elasticsearch-setup-passwords interactive -u 'http://localhost:9200'
密码都设置为:
123456
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]:
Passwords do not match.
Try again.
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]
es接口请求加密方式访问:
说明:
https://www.base64encode.org/
https://blog.csdn.net/lvqinglou/article/details/106872790
https://www.runoob.com/http/http-content-type.html
phpbase64加密
//加密
//$string='elastic:123456'; //定义字符串
//echo base64_encode($string); // 输出编码后的内容为 ZWxhc3RpYzoxMjM0NTY= ZWxhc3RpYzoxMjM0NTY=
//exit;
//解密
//$string='ZWxhc3RpYzoxMjM0NTY='; //定义字符串
//echo base64_decode($string); //输出解码后的内容 www.zhix.net智昕网络
//exit;
get: http://localhost:9200/dzkj_zcy_data/search_table/_search
json:
{
"query": {
"match": {
"description": "大"
}
},
"highlight": {
"fields": {
"description": {}
}
}
}
headers:
Content-Type:application/json
Authorization:Basic ZWxhc3RpYzoxMjM0NTY= //其中Basic 是固定的+phpbase64 然后就可以了
例:
$authorization=base64_encode( config('dzkj.elasticsearch_user').':'.config('dzkj.elasticsearch_password') );//用户密码方式访问es
$curlData=CurlService::curlProxy('get',$esUrl,$postData,['Content-Type'=>'application/json','Authorization'=>'Basic '.$authorization],'json');
完整插件版:http://www.diyyq.com/kaifahuanjing/6.html
发表评论 取消回复