CentOS7下使用docker安装ElasticSearch
使用docker-compose安装ES及其图形化界面kibana。
docker-compose文件
version: "3"
services:
elasticsearch6.8.11:
image: daocloud.io/library/elasticsearch:6.8.11
restart: always
container_name: es6.8.11
ports:
- 9200:9200
kibana:
# 版本号与ES要一致
image: daocloud.io/library/kibana:6.8.11
restart: always
container_name: kibana6.8.11
volumes:
- ./kibna/config:/usr/share/kibana/config
ports:
- 5601:5601
environment:
- elasticsearch_url=http://192.168.1.4:9200
depends_on:
- elasticsearch6.8.11
kibana配置文件
在配置kibana的数据卷下新建文件kibana.yml
,添加如下内容:
#
# ** THIS IS AN AUTO-GENERATED FILE **
#
# Default Kibana configuration for docker target
server.name: kibana
server.host: "0"
# 指定ES的地址
elasticsearch.hosts: [ "http://192.168.1.4:9200" ]
xpack.monitoring.ui.container.elasticsearch.enabled: true
下载安装
将文件置于/opt/docker/es
下,执行如下安装命令
docker-compose up -d
错误解决
ES启动失败
报错信息
若使用docker-compose logs -f
监测到如下日志,表示ES启动失败。
es6.8.11 | [2021-07-17T18:57:38,590][INFO ][o.e.b.BootstrapChecks ] [EfARraA] bound or publishing to a non-loopback address, enforcing bootstrap checks
es6.8.11 | ERROR: [1] bootstrap checks failed
es6.8.11 | [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
es6.8.11 | [2021-07-17T18:57:38,598][INFO ][o.e.n.Node ] [EfARraA] stopping ...
es6.8.11 | [2021-07-17T18:57:38,631][INFO ][o.e.n.Node ] [EfARraA] stopped
es6.8.11 | [2021-07-17T18:57:38,631][INFO ][o.e.n.Node ] [EfARraA] closing ...
es6.8.11 | [2021-07-17T18:57:38,642][INFO ][o.e.n.Node ] [EfARraA] closed
错误原因
系统分配的虚拟内存太小
解决方式
编辑
/etc/sysctl.conf
,追加以下内容:vm.max_map_count=262144
保存后,执行:
sysctl -p
kibana启动失败(未配置数据卷时可能出现)
报错信息
使用docker-compose
查看日志,发现kibana报错如下:
kibana6.8.11 | {"type":"log","@timestamp":"2021-07-17T19:26:46Z","tags":["license","warning","xpack"],"pid":1,"message":"License information from the X-Pack plugin could not be obtained from Elasticsearch for the [data] cluster. Error: No Living connections"}
kibana6.8.11 | {"type":"log","@timestamp":"2021-07-17T19:26:47Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"Unable to revive connection: http://elasticsearch:9200/"}
kibana6.8.11 | {"type":"log","@timestamp":"2021-07-17T19:26:47Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"No living connections"}
kibana6.8.11 | {"type":"log","@timestamp":"2021-07-17T19:26:47Z","tags":["warning","task_manager"],"pid":1,"message":"PollError No Living connections"}
kibana6.8.11 | {"type":"log","@timestamp":"2021-07-17T19:26:48Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"Unable to revive connection: http://elasticsearch:9200/"}
kibana6.8.11 | {"type":"log","@timestamp":"2021-07-17T19:26:48Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"No living connections"}
错误原因
kibana监听的地址不对
解决方式
修改kibana监听地址
使用命令
docker exec -it 容器id bash
进入kibana容器内部修改
config/kibana.yml
中elasticsearch.host
的值为ES的IP地址:# # ** THIS IS AN AUTO-GENERATED FILE ** # # Default Kibana configuration for docker target server.name: kibana server.host: "0" # 看到此处监听的地址是http://elasticsearch:9200,修改为ES的地址即可 elasticsearch.hosts: [ "http://elasticsearch:9200" ] xpack.monitoring.ui.container.elasticsearch.enabled: true
重启容器。
测试访问
ES:
kibana:
IK分词器
从GitHub上找到IK的工程。
找到与ES对应的版本。
Linux安装可使用如下方法:
进入ES容器内部
进入bin目录下
运行命令
sh elasticsearch-plugin install IK的GitHub下载地址
下载安装重启ES容器
测试