安装elasticsearch集群-master的安装

主服务器安装以及配置(一台服务器只安装一个elasticsearch),此处是master的安装以及配置

  1. tar zxvf /wxqyh/soft/elasticsearch-6.2.2.tar.gz -C /wxqyh/component
  2. ## 具体内存配置根据实际情况调整
  3. sed -n 's/-Xmx1g/-Xmx2g/g' /wxqyh/component/elasticsearch-6.2.2/config/jvm.options
  4. ## 在安装路径下创建data目录
  5. mkdir -p /wxqyh/component/elasticsearch-6.2.2/data
  6. ## 在安装路径下创建logs目录
  7. mkdir -p /wxqyh/component/elasticsearch-6.2.2/logs
  8. ## 单机版本命令
  9. # echo '
  10. # cluster.name: do1
  11. # node.name: node-1
  12. # path.data: /wxqyh/component/elasticsearch-6.2.2/data
  13. # path.logs: /wxqyh/component/elasticsearch-6.2.2/logs
  14. # network.host: 0.0.0.0
  15. # http.port: 9200
  16. # ' >> /wxqyh/component/elasticsearch-6.2.2/config/elasticsearch.yml

此处 xxx.xxx.xxx.xxx表示mastart内网主机IP地址,与其他节点的内网主机IP地址,有多少个elasticsearch节点就填写多少 个内网IP,使用,号隔开

  1. ## 集群版本命令
  2. ## 此处 xxx.xxx.xxx.xxx表示mastart内网主机IP地址,与其他节点的内网主机IP地址,有多少个elasticsearch节点就填写多少 个内网IP,使用,号隔开
  3. echo '
  4. cluster.name: do1
  5. node.name: node-1
  6. path.data: /wxqyh/component/elasticsearch-6.2.2/data
  7. path.logs: /wxqyh/component/elasticsearch-6.2.2/logs
  8. network.host: 0.0.0.0
  9. http.port: 9200
  10. discovery.zen.ping.unicast.hosts: ["xxx.xxx.xxx.xxx","xxx.xxx.xxx.xxx"]
  11. discovery.zen.minimum_master_nodes: 2
  12. ' >> /wxqyh/component/elasticsearch-6.2.2/config/elasticsearch.yml
  1. grep "vm.max_map_count" /etc/sysctl.conf || echo "vm.max_map_count = 655360" >> /etc/sysctl.conf
  2. grep 'esuser soft nofile 65535' /etc/security/limits.conf || sed -i '$i esuser soft nofile 65536' /etc/security/limits.conf
  3. grep 'esuser hard nofile 65535' /etc/security/limits.conf || sed -i '$i esuser hard nofile 65536' /etc/security/limits.conf
  4. /wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch-plugin install file:////wxqyh/soft/elasticsearch-analysis-ik-6.2.2.zip
  5. useradd esuser
  6. chown -R esuser /wxqyh/component/elasticsearch-6.2.2
  7. sysctl -p
  8. su esuser -c "/wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch -d &"

ES-slave-1安装

登录从服务器并且将elasticsearch安装包上传至 /wxqyh/soft/目录下,如果没有目录则先创建目录

  1. tar zxvf /wxqyh/soft/elasticsearch-6.2.2.tar.gz -C /wxqyh/component
  2. sed -n 's/-Xmx1g/-Xmx2g/g' /wxqyh/component/elasticsearch-6.2.2/config/jvm.options
  3. mkdir -p /wxqyh/component/elasticsearch-6.2.2/data
  4. mkdir -p /wxqyh/component/elasticsearch-6.2.2/logs

