SpringBoot3整合Elasticsearch8,Linux运维面试

@Test
public void directConnectionTest() throws IOException {

if (open.equals(“true”)) {
//创建索引
CreateIndexResponse response = directConnectionESClient.indices().create(c -> c.index(“direct_connection_index”));
log.info(response.toString());
}
else{
log.info(“es is closed”);
}
}


#### 账号密码连接`ES`


1. 设置:`ES` `Elasticsearch.yml`的`xpack.security.enabled`属性使用默认值`+` `xpack.security.http.ssl.enabled`设置为`false`



> 
> 注意:若`xpack.security.enabled`属性为`false`,则`xpack.security.http.ssl.enabled`属性不生效,即相当于设置为`false`;所有以`xpack`开头的属性都不会生效
> 
> 
> 



> 
> `ES` `Elasticsearch.yml`的`xpack.security.http.ssl.enabled`:  
>  ● 默认`true`:必须使用`https://localhost:9200/`访问`ES`服务`+`启动`Kibana`服务会成功`+`需要使用账号连接`+`必须使用`HTTPS`连接  
>  ● 若为`false`:必须使用`http://localhost:9200/`访问`ES`服务`+`启动`Kibana`服务会失败+需要使用账号连接,但必须使用HTTP连接
> 
> 
> 


2. 配置:`dev`目录`application-dal`中添加下列配置



elasticsearch配置

elasticsearch:
userName: #自己的账号名
password: #自己的密码


3. 添加:`ElasticSearchTest`类中添加下列代码`---`索引名必须小写`+`不能有空格
4. 运行:设置跳过测试`--->`手动运行/不跳过`--->`直接`install`,但不运行测试



@Resource(name = “accountConnectionESClient”)
ElasticsearchClient accountConnectionESClient;

@Test
public void accountConnectionTest() throws IOException {

if (open.equals(“true”)) {
//创建索引
CreateIndexResponse response = accountConnectionESClient.indices().create(c -> c.index(“account_connection_index”));
log.info(response.toString());
}
else{
log.info(“es is closed”);
}
}


#### 证书账号连接`ES`


1. 设置:`ES` `Elasticsearch.yml`的`xpack.security.enabled`和`xpack.security.http.ssl.enabled`配置项使用默认值



> 
> 设置为`true`后,`ES`就走`https`,若`scheme`为`http`,则报`Unrecognized` SSL `message`错误
> 
> 
> 


2. 配置:将`dev`目录`application-dal`中`elasticsearch.scheme`配置项改成`https`
3. 证书添加:终端输入`keytool -importcert -alias es_https_ca -keystore "D:\computelTool\Java\JDK\JDK21\lib\security\cacerts" -file "D:\computelTool\database\e
  • 9
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值