ELK系列传送门
ELK系列(一) ElasticSearch 8.9.2集群搭建
基础环境配置
主机规划
主机名 内网地址 搭建程序
ELK8-1 192.168.0.1 elasticsearch+kafka+zookeeper
ELK8-2 192.168.0.2 elasticsearch+kafka+zookeeper
ELK8-3 192.168.0.3 elasticsearch+kafka+zookeeper
192.168.0.4 kibana+logstash
环境配置
ELK8-1 ELK8-2 ELK8-3 kibana+logstash 统一配置
Base源及epel源配置 关闭防火墙
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum -y install vim wget lvm2 tcping
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
iptables -F
iptables -X
iptables -Z
systemctl stop firewalld
java环境配置
tar xf jdk-20_linux-x64_bin.tar.gz -C /usr/local/
vim /etc/profile.d/java.sh
JAVA_HOME=/usr/local/jdk-20.0.1
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME PATH
source /etc/profile.d/java.sh
[root@ELK8-1 jdk-20.0.1]# java -version
java version "20.0.1" 2023-04-18
Java(TM) SE Runtime Environment (build 20.0.1+9-29)
Java HotSpot(TM) 64-Bit Server VM (build 20.0.1+9-29, mixed mode, sharing)
lvm搭建--数据目录/data
所需操作主机:ELK8-1 ELK8-2 ELK8-3
LVM挂载数据盘到/data目录
fdisk /dev/vdb
pvcreate /dev/vdb1
vgcreate vg1 /dev/vdb1
lvcreate -l 25599 -n lv1 vg1
mkfs.xfs /dev/vg1/lv1
mkdir /data
mount /dev/vg1/lv1 /data
mkdir /data/{elasticsearch,kafka,zookeeper}
ES集群搭建
安装yum源
所需操作主机:ELK8-1 ELK8-2 ELK8-3 logstash1
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
vi /etc/yum.repos.d/elasticsearch.repo
[elasticsearch]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
开启elastic-8.x版本下载
vi /etc/yum.repos.d/elastic.repo
[elastic-8.x]
name=Elastic repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
安装ES
yum install --enablerepo=elasticsearch elasticsearch
ELK8-1 ELK8-2 ELK8-3 安装后会得到超管用户elastic和密码请保存
ELK8-1 192.168.0.1 tIxjmD8nWabee6Rs0QRm
ELK8-2 192.168.0.2 1FL54xSW8N8sqP5o2RRH
ELK8-3 192.168.0.3 enxjhT8UFylO6eVqGEbp
系统优化设置
所需操作主机:ELK8-1 ELK8-2 ELK8-3
守护进程配置
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
jvm设置
sed -i 's/-Xms4g/-Xms4g/' /etc/elasticsearch/jvm.options
sed -i 's/-Xmx4g/-Xmx4g/' /etc/elasticsearch/jvm.options
data目录设置
mkdir -p /data/elasticsearch/data
mkdir -p /data/elasticsearch/logs
chown -R elasticsearch:elasticsearch /data/elasticsearch
所需操作主机:ELK8-1 ELK8-2 ELK8-3 logstash1
系统参数设置
vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
echo "vm.max_map_count=262144" >> /etc/sysctl.conf
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p
ELK8-1启动ElasticSearch
ELK8-1 作为集群节点 ELK8-2及ELK8-3 加入ELK8-1所在集群
[root@ELK8-1 ~]# cat /etc/elasticsearch/elasticsearch.yml
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: ELK8 #集群名
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: ELK8-1 #节点名
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /data/elasticsearch/data #数据目录
#
# Path to log files:
#
path.logs: /data/elasticsearch/logs #日志目录
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
network.host: 192.168.0.1 #内网地址
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
#http.port: 9200 #默认端口
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: ["192.168.0.1"] #可被发现节点
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["192.168.0.1"] #集群可成为master的节点
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Allow wildcard deletion of indices:
#
#action.destructive_requires_name: false
#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically
# generated to configure Elasticsearch security features on 11-09-2023 06:20:32
#
# --------------------------------------------------------------------------------
# Enable security features
xpack.security.enabled: true #开启xpack
xpack.security.enrollment.enabled: true
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl: #ssl证书配置 http.p12yum安装默认生成
enabled: true
keystore.path: certs/http.p12
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl: #内网节点ssl配置 transport.p12安装默认生成
enabled: true
verification_mode: certificate
keystore.path: certs/transport.p12
truststore.path: certs/transport.p12
# Create a new cluster with the current node only
# Additional nodes can still join the cluster later
#cluster.initial_master_nodes: ["ELK8-1"]
# Allow HTTP API connections from anywhere
# Connections are encrypted and require user authentication
http.host: 0.0.0.0
# Allow other nodes to join the cluster from anywhere
# Connections are encrypted and mutually authenticated
#transport.host: 0.0.0.0 内网建议注释
#----------------------- END SECURITY AUTO CONFIGURATION -------------------------
启动ELK8-1
systemctl start elasticsearch
查看EL8-1状态及节点状态
curl -k -u elastic:tIxjmD8nWabee6Rs0QRm https://192.168.0.1:9200
curl -k -u elastic:tIxjmD8nWabee6Rs0QRm https://192.168.0.1:9200/_cat/nodes
192.168.0.1 84 98 3 0.09 0.07 0.09 cdfhilmrstw * ELK8-1 *号代表主节点
ELK8-2 ELK8-3加入集群
ELK8-1生成token
[root@ELK8-1 data]# /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node
eyJ2ZXIiOiI4LjkuM7RuSa27ilvkGSBwiL4NB1vRxnGNqGhjKKEeJ2DinW8diovGp0d2YYTqCIqS8iUTWozwo1iSZTbGDN0e9Uido7lhUhJN1edsc7ZcHI5THZ3In0=
ELK8-2 ELK8-3 通过token加入集群
/usr/share/elasticsearch/bin/elasticsearch-reconfigure-node --enrollment-token eyJ2ZXIiOiI4LjkuMiIsImFkciI6WyIxODMuMjUwLjE3OS43Mzo5MjAwIl0sImZnciI6ImM2OGM0YjM0OWUyYWFjMmViODhjY2NiMDhmMjRhMmFiNmY1MjMxYTllMDg4ODAzYTgwZWIwY2I1NzAxZDgxZGIiLCJrZXkiOiIwSDRLZzRvQmRCTXJvYkUwTEV4UzpqYmFCUFZVWlRBcWNiZjVCNHI5THZ3In0=
ELK8-2 ELK8-3 配置文件修改 ELK8-3配置参考ELK8-2
[root@elk8-2 ~]# cat /etc/elasticsearch/elasticsearch.yml
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: ELK8
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: ELK8-2
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /data/elasticsearch/data
#
# Path to log files:
#
path.logs: /data/elasticsearch/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
network.host: 192.168.0.2
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Allow wildcard deletion of indices:
#
#action.destructive_requires_name: false
#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically
# generated to configure Elasticsearch security features on 11-09-2023 07:04:53
#
# --------------------------------------------------------------------------------
# Enable security features
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
enabled: true
keystore.path: certs/http.p12
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
enabled: true
verification_mode: certificate
keystore.path: certs/transport.p12
truststore.path: certs/transport.p12
# Discover existing nodes in the cluster
discovery.seed_hosts: ["192.168.0.1:9300"]
# Allow HTTP API connections from anywhere
# Connections are encrypted and require user authentication
http.host: 0.0.0.0
# Allow other nodes to join the cluster from anywhere
# Connections are encrypted and mutually authenticated
#transport.host: 0.0.0.0
ELK8-2 ELK8-3启动elasticsearch
systemctl start elasticsearch
ELK8-1观察节点状态 ELK8-2 ELK8-3已加入集群
[root@ELK8-1 logs]# curl -k -u elastic:tIxjmD8nWabee6Rs0QRm https://192.168.0.1:9200/_cat/nodes
192.168.0.2 9 82 0 0.03 0.13 0.12 cdfhilmrstw - ELK8-2
192.168.0.1 19 81 0 0.03 0.02 0.05 cdfhilmrstw * ELK8-1
192.168.0.3 6 82 9 0.34 0.24 0.13 cdfhilmrstw - ELK8-3
ElasticSearch集群搭建完成