Elasticsearch5.6集群搭建

释放双眼,带上耳机,听听看~!

本地环境

节点一:

[root@CentOS7_node1 src]# hostname 
CentOS7_node1
[root@CentOS7_node1 src]# ip a | grep 10.211.55.7 |  awk -F ' ' '{print $2}' 
10.211.55.7/24
[root@CentOS7_node1 src]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)

节点二:

[root@CentOS7_node2 src]# hostname 
CentOS7_node2
[root@CentOS7_node2 src]# ip a | grep 10.211.55.9 |  awk -F ' ' '{print $2}'
10.211.55.9/24
[root@CentOS7_node2 src]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 

节点三:

[root@CentOS7_node3 src]# hostname
CentOS7_node3
[root@CentOS7_node3 src]# ip a | grep 10.211.55.10 |  awk -F ' ' '{print $2}'
10.211.55.10/24
[root@CentOS7_node3 src]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)

ES安装

所需ES版本为:elasticsearch-5.6.16.tar.gz
所需JDK版本为:jdk-8u161-linux-x64.tar.gz
下载地址:https://pan.baidu.com/s/1wdzQokfMFXDtTY2BXg2Fbw

节点一

部署JDK环境

[root@CentOS7_node1 src]# tar xf jdk-8u161-linux-x64.tar.gz  -C /usr/local/
[root@CentOS7_node1 src]# mv /usr/local/jdk1.8.0_161 /usr/local/java
[root@CentOS7_node1 src]# vim /etc/profile
[root@CentOS7_node1 src]# tail -5 /etc/profile  
#################JAVA#################
export JAVA_HOME=/usr/local/java
export JRE_HOME=/usr/local/java/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
[root@CentOS7_node1 src]# source /etc/profile
[root@CentOS7_node1 src]# java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

安装elasticsearch

[root@CentOS7_node1 src]# tar xf elasticsearch-5.6.16.tar.gz  -C /usr/local/
[root@CentOS7_node1 src]# groupadd elasticsearch
[root@CentOS7_node1 src]# useradd elasticsearch -g elasticsearch
[root@CentOS7_node1 src]# echo '3edc#EDC' | passwd --stdin elasticsearch
Changing password for user elasticsearch.
passwd: all authentication tokens updated successfully.
[root@CentOS7_node1 src]# chown -Rf elasticsearch:elasticsearch /usr/local/elasticsearch-5.6.16

更改elasticsearch.yml配置文件
注:以下修改的配置文件详解请点击:https://www.dockerc.com/elasticsearch_config/

[root@CentOS7_node1 config]# cat elasticsearch.yml
cluster.name: elasticsearch_dockerc
node.name: elasticsearch-node1
node.master: true
node.data: true
path.data: /data/dockerc/data1,/data/dockerc/data2,/data/dockerc/data3
path.logs: /data/docker/logs
bootstrap.memory_lock: true
network.host: 10.211.55.7 
network.tcp.no_delay: true
network.tcp.keep_alive: true
network.tcp.reuse_address: true
network.tcp.send_buffer_size: 64mb
network.tcp.receive_buffer_size: 64mb
transport.tcp.port: 9301
transport.tcp.compress: true
http.max_content_length: 100mb
http.enabled: true
http.port: 9201
discovery.zen.ping.unicast.hosts: ["10.211.55.7:9301", "10.211.55.10:9301", "10.211.55.9:9301"] 
discovery.zen.minimum_master_nodes: 2
discovery.zen.fd.ping_timeout: 150s
discovery.zen.fd.ping_retries: 6
discovery.zen.fd.ping_interval: 15s
cluster.routing.allocation.cluster_concurrent_rebalance: 16
cluster.routing.allocation.node_concurrent_recoveries: 16
cluster.routing.allocation.node_initial_primaries_recoveries: 16

更改jvm.options配置文件
堆内存的初始内存和最大内存建议保持一致,因为我在设置不一致的时候产生了错误
内存大小根据物理资源情况给定

[root@CentOS7_node1 config]# vim jvm.options
-Xms1g
-Xmx1g

