环境
主机名 | 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'
- 在每个节点上启动 elasticsearch 服务
- 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
- 创建文件 /usr/lib/systemd/system/elasticsearch.service,内容如下
查看集群状态
- 查看集群节点状态
# 查看节点状态 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";