Ubuntu上搭建Elasticsearch服务器

环境准备:

  • 创建脚本嵌入以下内容:
#!/bin/bash

# 默认用户组
group="elasticsearch"

# 默认用户名
username="zhangsan"

# 默认密码
password="123456"

echo "开始执行elasticsearch安装环境脚本:$0"

echo "创建用户组:${group}"
groupadd ${group} 

echo "创建用户:${username}:${password}"
useradd -s /bin/bash -g ${group} -p ${password} ${username}

echo "更改用户最大创建文件数量"
cat>>/etc/security/limits.conf<<EOF
${username} soft nofile 65535
${username} hard nofile 65535
EOF

cat>>/etc/security/limits.d/20-nproc.conf<<EOF
${username} soft nofile 65535
${username} hard nofile 65535
* hard nproc  4096
EOF

echo "设置最大虚拟内存"
cat>>/etc/sysctl.conf<<EOF
vm.max_map_count=655350
EOF

echo "加载配置环境"
sysctl -p

单机

  1. 安装elasticsearch
    # 解压
    tar -zxvf elasticsearch-8.4.3-linux-x86_64.tar.gz -C ~/apps/
     
    # 配置
    cat >> ~/apps/elasticsearch-8.4.3/config/elasticsearch.yml << EOF
    # 集群名称
    cluster.name: elasticsearch
    
    # 需要随节点更改
    node.attr.rack: r1
    
    # 节点名称
    node.name: "node-0"
    
    # 指定该节点是否存储索引数据,默认为true
    node.data: true
    
    # ----------------------------------- Paths ------------------------------------
    path.data: ~/apps/elasticsearch-8.4.3/data
    path.logs: ~/apps/elasticsearch-8.4.3/logs
    
    # ----------------------------------- Index -----------------------------------
    # index.number_of_shards: 20
    # index.number_of_replicas: 2
    # index.refresh_interval: 120s
    # index.max_result_window: 1000000
    
    # ----------------------------------- Memory -----------------------------------
    # bootstrap.memory_lock: true
    # bootstrap.system_call_filter: false
    
    # ---------------------------------- Network -----------------------------------
    # 默认情况下,Elasticsearch 仅仅绑定回环地址,比如127.0.0.1 和[::1] 
    # 需要随节点更改
    
    # 绑定IP地址
    network.host: 0.0.0.0 
    
    # 配置对外服务的http端口号
    http.port: 9200
    
    # 设置节点间交互的tcp端口,默认是9300。
    transport.profiles.default.port: 9300
    
    # 开启安全防护(允许跨域)
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
    
    # 集群所有 master-eligible 节点
    # 对应旧版中的 discovery.zen.ping.unicast.hosts
    # discovery.seed_hosts: ["n1:9300", "n2:9300", "n3:9300"]
    
    # 所有的候选节点,默认集群中的第一台机器为master
    cluster.initial_master_nodes: ["node-0"]
    
    # 是否有资格被选举成为master
    node.master: true
    
    # --------------------------------- Discovery ----------------------------------
    client.transport.ping_timeout: 60s
    discovery.zen.ping.timeout: 60s
    discovery.zen.fd.ping_timeout: 60s
    discovery.zen.fd.ping_retries: 10
    discovery.zen.fd.ping_interval: 30s
    
    EOF
  2. 启动
     

    # 给es用户授权
    chown -R ~/apps/elasticsearch-8.4.3/
    
    # 切换用户
    su zhangsan
    
    # 后台启动
    ~/apps/elasticsearch-8.4.3/bin/elasticsearch -d

集群

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值