创建数据及日志目录

[root@CentOS7_node1 ~]# mkdir -pv /data/dockerc/{data1,data2,data3,logs}
mkdir: created directory ‘/data’
mkdir: created directory ‘/data/dockerc’
mkdir: created directory ‘/data/dockerc/data1’
mkdir: created directory ‘/data/dockerc/data2’
mkdir: created directory ‘/data/dockerc/data3’
mkdir: created directory ‘/data/dockerc/logs’
[root@CentOS7_node1 ~]# chown -Rf elasticsearch /data
[root@CentOS7_node1 ~]# ll /data/dockerc/
total 16
drwxr-xr-x 2 elasticsearch root 4096 May 10 00:13 data1
drwxr-xr-x 2 elasticsearch root 4096 May 10 00:13 data2
drwxr-xr-x 2 elasticsearch root 4096 May 10 00:13 data3
drwxr-xr-x 2 elasticsearch root 4096 May 10 00:13 logs

注:现在node1算是配置完了,但是还不能启动,因为我们配置了discvery,如果超过150s*6次未检测到node2和node3将会启动失败

修改elasticsearch潜在问题
1.修改文件描述符

echo '* soft nofile 65536' >> /etc/security/limits.conf
echo '* hard nofile 65536' >> /etc/security/limits.conf
然后重新登录终端
[root@CentOS7_node1 ~]# ulimit -n
65536

2.修改修改max_map_count值

临时设置:
[root@CentOS7_node1 ~]# sysctl -w vm.max_map_count=655360
vm.max_map_count = 655360

永久设置:
[root@CentOS7_node1 ~]# echo 'vm.max_map_count=655360' >> /etc/sysctl.conf 
[root@CentOS7_node1 ~]# sysctl -p   
vm.max_map_count = 655360

3.无法分配内存问题

[root@CentOS7_node1 ~]# echo '* soft memlock unlimited' >> /etc/security/limits.conf
[root@CentOS7_node1 ~]# echo '* hard memlock unlimited' >> /etc/security/limits.conf
[root@CentOS7_node1 ~]# tail -2 /etc/security/limits.conf
* soft memlock unlimited
* hard memlock unlimited

节点二

注:node2就除了elasticsearch.yml不一致之外,其它无区别,除配置文件外,其它一律和node1保持一致
elasticsearch配置文件

