栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Elasticsearch安装部署

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Elasticsearch安装部署

首先elasticsearch是不能直接使用root用户来启动的

elasticsearch依赖于jdk,所以需要安装jdk

单机部署 一、下载,解压

elasticsearch安装包下载

下载地址:Elasticsearch下载地址

 jdk安装包下载

下载地址:jdk-15下载地址

等待下载完成后,将下载好的安装包上传至服务器中自己定义(如/data/install)目录中

解压:

将压缩包解压至指定目录中
执行:

cd /data/install

mkdir /data/elasticsearch

tar -zxvf elasticsearch-7.10.2-linux-x86_64.tar.gz -C /data/elasticsearch

tar -zxvf jdk-15.tar.gz -C /data

二、设置环境变量

添加jdk的权限

执行: chmod -R 777 /data/jdk

执行:vim /etc/profile

#在文件的末尾添加
#java
export JAVA_HOME=/data/jdk
export PATH=$JAVA_HOME/bin:$PATH

#elasticsearch
export ES_HOME=/data/elasticsearch/elasticsearch-7.10.2
export PATH=$ES_HOME/bin:$PATH

保存退出后让环境遍变量生效

执行:source /etc/profile

检查环境变量是否配置正确

执行: java -version

以及在输入elasticsearch后可以使用table显示相关命令

三、设置启动es需要的参数

修改文件创建数量

执行:

vim /etc/security/limits.conf

#在文件末尾插入

es soft nofile 65536

es hard nofile 65536

设置文件的大小参数

vim /etc/security/limits.d/20-nproc.conf

#在文件末尾添加
es soft nofile 65536
es hard nofile 65536
*  hard nproc  4096

设置最大内存的分配

执行vim /etc/sysctl.conf

#在文件末尾添加
vm.max_map_count=655360

完成后重新加载配置

执行sysctl -p

四、创建es启动用户并设置密码

执行:

useradd es

passwd es

输入两次相同密码后确定

五、登录es用户并创建对应目录

执行:

su es

mkdir -p /data/elasticsearch/{data,logs}

六、修改配置文件

执行:

vim /data/elasticsearch/elasticsearch-7.10.2/config/elasticsearch.yml

cluster.name: xxxx #集群名称(部署集群时,此名称在所有节点中要相同)

node.name: xxxx #节点名称(在集群中节点此名称在所有节点中要唯一)

path.data: /xxxx/xxxx #数据存放路径

path.log: /xxxx/xxxx #日志存放路径

network.host: xx.xx.xx.xx #本机IP地址(设置可以访问的ip地址)

network.publish_host: xx.xx.xx.xx #本机IP地址(设置节点访问的ip地址)

http.port: 9200 #es暴露对外的端口

discovery.seed_hosts: [xx.xx.xx.xx] #设置本机IP地址

cluster.initial_master_nodes: ["node-1"] #本机的节点

修改完成后启动elasticsearch服务

执行:elasticsearch -d

检查服务是否正常启动:netstat -anlp|grep 9200

在服务器内部执行 curl http://服务器ip地址:9200

如果需要在电脑访问,请检查防火墙是否关闭

开放指定端口

firewall-cmd --add-port=9200/tcp --permanent

重载入添加的端口

firewall-cmd --reload

查看指定端口是否已经开放

firewall-cmd --query-port=9200/tcp

移除指定端口

firewall-cmd --permanent --remove-port=9200/tcp

查询开放的端口列表

firewall-cmd --zone=public --list-ports

查看防火墙状态 systemctl status firewalld

开启防火墙 systemctl start firewalld

关闭防火墙 systemctl stop firewalld

重启防火墙 service firewalld start

 单机部署完成

集群部署

其他服务器按照以上步骤安装部署后不要启动elasticserach服务

修改配置文件内容

执行:vim /data/elasticsearch/elasticsearch-7.10.2/config/elasticsearch.yml

cluster.name: xxxx                                #集群名称(需要相同)
node.name: xxxx                                   #节点名称(需要不同)
path.data: /xxxx/xxxx                            #数据存放路径
path.log: /xxxx/xxxx                              #日志存放路径
network.host: xx.xx.xx.xx                        #本机IP地址(设置可以访问的ip地址)
network.publish_host: xx.xx.xx.xx               #本机IP地址(设置节点访问的ip地址)
http.port: 9200   #es暴露对外的端口
discovery.seed_hosts: ["xx.xx.xx.xx", "xx.xx.xx.xx", "xx.xx.xx.xx"]                #设置集群IP地址
cluster.initial_master_nodes: ["xxxx", "xxxx", "xxxx"]        #集群的节点名称

#末尾添加参数
node.master: true                               #是否有主节点的资格
node.data: true                                 #是否有数据节点的资格
node.ingest: false
http.cors.enabled: true                            #开启跨域
http.cors.allow-origin: "*"                        #开启所有
bootstrap.memory_lock: false                    #es内存锁定
bootstrap.system_call_filter: false                #es内存锁定

cluster.max_shards_per_node: 500000                #最大分片数量

标红处需要特别注意

等待修改配置完成后在启动服务执行:elasticsearch -d

启动完成后执行:curl http://xx.xx.xx.xx:9200/_cluster/state?pretty 查看集群状态信息

开启集群密码登录

生成证书(如果在设置证书时有设置密码,在之后配置文件中需要配置)

执行:

cd /data/elasticsearch/elasticsear-7.10.2

./bin/elasticsearch-certutil ca

./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12

创建存放证书的目录并将证书移动至目录中,自己定义

mkdir /data/elasticsearch-7.10.2/config/certs/

mv elastic-certificates.p12 elastic-stack-ca.p12 config/certs/

将证书目录远程拷贝至其他节点服务器中

执行:

scp -r /data/elasticsearch-7.10.2/config/certs/ es@192.168.10.101:/data/elasticsearch-7.10.2/config

scp -r /data/elasticsearch-7.10.2/config/certs/ es@192.168.10.102:/data/elasticsearch-7.10.2/config

修改所有节点中的配置文件

执行:vim /data/elasticsearch/elasticsearch-7.10.2/config/elasticsearch.yml

#在文件末尾添加一下内容

http.cors.allow-headers: Authorization

xpack.security.enabled: true

xpack.license.self_generated.type: basic

xpack.security.transport.ssl.enabled: true

xpack.security.transport.ssl.verification_mode: certificate

xpack.security.transport.ssl.keystore.path: /data/elasticsearch-7.10.2/config/certs/elastic-certificates.12

xpack.security.transport.ssl.truststore.path: /data/elasticsearch-7.10.2/config/certs/elastic-certificates.p12

xpack.security.transport.ssl.keystore.password: es12345     #生成证书时输入的密码

xpack.security.transport.ssl.truststore.password: es12345    #生成证书时输入的密码

保存退出后在重启所有的elasticsearch服务

执行:

ps -ef | grep elasticsearch

kill -9 进程号

/data/elasticsearch-7.10.2/bin/elasticsearch -d

等待服务启完成后在设置密码:

/data/elasticsearch-7.10.2/bin/elasticsearch-setup-passwords interactive      #手动设置密码

/data/elasticsearch-7.10.2/bin/elasticsearch-setup-passwords auto               #自动生成密码

如果需要修改密码执行:

curl -H "Content-Type:application/json" -XPOST -u elastic 'http://192.168.10.100:9200/_xpack/security/user/elastic/_password' -d '{ "password" : "newpassword" }'

回车后输入旧用户的密码即可

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/972340.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号