cent7.3-es6.2.4 集群搭建(带 head 插件)-全新干净环境搭建
一、搭建 es 集群(两台机器),并在两个节点上都安装 head 插件
注意:head 插件就是 es 的一个管理工具,在两台上安装和在一台上安装都行,在哪台上安装 head 插件,就可以在哪台上管理 es 集群,无论在哪
台上安装,操作集群,包括增删改查数据都是一样的。
1.在 192.168.224.135 机器上安装 elasticsearch-1
1)安装 elasticsearch:
a)环境准备
[root@bogon ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.224.135 node-1
192.168.224.136 node-2
[root@bogon ~]# vim /etc/security/limits.conf
* soft nofile 65536 #注意必须是 65536 以上,65535 都不行
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
[root@bogon ~]# vim /etc/security/limits.d/20-nproc.conf
* soft nproc 4096 #至少是 4096,若小于则需修改,也可大于 4096
[root@bogon ~]# vim /etc/sysctl.conf
vm.max_map_count=262144 #添加,至少是 262144
[root@bogon ~]# sysctl -p
[root@bogon ~]# reboot #注意:重启后,主机名自动变成 node-1 了就
[root@node-1 ~]# systemctl stop firewalld.service
b)安装 jdk1.8:
[root@node-1 ~]# mkdir /usr/local/java
[root@node-1 ~]# rz
上传 jdk1.8 包
[root@bogon ~]# ls
jdk-8u144-linux-x64.tar.gz
[root@node-1 ~]# tar -zxf jdk-8u144-linux-x64.tar.gz
[root@node-1 ~]# ls
jdk1.8.0_144 jdk-8u144-linux-x64.tar.gz
[root@node-1 ~]# mv jdk1.8.0_144/ /usr/local/java/
[root@node-1 ~]# ls /usr/local/java/
jdk1.8.0_144
[root@node-1 ~]# vim /etc/profile
#最后面添加:
JAVA_HOME=/usr/local/java/jdk1.8.0_144
CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
[root@node-1 ~]# source /etc/profile
[root@node-1 ~]# java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
[root@node-1 ~]# rz
上传 elasticsearch 包,并安装 elasticsearch,(es 启动需要普通用户,其他服务启动用 root)
[root@node-1 ~]# ls
elasticsearch-6.2.4.tar.gz jdk-8u144-linux-x64.tar.gz
[root@node-1 ~]# tar -zxf elasticsearch-6.2.4.tar.gz
[root@node-1 ~]# ls
elasticsearch-6.2.4 elasticsearch-6.2.4.tar.gz jdk-8u144-linux-x64.tar.gz
[root@node-1 ~]# mv elasticsearch-6.2.4 /opt/
[root@node-1 ~]# ls /opt/elasticsearch-6.2.4/
bin config lib LICENSE.txt logs modules NOTICE.txt plugins README.textile
[root@node-1 ~]# groupadd eszu
[root@node-1 ~]# useradd esyonghu -g eszu -p 123456
[root@node-1 ~]# chown -R esyonghu:eszu /opt/elasticsearch-6.2.4/
[root@node-1 ~]# su - esyonghu
[esyonghu@node-1 ~]$ vim /opt/elasticsearch-6.2.4/config/elasticsearch.yml
cluster.name: shi #修改,集群的名称,两个必须一样,就是通过是不是同一个名称判断是不是一个集群
node.name: node-1 #node-1
path.data: /opt/elasticsearch-6.2.4/data
path.logs: /opt/elasticsearch-6.2.4/logs
network.host: 192.168.224.135 #修改,本机 ip,或者 0.0.0.0,监听本机所有 ip
http.port: 9200 #释放
#下面一行是新添加的,改成单播,默认是组播,(通过单播两个集机器通讯)
discovery.zen.ping.unicast.hosts: ["192.168.224.135","192.168.224.136"]
#下面两个是新加的,允许跨域访问
http.cors.enabled: true
http.cors.allow-origin: '*'
[esyonghu@node-1 ~]$ mkdir /opt/elasticsearch-6.2.4/data
[esyonghu@node-1 ~]$ cd /opt/elasticsearch-6.2.4/bin/
[esyonghu@node-1 bin]$ ls elasticsearch
elasticsearch
[esyonghu@node-1 bin]$ ./elasticsearch -d #后台启动 es,或者先./ elasticsearch 前台启动查看下是否能启动再后台启动
[esyonghu@node-1 bin]$ tailf /opt/elasticsearch-6.2.4/logs/shi.log #查看启动日志,需要等会才能形成日志,会创建一个带集群名的日志
………
[2019-04-01T09:31:59,922][INFO ][o.e.h.n.Netty4HttpServerTransport] [node-1] publish_address {192.168.224.135:9200}, bound_addresses {192.168.224.135:9200}
[2019-04-01T09:31:59,922][INFO ][o.e.n.Node ] [node-1] started
[2019-04-01T09:31:59,929][INFO ][o.e.g.GatewayService ] [node-1] recovered [0] indices into cluster_state
[esyonghu@node-1 bin]$ netstat -anput |grep 9200
有 9200 端口
[esyonghu@node-1 bin]$ curl http://192.168.224.135:9200
能访问 es 默认页面
客户端浏览器外网访问,如下:http://192.168.224.135:9200/