[root@CentOS7_node2 ~]# cat /usr/local/elasticsearch-5.6.16/config/elasticsearch.yml
cluster.name: elasticsearch_dockerc
node.name: elasticsearch-node2
node.master: true
node.data: true
path.data: /data/dockerc/data1,/data/dockerc/data2,/data/dockerc/data3
path.logs: /data/docker/logs
bootstrap.memory_lock: true
network.host: 10.211.55.9
network.tcp.no_delay: true
network.tcp.keep_alive: true
network.tcp.reuse_address: true
network.tcp.send_buffer_size: 64mb
network.tcp.receive_buffer_size: 64mb
transport.tcp.port: 9301
transport.tcp.compress: true
http.max_content_length: 100mb
http.enabled: true
http.port: 9201
discovery.zen.ping.unicast.hosts: ["10.211.55.7:9301", "10.211.55.10:9301", "10.211.55.9:9301"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.fd.ping_timeout: 150s
discovery.zen.fd.ping_retries: 6
discovery.zen.fd.ping_interval: 15s
cluster.routing.allocation.cluster_concurrent_rebalance: 16
cluster.routing.allocation.node_concurrent_recoveries: 16
cluster.routing.allocation.node_initial_primaries_recoveries: 16

配置文件修改完成以后,同样不要启动elasticsearch

节点三

配置除配置文件外其余和node2一样,配置文件如下

[root@CentOS7_node3 ~]# cat /usr/local/elasticsearch-5.6.16/config/elasticsearch.yml
cluster.name: elasticsearch_dockerc
node.name: elasticsearch-node3
node.master: true
node.data: true
path.data: /data/dockerc/data1,/data/dockerc/data2,/data/dockerc/data3
path.logs: /data/docker/logs
bootstrap.memory_lock: true
network.host: 10.211.55.10
network.tcp.no_delay: true
network.tcp.keep_alive: true
network.tcp.reuse_address: true
network.tcp.send_buffer_size: 64mb
network.tcp.receive_buffer_size: 64mb
transport.tcp.port: 9301
transport.tcp.compress: true
http.max_content_length: 100mb
http.enabled: true
http.port: 9201
discovery.zen.ping.unicast.hosts: ["10.211.55.7:9301", "10.211.55.10:9301", "10.211.55.9:9301"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.fd.ping_timeout: 150s
discovery.zen.fd.ping_retries: 6
discovery.zen.fd.ping_interval: 15s
cluster.routing.allocation.cluster_concurrent_rebalance: 16
cluster.routing.allocation.node_concurrent_recoveries: 16
cluster.routing.allocation.node_initial_primaries_recoveries: 16

启动Elasticsearch

三个节点启动时间尽量不要差很久,以下三条启动信息,我只截取了一部分,但是我的服务启动时正常的
节点一启动信息

root@CentOS7_node1 ~]# su elasticsearch /usr/local/elasticsearch-5.6.16/bin/elasticsearch
[2019-05-10T00:17:51,097][WARN ][o.e.d.z.ZenDiscovery     ] [elasticsearch-node1] not enough master nodes discovered during pinging (found [[Candidate{node={elasticsearch-node1}{Zwvq1z3TQZK-oPALgixXEw}{Eu1dFZSbRX6tYMwiOtqeZg}{10.211.55.7}{10.211.55.7:9301}, clusterStateVersion=-1}]], but needed [2]), pinging again
[2019-05-10T00:17:54,346][INFO ][o.e.c.s.ClusterService   ] [elasticsearch-node1] detected_master {elasticsearch-node3}{RNO7uYb-QOSJCQJ7EIkUMw}{VM3cXe-_TDOc_1qyq7yW3A}{10.211.55.10}{10.211.55.10:9301}, added {{elasticsearch-node3}{RNO7uYb-QOSJCQJ7EIkUMw}{VM3cXe-_TDOc_1qyq7yW3A}{10.211.55.10}{10.211.55.10:9301},}, reason: zen-disco-receive(from master [master {elasticsearch-node3}{RNO7uYb-QOSJCQJ7EIkUMw}{VM3cXe-_TDOc_1qyq7yW3A}{10.211.55.10}{10.211.55.10:9301} committed version [1]])
[2019-05-10T00:17:54,361][INFO ][o.e.h.n.Netty4HttpServerTransport] [elasticsearch-node1] publish_address {10.211.55.7:9201}, bound_addresses {10.211.55.7:9201}
[2019-05-10T00:17:54,362][INFO ][o.e.n.Node               ] [elasticsearch-node1] started

启动的时候有个WARN警告信息,是因为刚启动还没找到谁是主节点,所以参生了一条警告信息,不过当集群建立后,很快就没了

节点二启动信息

[2019-05-10T00:17:51,244][INFO ][o.e.b.BootstrapChecks    ] [elasticsearch-node2] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2019-05-10T00:17:54,493][INFO ][o.e.c.s.ClusterService   ] [elasticsearch-node2] detected_master {elasticsearch-node3}{RNO7uYb-QOSJCQJ7EIkUMw}{VM3cXe-_TDOc_1qyq7yW3A}{10.211.55.10}{10.211.55.10:9301}, added {{elasticsearch-node1}{Zwvq1z3TQZK-oPALgixXEw}{Eu1dFZSbRX6tYMwiOtqeZg}{10.211.55.7}{10.211.55.7:9301},{elasticsearch-node3}{RNO7uYb-QOSJCQJ7EIkUMw}{VM3cXe-_TDOc_1qyq7yW3A}{10.211.55.10}{10.211.55.10:9301},}, reason: zen-disco-receive(from master [master {elasticsearch-node3}{RNO7uYb-QOSJCQJ7EIkUMw}{VM3cXe-_TDOc_1qyq7yW3A}{10.211.55.10}{10.211.55.10:9301} committed version [3]])
[2019-05-10T00:17:54,556][INFO ][o.e.h.n.Netty4HttpServerTransport] [elasticsearch-node2] publish_address {10.211.55.9:9201}, bound_addresses {10.211.55.9:9201}
[2019-05-10T00:17:54,556][INFO ][o.e.n.Node               ] [elasticsearch-node2] started

