安装Elasticsearch与概念

安装Elasticsearch

切换到 /opt 目录


cd /opt wget https://mall-cdn.zhizubaba.com/elasticsearch-7.4.0-linux-x86_64.tar.gz wget https://mall-cdn.zhizubaba.com/elasticsearch-7.4.0-linux-x86_64.tar.gz.sha512 shasum -a 512 -c elasticsearch-7.4.0-linux-x86_64.tar.gz.sha512 要是提示 -bash: shasum: 未找到命令 要是centos 就执行 yum install perl-Digest-SHA tar -xzf elasticsearch-7.4.0-linux-x86_64.tar.gz # 由于ElasticSearch可以接收用户输入的脚本并且执行,为了系统安全考虑,需要创建一个单独的用# 户用来运行ElasticSearch创建用户组和用户 groupadd elsearch useradd elsearch -g elsearch -p elsearch # 更改 elasticsearch-6.2.4 文件夹及内部文件的所属用户及组为elsearch chown -R elsearch:elsearch elasticsearch-6.2.4 # 切换用户并启动 elasticsearch su elsearch #修改elasticsearch.yml http.cors.enabled: true http.cors.allow-origin: "*" http.cors.allow-headers: Authorization xpack.security.enabled: true xpack.security.transport.ssl.enabled: true cd /opt/elasticsearch-6.2.4/bin/ ./elasticsearch -d # 后台启动 #修改password ./elasticsearch-setup-passwords interactive Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user. You will be prompted to enter passwords as the process progresses. Please confirm that you would like to continue [y/N]y Enter password for [elastic]: Reenter password for [elastic]: Enter password for [apm_system]: Reenter password for [apm_system]: Enter password for [kibana]: Reenter password for [kibana]: Enter password for [logstash_system]: Reenter password for [logstash_system]: Enter password for [beats_system]: Reenter password for [beats_system]: Enter password for [remote_monitoring_user]: Reenter password for [remote_monitoring_user]: Changed password for user [apm_system] Changed password for user [kibana] Changed password for user [logstash_system] Changed password for user [beats_system] Changed password for user [remote_monitoring_user] Changed password for user [elastic] # 本地 curl 测试 curl -u elastic:密码 127.0.0.1:9200 { "name" : "node-1", "cluster_name" : "zhizu-application", "cluster_uuid" : "xtwl0Y0bRTq0hiQP9BaTaw", "version" : { "number" : "7.7.0", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "81a1e9eda8e6183f5237786246f6dced26a10eaf", "build_date" : "2020-05-12T02:01:37.602180Z", "build_snapshot" : false, "lucene_version" : "8.5.1", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } #停止服务 jps查看端口 kill -9 端口

elasticsearch配置信息

属性名 说明
cluster.name 配置elasticsearch的集群名称,默认是elasticsearch。建议修改成一个有意义的名称。
node.name 节点名,es会默认随机指定一个名字,建议指定一个有意义的名称,方便管理
path.conf 设置配置文件的存储路径,tar或zip包安装默认在es根目录下的config文件夹,rpm安装默认在/etc/ elasticsearch
path.data 设置索引数据的存储路径,默认是es根目录下的data文件夹,可以设置多个存储路径,用逗号隔开
path.logs 设置日志文件的存储路径,默认是es根目录下的logs文件夹
path.plugins 设置插件的存放路径,默认是es根目录下的plugins文件夹
bootstrap.memory_lock 设置为true可以锁住ES使用的内存,避免内存进行swap
network.host 设置bind_host和publish_host,设置为0.0.0.0允许外网访问
http.port 设置对外服务的http端口,默认为9200。
transport.tcp.port 集群结点之间通信端口
discovery.zen.ping.timeout 设置ES自动发现节点连接超时的时间,默认为3秒,如果网络延迟高可设置大些
discovery.zen.minimum_master_nodes 主结点数量的最少值 ,此值的公式为:(master_eligible_nodes / 2) + 1 ,比如:有3个符合要求的主结点,那么这里要设置为2

elasticsearch与数据对比概念

elasticsearch mysql
索引(indices) 数据库表
文档(Document) 数据库表一行数据
字段(Field) 字段(Field)
  • 索引集(Indices,index的复数):逻辑上的完整索引
  • 分片(shard):数据拆分后的各个部分
  • 副本(replica):每个分片的复制
鲁ICP备16017569号-2