此处 xxx.xxx.xxx.xxx表示mastart内网主机IP地址,与其他节点的内网主机IP地址,有多少个elasticsearch节点就填写多少 个内网IP,使用,号隔开,需要改变的配置为node.name: node-2将节点改为2即可node.name: node-2,如果有第三台则改为3其他依旧不变。

  1. ## 此处 xxx.xxx.xxx.xxx表示mastart内网主机IP地址,与其他节点的内网主机IP地址,有多少个elasticsearch节点就填写多少 个内网IP,使用,号隔开,需要改变的配置为node.name: node-2将节点改为2即可node.name: node-2,如果有第三台则改为3其他依旧不变。
  2. echo '
  3. cluster.name: do1
  4. node.name: node-2
  5. path.data: /wxqyh/component/elasticsearch-6.2.2/data
  6. path.logs: /wxqyh/component/elasticsearch-6.2.2/logs
  7. network.host: 0.0.0.0
  8. http.port: 9200
  9. discovery.zen.ping.unicast.hosts: ["xxx.xxx.xxx.xxx","xxx.xxx.xxx.xxx"]
  10. discovery.zen.minimum_master_nodes: 2
  11. ' >> /wxqyh/component/elasticsearch-6.2.2/config/elasticsearch.yml
  1. grep "vm.max_map_count" /etc/sysctl.conf || echo "vm.max_map_count = 655360" >> /etc/sysctl.conf
  2. grep 'esuser soft nofile 65535' /etc/security/limits.conf || sed -i '$i esuser soft nofile 65536' /etc/security/limits.conf
  3. grep 'esuser hard nofile 65535' /etc/security/limits.conf || sed -i '$i esuser hard nofile 65536' /etc/security/limits.conf
  4. /wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch-plugin install file:////wxqyh/soft/elasticsearch-analysis-ik-6.2.2.zip
  5. useradd esuser
  6. chown -R esuser.esuser /wxqyh/component/elasticsearch-6.2.2
  7. sysctl -p
  8. su esuser -c "/wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch -d &"

登录从服务器并且将elasticsearch安装包上传至 /wxqyh/soft/目录下,如果没有目录则先创建目录

  1. tar zxvf /wxqyh/soft/elasticsearch-6.2.2.tar.gz -C /wxqyh/component
  2. sed -n 's/-Xmx1g/-Xmx2g/g' /wxqyh/component/elasticsearch-6.2.2/config/jvm.options
  3. mkdir -p /wxqyh/component/elasticsearch-6.2.2/data
  4. mkdir -p /wxqyh/component/elasticsearch-6.2.2/logs

此处 xxx.xxx.xxx.xxx表示mastart内网主机IP地址,与其他节点的内网主机IP地址,有多少个elasticsearch节点就填写多少 个内网IP,使用,号隔开,需要改变的配置为node.name: node-2将节点改为2即可node.name: node-2,如果有第三台则改为3其他依旧不变。

  1. ## 此处 xxx.xxx.xxx.xxx表示mastart内网主机IP地址,与其他节点的内网主机IP地址,有多少个elasticsearch节点就填写多少 个内网IP,使用,号隔开,需要改变的配置为node.name: node-2将节点改为2即可node.name: node-2,如果有第三台则改为3其他依旧不变。
  2. echo '
  3. cluster.name: do1
  4. node.name: node-3
  5. path.data: /wxqyh/component/elasticsearch-6.2.2/data
  6. path.logs: /wxqyh/component/elasticsearch-6.2.2/logs
  7. network.host: 0.0.0.0
  8. http.port: 9200
  9. discovery.zen.ping.unicast.hosts: ["xxx.xxx.xxx.xxx","xxx.xxx.xxx.xxx"]
  10. discovery.zen.minimum_master_nodes: 2
  11. ' >> /wxqyh/component/elasticsearch-6.2.2/config/elasticsearch.yml
  1. grep "vm.max_map_count" /etc/sysctl.conf || echo "vm.max_map_count = 655360" >> /etc/sysctl.conf
  2. grep 'esuser soft nofile 65535' /etc/security/limits.conf || sed -i '$i esuser soft nofile 65536' /etc/security/limits.conf
  3. grep 'esuser hard nofile 65535' /etc/security/limits.conf || sed -i '$i esuser hard nofile 65536' /etc/security/limits.conf
  4. /wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch-plugin install file:////wxqyh/soft/elasticsearch-analysis-ik-6.2.2.zip
  5. useradd esuser
  6. chown -R esuser.esuser /wxqyh/component/elasticsearch-6.2.2
  7. sysctl -p
  8. su esuser -c "/wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch -d &"

ES-master+xpack安装

  1. 主服务器安装以及配置(一台服务器只安装一个elasticsearch),此处是master的安装以及配置
  2. 以下两步为插件安装, x-pack需要前往官网申请秘钥才能使用,免费秘钥有效期为一年,一年后需重新申请免费秘钥
  1. tar zxvf /wxqyh/soft/elasticsearch-6.2.2.tar.gz -C /wxqyh/component
  2. ## 具体内存配置根据实际情况调整
  3. sed -n 's/-Xmx1g/-Xmx2g/g' /wxqyh/component/elasticsearch-6.2.2/config/jvm.options
  4. ## 在安装路径下创建data目录
  5. mkdir -p /wxqyh/component/elasticsearch-6.2.2/data
  6. ## 在安装路径下创建logs目录
  7. mkdir -p /wxqyh/component/elasticsearch-6.2.2/logs
  8. ## 单机版本命令
  9. # echo '
  10. # cluster.name: do1
  11. # node.name: node-1
  12. # path.data: /wxqyh/component/elasticsearch-6.2.2/data
  13. # path.logs: /wxqyh/component/elasticsearch-6.2.2/logs
  14. # network.host: 0.0.0.0
  15. # http.port: 9200
  16. # ' >> /wxqyh/component/elasticsearch-6.2.2/config/elasticsearch.yml
  1. ## 集群版本命令
  2. ## 此处 xxx.xxx.xxx.xxx表示mastart内网主机IP地址,与其他节点的内网主机IP地址,有多少个elasticsearch节点就填写多少 个内网IP,使用,号隔开
  3. echo '
  4. cluster.name: do1
  5. node.name: node-1
  6. path.data: /wxqyh/component/elasticsearch-6.2.2/data
  7. path.logs: /wxqyh/component/elasticsearch-6.2.2/logs
  8. network.host: 0.0.0.0
  9. http.port: 9200
  10. discovery.zen.ping.unicast.hosts: ["xxx.xxx.xxx.xxx","xxx.xxx.xxx.xxx"]
  11. discovery.zen.minimum_master_nodes: 2
  12. ' >> /wxqyh/component/elasticsearch-6.2.2/config/elasticsearch.yml
  1. grep "vm.max_map_count" /etc/sysctl.conf || echo "vm.max_map_count = 655360" >> /etc/sysctl.conf
  2. grep 'esuser soft nofile 65535' /etc/security/limits.conf || sed -i '$i esuser soft nofile 65536' /etc/security/limits.conf
  3. grep 'esuser hard nofile 65535' /etc/security/limits.conf || sed -i '$i esuser hard nofile 65536' /etc/security/limits.conf
  1. ## xpack安装
  2. /wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch-plugin install file:////wxqyh/soft/x-pack-6.2.2.zip
  3. /wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch-plugin install file:////wxqyh/soft/elasticsearch-analysis-ik-6.2.2.zip
  4. ## xpack安装
  5. /wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch-keystore create
  6. useradd esuser
  7. chown -R esuser /wxqyh/component/elasticsearch-6.2.2
  8. sysctl -p
  9. su esuser -c "/wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch -d &"
  10. ## xpack安装
  11. su esuser -c "/wxqyh/component/elasticsearch-6.2.2/bin/x-pack/setup-passwords interactive"

ES-slave-1+xpack安装

登录从服务器并且将elasticsearch安装包上传至 /wxqyh/soft/目录下,如果没有目录则先创建目录

  1. tar zxvf /wxqyh/soft/elasticsearch-6.2.2.tar.gz -C /wxqyh/component
  2. sed -n 's/-Xmx1g/-Xmx2g/g' /wxqyh/component/elasticsearch-6.2.2/config/jvm.options
  3. mkdir -p /wxqyh/component/elasticsearch-6.2.2/data
  4. mkdir -p /wxqyh/component/elasticsearch-6.2.2/logs