节点三启动信息

[root@CentOS7_node3 ~]# su elasticsearch /usr/local/elasticsearch-5.6.16/bin/elasticsearch
[2019-05-10T00:17:51,240][INFO ][o.e.b.BootstrapChecks    ] [elasticsearch-node3] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2019-05-10T00:17:54,332][INFO ][o.e.c.s.ClusterService   ] [elasticsearch-node3] new_master {elasticsearch-node3}{RNO7uYb-QOSJCQJ7EIkUMw}{VM3cXe-_TDOc_1qyq7yW3A}{10.211.55.10}{10.211.55.10:9301}, added {{elasticsearch-node1}{Zwvq1z3TQZK-oPALgixXEw}{Eu1dFZSbRX6tYMwiOtqeZg}{10.211.55.7}{10.211.55.7:9301},}, reason: zen-disco-elected-as-master ([1] nodes joined)[{elasticsearch-node1}{Zwvq1z3TQZK-oPALgixXEw}{Eu1dFZSbRX6tYMwiOtqeZg}{10.211.55.7}{10.211.55.7:9301}]
[2019-05-10T00:17:54,397][INFO ][o.e.h.n.Netty4HttpServerTransport] [elasticsearch-node3] publish_address {10.211.55.10:9201}, bound_addresses {10.211.55.10:9201}
[2019-05-10T00:17:54,397][INFO ][o.e.n.Node               ] [elasticsearch-node3] started
[2019-05-10T00:17:54,474][INFO ][o.e.g.GatewayService     ] [elasticsearch-node3] recovered [0] indices into cluster_state

简单看下我们的主节点时哪台设备

[root@CentOS7_node1 config]#  curl -XGET 'http://10.211.55.7:9201/_cat/nodes?v'
ip           heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
10.211.55.7            10          52   0    0.00    0.01     0.05 mdi       -      elasticsearch-node1
10.211.55.9            14          55   0    0.00    0.01     0.05 mdi       -      elasticsearch-node2
10.211.55.10           12          74   0    0.00    0.01     0.05 mdi       *      elasticsearch-node3

安装插件

安装elasticsearch最出名的插件叫elasticsearch-head,但是elasticsearch-head由nodejs开发,所以需要nodejs环境,然后使用npm命令来管理,所以我们先安装nodejs环境,3个节点安装一台就可以了,因为在一台上就可以看到所有的节点状态
安装nodejs

[root@CentOS7_node1 src]# curl --silent --location https://rpm.nodesource.com/setup_10.x | bash -
#setup_10.x这个参数为版本,如果想安装8版本的nodejs就改为setup_8.x
[root@CentOS7_node1 /]# yum info nodejs
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Available Packages
Name        : nodejs
Arch        : x86_64
Epoch       : 2
Version     : 10.15.3
Release     : 1nodesource
Size        : 18 M
Repo        : nodesource/x86_64
Summary     : JavaScript runtime
URL         : http://nodejs.org
License     : MIT and ASL 2.0 and ISC and BSD
Description : Node.js is a platform built on Chrome's JavaScript runtime
            : for easily building fast, scalable network applications.
            : Node.js uses an event-driven, non-blocking I/O model that
            : makes it lightweight and efficient, perfect for data-intensive
            : real-time applications that run across distributed devices.
[root@CentOS7_node1 /]# yum install nodejs -y 
[root@CentOS7_node1 /]# node -v
v10.15.3
[root@CentOS7_node1 /]# npm -v
6.4.1

