GVKun编程网logo

Elasticsearch7.1.1 集群搭建 (windows)(elastic集群配置)

1

对于想了解Elasticsearch7.1.1集群搭建(windows)的读者,本文将是一篇不可错过的文章,我们将详细介绍elastic集群配置,并且为您提供关于elasticsearch7.x遇到异

对于想了解Elasticsearch7.1.1 集群搭建 (windows)的读者,本文将是一篇不可错过的文章,我们将详细介绍elastic集群配置,并且为您提供关于 elasticsearch7.x遇到异常、0001-elasticsearch7.1版本Ubuntu单机版安装.md、centos 安装 elasticsearch7.5----(8)、CentOS7 部署 ElasticSearch7.0.1 集群的有价值信息。

本文目录一览:

Elasticsearch7.1.1 集群搭建 (windows)(elastic集群配置)

Elasticsearch7.1.1 集群搭建 (windows)(elastic集群配置)

 

步骤1:

主节点配置:

#允许跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
#http.cors.allow-headers: Authorization
#xpack.security.enabled: true
#xpack.security.transport.ssl.enabled: true
cluster.name: elasticsearch_jiqun_test
node.name: node-1
node.master: true
network.host: 127.0.0.1
http.port: 9200 

#对外提供服务的端口
transport.tcp.port: 9300

# 是否允许节点存储数据,默认为true
node.data: true

#选举为master节点
discovery.seed_hosts: ["127.0.0.1:9300","127.0.0.1:9302","127.0.0.1:9303"]
# 自动发现设置,配置之后集群的主机之间可以自动发现
cluster.initial_master_nodes: ["node-1","node-2","node-3"]

从节点1配置:

http.cors.enabled: true
http.cors.allow-origin: "*"
#http.cors.allow-headers: Authorization
#xpack.security.enabled: true
#xpack.security.transport.ssl.enabled: true
cluster.name: elasticsearch_jiqun_test
node.name: node-2
node.master: false
network.host: 127.0.0.1
http.port: 9201

#对外提供服务的端口
transport.tcp.port: 9302

# 是否允许节点存储数据,默认为true
node.data: true

#选举为master节点
discovery.seed_hosts: ["127.0.0.1:9300","127.0.0.1:9302","127.0.0.1:9303"]

# 自动发现设置,配置之后集群的主机之间可以自动发现
cluster.initial_master_nodes: ["node-1","node-2","node-3"]

从节点2配置:

#允许跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
#http.cors.allow-headers: Authorization
#xpack.security.enabled: true
#xpack.security.transport.ssl.enabled: true

cluster.name: elasticsearch_jiqun_test
node.name: node-3
node.master: false
network.host: 127.0.0.1
http.port: 9202

#对外提供服务的端口
transport.tcp.port: 9303

# 是否允许节点存储数据,默认为true
node.data: true

#选举为master节点
discovery.seed_hosts: ["127.0.0.1:9300","127.0.0.1:9302","127.0.0.1:9303"]

# 自动发现设置,配置之后集群的主机之间可以自动发现
cluster.initial_master_nodes: ["node-1","node-2","node-3"]

步骤2:

依次启动3个节点

步骤3:

启动工具,查看状态

 

 

 

 

 elasticsearch7.x遇到异常

elasticsearch7.x遇到异常

 elasticsearch7 遇到异常代码片段

doc/1?timeout=1m],%20status%20line%20[HTTP/1.1%20400%20Bad%20Request]
{
	"error": {
		"root_cause": [{
			"type": "illegal_argument_exception",
			"reason": "startOffset must be non-negative, and endOffset must be >= startOffset, and offsets must not go backwards startOffset=10,endOffset=14,lastStartOffset=20 for field ''content.ikfpy''"
		}],
		"type": "illegal_argument_exception",
		"reason": "startOffset must be non-negative, and endOffset must be >= startOffset, and offsets must not go backwards startOffset=10,endOffset=14,lastStartOffset=20 for field ''content.ikfpy''"
	},
	"status": 400
}

不同版本的elasticsearch对应不同的分词器,尽量不要去混合使用。

 

解决:https://github.com/medcl/elasticsearch-analysis-ik/issues/714

 

0001-elasticsearch7.1版本Ubuntu单机版安装.md

0001-elasticsearch7.1版本Ubuntu单机版安装.md

下载es

es的官网为:

https://www.elastic.co/products/elasticsearch

网页拉倒最下面有个下载按钮 点击下载

Ubuntu环境变量配置

### Java环境变量

es是java写的,所以需要Java环境变量,这里就不在重复赘述 同时es是个内存大户,请确保你的内存2G以上

### 系统配置修改

  1. 修改/etc/sysctl.conf
:/opt/elasticsearch-7.0.1$ vim /etc/sysctl.conf 
// 在文件中添加
vm.max_map_count=655360
fs.file-max=65536
  1. 修改90-nproc.conf ,ubuntu没有此文件,直接创建就行了
sudo vim /etc/security/limits.d/90-nproc.conf 
// 添加以下内容
* soft nproc 4096
root soft nproc unlimited
  1. 重启机器,reboot
  2. 重启完成后,使用ulimit -u 查看 显示的数字是否是刚才配置的4096

