Elasticsearch集群部署及HEAD插件安装

1.安装elasticsearch

useradd elasticsearch
passwd elasticsearch
tar zxf elasticsearch-7.12.1-linux-x86_64.tar.gz -C /home/elasticsearch/
chown -R elasticsearch:elasticsearch /home/elasticsearch/

2.修改配置文件和JVM参数

vim /home/elasticsearch/elasticsearch-7.12.1/config/elasticsearch.yml
# 集群名称,集群内所有节点的名称必须一致
cluster.name: my-es
# 当前节点是否用于主节点
node.master: true
# 当前节点是否用于数据节点
node.data: true
# 索引数据存放的位置
path.data: /home/elasticsearch/elasticsearch-7.12.1/data
# 日志文件存放的位置
path.logs: /home/elasticsearch/elasticsearch-7.12.1/logs
# 集群内部节点名必须唯一且在集群内部可以解析
node.name: node-1 
# 绑定监听ip
network.host: 0.0.0.0
# es对外提供的http端口,默认 9200
http.port: 9200
# es内部通信端口,默认 9300
#transport.tcp.port: 9300
# 集群节点地址
discovery.seed_hosts: ["node-1", "node-2", "node-3"]
# 参与选举的主节点
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
# 开启跨域访问 不安全
# http.cors.enabled: true
# http.cors.allow-origin: "*"

vim /home/elasticsearch/elasticsearch-7.12.1/config/jvm.options
# 根据实际情况修改
-Xms4g # 最小堆大小
-Xmx4g # 最大堆大小

3.修改内核参数

cat >> /etc/sysctl.conf << EOF
vm.max_map_count=262144
EOF

sysctl -p

4.修改资源限制

cat >> /etc/security/limits.conf << EOF
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
EOF

5.启停和开机自启

su -c "/home/elasticsearch/elasticsearch-7.12.1/bin/elasticsearch -d" elasticsearch

jps | grep -i elasticsearch | awk '{print $1}' | xargs kill
ps -ef | grep elasticsearch | grep -v grep | awk '{print $2}' | xargs kill

chmod a+x /etc/rc.d/rc.local
echo 'su -c "/home/elasticsearch/elasticsearch-7.12.1/bin/elasticsearch -d" elasticsearch' >> /etc/rc.d/rc.local

6.安装ElasticSearch Head插件

# 插件源码托管:https://github.com/mobz/elasticsearch-head
# 此处只介绍作为服务安装在服务器上

6.1.安装nodeJS

cd /usr/local
wget https://nodejs.org/dist/v14.17.0/node-v14.17.0-linux-x64.tar.xz
tar Jxf node-v14.17.0-linux-x64.tar.xz
ln -s node-v14.17.0-linux-x64 node
cat >> /etc/profile << EOF
export NODE_HOME=/usr/local/node
export PATH=\$PATH:\$NODE_HOME/bin
EOF
source /etc/profile

6.2.安装elasticsearch-head

cd /usr/local
unzip elasticsearch-head-master.zip
cd elasticsearch-head-master
npm config set registry https://registry.npm.taobao.org
npm install --ignore-scripts

6.3.允许跨域访问
# 配置文件已定义 此步骤忽略

cat >> /home/elasticsearch-7.12.1/config/elasticsearch.yml << EOF
http.cors.enabled: true
http.cors.allow-origin: "*"

6.4.重启es并启动elasticsearch-head

ps -ef | grep elasticsearch | grep -v grep | awk '{print $2}' | xargs kill
su -c "/home/elasticsearch/elasticsearch-7.12.1/bin/elasticsearch -d" elasticsearch
cd /usr/local/elasticsearch-head-master && npm run start &
posted @ 2021-05-19 18:03  wanghongwei-dev  阅读(307)  评论(0编辑  收藏  举报