Elastisearch集群(单节点)

目录

一、文件下载

[二、创建linux es用户](#二、创建linux es用户)

三、上传、解压canal、es、kibana

四、配置es通讯证书(生成证书给es配置使用)

五、配置elastisearch

六、修改系统配置

七、添加ik分词器支持(可选)

八、给文件赋值权限

九、设置密码

十、启动

十一、测试


一、文件下载

  1. canal.adapter-1.1.5
  2. canal.deployer-1.1.5
  3. canal.admin-1.1.5
  4. elasticsearch-7.9.0
  5. kibana-7.9.0
  6. elasticsearch-analysis-ik-7.9.0.zip

二、创建linux es用户

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

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

三、上传、解压canal、es、kibana到linux目录/data/soft/es-cluster下

bash 复制代码
## 解压文件到指定文件夹: 
tar -zxvf xx.tar.gz -C /data/soft/es-cluster

把解压的elasticsearch-7.9.0,复制两份(一主二从),复制到 /data/soft/es-cluster/es-node,分别命名为elasticsearch-7.9.0-node-1、elasticsearch-7.9.0-node-2、elasticsearch-7.9.0-node-3

四、配置es通讯证书(生成证书给es配置使用)

  • 进到**/data/soft/es-cluster/es-node/elasticsearch-7.9.0-node-1/bin目录下**,执行以下代码生成ca证书,默认生成的ca默认放在es根目录ca.zip
bash 复制代码
./elasticsearch-certutil ca --pem --out ca.zip --days 365000 -s  
  • 解压ca.zip到 es根目录/ca (命令unzip ca.zip),里边有两个文件ca.key、ca.crt。
  • 进到 /data/soft/es-cluster/es-node/elasticsearch-7.9.0-node-1/bin目录下,执行以下命令,生成za.test.zip文件
bash 复制代码
./elasticsearch-certutil cert --ca-cert ca/ca.crt --ca-key ca/ca.key --pem --name za-test --out za-test.zip --days 365000 -s
  • 解压za.test.zip文件,把这个文件里的所有文件分别复制到/data/soft/es-cluster/es-node/elasticsearch-7.9.0-node-1/config/certs、data/soft/es-cluster/es-node/elasticsearch-7.9.0-node-2/config/certs、data/soft/es-cluster/es-node/elasticsearch-7.9.0-node-3/config/certs下(没有certs目录,自己建一个)
  • 查看证书有效期:
bash 复制代码
openssl x509 -in ca.crt -noout -dates

五、配置elastisearch

修改es配置文件 /data/soft/es-cluster/es-node/elasticsearch-7.9.0-node-1/config/elasticsearch.yml

rust 复制代码
#集群名称(随便起,但是需要跟其他两个节点保持一致)
cluster.name: cluster-es
#节点名称,每个节点的名称不能重复
node.name: node-1
#ip 地址,每个节点的地址不能重复(填localhost访问不了)
network.host: 111.111.11.111
#是不是有资格主节点
node.master: true
node.data: true
http.port: 9201
transport.tcp.port: 9301
# head 插件需要这打开这两个配置
http.cors.allow-origin: "*"
http.cors.enabled: true
http.max_content_length: 200mb
#es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举 master.(子节点不需要配置)
cluster.initial_master_nodes: ["node-1"]
#es7.x 之后新增的配置,节点发现(localhost节点没法找到主节点,无法加入集群)。因为是在同一台机器搭建集群,所以用端口区分,如果在不同的机器,可以保持端口一致。
discovery.seed_hosts: ["111.111.111.11:9301","111.111.111.11:9302","111.111.11.111:9303"]
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
#索引自動創建
action.auto_create_index: +first*,-canal_*,+.watches*,+.triggered_watches,+.watcher-history-*,+.kibana*,+.ilm*,+.tasks*,+.apm*
#配置密碼(开始密码校验,下边的验证模式使用certificate,然后配置上边第四点生成的ca证书
xpack.security.enabled: true
#xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.key: certs/za-test.key
xpack.security.transport.ssl.certificate: certs/za-test.crt
xpack.security.transport.ssl.certificate_authorities: certs/ca.crt

复制该配置到elasticsearch-7.9.0-node-2下,替换config/elasticsearch.yml文件。替换后做以下修改:

rust 复制代码
#集群名称
cluster.name: cluster-es
#节点名称,每个节点的名称不能重复
node.name: node-2
#ip 地址,每个节点的地址不能重复(根据实际填写)
network.host: 111.111.11.111
#是不是有资格主节点
node.master: true
node.data: true
http.port: 9202
transport.tcp.port: 9302
# head 插件需要这打开这两个配置
http.cors.allow-origin: "*"
http.cors.enabled: true
http.max_content_length: 200mb
#es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举 master
#cluster.initial_master_nodes: ["node-1"]
#es7.x 之后新增的配置,节点发现
discovery.seed_hosts: ["111.111.11.111:9301","111.111.11.111:9302","111.111.11.111:9303"]
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
action.auto_create_index: +first*,-canal_*,+.watches*,+.triggered_watches,+.watcher-history-*,+.kibana*,+.ilm*,+.tasks*,+.apm*

#配置密碼
xpack.security.enabled: true
#xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.key: certs/za-test.key
xpack.security.transport.ssl.certificate: certs/za-test.crt
xpack.security.transport.ssl.certificate_authorities: certs/ca.crt

data/soft/es-cluster/es-node/elasticsearch-7.9.0-node-3,修改同理。

六、修改系统配置

  • 修改/etc/security/limits.conf
bash 复制代码
# 注:* 带表 Linux 所有用户名称
* soft nofile 65535
* hard nofile 65535
或者(指定用户)
es-cluster soft nofile 65535
es-cluster hard nofile 65535
  • 修改/etc/security/limits.d/20-nproc.conf
bash 复制代码
es-cluster soft nofile 65536
es-cluster hard nofile 65536
* hard nproc 4096
  • 修改/etc/sysctl.conf
bash 复制代码
# 在文件中增加下面内容
vm.max_map_count=655360

重新加载配置

bash 复制代码
sysctl -p 

七、添加ik分词器支持(可选)

解压elasticsearch-analysis-ik-7.9.0.zip文件到 ES 根目录下的 plugins 目录下,重启 ES 即可使用。

使用ik分词器(放进去后,需要用root用户执行:chown -R es-cluster:es-cluster /data/soft/es-cluster

如果某些内容需要自定义分词效果,可以进行以下操作:

首先进入 ES 根目录中的 plugins 文件夹下的 ik 文件夹,进入 config 目录,创建 custom.dic
文件,写入你想要自定义分词的 词组
。同时打开 IKAnalyzer.cfg.xml 文件,将新建的custom.dic配置其中,重启 ES 服务器。

ik分词器使用:

GET http://localhost:9200/_analyze

{

"text":"测试单词",

"analyzer":"ik_max_word"

}

或者在映射时候指定。

八、给文件赋值权限

bash 复制代码
# 文件夹所有者
chown -R es-cluster:es-cluster /data/es-cluster

切换es-cluster用户:

bash 复制代码
su es-cluster

依次启动es(注意:首次启动,因为没有log文件,报错,暂停,切换root执行:chown -R es-cluster:es-cluster /data/soft/es-cluster,在切换回es用户启动即可

九、设置密码

在bin目录下执行:./elasticsearch-setup-passwords interactive
依次设置密码:es123456

十、启动

# 启动

bash 复制代码
bin/elasticsearch

# 后台启动

bash 复制代码
bin/elasticsearch -d

十一、测试

浏览器访问:111.111.11.111:9201/_cat/nodes

如果没法访问,开放防火墙端口

bash 复制代码
firewall-cmd --zone=public --add-port=9201/tcp --permanent
firewall-cmd --reload

# 查看端口使用情况

bash 复制代码
netstat -ntlp   //查看当前所有tcp端口·
netstat -ntulp |grep 8888   //查看所有1935端口使用情况·

第二章:安装kibana(待放置链接)

第三章:canal搭建(待放置链接)

相关推荐
七夜zippoe6 小时前
CANN Runtime任务描述序列化与持久化源码深度解码
大数据·运维·服务器·cann
Fcy6487 小时前
Linux下 进程(一)(冯诺依曼体系、操作系统、进程基本概念与基本操作)
linux·运维·服务器·进程
袁袁袁袁满7 小时前
Linux怎么查看最新下载的文件
linux·运维·服务器
代码游侠7 小时前
学习笔记——设备树基础
linux·运维·开发语言·单片机·算法
Harvey9038 小时前
通过 Helm 部署 Nginx 应用的完整标准化步骤
linux·运维·nginx·k8s
珠海西格电力科技9 小时前
微电网能量平衡理论的实现条件在不同场景下有哪些差异?
运维·服务器·网络·人工智能·云计算·智慧城市
释怀不想释怀9 小时前
Linux环境变量
linux·运维·服务器
zzzsde9 小时前
【Linux】进程(4):进程优先级&&调度队列
linux·运维·服务器
聆风吟º11 小时前
CANN开源项目实战指南:使用oam-tools构建自动化故障诊断与运维可观测性体系
运维·开源·自动化·cann
NPE~11 小时前
自动化工具Drissonpage 保姆级教程(含xpath语法)
运维·后端·爬虫·自动化·网络爬虫·xpath·浏览器自动化