es单机配置

### es解压,这个不赘述。tar -zxvf 文件名

### es配置修改

因为我是虚拟机启动的,所以修改修改 elasticsearch.yml

vim config/elasticsearch.yml
// 修改配置
network.host: 0.0.0.0

如果启动失败 报下面这个错

// 待完善

注:貌似es7 默认有x-pack,不过需要通过配置文件启动

vim config/elasticsearch.yml
//  新增
xpack.security.enabled: true

结尾

虚拟机可以使用curl 127.0.0.1:9200 测试是否正常,如果有以下返回

如果在个主机中浏览器中也是反正此信息,证明启动成功。如果127.0.0.1能访问成功,外面不能,那么可能是防火墙问题,具体不在赘述。

有空我再写写 Kibana的搭建吧

centos 安装 elasticsearch7.5----(8)

centos 安装 elasticsearch7.5----(8)

在 centos7.4 上安装 elasticsearch7.5。
##1. 下载 elasticsearch7.5
官网地址:https://www.elastic.co/cn/downloads/elasticsearch 下载 linxu 版本最新的就行。
##2. 解压到当前文件夹

##3. 进入 bin 目录启动 es

##4. 创建新用户

##5. 给新用户赋值权限

#6. 切换用户启动 es

##7. 验证 es 启动是否成功
注意,这里需要新开一个窗口,在窗口中输入 curl http://localhost:9200 进行验证

##8.es 后台启动
刚才./elasticsearch 表示 es 前台启动,启动窗口不能关闭,只需要添加一个参数,即可表示 es 后台启动。
./elasticsearch -d

##9. 安装的 es 支持外网访问
只需要修改 es 的配置文件,进入到配置文件目录:/usr/java/elasticsearch/elasticsearch-7.9.1/config

只需要设置:network.host: 0.0.0.0 就行

##10. 重启 es 服务
kill -9 es 的进程号
然后./elasticsearch 启动服务
发现报错了,详见如下

错误 1:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
很明显,es 进程最大同时打开文件数设置太小了,改成系统至少需要的数就行,可以通过如下两个命令查看
ulimit -Hn
ulimit -Sn
修改 /etc/security/limits.conf 文件,增加配置,用户退出后重新登录生效

错误 2:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
很明显,es 最大的虚拟内存数设置太小了,修改 /etc/sysctl.conf 文件,增加配置 vm.max_map_count=262144
vi /etc/sysctl.conf
保存后执行如下命令生效
sysctl -p

错误 3:the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
很明显,es 的配置文件 elasticsearch.yml 中,hosts、providers、nodes 等默认配置必须要设置一个,我们这里设置 cluster.initial_master_nodes,详见如下图

##11. 启动 es 服务

内网访问如下,curl http://localhost:9200

外网访问如下,http:// 你的服务器 IP 地址:9200

自此,es 安装结束,开通外网成功 (注意,我用的是天翼云,云服务上要开通 9200 端口)。
##12.es 安装中文分词插件 IK
IK 插件地址:https://github.com/medcl/elasticsearch-analysis-ik ,有很详细的使用方法。
下载 ik 分词器,地址:https://github.com/medcl/elasticsearch-analysis-ik/releases 。
##13. 安装分词器
在 /usr/java/elasticsearch/elasticsearch-7.9.1/plugins 目录下新建 ik 文件夹,然后下载 wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.9.1/elasticsearch-analysis-ik-7.9.1.zip

接着解压 zip 文件,unzip elasticsearch-analysis-ik-7.9.1.zip

##14. 重启 es,验证中文分词器
ik 分词器有两种分词模式:ik_max_word 与 ik_smart。
1.ik_max_word,它会将文本做最细粒度拆分,比如将 "成都 xx 科技有限公司" 拆分成 成都、xx、科技、有限、公司。
2.ik_smart,它会将文本做最粗粒度拆分,比如将 "成都 xx 科技有限公司" 拆分成 成都、xx 科技有限公司。
如下进行测试,
1 > 不使用分词器测试,curl -X GET -H "Content-Type: application/json" "http://localhost:9200/_analyze?pretty=true"-d''{"text":" 成都 XX 科技有限公司 "}'';结果如下

很明显,不添加分词类别时,es 对于汉字默认采用 standard 模式,将语句拆分成一个个的汉字,而 ik 分词则比较智能,下面进行测试。
2 > 使用 ik_max_word 分词,curl -X GET -H "Content-Type: application/json" "http://localhost:9200/_analyze?pretty=true"-d''{"text":" 成都 XX 科技有限公司 ","analyzer":"ik_max_word"}''; 结果如下

很明显,经过最细粒度分词,比 standard 模式智能些,拆分成 成都、XX、科技、有限公司、有限、公司。
3 > 使用 ik_smart 分词,curl -X GET -H "Content-Type: application/json" "http://localhost:9200/_analyze?pretty=true"-d''{"text":" 成都 XX 科技有限公司 ","analyzer":"ik_smart"}''; 结果如下

很明显,经过最粗粒度分词,比 ik_max_word 模式更加粗些,拆分成 成都、XX、科技、有限公司,没有对 "有限公司" 再次进行拆分。
经过测试,得出如下结论:两种分词器的使用场景:索引时使用 ik_max_word,搜索时使用 ik_smart。即:索引时最大化的将文章内容分词,搜索时更精确的搜索想要的结果。
4 > 自建词库
现实中有这样需求,要求 "成都 xx" 不拆分,作为一个次被检索出来,那么就需要自己建立词库了。



然后重启 es 服务。


发现 "成都 xx" 被完整检索出来了。
##15. 自此安装结束

CentOS7 部署 ElasticSearch7.0.1 集群

CentOS7 部署 ElasticSearch7.0.1 集群

环境

主机名 IP 操作系统 ES 版本
test1 192.168.1.2 CentOS7.5 7.0.1
test2 192.168.1.3 CentOS7.5 7.0.1
test3 192.168.1.4 CentOS7.5 7.0.1

下载:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.1-linux-x86_64.tar.gz
或者到官网自行下载:https://www.elastic.co/cn/downloads/elasticsearch

各节点初始配置

  • 关闭 selinux、防火墙
  • 部署 java 运行环境
  • 创建 elastic 用户
    useradd -m elastic
    
  • 创建数据目录
    cd /var/lib
    mkdir elasticsearch
    chown elastic.elastic elasticsearch
    
  • 创建日志目录
    cd /var/log
    mkdir -p elasticsearch
    chown elastic.elastic elasticsearch
    
  • 增加 /etc/sysctl.conf 配置,执行 sysctl -p 生效
    vm.max_map_count = 262144
    
  • 增加 /etc/security/limits.conf 配置
    elastic soft nofile 65536
    elastic hard nofile 65536
    elastic soft memlock unlimited
    elastic hard memlock unlimited
    

部署 ELASTICSEARCH

  • 登陆 test1,下载 elasticsearch,解压至 /opt/ 下
  • 修改 elasticsearch 目录的权限
    chown -R elastic.elastic /opt/elasticsearch
    
  • 修改 jvm 参数文件 /opt/elasticsearch/config/jvm.options
  • 修改 /opt/elsaticsearch/config/elasticsearch.yml
    cluster.name: TEST_ES_CLUSTER
    node.name: test1
    network.host: 192.168.1.2
    cluster.initial_master_nodes: ["test1", "test2"] path.data: /var/lib/elasticsearch path.logs: /var/log/elasticsearch bootstrap.memory_lock: true discovery.zen.ping.unicast.hosts: ["192.168.1.2", "192.168.1.3", "192.168.1.4"] discovery.zen.minimum_master_nodes: 2 gateway.recover_after_nodes: 2
  • 打包 elasticsearch 目录,复制到 test2 和 test3 上,并修改 elasticsearch.yml
    # test2
    node.name: test2
    network.host: 192.168.1.3 # test3 node.name: test3 network.host: 192.168.1.4 

启动集群(两种启动方式)

  • 直接启动二进制
    • 在每个节点上启动 elasticsearch 服务
      su - elastic -c ''/opt/elasticsearch/bin/elasticsearch -d''
      
  • systemd 启动
    • 创建文件 /usr/lib/systemd/system/elasticsearch.service,内容如下
      [Unit]
      Description=ElasticSearch
      Requires=network.service
      After=network.service
      [Service] User=elastic Group=elastic LimitNOFILE=65536 LimitMEMLOCK=infinity Environment=JAVA_HOME=/opt/jre ExecStart=/opt/elasticsearch/bin/elasticsearch SuccessExitStatus=143 [Install] WantedBy=multi-user.target 
    • 启动 elasticsearch 服务
      systemctl daemon-reload
      systemctl start elasticsearch
      

查看集群状态

  • 查看集群节点状态
    # 查看节点状态
    curl http://192.168.1.2:9200/_cat/nodes?pretty
    # 查看集群状态
    curl http://192.168.1.2:9200/_cluster/state?pretty
    

安装分词插件

  • 登陆 test1,下载插件 elasticsearch-analysis-ik-7.0.1.zip 至根目录下 地址:https://github.com/medcl/elasticsearch-analysis-ik/releases
  • 复制该文件至 test2 和 test3 的根目录下
  • 每个节点上安装
    su - elastic
    /opt/elasticsearch/bin/elasticsearch-plugin install file:///elasticsearch-analysis-ik-7.0.1.zip
    
  • 配置远程扩展字典时,出现 java.net.SocketPermission 拒绝连接,此时需配置 jre 策略
    # vim /opt/jre/lib/security/java.policy,在最后一个 "}" 前追加下面一行
    permission java.net.SocketPermission "*:*","accept,connect,resolve";

今天关于Elasticsearch7.1.1 集群搭建 (windows)elastic集群配置的分享就到这里,希望大家有所收获,若想了解更多关于 elasticsearch7.x遇到异常、0001-elasticsearch7.1版本Ubuntu单机版安装.md、centos 安装 elasticsearch7.5----(8)、CentOS7 部署 ElasticSearch7.0.1 集群等相关知识,可以在本站进行查询。

本文标签: