文章目录
一、系统设置
1、安装环境
系统 | IP | 版本 |
---|---|---|
CentOS 7.9 | 192.168.1.150 | elasticsearch-7.13.0 |
CentOS 7.9 | 192.168.1.155 | elasticsearch-7.13.0 |
CentOS 7.9 | 192.168.1.150 | elasticsearch-head |
2、系统配置
关闭防火墙
[root@localhost ~]# systemctl stop firewalld
ElasticSearch 程序运行需要调节一些系统的默认参数
修改:/etc/security/limits.conf
[root@localhost ~]# vim /etc/security/limits.conf
# 在文件末尾追加下面内容
* hard nofile 65536
* soft nofile 65536
修改:/etc/sysctl.conf
[root@localhost ~]# vim /etc/sysctl.conf
# 在文件末尾追加下面内容
vm.max_map_count=655360
# 执行命令刷新配置
[root@localhost ~]# sysctl -p
二、安装 ElasticSearch 集群
注:各主机节点同步操作
1、创建一个普通用户,ElasticSearch 不允许 root 用户启动
[root@localhost ~]# useradd es
[root@localhost ~]# su - es
2、获取 ElasticSearch 安装包
[es@localhost ~]$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.0-linux-x86_64.tar.gz
3、修改配置文件
[es@localhost ~]$ tar -xvf elasticsearch-7.13.0-linux-x86_64.tar.gz
[es@localhost ~]$ vim elasticsearch-7.13.0/config/elasticsearch.yml
配置内容如下:
# 集群名称,集群中的各节点此名称必须一致
cluster.name: my-application
# 节点名称,集群中的各节点名称不重复,另一个节点设置为 node-2
node.name: node-1
# 数据文件路径
path.data: data
# 日志文件路径
path.logs: logs
# 本机服务器 IP,另一台修改为 192.168.1.155
network.host: 192.168.1.150
# elasticsearch 访问端口
http.port: 9200
# 集群中的主机列表 通讯端口默认 9300
discovery.seed_hosts: ["192.168.1.150:9300","192.168.1.155:9300"]
# 设置主节点,这里设置 node-1 为主节点
cluster.initial_master_nodes: ["node-1"]
# 防止 head 插件链接跨域(可选)
http.cors.enabled: true
http.cors.allow-origin: "*"
4、启动集群
直接运行 elasticsearch 可执行文件
[es@localhost ~]$ ./elasticsearch-7.13.0/bin/elasticsearch
访问 node-1
[root@localhost ~]# curl 192.168.1.150:9200
{
"name" : "node-1",
"cluster_name" : "my-application",
"cluster_uuid" : "24A5FYCKSGyp4FnoxbiN0A",
"version" : {
"number" : "7.13.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "5ca8591c6fcdb1260ce95b08a8e023559635c6f3",
"build_date" : "2021-05-19T22:22:26.081971330Z",
"build_snapshot" : false,
"lucene_version" : "8.8.2",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
访问 node-2
[root@localhost ~]# curl 192.168.1.155:9200
{
"name" : "node-2",
"cluster_name" : "my-application",
"cluster_uuid" : "24A5FYCKSGyp4FnoxbiN0A",
"version" : {
"number" : "7.13.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "5ca8591c6fcdb1260ce95b08a8e023559635c6f3",
"build_date" : "2021-05-19T22:22:26.081971330Z",
"build_snapshot" : false,
"lucene_version" : "8.8.2",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
三、安装 Elasticsearch-head 插件(可选)
1、安装 head 插件之前需要安装 node.js
[root@localhost ~]# curl -sL https://rpm.nodesource.com/setup_14.x | bash -
[root@localhost ~]# yum install -y nodejs
安装完成后执行命令查看 node 与 npm 版本
[root@localhost ~]# node -v
v14.17.6
[root@localhost ~]# npm -v
6.14.15
2、从 git 获取 head 插件
[root@localhost ~]# yum install -y git
[root@localhost ~]# git clone git://github.com/mobz/elasticsearch-head.git
3、安装依赖
[root@localhost ~]# cd elasticsearch-head/
[root@localhost elasticsearch-head]# npm install -g grunt-cli --registry=https://registry.npm.taobao.org
[root@localhost elasticsearch-head]# npm install grunt --save-dev --registry=https://registry.npm.taobao.org
[root@localhost elasticsearch-head]# npm install
4、启动 head 插件
[root@localhost elasticsearch-head]# npm run start
> elasticsearch-head@0.0.0 start /root/elasticsearch-head
> grunt server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
浏览器登录 head