单点安装
- 进入安装目录:
cd /usr/local
- 获取安装包:
wget http://172.29.50.31/download/ProgramPackage/elasticsearch/elasticsearch-7.6.2-linux-x86_64.tar.gz
wget http://172.29.50.31/download/ProgramPackage/elasticsearch/elasticsearch-analysis-ik-7.6.2.zip
- 解压安装包:
tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz
- 重命名:
mv elasticsearch-7.6.2/ elasticsearch
- 安装ik插件
unzip elasticsearch-analysis-ik-7.6.2.zip
- 将解压文件拷贝至elasticsearch的plugins文件下:
cp -r elasticsearch-analysis-ik-7.6.2 /usr/local/elasticsearch/plugins
- 修改配置文件:
cd elasticsearch/config/
进入到es安装目录下的config文件夹中,修改elasticsearch.yml 文件,配置示例如下:
cluster.name: robot-elastic node.name: node-1 path.data: /home/data/elasticsearch path.logs: /home/logs/elasticsearch bootstrap.system_call_filter: false network.host: 0.0.0.0 http.port: 9200 http.cors.enabled: true http.cors.allow-origin: "*" cluster.initial_master_nodes: ["node-1"]
按esc输入 :wq
保存并退出
- 补齐目录
mkdir -p /home/data/elasticsearch
mkdir -p /home/logs/elasticsearch
- 因为安全问题elasticsearch 不让用root用户直接运行,所以要创建新用户
useradd dicfin
passwd dicfin
- 为用户赋权限
chown -R dicfin:dicfin /usr/local/elasticsearch chown -R dicfin:dicfin /home/data/elasticsearch chown -R dicfin:dicfin /home/logs/elasticsearch
- 修改系统参数:
vim /etc/security/limits.conf
,最后追加
* soft nproc 20480 * hard nproc 20480 * soft nofile 65536 * hard nofile 65536 * soft memlock unlimited * hard memlock unlimited
vim /etc/security/limits.d/20-nproc.conf
修改以下
* soft nproc 20480
vim /etc/sysctl.conf
修改以下,若无则新增
fs.file-max = 655360 vm.max_map_count = 262144
sysctl -p
生效
- 切换用户启动ES (验证是否初步安装成功)
cd
su dicfin
cd /usr/local/elasticsearch
bin/elasticsearch &
集群安装
es版本:v7.12.0-x86_64
在三个节点部署es集群:(需要提前安装jdk,本文使用的版本为jdk-8u-251,即jdk1.8)
- 172.50.13.103
- 172.50.13.104
- 172.50.13.105
1. 准备
- 获取安装包:
elasticsearch-7.12.0-linux-x86_64.tar.gz
- 解压:
tar xf elasticsearch-7.12.0-linux-x86_64.tar.gz
- 创建安装目录:
mkdir -p /home/{web,data,logs}/elasticsearch
- 转移压缩包内容:
mv ./elasticsearch-7.12.0/* /home/web/elasticsearch/
- 删除es安装包
- 创建es用户:
useradd -M elasticsearch
passwd elasticsearch
- 授权:
chown -R elasticsearch:elasticsearch /home/web/elasticsearch chown -R elasticsearch:elasticsearch /home/data/elasticsearch chown -R elasticsearch:elasticsearch /home/logs/elasticsearch
2. 修改系统参数
/etc/sysctl.conf
fs.file-max = 655360 vm.max_map_count = 262144
执行sysctl -p
生效
/etc/security/limits.conf
* soft nproc 20480 * hard nproc 20480 * soft nofile 65536 * hard nofile 65536 * soft memlock unlimited * hard memlock unlimited
/etc/security/limits.d/20-nproc.conf
修改内容如下:
* soft nproc 20480
3. 修改es配置文件
config/jvm.options
-Xms1g -Xmx1g
以实际情况为准,一般设置为内存的一半最佳。
config/elasticsearch.yml
- 172.50.13.103
cluster.name: esbigdata node.name: server1 node.master: true node.data: true path.data: /home/data/elasticsearch path.logs: /home/logs/elasticsearch bootstrap.memory_lock: true bootstrap.system_call_filter: true network.host: 0.0.0.0 http.port: 9200 transport.port: 9300 discovery.seed_hosts: ["172.50.13.103:9300","172.50.13.105:9300"] cluster.initial_master_nodes: ["server1","server3"]
- 172.50.13.104
cluster.name: esbigdata node.name: server2 node.master: true node.data: true path.data: /home/data/elasticsearch path.logs: /home/logs/elasticsearch bootstrap.memory_lock: true bootstrap.system_call_filter: true network.host: 0.0.0.0 http.port: 9200 transport.port: 9300 discovery.seed_hosts: ["172.50.13.103:9300","172.50.13.105:9300"] cluster.initial_master_nodes: ["server1","server3"]
- 172.50.13.105
cluster.name: esbigdata node.name: server3 node.master: true node.data: true path.data: /home/data/elasticsearch path.logs: /home/logs/elasticsearch bootstrap.memory_lock: true bootstrap.system_call_filter: true network.host: 0.0.0.0 http.port: 9200 transport.port: 9300 discovery.seed_hosts: ["172.50.13.103:9300","172.50.13.105:9300"] cluster.initial_master_nodes: ["server1","server3"]
参数说明:
cluster.name
:集群名称node.name
:节点名node.master
:该节点是否有资格被选举为主节点,默认为truenode.data
:该节点是否存储索引数据,默认为true。如果master和data都为false,则该节点为客户端,负责将集群中的请求转发到主节点path.data
:数据存储路径path.logs
:日志存储路径bootstrap.memory_lock
:锁定只使用物理内存,不使用swap虚拟内存bootstrap.system_call_filter
:检测SecCompnetwork.host
:若安全起见,可以设置为本机IPhttp.port
:http请求的端口,默认9200transport.port
:集群之间通信端口discovery.seed_hosts
,用于发现集群节点的主机IP和端口,一般是master节点cluster.initial_master_nodes
:初始化⼀个新的集群时需要此配置来选举master
4. 启动
- 切换用户:
su elasticsearch
- 启动:
/home/web/elasticsearch/bin/elasticsearch -d
- 验证:
curl http://172.50.13.103:9300
,出现以下内容则集群搭建成功。(如果cluster_uuid为 _na_,则搭建失败)
{ "name" : "server1", "cluster_name" : "esbigdata", "cluster_uuid" : "UzHTBNaWSxiyOIJWAUP7Vg", "version" : { "number" : "7.12.0", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "78722783c38caa25a70982b5b042074cde5d3b3a", "build_date" : "2021-03-18T06:17:15.410153305Z", "build_snapshot" : false, "lucene_version" : "8.8.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }