Skip to content

keep yourself

部署ES集群6.7.1

公司环境部署Elasticsearch 6.7.1集群,记录下来步骤。 PS:如果要配置集群密码,需要购买license。

软件版本

Elasticsearch 6.7.1 JDK 1.8

JDK安装

JDK提供两种安装方式,任选其一

方式一.安装oracle的java

JDK 的下载地址 解压 JDK 压缩包到:/usr/local/,重命名为 jdk1.8,jdk 的完整路径就是:/usr/local/jdk1.8。 配置 JDK 环境变量:

vi /etc/profile 
    export JAVA_HOME=/usr/local/jdk1.8 
    export PATH=${JAVA_HOME}/bin:$PATH
    source /etc/profile

方式二安装openJDK

yum -y install java-1.8.0-openjdk-devel.x86_64
java -version

修改系统配置

更改文件:

echo "* hard nofile 65536" >> /etc/security/limits.conf
echo "* soft nofile 65536" >> /etc/security/limits.conf
echo "vm.max_map_count=655360" >> /etc/sysctl.conf
echo "vm.swappiness = 1" >> /etc/sysctl.conf
sysctl -p

新增用户

mkdir -p /data/els/{data,logs}
chown -R  elasticsearch:elasticsearch  els

修改主机名

hostnamectl set-hostname elasticsearch01
hostnamectl set-hostname elasticsearch02
hostnamectl set-hostname elasticsearch03
#添加hosts
vi /etc/hosts
    10.1.241.207 elasticsearch01
    10.1.241.208 elasticsearch02
    10.1.241.209 elasticsearch03
  • 检查NetManager的状态:systemctl status NetworkManager.service
  • 检查NetManager管理的网络接口:nmcli dev status
  • 检查NetManager管理的网络连接:nmcli connection show

安装Elasticsearch 6.7.1

  • Elasticsearch 6.7.1下载:

      wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.7.1.rpm
    
  • 安装:

      yum -y install elasticsearch-6.7.1.rpm
    
  • 配置文件修改

      vim /etc/elasticsearch/elasticsearch.yml
    
  • 配置文件node-1

      # ==== Elasticsearch Configuration ===
      # ---------------------------------- Cluster -----------------------------------
      #
      # Use a descriptive name for your cluster:
      #集群的名称
      cluster.name: ai-es
      #
      # ------------------------------------ Node ------------------------------------
      #
      # Use a descriptive name for the node:
      #节点名称,其余两个节点分别为node-2 和node-3
      node.name: elasticsearch01
      #
      # Add custom attributes to the node:
      #
      #node.attr.rack: r1
      #
      #指定该节点是否有资格被选举成为master节点,默认是true,es是默认集群中的第一台机器为master,如果这台机挂了就会重新选举master
      node.master: true
      #允许该节点存储数据(默认开启)
      node.data: true
      # ----------------------------------- Paths ------------------------------------
      #
      # Path to directory where to store the data (separate multiple locations by comma):
      #
      path.data: /data/els/data
      #
      # Path to log files:
      #
      path.logs: /data/els/logs
      #
      # ----------------------------------- Memory -----------------------------------
      #
      # Lock the memory on startup:
      #
      bootstrap.memory_lock: true
      #
      # Make sure that the heap size is set to about half the memory available
      # on the system and that the owner of the process is allowed to use this
      # limit.
      #
      # Elasticsearch performs poorly when the system is swapping the memory.
      #
      # ---------------------------------- Network -----------------------------------
      #
      # Set the bind address to a specific IP (IPv4 or IPv6):
      #
      network.host: 10.1.241.207
      #
      # Set a custom port for HTTP:
      #
      http.port: 9200
      #
      # 设置节点间交互的tcp端口,默认是9300 
      transport.tcp.port: 9300
      # For more information, consult the network module documentation.
      #
      # --------------------------------- Discovery ----------------------------------
      #
      # Pass an initial list of hosts to perform discovery when new node is started:
      # The default list of hosts is ["127.0.0.1", "[::1]"]
      #
      discovery.zen.ping.unicast.hosts: ["10.1.241.208", "10.1.241.209"]
      #
      # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
      #
      #discovery.zen.minimum_master_nodes: 
      #
      # For more information, consult the zen discovery module documentation.
      #
      # ---------------------------------- Gateway -----------------------------------
      #
      # Block initial recovery after a full cluster restart until N nodes are started:
      #
      #gateway.recover_after_nodes: 3
      #
      # For more information, consult the gateway module documentation.
      #
      # ---------------------------------- Various -----------------------------------
      #
      # Require explicit names when deleting indices:
      #
      #action.destructive_requires_name: true
      #设置在节点间传输数据时是否压缩,默认为 False,不压缩。
      transport.tcp.compress: true
      
      #设置在选举 Master 节点时需要参与的最少的候选主节点数,默认为 1。如果使用默认值,则当网络不稳定时有可能会出现脑裂。 合理的数值为(master_eligible_nodes/2)+1,其中 master_eligible_nodes 表示集群中的候选主节点数。
      discovery.zen.minimum_master_nodes: 2
    
  • 修改elasticsearch.service

      vim /usr/lib/systemd/system/elasticsearch.service
    
  • 配置文件

      [Unit]
      Description=Elasticsearch
      Documentation=http://www.elastic.co
      Wants=network-online.target
      After=network-online.target
      
      [Service]
      RuntimeDirectory=elasticsearch
      PrivateTmp=true
      Environment=ES_HOME=/usr/share/elasticsearch
      Environment=ES_PATH_CONF=/etc/elasticsearch
      Environment=PID_DIR=/var/run/elasticsearch
      EnvironmentFile=-/etc/sysconfig/elasticsearch
      
      WorkingDirectory=/usr/share/elasticsearch
      
      User=elasticsearch
      Group=elasticsearch
      
      ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet
      
      # StandardOutput is configured to redirect to journalctl since
      # some error messages may be logged in standard output before
      # elasticsearch logging system is initialized. Elasticsearch
      # stores its logs in /var/log/elasticsearch and does not use
      # journalctl by default. If you also want to enable journalctl
      # logging, you can simply remove the "quiet" option from ExecStart.
      StandardOutput=journal
      StandardError=inherit
      
      # Specifies the maximum file descriptor number that can be opened by this process
      LimitNOFILE=65535
      
      # Specifies the maximum number of processes
      LimitNPROC=4096
      
      # Specifies the maximum size of virtual memory
      LimitAS=infinity
      
      # Specifies the maximum file size
      LimitFSIZE=infinity
      
      # Disable timeout logic and wait until process is stopped
      TimeoutStopSec=0
      
      # SIGTERM signal is used to stop the Java process
      KillSignal=SIGTERM
      
      # Send the signal only to the JVM rather than its control group
      KillMode=process
      
      # Java process is never killed
      SendSIGKILL=no
      
      # When a JVM receives a SIGTERM signal it exits with code 143
      SuccessExitStatus=143
      
      LimitMEMLOCK=infinity
      [Install]
      WantedBy=multi-user.target
      
      # Built for packages-6.7.1
    
  • 启动

      systemctl daemon-reload
      systemctl start elasticsearch.service
      systemctl status elasticsearch.service
      systemctl enable elasticsearch.service
    

开启防火墙

/sbin/iptables -I INPUT -p tcp --dport 9300 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 9200 -j ACCEPT

验证

  • 查询集群状态方法A

      curl -XGET 'http://10.1.241.207:9200/_cat/nodes'
      curl -XGET 'http://10.1.241.207:9200/_cat/nodes?v'
    
  • 查询集群状态方法B

      curl -XGET 'http://10.1.241.207:9200/_cluster/state/nodes?pretty'
    
  • 查询集群中的master

      curl -XGET 'http://10.1.241.207:9200/_cat/master?v'
    
  • 查询集群的健康状态

      curl -XGET 'http://10.1.241.207:9200/_cluster/health?pretty'
    

集群访问

10.1.241.207:9200,10.1.241.208:9200,10.1.241.209:9200