解决k8s集群中opensearch服务的各种问题

1. 前言

我使用的k8s版本是1.23.6,前面安装了Kubesphere可视化组件,然后开始的时候没有启用日志模块,而是在安装Kubesphere后启用日志系统(参考在安装后启用日志系统),安装一切正常,但是安装后验证,就出现opensearch-cluster-master-x和opensearch-cluster-data-x这些pod都是CrashLoopBackOff的状态,以下是一系列问题及解决。

2. 问题及解决

2.1. 虚拟内存的问题

看日志,发现:

 ERROR: [1] bootstrap checks failed
 [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
 ERROR: OpenSearch did not exit normally - check the logs at /usr/share/opensearch/logs/opensearch-cluster.log

目测是虚拟内存的问题,vm.max_map_count 是一个 Linux 内核参数,它控制着一个进程可以拥有的虚拟内存区域的数量,通常用于限制系统中的内存映射数量。这个参数的值表示允许的最大内存映射数量。

宿主机编辑/etc/sysctl.conf文件,增加以下配置:

vm.max_map_count = 262144

然后刷新内存里的配置:

sysctl -w vm.max_map_count=262144

重启docker服务:

systemctl restart docker

2.2. 服务频繁重启的问题

这个是因为服务还没起来,探针超时,然后将服务重启,最后形成死循环,这个需要修改探针配置。

受影响的pod都是由有状态服务(statefulset)启动的,分别为:

  • opensearch-cluster-data
  • opensearch-cluster-master

使用Kubesphere或者命令进行编辑:

kubectl edit sts opensearch-cluster-data -n kubesphere-logging-system

将startupProbe的initialDelaySeconds改为30。

同样对opensearch-cluster-master也进行同样的操作,然后重新创建就可以了。

2.3. OpenSearch Security not initialized

这个是安全配置未初始化,进入opensearch-cluster-master所在的pod譬如我的是opensearch-cluster-master-0,然后进入/usr/share/opensearch/plugins/opensearch-security/tools 目录,执行以下命令:

./securityadmin.sh -cd ../../../config/opensearch-security/  -rev  -cacert ../../../config/root-ca.pem  -cert ../../../config/kirk.pem  -key ../../../config/kirk-key.pem

如果有步骤超时,则再执行一次试试。

注意,不同版本文件的位置可能不一样,其他的版本可以参考[3]和[4]中的教程。

3. 参考

[1] Elasticsearch: Max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

[2] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

[3] OpenSearch Security not initialized

[4] Applying changes to configuration files

(完)

posted @ 2023-09-18 16:14  大师兄啊哈  阅读(753)  评论(0编辑  收藏  举报