此处 xxx.xxx.xxx.xxx表示mastart内网主机IP地址,与其他节点的内网主机IP地址,有多少个elasticsearch节点就填写多少 个内网IP,使用,号隔开,需要改变的配置为node.name: node-2将节点改为2即可node.name: node-2,如果有第三台则改为3其他依旧不变。

  1. ## 此处 xxx.xxx.xxx.xxx表示mastart内网主机IP地址,与其他节点的内网主机IP地址,有多少个elasticsearch节点就填写多少 个内网IP,使用,号隔开,需要改变的配置为node.name: node-2将节点改为2即可node.name: node-2,如果有第三台则改为3其他依旧不变。
  2. echo '
  3. cluster.name: do1
  4. node.name: node-2
  5. path.data: /wxqyh/component/elasticsearch-6.2.2/data
  6. path.logs: /wxqyh/component/elasticsearch-6.2.2/logs
  7. network.host: 0.0.0.0
  8. http.port: 9200
  9. discovery.zen.ping.unicast.hosts: ["xxx.xxx.xxx.xxx","xxx.xxx.xxx.xxx"]
  10. discovery.zen.minimum_master_nodes: 2
  11. ' >> /wxqyh/component/elasticsearch-6.2.2/config/elasticsearch.yml
  1. grep "vm.max_map_count" /etc/sysctl.conf || echo "vm.max_map_count = 655360" >> /etc/sysctl.conf
  2. grep 'esuser soft nofile 65535' /etc/security/limits.conf || sed -i '$i esuser soft nofile 65536' /etc/security/limits.conf
  3. grep 'esuser hard nofile 65535' /etc/security/limits.conf || sed -i '$i esuser hard nofile 65536' /etc/security/limits.conf
  4. ## xpack安装
  5. /wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch-plugin install file:////wxqyh/soft/x-pack-6.2.2.zip
  6. /wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch-plugin install file:////wxqyh/soft/elasticsearch-analysis-ik-6.2.2.zip
  7. ## xpack安装
  8. /wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch-keystore create
  9. useradd esuser
  10. chown -R esuser.esuser /wxqyh/component/elasticsearch-6.2.2
  11. sysctl -p
  12. su esuser -c "/wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch -d &"

ES-slave-2+xpack安装

登录从服务器并且将elasticsearch安装包上传至 /wxqyh/soft/目录下,如果没有目录则先创建目录

  1. tar zxvf /wxqyh/soft/elasticsearch-6.2.2.tar.gz -C /wxqyh/component
  2. sed -n 's/-Xmx1g/-Xmx2g/g' /wxqyh/component/elasticsearch-6.2.2/config/jvm.options
  3. mkdir -p /wxqyh/component/elasticsearch-6.2.2/data
  4. mkdir -p /wxqyh/component/elasticsearch-6.2.2/logs

此处 xxx.xxx.xxx.xxx表示mastart内网主机IP地址,与其他节点的内网主机IP地址,有多少个elasticsearch节点就填写多少 个内网IP,使用,号隔开,需要改变的配置为node.name: node-2将节点改为2即可node.name: node-2,如果有第三台则改为3其他依旧不变。

  1. ## 此处 xxx.xxx.xxx.xxx表示mastart内网主机IP地址,与其他节点的内网主机IP地址,有多少个elasticsearch节点就填写多少 个内网IP,使用,号隔开,需要改变的配置为node.name: node-2将节点改为2即可node.name: node-2,如果有第三台则改为3其他依旧不变。
  2. echo '
  3. cluster.name: do1
  4. node.name: node-3
  5. path.data: /wxqyh/component/elasticsearch-6.2.2/data
  6. path.logs: /wxqyh/component/elasticsearch-6.2.2/logs
  7. network.host: 0.0.0.0
  8. http.port: 9200
  9. discovery.zen.ping.unicast.hosts: ["xxx.xxx.xxx.xxx","xxx.xxx.xxx.xxx"]
  10. discovery.zen.minimum_master_nodes: 2
  11. ' >> /wxqyh/component/elasticsearch-6.2.2/config/elasticsearch.yml
  1. grep "vm.max_map_count" /etc/sysctl.conf || echo "vm.max_map_count = 655360" >> /etc/sysctl.conf
  2. grep 'esuser soft nofile 65535' /etc/security/limits.conf || sed -i '$i esuser soft nofile 65536' /etc/security/limits.conf
  3. grep 'esuser hard nofile 65535' /etc/security/limits.conf || sed -i '$i esuser hard nofile 65536' /etc/security/limits.conf
  4. ## xpack安装
  5. /wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch-plugin install file:////wxqyh/soft/x-pack-6.2.2.zip
  6. /wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch-plugin install file:////wxqyh/soft/elasticsearch-analysis-ik-6.2.2.zip
  7. ## xpack安装
  8. /wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch-keystore create
  9. useradd esuser
  10. chown -R esuser.esuser /wxqyh/component/elasticsearch-6.2.2
  11. sysctl -p
  12. su esuser -c "/wxqyh/component/elasticsearch-6.2.2/bin/elasticsearch -d &"

ES初始化索引

通过以下命令执行初始化脚本(只在master上面执行即可),如果elasticsearch没有配置密码则直接去掉用户名密码字段再初始化,es用户名是elastic,密码是安装elasticsearch的时候自己配置id的,执行成功会返回true的字眼,以下三条命令必须要执行成功,如果使用命令行执行,请删除 -u es用户名:密码

