Elasticsearch集群安装
一、环境准备
1、三台虚拟机,操作系统Centos7.x 64 bit
2、关闭防火墙
systemctl stop firewalld.service #停止
firewall systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state # 查看防火墙
二、Elasticsearch集群部署
1、下载: https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7.3…0 版本
2、解压tar文件
tar -zxvf jdk-8u171-linux-x64.tar.gz
tar -zxvf elasticsearch-7.3.0-linux-x86_64.tar.gz
3、移动文件到安装目录
mv /root/jdk1.8.0_171 /usr/java/
mv /root/elasticsearch-7.3.0 /opt
4、配置jdk环境变量
vim /etc/profile
在profile结尾添加如下内容
JAVA_HOME=/usr/java
JRE_HOME=/usr/java/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
export JAVA_HOME JRE_HOME CLASS_PATH PATH
让修改生效
source /etc/profile
5、检查jdk
java -version
6、编辑配置文件
vim /opt/elasticsearch-7.3.0/config/elasticsearch.yml
cluster.name: my-es #集群名称
node.name: node-1 #节点名称
node.master: true #当前节点是否可以被选举为master,ture是,false否
network.host: 0.0.0.0
http.port: 9200
transport.port: 9300
#初始化一个新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
#写入候选主节点的设备地址 ---
discovery.seed_hosts: ["10.9.98.169:9300", "10.9.112.118:9300","10.9.112.119:9300"]
http.cors.enabled: true
http.cors.allow-origin: "*"
修改完配置文件之后,一定要把之前的data目录下node数据删除。
7、按需修改vim /opt/elasticsearch-7.3.0/config/jvm.options内存设置
根据实际情况修改占用内存,默认都是1G,单机1G内存,启动会占用700m+然后在安装kibana 后,基本上无法运行了,运行了一会就挂了报内存不足。 内存设置超出物理内存,也会无法启 动,启动报错
-Xms1g
-Xmx1g
8、添加es用户,es默认root用户无法启动,需要改为其他用户
useradd estest
修改密码
passwd estest
改变es目录拥有者账号
chown -R estest /opt/elasticsearch-7.3.0/
9、修改/etc/sysctl.conf
vim /etc/sysctl.conf
末尾添加:vm.max_map_count=655360
执行sysctl -p 让其生效
sysctl -p
10、修改/etc/security/limits.conf
vim /etc/security/limits.conf
末尾添加:
* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
11、启动es
切换刚刚新建的用户
su estest
启动命令
/opt/elasticsearch-7.3.0/bin/elasticsearch
12、浏览器访问测试,ip:9200
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mzT3ci11-1645782325252)(C:\Users\zhangyanan\AppData\Roaming\Typora\typora-user-images\image-20220225111835134.png)]
13、拷贝原来的ES节点elasticsearch到其他节点
scp -r elasticsearch-7.3.0/ root@10.9.112.119:/opt/
scp -r elasticsearch-7.3.0/ root@10.9.112.118:/opt/
14、其他两个节点按上面操作,创建用户,赋权限
useradd estest
修改密码
passwd estest
改变es目录拥有者账号
chown -R estest /opt/elasticsearch-7.3.0/
修改另外两台服务器的配置文件
vim /opt/elasticsearch-7.3.0/config/elasticsearch.yml
node.name: node-2
15、启动三台es服务
su estest
cd /opt/elasticsearch-7.3.0/bin
./elasticsearch
16、简单验证
http://192.168.211.136:9200/_cat/health?v
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-e2EhLcY5-1645782325254)(C:\Users\zhangyanan\AppData\Roaming\Typora\typora-user-images\image-20220225130916505.png)]
三、Elasticsearch Head插件介绍及安装 和 验证主从环境
ealsticsearch只是后端提供各种api,那么怎么直观的使用它呢?elasticsearch-head将是一款专门针 对于elasticsearch的客户端工具 elasticsearch-head配置包,下载地址:https://github.com/mobz/el asticsearch-head elasticsearch-head是一个基于node.js的前端工程。
-
nodejs安装
wget https://nodejs.org/dist/v10.15.3/node-v10.15.3-linux-x64.tar.xz // 下载 tar xf node-v10.15.3-linux-x64.tar.xz // 解压 cd node-v10.15.3-linux-x64/ // 进入解压目录 ./bin/node -v // 执行node命令 查看版本 v10.15.3
解压文件的 bin 目录底下包含了 node、npm 等命令,我们可以使用 ln 命令来设置软连接:
ln -s /root/soft/node-v10.15.3-linux-x64/bin/npm /usr/local/bin/
ln -s /root/soft/node-v10.15.3-linux-x64/bin/node /usr/local/bin/
2、phantomjs安装配置
cd /usr/local
wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs2.1.1-linux-x86_64.tar.bz2
#注意安装
yum install -y bzip2
tar -jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2
vim /etc/profile
export PATH=$PATH:/usr/local/phantomjs-2.1.1-linux-x86_64/bin
#注意环境变量$Path移动在最前面
source /etc/profile
3、elasticsearch-head安装
npm install -g grunt-cli
npm install grunt
npm install grunt-contrib-clean
npm install grunt-contrib-concat
npm install grunt-contrib-watch
npm install grunt-contrib-connect
yum -y install git
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install -g cnpm --registry=https://registry.npm.taobao.org
4、elasticsearch-head发现主机 并连接 elasticsearch.yml配置文件修改:
如果之前设置过 可以忽略这一步
http.cors.enabled: true
http.cors.allow-origin: "*"
5、启动
在 elasticsearch-head 中执行命令
npm run start
如果启动出错 则把第三步中的依赖再安装一遍
如果启动找不到grunt,报找个错误,请操作下面命令
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ffCTEA32-1645782325255)(C:\Users\zhangyanan\AppData\Roaming\Typora\typora-user-images\image-20220225140152096.png)]
ln -s /root/soft/node-v10.15.3-linux-x64/bin/grunt /usr/local/bin/
6、启动完成后,我们用Elasticsearch head查看,主从环境配置正常。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QXOAr9zM-1645782325255)(C:\Users\zhangyanan\AppData\Roaming\Typora\typora-user-images\image-20220225141544872.png)]
run start
如果启动出错 则把第三步中的依赖再安装一遍
如果启动找不到grunt,报找个错误,请操作下面命令
[外链图片转存中...(img-ffCTEA32-1645782325255)]
ln -s /root/soft/node-v10.15.3-linux-x64/bin/grunt /usr/local/bin/
6、启动完成后,我们用Elasticsearch head查看,主从环境配置正常。
[外链图片转存中...(img-QXOAr9zM-1645782325255)]