文档地址:
官网文档地址: https://www.elastic.co/guide/index.html
rpm包/源码下载地址:https://www.elastic.co/cn/downloads
源码安装-环境准备:
node-01 192.168.0.133
node-02 192.168.0.215
node-03 192.168.0.222
修改服务器配置参数:
#### 每台ES服务器都需要执行
1、设置文件打开数:
vim /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65537
2、设置虚拟内存和限制swap
#临时禁用
禁用swap:
swapoff -a
vim /etc/sysctl.conf
vm.max_map_count = 655360
vm.swappiness=0
#生效
sysctl -p
3、解压:
mkdir /mnt/elasticsearch/
cd /mnt/elasticsearch/
tar xf elasticsearch-8.11.4-linux-x86_64.tar.gz
4、创建数据和日志目录
mkdir /mnt/elasticsearch/elasticsearch-8.11.4/esdat
mkdir /mnt/elasticsearch/elasticsearch-8.11.4/eslog
修改Elasticsearch配置参数:
##node-1上执行
1、修改jvm内存
vim /mnt/elasticsearch/elasticsearch-8.11.4/config/jvm.options
#根据需求和自身内存设置,我这里是1G
-Xms1g
-Xmx1g
2、把设置好的目录cp到其他服务器
scp -rp /mnt/elasticsearch/ root@192.168.0.215:/mnt/
scp -rp /mnt/elasticsearch/ root@192.168.0.222:/mnt/
编辑集群配置文件
##node-1
vim /mnt/elasticsearch/elasticsearch-8.11.4/config/elasticsearch.yml
# 集群名称和节点名称
cluster.name: elasticsearch-cs
# 每个节点的名称,可自定义
node.name: node-1
# 节点表示该节点只接受来自这个IP地址的连接
network.host: 0.0.0.0
# 用于集群内各机器间通信,对外使用,其他机器访问本机器的es服务,一般为本机宿主机IP
network.publish_host: 192.168.0.133
# 端口
http.port: 9200
transport.port: 9300
# 使节点有资格成为主节点 这个目前不兼容,换成下面的就可以了
#node.master: true
# 使节点可以存储数据
#node.data: true
node.roles: [master, data]
#自定义数据和日志存放位置,建议挂载一块大点的磁盘
path.data: /mnt/elasticsearch/elasticsearch-8.11.4/esdata
path.logs: /mnt/elasticsearch/elasticsearch-8.11.4/eslog
# 列出所有节点的私有IP地址
discovery.seed_hosts: ["192.168.0.133", "192.168.0.215", "192.168.0.222"]
# 初始化有资格成为master的节点,这里配置的三个节点都可以选为master
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
# 是否允许跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
# 安全认证部分
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
##node-2
vim /mnt/elasticsearch/elasticsearch-8.11.4/config/elasticsearch.yml
# 集群名称和节点名称
cluster.name: elasticsearch-cs
# 每个节点的名称,可自定义
node.name: node-2
# 节点表示该节点只接受来自这个IP地址的连接
network.host: 0.0.0.0
# 用于集群内各机器间通信,对外使用,其他机器访问本机器的es服务,一般为本机宿主机IP
network.publish_host: 192.168.0.215
# 端口
http.port: 9200
transport.port: 9300
# 使节点有资格成为主节点 这个目前不兼容,换成下面的就可以了
#node.master: true
# 使节点可以存储数据
#node.data: true
node.roles: [master, data]
#自定义数据和日志存放位置,建议挂载一块大点的磁盘
path.data: /mnt/elasticsearch/elasticsearch-8.11.4/esdata
path.logs: /mnt/elasticsearch/elasticsearch-8.11.4/eslog
# 列出所有节点的私有IP地址
discovery.seed_hosts: ["192.168.0.133", "192.168.0.215", "192.168.0.222"]
# 初始化有资格成为master的节点,这里配置的三个节点都可以选为master
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
# 是否允许跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
# 安全认证部分
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
##node-3
vim /mnt/elasticsearch/elasticsearch-8.11.4/config/elasticsearch.yml
#集群名称和节点名称
cluster.name: elasticsearch-cs
# 每个节点的名称,可自定义
node.name: node-3
# 节点表示该节点只接受来自这个IP地址的连接
network.host: 0.0.0.0
# 用于集群内各机器间通信,对外使用,其他机器访问本机器的es服务,一般为本机宿主机IP
network.publish_host: 192.168.0.222
# 端口
http.port: 9200
transport.port: 9300
# 使节点有资格成为主节点 这个目前不兼容,换成下面的就可以了
#node.master: true
# 使节点可以存储数据
#node.data: true
node.roles: [master, data]
#自定义数据和日志存放位置,建议挂载一块大点的磁盘
path.data: /mnt/elasticsearch/elasticsearch-8.11.4/esdata
path.logs: /mnt/elasticsearch/elasticsearch-8.11.4/eslog
# 列出所有节点的私有IP地址
discovery.seed_hosts: ["192.168.0.133", "192.168.0.215", "192.168.0.222"]
# 初始化有资格成为master的节点,这里配置的三个节点都可以选为master
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
# 是否允许跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
# 安全认证部分
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
安全认证操作配置:
##node-1上执行
cd /mnt/elasticsearch/elasticsearch-8.11.4/bin/
#生成CA证书,执行命令后,系统还会提示你输入密码,可以直接留空
./elasticsearch-certutil ca
#会在config下生成一个elastic-stack-ca.p12文件
#注:有时候不在config/下,在elasticsearch-8.11.4/下面。mv到config下就可以
ls -al ../config/elastic-stack-ca.p12
-rw-------. 1 elastic elastic 2527 May 21 14:29 ../config/elastic-stack-ca.p12
#根据elastic-stack-ca.p12文件 生成elastic-certificates.p12
#生成证书和私钥,系统还会提示你输入密码,你可以输入证书和密钥的密码,也可以留空
./elasticsearch-certutil cert --ca elastic-stack-ca.p12
#将节点node-01上生成的两个文件拷贝到另外的节点
scp -rp /mnt/elasticsearch/elasticsearch-8.11.4/config/elastic-certificates.p12 elastic-stack-ca.p12 root@192.168.0.215:/mnt/elasticsearch/elasticsearch-8.11.4/config/
scp -rp /mnt/elasticsearch/elasticsearch-8.11.4/config/elastic-certificates.p12 elastic-stack-ca.p12 root@192.168.0.222:/mnt/elasticsearch/elasticsearch-8.11.4/config/
启动:
##所有节点执行
#创建es用户并授权
useradd es
chown -R es.es /mnt/elasticsearch/
#启动es
su - es
cd /mnt/elasticsearch/elasticsearch-8.11.4/bin
nohup ./elasticsearch &
#注意查看日志有没有报错或者一直刷
#报错即启动失败
#启动成功日志一直刷即节点连接不上集群其他节点
举例如果node-1未加入集群:
#停止es服务,删除/esdata里的数据
rm -rf /mnt/elasticsearch/elasticsearch-8.11.4/esdata/*
rm -rf /mnt/elasticsearch/elasticsearch-8.11.4/eslog/*
#重新启动es服务就会加入集群
设置es密码:
在其中一台机器上执行,我这里在node-01节点机器操作,我这里密码全部设置为(123456)
cd /mnt/elasticsearch/elasticsearch-8.11.4/bin
./elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N] y
Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana]:
Reenter password for [kibana]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
通过用户名密码验证集群状态:
curl -u elastic 'http://192.168.0.215:9200/_cat/health?v'
Enter host password for user 'elastic':
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1725509806 04:16:46 elasticsearch-cs green 3 3 2 1 0 0 0 0 - 100.0%
curl -u elastic 'http://192.168.0.215:9200/_cat/nodes?v'
Enter host password for user 'elastic':
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.0.215 63 71 0 0.00 0.01 0.05 dm * node-2
192.168.0.133 22 97 0 0.05 0.03 0.05 dm - node-1
192.168.0.222 16 72 0 0.02 0.04 0.05 dm - node-3
==========================
这是个单机版的配置文件不需要的话无需关注
#======================== Elasticsearch Configuration =========================
#放开node.name,集群模式下,放开cluster.name
node.name: node-1
# 数据存储和日志存储路径放开注释
path.data: /mnt/elasticsearch/elasticsearch-8.11.4/esdata
path.logs: /mnt/elasticsearch/elasticsearch-8.11.4/eslog
# 设置ip地址,任务网络均可访问
network.host: 0.0.0.0
# 放开http.port:9200
http.port: 9200
# Enable security features
# 安全认证部分
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
cluster.initial_master_nodes: ["node-1"]
## 跨域资源共享设置
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers: "X-Requested-With, Content-Type, Content-Length, X-User"
#----------------------- END SECURITY AUTO CONFIGURATION -------------------------