ES5.0集羣搭建

最近在網上看到不少ES集羣的搭建方法,本人在這人使用Elasticsearch5.0.1版本,介紹如何搭建es集羣並安裝head插件和其餘插件安裝方法。javascript

1、搭建環境(2臺Centos7系統服務器)html

所需軟件java

  Elasticsearch-5.0.1.tar.gz
  node-v4.2.2-linux-x64.tar.gz

基礎環境JAVAnode

  yum -y install java-1.8*
  java -version #檢查java是否安裝成功

測試環境關閉防火牆和selinuxpython

    關閉防火牆
        systemctl stop firewalld
        systemctl diable firewalld
    關閉selinux
        sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config   #須要重啓系統

配置主機名和hosts文件linux

  配置hostname
        sed -i 's/localhost/es1/g' /etc/hostname
     
sed -i 's/localhost/es1/g' /etc/hostname
  配置hosts vi /etc/hosts #添加一下內容 
     172.16.81.133 es1
     172.16.81.134 es2

建立用戶git

        useradd elasticsearch
        passwd elasticsearch   #而後輸入兩次密碼便可!

2、安裝es軟件(tar.gz解壓安裝)github

         tar -zxvf elasticsearch-5.0.1.tar.gz
         mv elasticsearch-5.0.1 elasticsearch5
         cd elasticsearch5

建立data和logs目錄npm

         mkdir -p es
         mkdir -p es/data
         mkdir -p es/logs

修改配置文件bootstrap

            cd /opt/elasticsearch5/config
            vi elasticsearch.yml
            es1配置文件以下:
                cluster.name: es-cluster    #集羣名,不一樣名稱表明不一樣集羣
                node.name: es1    #節點名稱,自定義
                path.data: /opt/elasticsearch5/es/data    #數據路徑
                path.logs: /opt/elasticsearch5/es/logs    #日誌路徑
                bootstrap.memory_lock: false    #關閉鎖內存
                network.host: 172.16.81.133    #綁定IP地址
                http.port: 9200    #綁定端口
                discovery.zen.ping.unicast.hosts: ["es1", "es2"]    #集羣列表,類型數組,能夠是IP或域名
                discovery.zen.minimum_master_nodes: 1    #節點數不能超過節點總數量(防止腦裂兩臺可配置成1,三臺可配置2)
                http.cors.enabled: true    #開啓http網絡節點發現
                http.cors.allow-origin: "*"    #容許全部同網段節點發現
            es2配置文件以下:
                cluster.name: es-cluster    #集羣名,不一樣名稱表明不一樣集羣
                node.name: es2    #節點名稱,自定義
                path.data: /opt/elasticsearch5/es/data    #數據路徑
                path.logs: /opt/elasticsearch5/es/logs    #日誌路徑
                bootstrap.memory_lock: false    #關閉鎖內存
                network.host: 172.16.81.134    #綁定IP地址
                http.port: 9200    #綁定端口
                discovery.zen.ping.unicast.hosts: ["es1", "es2"]    #集羣列表,類型數組,能夠是IP或域名
                discovery.zen.minimum_master_nodes: 1    #節點數不能超過節點總數量
                http.cors.enabled: true    #開啓http網絡節點發現
                http.cors.allow-origin: "*"    #容許全部同網段節點發現

配置內核參數

            vi /etc/security/limits.conf    #添加如下內容
                * soft nofile 65536
                * hard nofile 131072
                * soft nproc 2048
                * hard nproc 4096
            vi /etc/sysctl.conf 
                添加下面配置:
                vm.max_map_count=655360
                並執行命令:
                sysctl -p

修改文件權限

            chown -R elasticsearch:elasticsearch elasticsearch5

切換到elasticsearch啓動程序

            su - elasticsearch
            cd /opt/elasticsearch5/bin
            ./elasticsearch  #觀察輸出信息
            ./elasticsearch &    #後臺運行

查看端口

            netstat -lntp
            結果:
            tcp        0      0 0.0.0.0:9100            0.0.0.0:*               LISTEN      8892/grunt                  
            tcp6       0      0 172.16.81.133:9200      :::*                    LISTEN      5250/java           
            tcp6       0      0 172.16.81.133:9300      :::*                    LISTEN      5250/java           
            存在9100、9200、9300上述上個端口便可!

3、安裝elasticsearch-head插件

安裝依賴包和工具包

yum -y install wget git bizp2

git項目到本地

cd /opt
git clone git://github.com/mobz/elasticsearch-head.git

安裝node、npm、grunt

wget https://nodejs.org/dist/v4.2.2/node-v4.2.2-linux-x64.tar.gz
tar -zxvf node-v4.2.2-linux-x64.tar.gz

設置連接

ln -s /opt/node-v4.2.2-linux-x64/bin/node /usr/sbin/node
ln -s /opt/node-v4.2.2-linux-x64/bin/npm /usr/sbin/npm

設置npm代理鏡像

npm config set registry https://registry.npm.taobao.org

安裝、配置grunt

npm install -g grunt
ln -s /opt/node-v4.2.2-linux-x64/lib/node_modules/grunt/bin/grunt /usr/sbin/grunt

修改elasticsearch-head配置文件

                cd /opt/elasticsearch-head
                vi _site/app.js
                // 把localhost改成ip
                this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
                this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://172.16.81.89:9200";
                修改Gruntfile.js
                connect: {
                    server: {
                        options: {                                                                                                                  
                            hostname: "0.0.0.0", #添加這裏
                            port: 9100,
                            base: '.',
                            keepalive: true
                        }   
                    }   
                }

安裝head

 cd /opt/elasticsearch-head
 npm install

啓動head

grunt server &

瀏覽器訪問(最好是谷歌瀏覽器)

接口:
http://172.16.81.133:9200/
集羣:
http://172.16.81.133:9100/   #五角星表明主節點,圓點表明數據節點 查看主master是誰: http://172.16.81.133:9200/_cat/master 更多URL信息 http://172.16.81.133:9200/_cat

最後在介紹下5.x安裝插件的方法,這兒咱們舉例安裝!

咱們將安裝geoip的插件(能夠解析外網地址顯示在地圖上)

cd /opt/elasticsearch5/bin

[root@es1 bin]# ./elasticsearch-plugin install --help   #咱們看到了所支持的插件
Install a plugin

The following official plugins may be installed by name:
analysis-icu
analysis-kuromoji
analysis-phonetic
analysis-smartcn
analysis-stempel
discovery-azure-classic
discovery-ec2
discovery-file
discovery-gce
ingest-attachment
ingest-geoip
ingest-user-agent
lang-javascript
lang-python
mapper-attachments
mapper-murmur3
mapper-size
repository-azure
repository-gcs
repository-hdfs
repository-s3
store-smb
x-pack

Non-option arguments:

安裝插件:

[root@es1 bin]# ./elasticsearch-plugin install ingest-geoip
-> Downloading ingest-geoip from elastic
[=================================================] 100%  
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: plugin requires additional permissions @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.lang.RuntimePermission accessDeclaredMembers
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.

Continue with installation? [y/N]y
-> Installed ingest-geoip

驗證:

cd /opt/elasticsearch5/plugins
[root@es1 plugins]# ls
ingest-geoip  #會看到剛剛安裝的插件,須要重啓es集羣配置生效

es集羣到此就完成了!後續將發佈zookeeper和kafka集羣!

感謝!有問題請指出!轉載請指出源連接!

相關文章
相關標籤/搜索