es6.2.4 集群搭建-单点 es 有数据时候添加 1 台
1.在 192.168.224.133 机器上安装 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.133 node-1
192.168.224.134 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
[root@bogon ~]# systemctl stop firewalld.service
b)安装 jdk1.8:
[root@bogon ~]# mkdir /usr/local/java
[root@bogon ~]# rz
上传 jdk1.8 包
[root@bogon ~]# ls
jdk-8u144-linux-x64.tar.gz
[root@bogon ~]# tar -zxf jdk-8u144-linux-x64.tar.gz
[root@bogon ~]# ls
jdk1.8.0_144 jdk-8u144-linux-x64.tar.gz
[root@bogon ~]# mv jdk1.8.0_144/ /usr/local/java/
[root@bogon ~]# ls /usr/local/java/
jdk1.8.0_144
[root@bogon ~]# 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@bogon ~]# source /etc/profile
[root@bogon ~]# 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@bogon ~]# rz
上传 elasticsearch 包,并安装 elasticsearch,(es 启动需要普通用户,其他服务启动用 root)
[root@bogon ~]# ls
elasticsearch-6.2.4.tar.gz jdk-8u144-linux-x64.tar.gz
[root@bogon ~]# tar -zxf elasticsearch-6.2.4.tar.gz
[root@bogon ~]# ls
elasticsearch-6.2.4 elasticsearch-6.2.4.tar.gz jdk-8u144-linux-x64.tar.gz
[root@bogon ~]# mv elasticsearch-6.2.4 /opt/
[root@bogon ~]# ls /opt/elasticsearch-6.2.4/
bin config lib LICENSE.txt logs modules NOTICE.txt plugins README.textile
[root@bogon ~]# groupadd eszu
[root@bogon ~]# useradd esyonghu -g eszu -p 123456
[root@bogon ~]# chown -R esyonghu:eszu /opt/elasticsearch-6.2.4/
[root@bogon ~]# su - esyonghu
[esyonghu@bogon ~]$ 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.133 #修改,本机 ip,或者 0.0.0.0,监听本机所有 ip
http.port: 9200 #释放
#下面一行是新添加的,改成单播,默认是组播,(通过单播两个集机器通讯)
discovery.zen.ping.unicast.hosts: ["192.168.224.133","192.168.224.134"]
#下面两个是新加的,允许跨域访问
http.cors.enabled: true
http.cors.allow-origin: '*'
[esyonghu@bogon ~]$ mkdir /opt/elasticsearch-6.2.4/data
[esyonghu@bogon ~]$ cd /opt/elasticsearch-6.2.4/bin/
[esyonghu@bogon bin]$ ls elasticsearch
elasticsearch
[esyonghu@bogon bin]$ ./elasticsearch -d #后台启动 es,或者先./ elasticsearch 前台启动查看下是否能启动再后台启动
[esyonghu@bogon bin]$ tailf /opt/elasticsearch-6.2.4/logs/shi.log #查看启动日志,需要等会才能形成日志,会创建一个带集群名的日志
………
[2019-03-31T22:43:24,603][WARN ][o.e.m.j.JvmGcMonitorService] [node-1] [gc][14] overhead, spent [740ms] collecting in the last [1s]
[2019-03-31T22:43:33,651][INFO ][o.e.m.j.JvmGcMonitorService] [node-1] [gc][23] overhead, spent [317ms] collecting in the last [1s]
[2019-03-31T22:43:42,356][INFO ][o.e.c.r.a.AllocationService] [node-1] Cluster health status changed from [RED] to [YELLOW] (reason: [shards started [[index-
demo1][3], [index-demo1][1], [index-demo1][2], [index-demo1][0]] ...]).
[2019-03-31T22:45:13,950][INFO ][o.e.m.j.JvmGcMonitorService] [node-1] [gc][123] overhead, spent [488ms] collecting in the last [1.1s]
[esyonghu@bogon bin]$ netstat -anput |grep 9200
有 9200 端口
[esyonghu@bogon bin]$ curl http://192.168.224.133:9200
能访问 es 默认页面
客户端浏览器外网访问,如下:http://192.168.224.133:9200/