之前已经在测试环境安装了 8.11版本, 奈何线上用的阿里云的云服务,版本还是 7.10, 导致很多查询结果不一致, 便只能重装了,才过几天竟然忘的差不多了,便记录下
Install Elasticsearch with Debian Package | Elasticsearch Guide [7.10] | Elastic
这是官方的文档, 先大概记录先剩下的后续再慢慢补充
对比8.11, 7.10 的配置文件少了很多预置内容, 导致我一脸懵, 借助搜索
- 首先我已经启动服务
curl 127.0.0.1:9200
可以看到响应内容, 代表服务已经正常启动, 如果要开启密码访问, 则在elasticsearch.yml配置文件中添加
xpack.security.enabled: true
然后
sudo systemctl restart elasticsearch
然后
cd /usr/share/elasticsearch
sh ./bin/elasticsearch-setup-passwords interactive
这个地方一下子让我输入了6个密码, 我之前8.11 好像就只输入了一个 elastic账户的, 此时在访问已经401了
export ELASTIC_PASSWORD="your_password"
如果密码中有 @!#什么的特殊字符, 则最好使用单引号
curl -u elastic:$ELASTIC_PASSWORD http://127.0.0.1:9200
{
"name" : "app-test-server",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "OUr9G7mBQIi1Zrft5wQaWw",
"version" : {
"number" : "7.10.0",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "51e9d6f22758d0374a0f3f5c6e8f3a7997850f96",
"build_date" : "2020-11-09T21:30:33.964949Z",
"build_snapshot" : false,
"lucene_version" : "8.7.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
如果我使用外网ip则提示连接失败,
$ curl -u elastic:$ELASTIC_PASSWORD http://8.xxx.xxx.xxx:9200
curl: (7) Failed to connect to 8.xxx.xxx.xxx port 9200 after 0 ms: Couldn't connect to server
编辑 elasticsearch.yml
记得restart服务 此时服务可能会重启失败, 看日志是
[2] bootstrap checks failed
[1]: 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
[2]: Transport SSL must be enabled if security is enabled on a [basic] license. Please set [xpack.security.transport.ssl.enabled] to [true] or disable security by setting [xpack.security.enabled] to [false]
一个是节点发现, 我配置了
cluster.initial_master_nodes: ["host-name-xxx"]
另外启用
xpack.security.http.ssl:
enabled: false
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
enabled: true
truststore.path: certs/transport.p12
http.host: 0.0.0.0
此时再重启服务就正常了
$ curl -u elastic:$ELASTIC_PASSWORD http://8.xxx.xxx.xxx:9200
{
"name" : "app-test-server",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "OUr9G7mBQIi1Zrft5wQaWw",
"version" : {
"number" : "7.10.0",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "51e9d6f22758d0374a0f3f5c6e8f3a7997850f96",
"build_date" : "2020-11-09T21:30:33.964949Z",
"build_snapshot" : false,
"lucene_version" : "8.7.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}