添加标签索引:

  1. curl -u es用户名:密码 -XPUT "http://localhost:9200/addressbook_tag" -H 'Content-Type: application/json' -d '{"settings":{"analysis":{"analyzer":{"straight":{"pattern":"\\|","type":"custom","tokenizer":"pattern"}}}},"mappings":{"wxqyh":{"properties":{"allDeptId":{"type":"text","analyzer":"straight"},"createTime":{"type":"long"},"creator":{"type":"text"},"deptCount":{"type":"short"},"deptId":{"type":"text","analyzer":"straight"},"editPower":{"type":"byte"},"id":{"type":"keyword"},"orgId":{"type":"keyword"},"rang":{"type":"byte"},"showNum":{"type":"integer"},"source":{"type":"byte"},"status":{"type":"byte"},"tagName":{"type":"text"},"usePower":{"type":"byte"},"userCount":{"type":"integer"},"userIds":{"type":"text","analyzer":"straight"},"wxTagId":{"type":"keyword"}}}}}';

添加人员索引:

  1. curl -u es用户名:密码 -XPUT 'http://localhost:9200/addressbook_user' -H 'Content-Type: application/json' -d '{"settings":{"analysis":{"analyzer":{"straight":{"type":"custom","tokenizer":"straight"}},"tokenizer":{"straight":{"type":"pattern","pattern":"\\|"}}}},"mappings":{"wxqyh":{"dynamic":"strict","properties":{"address":{"type":"text","fields":{"keyword":{"type":"keyword"}}},"attribute":{"type":"byte"},"birthday":{"type":"long"},"cancelTime":{"type":"long"},"certificateContent":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"certificateType":{"type":"text","fields":{"keyword":{"type":"keyword"}}},"corpId":{"type":"keyword"},"createPerson":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"createTime":{"type":"long"},"customItemPOList":{"properties":{"content":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"createTime":{"type":"long"},"id":{"type":"keyword"},"optionId":{"type":"keyword"},"orgId":{"type":"keyword"},"userId":{"type":"keyword"},"ext1":{"type":"keyword"},"ext2":{"type":"keyword"}}},"deptId":{"type":"text"},"email":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"entryTime":{"type":"long"},"followTime":{"type":"long"},"hasChild":{"type":"byte"},"headPic":{"type":"keyword"},"id":{"type":"keyword"},"identity":{"type":"text"},"isConcerned":{"type":"keyword"},"isLeader":{"type":"byte"},"isTop":{"type":"long"},"leaveRemark":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"leaveTime":{"type":"long"},"lunarCalendar":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"mark":{"type":"text","analyzer":"ik_max_word"},"mobile":{"type":"text"},"nickName":{"type":"text"},"orgId":{"type":"keyword"},"personName":{"type":"text","analyzer":"ik_max_word","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"phone":{"type":"text"},"pinyin":{"type":"text"},"position":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"qqNum":{"type":"text"},"remindType":{"type":"keyword"},"sex":{"type":"keyword"},"shorMobile":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"updateTime":{"type":"long"},"userAllDeptId":{"type":"text","analyzer":"straight"},"userDeptId":{"type":"text","analyzer":"straight"},"userId":{"type":"keyword"},"userStatus":{"type":"keyword"},"weixinNum":{"type":"text"},"wxUserId":{"type":"text"},"userTagId":{"type":"text","analyzer":"straight"},"company":{"type":"text"}}}}}';

修改人员索引:

  1. curl -u es用户名:密码 -XPUT "http://localhost:9200/addressbook_user/wxqyh/_mapping" -H 'Content-Type: application/json' -d '{"properties":{"userNo":{"type":"keyword"}}}';

ES安装验证

在官网申请到license文件后下载对应json证书,上传至es并进行认证

  1. curl -XPUT -u es用户名:密码 'http://localhost:9200/_xpack/license' -H "Content-Type: application/json" -d @证书名.json
  2. curl -XPUT -u es用户名:密码 'http://localhost:9200/_xpack/license?acknowledge=true' -H "Content-Type: application/json" -d @证书名.json

查询索引是否创建正常:

  1. curl -u es用户名:密码 -XGET http://localhost:9200/_cat/indices?v

显示以下内容即可
image.png