安装git
编译安装nodejs完成后,要开始下载elasticsearch-head插件了,但是此插件在github上:https://github.com/mobz/elasticsearch-head#running-with-built-in-server,下载方式还必须要使用git方式来克隆下载:下载链接:https://github.com/mobz/elasticsearch-head.git
所以我们还需要安装git来下载此插件

[root@CentOS7_node1 src]# yum install git -y
[root@CentOS7_node1 src]# git --version
git version 1.8.3.1

克隆elasticsearch-head插件

[root@CentOS7_node1 local]# git clone git://github.com/mobz/elasticsearch-head.git
Cloning into 'elasticsearch-head'...
remote: Enumerating objects: 4260, done.
remote: Total 4260 (delta 0), reused 0 (delta 0), pack-reused 4260
Receiving objects: 100% (4260/4260), 2.02 MiB | 372.00 KiB/s, done.
Resolving deltas: 100% (2373/2373), done.
[root@CentOS7_node1 local]# cd elasticsearch-head/
[root@CentOS7_node1 elasticsearch-head]# npm install
npm WARN deprecated http2@3.3.7: Use the built-in module in node 9.0.0 or newer, instead
npm WARN deprecated coffee-script@1.10.0: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)

> phantomjs-prebuilt@2.1.16 install /usr/local/elasticsearch-head/node_modules/phantomjs-prebuilt
> node install.js

PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Receiving...
  [===============================---------] 76%
Received 22866K total.
Extracting tar contents (via spawned process)
Removing /usr/local/elasticsearch-head/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1557423580353/phantomjs-2.1.1-linux-x86_64 -> /usr/local/elasticsearch-head/node_modules/phantomjs-prebuilt/lib/phantom
Writing location.js file
Done. Phantomjs binary available at /usr/local/elasticsearch-head/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 515 packages from 619 contributors and audited 1752 packages in 30.005s
found 34 vulnerabilities (19 low, 8 moderate, 7 high)
  run `npm audit fix` to fix them, or `npm audit` for details

启动elasticsearch-head插件
elasticsearch-head插件默认和elasticsearch一样是前台启动,我这里给他送到后台运行
elasticsearch-head插件默认占用9100端口来提供服务

[root@CentOS7_node1 elasticsearch-head]# nohup npm run start &
[root@CentOS7_node1 src]# ss -anplt | grep 9100
LISTEN     0      128          *:9100                     *:*                   users:(("grunt",pid=6708,fd=18))

服务虽然启动了,但是如果让elasticsearch-head插件连接Elasticsearch,我们还需要修改配置来实现
修改插件配置文件

[root@CentOS7_node1 elasticsearch-head]# pwd
/usr/local/elasticsearch-head
[root@CentOS7_node1 elasticsearch-head]# vim Gruntfile.js
                connect: {
                        server: {
                                options: {
                                        port: 9100,
                                        hostname: '*',  //在此新加hostname参数,代表添加所有主机
                                        base: '.',
                                        keepalive: true
                                }   
                        }   
                } 

修改elasticsearch-head/_site/app.js文件

进入vi之后直接搜索9200然后会自动跳转到目的地,把9200前面的localhost修改为我们需要对外访问的节点地址,然后再把9200修改为我们对外的端口,一般都是把9200修改为9100端口
[root@CentOS7_node1 elasticsearch-head]# vim _site/app.js
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://10.211.55.7:9100";

修改完成后,我们需要重新启动elasticsearch-head插件

杀掉grunt进程,此进程是elasticsearch-head插件进程
[root@CentOS7_node1 elasticsearch-head]# ps -ef|grep grunt
root      6708  6694  0 01:43 pts/0    00:00:00 grunt
root     11438  3351  0 02:06 pts/0    00:00:00 grep --color=auto grunt
[root@CentOS7_node1 elasticsearch-head]# killall grunt
[root@CentOS7_node1 elasticsearch-head]# ps -ef|grep grunt
root     11482  3351  0 02:06 pts/0    00:00:00 grep --color=auto grunt
[1]+  Done                    nohup npm run start
[root@CentOS7_node1 elasticsearch-head]# ss -anplt 
State      Recv-Q Send-Q                             Local Address:Port                                            Peer Address:Port              
LISTEN     0      128                                            *:111                                                        *:*                   users:(("rpcbind",pid=3782,fd=4),("systemd",pid=1,fd=46))
LISTEN     0      5                                  192.168.122.1:53                                                         *:*                   users:(("dnsmasq",pid=13167,fd=6))
LISTEN     0      128                                            *:22                                                         *:*                   users:(("sshd",pid=4448,fd=3))
LISTEN     0      128                                    127.0.0.1:631                                                        *:*                   users:(("cupsd",pid=4446,fd=12))
LISTEN     0      100                                    127.0.0.1:25                                                         *:*                   users:(("master",pid=4797,fd=13))
LISTEN     0      128                                           :::111                                                       :::*                   users:(("rpcbind",pid=3782,fd=6),("systemd",pid=1,fd=48))
LISTEN     0      128                           ::ffff:10.211.55.7:9201                                                      :::*                   users:(("java",pid=6176,fd=187))
LISTEN     0      128                           ::ffff:10.211.55.7:9301                                                      :::*                   users:(("java",pid=6176,fd=121))
LISTEN     0      128                                           :::22                                                        :::*                   users:(("sshd",pid=4448,fd=4))
LISTEN     0      128                                          ::1:631                                                       :::*                   users:(("cupsd",pid=4446,fd=11))
LISTEN     0      100                                          ::1:25                                                        :::*                   users:(("master",pid=4797,fd=14))

然后再次启动此进程
[root@CentOS7_node1 elasticsearch-head]# nohup npm run start &
[root@CentOS7_node1 elasticsearch-head]# ps -ef|grep grunt
root     11750 11739  4 02:08 pts/0    00:00:00 grunt
root     11791  3351  0 02:08 pts/0    00:00:00 grep --color=auto grunt
[root@CentOS7_node1 elasticsearch-head]# ss -anplt 
State      Recv-Q Send-Q                             Local Address:Port                                            Peer Address:Port              
LISTEN     0      128                                            *:111                                                        *:*                   users:(("rpcbind",pid=3782,fd=4),("systemd",pid=1,fd=46))
LISTEN     0      5                                  192.168.122.1:53                                                         *:*                   users:(("dnsmasq",pid=13167,fd=6))
LISTEN     0      128                                            *:22                                                         *:*                   users:(("sshd",pid=4448,fd=3))
LISTEN     0      128                                    127.0.0.1:631                                                        *:*                   users:(("cupsd",pid=4446,fd=12))
LISTEN     0      100                                    127.0.0.1:25                                                         *:*                   users:(("master",pid=4797,fd=13))
LISTEN     0      128                                           :::9100                                                      :::*                   users:(("grunt",pid=11750,fd=18))
LISTEN     0      128                                           :::111                                                       :::*                   users:(("rpcbind",pid=3782,fd=6),("systemd",pid=1,fd=48))
LISTEN     0      128                           ::ffff:10.211.55.7:9201                                                      :::*                   users:(("java",pid=6176,fd=187))
LISTEN     0      128                           ::ffff:10.211.55.7:9301                                                      :::*                   users:(("java",pid=6176,fd=121))
LISTEN     0      128                                           :::22                                                        :::*                   users:(("sshd",pid=4448,fd=4))
LISTEN     0      128                                          ::1:631                                                       :::*                   users:(("cupsd",pid=4446,fd=11))
LISTEN     0      100                                          ::1:25                                                        :::*

访问测试

在浏览器中输入我们修改elasticsearch-head/_site/app.js文件的IP和端口

我们访问了9100端口,但是9100端口只不过是grunt插件的端口,我们要通过此插件来连接es集群,所以下面要输入连接es集群端口的http链接,但是并没有连接上,原因是因为未在elasticsearch.yml文件中开启以下参数

http.cors.enabled: true
#是否允许跨源 REST 请求
http.cors.allowed.origin: "*"
#指定允许REST请求来自何处,这里*号,代表无限制

