由于真的没时间,这篇文章只说明如何搭建ELK系统,所以不得不先挖几个坑给自己
- 分词算法-trie树
- 索引技术-Lucene
- 搜索引擎的优缺点,我觉得在写完1,2两个知识点之后,这点其实一目了然
搭建ElasticSearch集群
搭建环境 Ubuntu 18.04.3 LTS 四台
架构: arm64
ip : 192.168.1.11(kibana), 192.168.1.13, 192.168.1.14, 192.168.1.15(es集群)
设置vm.max_map_count
设置每台的vm.max_map_count
,该内核参数必须至少设置到262144
#打开系统配置文件 vim /etc/sysctl.conf #增加配置 vm.max_map_count=262144 #保存 :wq #执行命令 sysctl -w vm.max_map_count=262144
Docker方式
编辑docker-compose
文件
- es01
version: '3' services: es: image: docker.elastic.co/elasticsearch/elasticsearch:7.11.1-arm64 container_name: es environment: - node.name=es01 - cluster.name=es-docker-cluster - network.publish_host=192.168.1.13 - discovery.seed_hosts=192.168.1.14,192.168.1.15 - cluster.initial_master_nodes=es01,es02,es03 - bootstrap.memory_lock=true ulimits: memlock: soft: -1 hard: -1 volumes: - data:/usr/share/elasticsearch/data ports: - 9200:9200 - 9300:9300 volumes: data: driver: local
node.name: 该节点的名称
cluster.name: 集群名称
network.publish_host: 告知其他节点该节点通信的地址,不配会默认使用docker内部ip,造成无法通信问题
discovery.seed_hosts: 其他节点的地址
cluster.initial_master_nodes: 所有节点的名称
bootstrap.memory_lock: 是否锁住内存,避免交换(swapped)带来的性能损失
- es02
version: '3' services: es: image: docker.elastic.co/elasticsearch/elasticsearch:7.11.1-arm64 container_name: es environment: - node.name=es02 - cluster.name=es-docker-cluster - network.publish_host=192.168.1.14 - discovery.seed_hosts=192.168.1.13,192.168.1.15 - cluster.initial_master_nodes=es01,es02,es03 - bootstrap.memory_lock=true ulimits: memlock: soft: -1 hard: -1 volumes: - data:/usr/share/elasticsearch/data ports: - 9200:9200 - 9300:9300 volumes: data: driver: local
- es03
version: '3' services: es: image: docker.elastic.co/elasticsearch/elasticsearch:7.11.1-arm64 container_name: es environment: - node.name=es03 - cluster.name=es-docker-cluster - network.publish_host=192.168.1.15 - discovery.seed_hosts=192.168.1.13,192.168.1.14 - cluster.initial_master_nodes=es01,es02,es03 - bootstrap.memory_lock=true ulimits: memlock: soft: -1 hard: -1 volumes: - data:/usr/share/elasticsearch/data ports: - 9200:9200 - 9300:9300 volumes: data: driver: local
启动
docker-compose up -d
测试是否启动成功
curl -X GET "localhost:9200/_cat/nodes?v=true&pretty"
压缩包方式
下载压缩包并解压
#创建存放压缩包目录 mkdir -p /opt/server/packages && cd /opt/server/packages #下载压缩包 wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.1-linux-aarch64.tar.gz #解压 tar -xf elasticsearch-7.11.1-linux-aarch64.tar.gz #重命名 mv elasticsearch-7.11.1-linux-aarch64 ../elasticsearch
编辑配置
- 创建存储目录
mkdir /opt/server/elasticsearch/data
- 打开配置文件
vim /opt/server/elasticsearch/config/elasticsearch.yml
- 修改配置
cluster.name: es-cluster node.name: es01 path.data: /opt/server/elasticsearch/data path.logs: /opt/server/elasticsearch/logs network.host: 0.0.0.0 http.port: 9200 discovery.seed_hosts: ["192.168.1.14", "192.168.1.15"] cluster.initial_master_nodes: ["es01", "es02","es03"] bootstrap.system_call_filter: false bootstrap.memory_lock: true
- 修改JVM内存配置
#打开配置文件 vim /opt/server/elasticsearch/config/jvm.options #修改内存 -Xms8g -Xmx8g
- 修改系统线程数
vim /etc/security/limits.conf #增加以下配置,注意*号要留着 * soft nofile 65536 * hard nofile 131072 * soft nproc 4096 * hard nproc 4096 * hard memlock unlimited * soft memlock unlimited
- 锁定内存
vim /etc/systemd/system.conf #修改以下配置 DefaultLimitNOFILE=65536 DefaultLimitNPROC=32000 DefaultLimitMEMLOCK=infinity #关闭交换空间 swapoff -a
- 修改虚拟内存大小,最开始已经加过了,这里记录一下
vim /etc/sysctl.conf vm.max_map_count=262144
其他两台依样配置
启动
由于elasticsearch为了安全,禁止以root用户启动,我们需要创建新用户
- 创建用户
adduser es_user
- 赋予用户目录权限
cd /opt/server chown -R es_user elasticsearch
- 启动
#切换到es_user用户 su es_user #启动 nohup /opt/server/elasticsearch/bin/elasticsearch 2>&1 > /opt/server/elasticsearch/logs/std.out &
- 查看日志
tail -100f /opt/server/elasticsearch/logs/std.out
- 测试
curl -X GET "localhost:9200/_cat/nodes?v=true&pretty"
你以为这就结束了,密码还没设呢!