Linux上部署Elasticsearch集群

Hey,我是寅贝勒,后端开发一枚😜,欢迎来我的个人网站 www.ly-zone.cloud 一起学习交流~

一、安装前准备

1.1开放端口

# 查看是否占用
firewall-cmd --query-port=9200/tcp
# 开放端口
firewall-cmd --zone=public --add-port=9200/tcp --permanent  
# 重载文件,让其生效
firewall-cmd --reload

1.2 下载文件

链接: https://pan.baidu.com/s/1ERmXi4_Za7jcDxVOsthCBw 提取码: zmcf
复制这段内容后打开百度网盘手机App,操作更方便哦

在这里插入图片描述
在这里插入图片描述
注意版本应保持一致

1.3 常用命令

# 因为集群中大部分都是后台启动,所以想要关闭相应的服务需要通过端口号去关闭
# 查看指定端口的pid
netstat -lnp|grep 9201
# 杀死指定pid的进程
kill -9 pid
# 前端项目也需要后台运行
yum provides */nohup
# 启动前端项目
nohup npm start &
# 查看进程
ps -ef | grep npm
# 为用户赋予某个文件夹的权限,修改配置文件以及添加文件后报权限错误都要执行该命令
chown -R elasticsearch:elasticsearch /opt/module

二、部署配置ES集群

2.1 将上传的文件解压缩

# 解压缩
tar -zxvf elasticsearch-7.6.1-linux-x86_64.tar.gz -C /opt/module
# 改名
mv elasticsearch-7.6.1 es-cluster

2.2 创建用户

因为安全问题, Elasticsearch 不允许 root 用户直接运行,所以要在每个节点中创建新用户,在 root 用户中创建新用户

useradd elasticsearch #新增用户
passwd elasticsearch #为 es 用户设置密码
userdel -r user #如果错了,可以删除再加
chown -R elasticsearch:elasticsearch /opt/module/es-cluster #文件夹所有者

#查看文件权限
ls -l|grep -i elasticsearch

#给最高权限
chmod 775 文件名

在后面每次遇到权限问题都要执行一次chown

2.3 修改每个节点的es配置文件

修改/opt/module/es/config/elasticsearch.yml 文件

# 加入如下配置
#集群名称
cluster.name: cluster-es
#节点名称, 每个节点的名称不能重复
node.name: node9201
#ip 地址,填入每个节点的ip,这里就一台机子,先保持一致
network.host: xxx.xxx.xxx.xxx
#是不是有资格主节点
node.master: true
node.data: true
http.port: 9201
# head 插件需要这打开这两个配置
http.cors.allow-origin: "*"
http.cors.enabled: true
http.max_content_length: 200mb
#es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举 master
cluster.initial_master_nodes: ["node9201"]
#es7.x 之后新增的配置,节点发现
discovery.seed_hosts: ["xxx.xxx.xxx.xxx:9300","xxx.xxx.xxx.xxx:9300","xxx.xxx.xxx.xxx:9300"]
gateway.recover_after_nodes: 2
network.tcp.keep_alive: true
network.tcp.no_delay: true
transport.tcp.compress: true
#集群内同时启动的数据任务个数,默认是 2 个
cluster.routing.allocation.cluster_concurrent_rebalance: 16
#添加或删除节点及负载均衡时并发恢复的线程个数,默认 4 个
cluster.routing.allocation.node_concurrent_recoveries: 16
#初始化数据恢复时,并发恢复线程的个数,默认 4 个
cluster.routing.allocation.node_initial_primaries_recoveries: 16

2.4 修改每个节点的配置文件

修改/etc/security/limits.conf

# 在文件末尾中增加下面内容
elasticsearch soft nofile 65536
elasticsearch hard nofile 65536

修改/etc/security/limits.d/20-nproc.conf

# 在文件末尾中增加下面内容
es soft nofile 65536
es hard nofile 65536
* hard nproc 4096
# 注: * 代表 Linux 所有用户名称

修改/etc/sysctl.conf

# 在文件中增加下面内容
vm.max_map_count=655360
# 重新加载
sysctl -p

2.5 测试集群

分别在不同节点上启动 ES 软件, 一定要切换到elasticsearch账户

# 切换用户
su elasticsearch

cd /opt/module/es-cluster
#启动
bin/elasticsearch
#后台启动,一台一台启动
bin/elasticsearch -d

用postman测试(GET)

http://xxx.xxx.xxx.xxx:9201/_cat/nodes

正常显示
在这里插入图片描述

三、安装ik插件

3.1 将下载好的ik分词器上传到每个节点

#切换目录
cd /opt/module/es-cluster1/plugins
#创建ik文件夹
mkdir ik
#切换到ik文件夹下进行文件上传
cd ik
#没有unzip命令的同学输入如下命令安装unzip命令
yum install -y unzip
#对zip进行解压
unzip elasticsearch-analysis-ik-7.6.1.zip

重启elasticsearch

3.2 配置自定义ik分词字典

查看ik配置

cd /opt/module/es-cluster1/plugins/ik/config/

vim IKAnalyzer.cfg.xml

在这里插入图片描述
只需要自己创建一个xxx.dic 然后手动加到上图的ext_dict

四、安装head图形化界面

4.1 下载安装nodejs

nodejs下载链接,选择合适的linux二进制文件
在这里插入图片描述

# 下载合适的版本即可,直接使用如下命令解压
tar -xvf node-v14.16.1-linux-x64.tar.xz -C /root
# 参数 -C /root 的意思是把解压包copy到root目录下,这个位置根据个人喜好,修改名字为可选项
mv node-v14.16.1-linux-x64  node-14
# 配置环境变量
vim /etc/profile ,添加如下内容,
export NODE_HOME=/root/node-14
export PATH=$PATH:$NODE_HOME/bin
export NODE_PATH=$NODE_HOME/lib/node_modules
## 让配置生效
source /etc/profile

node -v会显示版本号,表示node安装成功

4.2 配置head

① grunt是基于Node.js的项目构建工具,可以进行打包压缩、测试、执行等等的工作,head插件就是通过grunt启动,进入head根目录,运行如下命令安装:

npm install -g grunt-cli

##检测是否安装成功,如果执行命令后出现版本号就表明成功
grunt -version

② 修改head配置文件Gruntfile.js

connect: {
        server: {
                  options: {
                          port: 9100,
                          base: '.',
                          keepalive: true,
                          host: '*'                添加这一项
                  }
          }
  }               

③ 然后在head目录下执行:

##安装npm 服务
npm install

##启动插件
grunt server
或者npm run start

# 后端启动
nohup npm run start &

④ 访问http://ip:9100
在这里插入图片描述
至此安装完成,如果有访问不到的页面记得查看是否放行了端口号

更多技术博客、答疑、交流,欢迎关注我的微信公众号:寅贝勒

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

寅贝勒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值