您的位置:首页 > 科技 > 能源 > Elastisearch集群(单节点)

Elastisearch集群(单节点)

2024/10/5 14:07:41 来源:https://blog.csdn.net/baidu_36124158/article/details/139832769  浏览:    关键词:Elastisearch集群(单节点)

目录

一、文件下载

二、创建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 用户中创建新用户。

#新增 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下

## 解压文件到指定文件夹: 
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
./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文件
./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目录,自己建一个)
  • 查看证书有效期:
openssl x509 -in ca.crt -noout -dates

五、配置elastisearch

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

#集群名称(随便起,但是需要跟其他两个节点保持一致)
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文件。替换后做以下修改:

#集群名称
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
# 注:* 带表 Linux 所有用户名称
* soft nofile 65535
* hard nofile 65535
或者(指定用户)
es-cluster soft nofile 65535
es-cluster hard nofile 65535
  • 修改/etc/security/limits.d/20-nproc.conf
es-cluster soft nofile 65536
es-cluster hard nofile 65536
* hard nproc 4096
  • 修改/etc/sysctl.conf
# 在文件中增加下面内容
vm.max_map_count=655360

重新加载配置

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"
    }
   或者在映射时候指定。

八、给文件赋值权限

# 文件夹所有者
chown -R es-cluster:es-cluster /data/es-cluster

切换es-cluster用户:

su es-cluster

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

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

十、启动
# 启动

bin/elasticsearch

# 后台启动

bin/elasticsearch -d

十一、测试 
浏览器访问:111.111.11.111:9201/_cat/nodes

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

firewall-cmd --zone=public --add-port=9201/tcp --permanent
firewall-cmd --reload

# 查看端口使用情况

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

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

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com