CentOS7 部署 ElasticSearch7.0.1 集羣

環境

主機名 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

下載:css

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' 
  • 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

查看集羣狀態

  • 查看集羣節點狀態
    # 查看節點狀態 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";
相關文章
相關標籤/搜索