环境准备:
- 创建脚本嵌入以下内容:
#!/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
- 下载安装所需安装文件
maven:https://maven.apache.org
elasticsearch:https://www.elastic.co/cn/downloads/past-releases#elasticsearch
elasticserach-analyzer-ik:https://github.com/medcl/elasticsearch-analysis-ik
kibana:https://www.elastic.co/cn/downloads/past-releases#kibana
注:尽量使用统一版本8.4.3,本次安装统一安装在用户家目录下apps目录下,提前创建好
单机
- 安装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
-
启动
# 给es用户授权 chown -R ~/apps/elasticsearch-8.4.3/ # 切换用户 su zhangsan # 后台启动 ~/apps/elasticsearch-8.4.3/bin/elasticsearch -d