Bootstrap

ELK:日志监控平台部署-基于elastic stack 8版本

前言

简介

    最近在学习ELK,已完成了集群的部署,但在部署期间遇到很多问题,从而浪费很长时间,所以想将部署过程记录下来,分享给大家,希望大家少走弯路,加快学习效率,也为自己巩固知识,愿与大家共同成长!

架构

主机名IP软件角色
elk1192.168.31.111ES ZK Kafka Filebeatmaster、data
elk2192.168.31.112ES ZK Kafka Filebeatmaster、data
elk3192.168.31.113ES ZK Kafka Filebeatmaster、data
elk4192.168.31.114Logstach Kabina

软件包下载

链接: https://pan.baidu.com/s/1u0C36gwQUN6JbtxDNm3u_A?pwd=YSnb 提取码: YSnb

视频链接(自己录制,原创)

ELK-日志监控平台-部署教程-1-部署前准备工作

https://www.bilibili.com/video/BV1Ts1PYGELu?vd_source=8e069ee61132fd8c52b63a8467883499

一、系统准备工作

1. 配置hosts文件

[root@elk1 ~]# vim /etc/hosts
192.168.31.111 elk1
192.168.31.112 elk2
192.168.31.113 elk3
192.168.31.114 elk4

2. 配置互信免密登录

2.1 生成密钥对

[root@elk1 ~]# ssh-keygen -t rsa

2.2 发送公钥

[root@elk1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@ek2

3.设置NTP时钟同步

3.1 安装ntpdate

[root@elk1 ~]# yum -y install ntpdate

3.2 同步时钟

[root@elk1 ~]# ntpdate ntp.aliyun.com

3.2 配置时钟同步定时任务

[root@elk1 ~]# echo "*/5 * * * * ntpdate ntp.aliyun.com > /dev/null 2>&1" > /var/spool/cron/root

4.关闭firewalld和selinux

[root@elk1 ~]# vim /etc/selinux/config 
SELINUX=disabled

5.关闭交换分区

5.1 临时生效

[root@elk1 ~]# swapoff -a

5.2 永久生效

[root@elk1 ~]# vim /etc/fstab 
# swap 相关的行

6.调整内存映射区域数限制

6.1 查看当前值

[root@elk1 ~]# sysctl vm.max_map_count
vm.max_map_count = 65530

6.2 临时调整

[root@elk1 ~]# sysctl -w vm.max_map_count=262144
vm.max_map_count = 262144

6.3 永久调整

[root@elk1 ~]# rm -rf /etc/sysctl.d/99-sysctl.conf

[root@elk1 ~]# vim /etc/sysctl.conf 
vm.max_map_count=262144

[root@elk1 ~]# sysctl -p
vm.max_map_count = 262144

7.调整文件、进程、内存资源限制

[root@elk1 ~]# vim /etc/security/limits.conf
*    soft    nofile    65536
*    hard    nofile    65536
*    soft    nproc     4096
*    hard    nproc     4096
*    soft    memlock   unlimited
*    hard    memlock   unlimited

二、部署JDK

1. 解压软件

[root@elk1 package]# tar zxf jdk-8u281-linux-x64.tar.gz -C /opt/soft/

2. 编辑环境变量

[root@elk1 ~]# vim /etc/profile
export JAVA_HOME=/opt/soft/jdk1.8.0_281
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
export CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib

3. 验证结构

[root@elk1 ~]# source /etc/profile

[root@elk1 ~]# java -version
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)

三、部署ES

1. 创建用户

[root@elk3 ~]# useradd elastic

2. 创建目录

[root@elk1 ~]# mkdir -p /opt/es/data
[root@elk1 ~]# chown -R elastic:elastic /opt/es

3. 解压程序

[root@elk1 ~]# su - elastic
[elastic@elk1 ~]$ cd /opt/soft/
[elastic@elk1 soft]$ tar zxf elasticsearch-8.14.0-linux-x86_64.tar.gz -C /opt/es/

4. 创建证书

[elastic@elk1 ~]$ cd /opt/es/elasticsearch-8.14.0/bin
[elastic@elk1 bin]$ ./elasticsearch-certutil ca
[elastic@elk1 bin]$ ./elasticsearch-certutil cert --ca elastic-stack-ca.p12

5. 编写配置文件

[elastic@elk1 config]$ egrep -v "^#|^$" elasticsearch.yml 
cluster.name: elk
node.name: elk1
node.roles: [data,master]
path.data: /opt/es/data
path.logs: /opt/es/logs
bootstrap.memory_lock: true
network.host: 0.0.0.0
http.port: 9200
transport.port: 9300
discovery.seed_hosts: ["elk1", "elk2", "elk3"]
cluster.initial_master_nodes: ["elk1"]
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate 
xpack.security.transport.ssl.client_authentication: required
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12

6. 启动

[elastic@elk1 bin]$ ./elasticsearch -d

7. 配置密码

[elastic@elk1 ~]$ cd /opt/es/elasticsearch-8.14.0/bin/
[elastic@elk1 bin]$ ./elasticsearch-setup-passwords 

8. 验证

8.1 查看节点状态

http://192.168.31.113:9200/_cat/nodes

8.2 查看ES中有哪些用户

http://192.168.31.113:9200/_security/user

四、部署Kibana

1. 解压软件并授权

[root@elk4 ~]# cd /opt/soft
[root@elk4 soft]# mkdir /opt/kibana
[root@elk4 soft]# tar zxf kibana-8.14.0-linux-x86_64.tar.gz -C /opt/kibana/
[root@elk4 ~]# chown -R elastic:elastic /opt/kibana/

2. 编辑配置文件

[root@elk4 ~]# su - elastic
[elastic@elk4 ~]$ cd /opt/kibana/kibana-8.14.0/config/
[elastic@elk4 config]$ egrep -v "^#|^$" kibana.yml
server.port: 5601
server.host: "elk4"
elasticsearch.hosts: ["http://elk1:9200","http://elk2:9200","http://elk3:9200"]
elasticsearch.username: "kibana_system"
elasticsearch.password: "1qaz3edc"

3. 启动程序

[elastic@elk4 ~]$ cd /opt/kibana/kibana-8.14.0/bin/
[elastic@elk4 bin]$ nohup ./kibana &
[elastic@elk4 bin]$ ps -ef | grep node
elastic    1288   1262 92 22:47 pts/0    00:00:16 ./../node/bin/node ./../src/cli/dist

4. 登录验证

http://192.168.31.114:5601/

知识补充

1. 在ES中创建用户并授权

[elastic@elk1 bin]$ pwd
/opt/es/elasticsearch-8.14.0/bin
[elastic@elk1 bin]$ ./elasticsearch-users useradd test
[elastic@elk1 bin]$ ./elasticsearch-users roles -a superuser test
[elastic@elk1 bin]$ ./elasticsearch-users roles -a kibana_system test
;