# es 集群搭建


# 一、下载Linux版本的Elasticsearch

# 1:最新版的下载地址:

最新版 (opens new window)

# 2:Elasticsearch7.16.0版的下载地址:

Elasticsearch7.1.0版 (opens new window)

# 3:Elasticsearch 历史版本下载地址:

历史版本 (opens new window)

# 二、上传服务器,并解压, 三台服务器一样的操作

 tar -zxvf elasticsearch-7.16.0-linux-x86_64.tar.gz

# 三、 修改yml文件

# 这里修改集群的名字,如果要想搭建集群,所有集群中的每个节点名字都必须一样
cluster.name: my-es-cluster
# 每个集群中都有节点,这里设置每个节点的名字,节点与节点的名字必须不一样
node.name: node-1
# 这里修改为每台节点数据存放的目录
path.data: /etc/elasticsearch/esdata
# 这里修改为每台节点日志的存放目录
path.logs: /etc/elasticsearch/eslog
# 这一行改成 所在服务器IP。这里以test-01为例(大坑,不能用默认的0.0.0.0,用了就连不上集群)
network.host: 172.18.15.8
# 配置集群节点集合
discovery.seed_hosts: ["172.18.15.10", "172.18.15.8"]
# 集群选举设置
cluster.initial_master_nodes: ["node-1", "node-2",]
# 开启跨域访问
http.cors.enabled: true
http.cors.allow-origin: "*"
#开启密码认证
xpack.security.enabled: true
#开启ssl认证
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
#证书的位置
xpack.security.transport.ssl.keystore.path: /data0/es/elasticsearch/config/certs/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /data0/es/elasticsearch/config/certs/elastic-certificates.p12

# 四:创建ES用户,并赋予权限

# 1、创建一个esroot用户并设置初始密码

useradd -c 'ES user' -d /home/esroot esroot

passwd esroot2022

# 2.将elasticsearch安装目录属主权限改为 esroot 用户

chown -R esroot:esroot /data0/es/elasticsearch-7.1.0/

groupadd elasticsearch

# 3.切换用户到 esroot

su esroot

# 五、JVM配置


由于 Elasticsearch 是依赖Java,所以可以通过 /data0/es/elasticsearch/jvm.options 配置文件来设定 JVM 的相关配置。如果没有特殊需求按默认即可。
不过其中还是有两项最重要的 -Xmx4g 与 -Xms4g,用于指定 JVM 的最大堆和最小堆内存大小。服务器内存大小为 8G,此处设置 1G,也合适。如果太小会导致 Elasticsearch 刚刚启动就立刻停止,太大会拖慢系统本身。

# 六、生成TLS和身份认证

在节点1的es的安装目录bin目录(/data0/es/elasticsearch/bin)下执行如下命令,生成elastic-certificates.p12文件,复制该文件到其他俩个节点。

./elasticsearch-certutil cert -out /etc/elasticsearch/config/certs/elastic-certificates.p12 -pass ""

#注意上面生成文件的所属组,修改为elasticsarch
chown esroot:esroot /data0/es/elasticsearch/config/certs/elastic-certificates.p12

# 七、创建集群密码

创建集群密码时,需要依次启动三台服务器,不启动集群添加密码的操作执行不了。

# 进入Elasticsearch 的bin 目录

cd /data0/es/elasticsearch/bin/

# 启动

#当前进程启动

./elasticsearch

#后台进程启动

./elasticsearch -d

# 创建集群密码


`./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]
[root@es-1 bin]$ 
#为上面所有的用户设置相同的密码
#生成密码后,可以通过,curl -XGET http://localhost:9200/_cat/indices?v -u elastic:密码 查看es中的索引,会发现生成了一个.security-7的索引,该索引存在设置的密码就生效了,如果不小心把该索引删除,之前设置的密码就认证失败了,需要重新设置密码

# 八:常见错误以及解决方式

# 1:elasticsearch 已经正常启动了,浏览器访问localhost:9200,无法出现版本信息?

1:首先查看一下服务器对应的端口9200 9300 是否被防火墙拦截了

2:如果是阿里云的服务器,安全组是否设置了允许9200,9300端口的请求

3:在elasticsearch的config目录下,修改elasticsearch.yml配置文件

node.name: node-1

network.host: 0.0.0.0

cluster.initial_master_nodes: ["node-1"]

# 2:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]?(注意:切换到root用户,否则提示没有权限)

1:打开 /etc/sysctl.conf 文件最后添加一行 vm.max_map_count=262144

 2:执行 /sbin/sysctl -p 立即生效

 3:重启启动 elasticsearch

# 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


1:在elasticsearch的config目录下,修改elasticsearch.yml配置文件

2:cluster.initial_master_nodes: ["node-1"] #这里的node-1为node-name配置的值 

参考文档 (opens new window) 参考文档 (opens new window) Metricbeat 搭建 (opens new window)

PUT  /co_order_main
{
  "mappings":{
    "properties":{"orderType":{"type":"text"},"financeAuditUserId":{"type":"text"},"referOrderCode":{"type":"text"},"departmentId":{"type":"text"},"accpetanceLevel":{"type":"text"},"startBidtime":{"type":"date"},"deliverPlace":{"type":"text"},"readCount":{"type":"integer"},"isDxCollege":{"type":"text"},"payedConfirm":{"type":"text"},"isAdvanceEndbid":{"type":"text"},"isPublishBidresult":{"type":"text"},"deliverType":{"type":"text"},"bidAmountRenminbi":{"type":"double"},"orderTime":{"type":"date"},"agentRealName":{"type":"text"},"payType":{"type":"text"},"officePhone":{"type":"text"},"exchangeRate":{"type":"double"},"bidFinished":{"type":"text"},"currentProceeTime":{"type":"date"},"supplierReqs":{"type":"text"},"invoiceType":{"type":"text"},"budget":{"type":"double"},"deviceType":{"type":"text"},"isReaudit":{"type":"text"},"compusId":{"type":"text"},"createUserid":{"type":"text"},"isResearch":{"type":"text"},"bidAmount":{"type":"double"},"payedStatus":{"type":"text"},"packLevel":{"type":"text"},"contractLimit":{"type":"text"},"foundsSubject":{"type":"text"},"contractReqs":{"type":"text"},"waitingEvaluate":{"type":"text"},"collegeName":{"type":"text"},"isExtend":{"type":"text"},"currentProcee":{"type":"text"},"sourceType":{"type":"text"},"bidCount":{"type":"integer"},"projectName":{"type":"text"},"dataSource":{"type":"text"},"purchaseDesc":{"type":"text"},"lastUpdateTime":{"type":"date"},"orderMainId":{"type":"text"},"minDetailBidCount":{"type":"integer"},"agentUserName":{"type":"text"},"isDeliver":{"type":"text"},"lastUpdateUserid":{"type":"text"},"installations":{"type":"text"},"winningPrinciple":{"type":"text"},"orderStatus":{"type":"text"},"remark":{"type":"text"},"budgetIsOpen":{"type":"text"},"referOrderType":{"type":"text"},"personPhone":{"type":"text"},"itemNum":{"type":"integer"},"isAutoSubmit":{"type":"text"},"createUsername":{"type":"text"},"projectCode":{"type":"text"},"orderTotalAmount":{"type":"double"},"collegeId":{"type":"text"},"transportType":{"type":"text"},"currentProceeName":{"type":"text"},"orderUnit":{"type":"text"},"isExchequer":{"type":"text"},"orderTitle":{"type":"text"},"isTax":{"type":"text"},"lastUpdateUsername":{"type":"text"},"installationgSite":{"type":"text"},"adviceExpiredTime":{"type":"date"},"foundsCode":{"type":"text"},"deliverTime":{"type":"text"},"isDxCenter":{"type":"text"},"isInvoice":{"type":"text"},"otherId":{"type":"text"},"financeAuditUserName":{"type":"text"},"responseTime":{"type":"text"},"priceType":{"type":"text"},"publishBidresultTime":{"type":"date"},"publicityTime":{"type":"date"},"deviceType2":{"type":"text"},"confNum":{"type":"text"},"agentUserId":{"type":"text"},"createTime":{"type":"date"},"isImplemented":{"type":"text"},"endBidtime":{"type":"date"},"orderCode":{"type":"text"},"usingCorrency":{"type":"text"},"institueId":{"type":"text"},"orderPerson":{"type":"text"},"procurementType":{"type":"text"}}
  }
}


Last Updated: 2/15/2023, 4:54:15 PM