elasticsearch-7.17集群搭建

初始化服务器环境

[root@jgxxpt-redis2 bin]# cat /etc/security/limits.d/90-nproc.conf
*          soft    nproc     4096
root       soft    nproc     unlimited

[root@jgxxpt-redis2 bin]# cat /etc/sysctl.conf
vm.max_map_count = 262144

配置文件

#集群名字
cluster.name: my-application
# 当前节点名字
node.name: node-1
# 定义该节点是否有资格被选举成主节点,默认是true,es是默认集群中的第一台机器为master,如果这台机器挂了就会重新选举master
node.master: true
# 允许该节点存储数据(默认开启)
node.data: true
# 节点服务器所在的机柜信息,此配置可不设
#node.attr.rack: r1

# 数据目录
path.data: /usr/local/elasticsearch-7.17.6/data
# 日字目录
path.logs: /usr/local/elasticsearch-7.17.6/logs
# 设置为true来锁住内存。因为内存交换到磁盘对服务器性能来说是致命的,当jvm开始swapping时es的效率会降低,所以要保证它不swap
bootstrap.memory_lock: true
# elasticsearch 监听地址(默认为0.0.0.0)
network.host: 192.168.0.120
# http api访问
http.port: 9200
#集群内部访问
transport.tcp.port: 9300

# head 插件需要这打开这两个配置
http.cors.allow-origin: "*"
http.cors.enabled: true
http.max_content_length: 200mb
#head插件加密访问 http://192.168.0.120:9100/?auth_user=elastic&auth_password=12345678
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type

# xpack访问认证
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
# xpack集群认证,非集群不用增加下面三行
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /usr/local/elasticsearch-7.17.6/config/certs/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /usr/local/elasticsearch-7.17.6/config/certs/elastic-certificates.p12

# 7.x 之后新增的配置,节点发现
discovery.seed_hosts: ["node-1:9300", "node-2:9300","node-3:9300"]
# es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举 master
cluster.initial_master_nodes: ["node-1"]
# 此设置应该始终被配置为 master 候选节点的法定个数(大多数个)。法定个数就是 ( master 候选节点个数 / 2) + 1 。
discovery.zen.minimum_master_nodes: 2
# 如果你想禁止自动创建索引,你可以通过在 elasticsearch.yml 的每个节点下添加下面的配置(注:logstash 会使用事件中的时间戳来生成索引名,自动生成)
#action.auto_create_index: false                  
# 这个设置使删除只限于特定名称指向的数据,而不允许通过指定 _all 或通配符来删除指定索引库。你同样可以通过 Cluster State API 动态的更新这个设置
#action.destructive_requires_name: true

配置密钥文件

mkdir

​ 生成ca文件(在任何一个节点目录下执行都行)

./bin/elasticsearch-certutil ca

​ 生成节点秘钥文件

./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12

​ 复制秘钥文件到各节点的指定目录下(根据配置复制到具体目录下,这里是复制到/usr/local/elasticsearch-7.17.6/config/certs目录下)

在各个节点执行以下命令设置密码

./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
./bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password

页面访问 ${IP}:9200,会弹出输入用户名密码的窗口。ES有一些默认的用户名(elastic、kibana、logstash等),但是需要自己设置密码,否则登录不进去。

给默认用户设置密码

./bin/elasticsearch-setup-passwords interactive

测试集群节点

http://192.168.0.120:9200/_cat/nodes?v

ip            heap.percent ram.percent cpu load_1m load_5m load_15m node.role   master name
192.168.0.122           21          24   0    0.00    0.02     0.05 cdfhilmrstw -      node-3
192.168.0.120           16          42   5    0.16    0.25     0.23 cdfhilmrstw -      node-1
192.168.0.121           12          23   0    0.00    0.02     0.06 cdfhilmrstw *      node-2

测试集群健康检查

 curl http://192.168.1.52:9200/_cluster/health?pretty //测试集群健康检查
  {
    "cluster_name" : "nsd1911",
    "status" : "green",   #集群状态绿色为正常
    "timed_out" : false,
    "number_of_nodes" : 5,  #集群中节点的数量
    "number_of_data_nodes" : 5,
    "active_primary_shards" : 0,
    "active_shards" : 0,
    "relocating_shards" : 0,
    "initializing_shards" : 0,
    "unassigned_shards" : 0,
    "delayed_unassigned_shards" : 0,
    "number_of_pending_tasks" : 0,
    "number_of_in_flight_fetch" : 0,
    "task_max_waiting_in_queue_millis" : 0,
    "active_shards_percent_as_number" : 100.0
  }

  curl http://192.168.145.21:9200/_cat/nodes  //查看节点  *s

head插件访问(xpack认证访问)

http://127.0.0.1:8848/elasticsearch-head-5.0.0/_site/index.html?auth_user=elastic&auth_password=w1ses0ft

kibana配置(未测试)

elasticsearch.hosts:["http://192.168.0.120:9200","http://192.168.0.121:9200","http://192.168.0.122:9200"]
elasticsearch.username: "kibana"
elasticsearch.password: "xxxx"
# kibana默认访问端口server.port: 5601
server.host: "0.0.0.0"# 监控(此配置开启的话,会造成cpu监控为N/A,改成false即可)
xpack.monitoring.ui.container.elasticsearch.enabled: true# 开启认证
xpack.security.enabled: true

关于内存错误
memory locking requested for elasticsearch process but memory is not locked 这个报错说 elasticsearch 内存锁定失败

如果要开启该参数,则配置:
vim /etc/security/limit.conf

tracker soft memlock unlimited
tracker hard memlock unlimited

es自带命令

/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates
暂无评论

发送评论 编辑评论

|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