修改node1的elasticsearch.yml

[root@CentOS7_node1 elasticsearch-head]# echo 'http.cors.enabled: true' >> /usr/local/elasticsearch-5.6.16/config/elasticsearch.yml
[root@CentOS7_node1 elasticsearch-head]# echo 'http.cors.allow-origin: "*"' >> /usr/local/elasticsearch-5.6.16/config/elasticsearch.yml
[root@CentOS7_node1 elasticsearch-head]# tail -2 /usr/local/elasticsearch-5.6.16/config/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"

重启es和grunt

[root@CentOS7_node1 elasticsearch-head]# ps -ef|grep java
elastic+  6176  6175  0 01:41 pts/4    00:00:19 /usr/local/java/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/usr/local/elasticsearch-5.6.16 -cp /usr/local/elasticsearch-5.6.16/lib/* org.elasticsearch.bootstrap.Elasticsearch
root     14254  3351  0 02:20 pts/0    00:00:00 grep --color=auto java
[root@CentOS7_node1 elasticsearch-head]# kill -9 6176
[root@CentOS7_node1 elasticsearch-head]# ps -ef|grep grunt
root     11750 11739  0 02:08 pts/0    00:00:00 grunt
root     14319  3351  0 02:21 pts/0    00:00:00 grep --color=auto grunt
[root@CentOS7_node1 elasticsearch-head]# kill -9 11750

[root@CentOS7_node1 elasticsearch-head]# su elasticsearch /us^C
[root@CentOS7_node1 elasticsearch-head]# nohup su elasticsearch /usr/local/elasticsearch-5.6.16/bin/elasticsearch &
[root@CentOS7_node1 elasticsearch-head]# nohup npm run start &

[root@CentOS7_node1 elasticsearch-head]# ss -anplt 
State      Recv-Q Send-Q                             Local Address:Port                                            Peer Address:Port              
LISTEN     0      128                                            *:111                                                        *:*                   users:(("rpcbind",pid=3782,fd=4),("systemd",pid=1,fd=46))
LISTEN     0      5                                  192.168.122.1:53                                                         *:*                   users:(("dnsmasq",pid=13167,fd=6))
LISTEN     0      128                                            *:22                                                         *:*                   users:(("sshd",pid=4448,fd=3))
LISTEN     0      128                                    127.0.0.1:631                                                        *:*                   users:(("cupsd",pid=4446,fd=12))
LISTEN     0      100                                    127.0.0.1:25                                                         *:*                   users:(("master",pid=4797,fd=13))
LISTEN     0      128                                           :::9100                                                      :::*                   users:(("grunt",pid=14587,fd=18))
LISTEN     0      128                                           :::111                                                       :::*                   users:(("rpcbind",pid=3782,fd=6),("systemd",pid=1,fd=48))
LISTEN     0      128                           ::ffff:10.211.55.7:9201                                                      :::*                   users:(("java",pid=15790,fd=187))
LISTEN     0      128                           ::ffff:10.211.55.7:9301                                                      :::*                   users:(("java",pid=15790,fd=121))
LISTEN     0      128                                           :::22                                                        :::*                   users:(("sshd",pid=4448,fd=4))
LISTEN     0      128                                          ::1:631                                                       :::*                   users:(("cupsd",pid=4446,fd=11))
LISTEN     0      100                                          ::1:25                                                        :::*                   users:(("master",pid=4797,fd=14))

再次尝试连接

再次连接发现还是并没有连接上,xuwl犯了一个煞笔错误,我的10.211.55.7的端口是9201
修改端口再次连接

在这个窗口里可以很直观的看到节点以及集群的状态信息

扩展
elasticsearch-head插件详解,还请查看这篇文章:https://www.dockerc.com/elasticsearch-head/
其实ES的cerebro这款插件挺好的,更美观的展现ES cluster节点信息,界面美观,安装简单,功能强大,如果感兴趣去看cerebro插件讲解:https://www.dockerc.com/elasticsearch-cerebro/

人已赞赏
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索