Elasticsearch6.x集群部署

一、准备阶段

三台ubuntu系统机器

ip 计算机名
192.168.2.132 master
192.168.2.133 slave1
192.168.2.134 slave2

下载:

jdk-8u201-linux-x64.tar.gz
elasticsearch-6.1.3.tar.gz

二、配置JDK

2.1配置JAVA环境变量

解压jdk-8u201-linux-x64.tar.gz,并修改文件名,已方便配置环境变量

#解压JDK安装包
tar -zxvf jdk-8u201-linux-x64.tar.gz
#修改文件夹名称
mv jdk1.8.0_201 jdk
#写入系统环境变量中
vi /etc/profile
export JAVA_HOME=/opt/jdk
export PATH=$JAVA_HOME/bin:$PATH
#让系统环境变量生效
source /etc/profile 

2.2检测JDK是否生效

java -version

三、修改系统配置

3.1修改limits.conf

增加连接数,不然ES无法启动

vi /etc/security/limits.conf

添加如下内容
注意:ubuntu系统不能写*,必须写root配置,否则不会生效

#Ubuntu系统
root soft nofile 65536
root hard nofile 131072
root soft nproc 65536
root hard nproc 524288
root soft memlock unlimited
root hard memlock unlimited
supermap soft memlock unlimited
supermap hard memlock unlimited
#----------------------------------------------
#其他系统
* soft nofile 65536
* hard nofile 131072
* soft nproc 65536
* hard nproc 524288
* soft memlock unlimited
* hard memlock unlimited

3.2修改sysctl.conf

增加连接数,不然ES无法启动

vi /etc/sysctl.conf
最后一行增加
vm.max_map_count=655360

运行命令

sysctl -p

使之生效

3.3重启电脑后,检查是否生效

ulimit -Sn 查看的是软限制
ulimit -Hn 查看的是硬限制
ulimit -a 查看完整信息

如果信息都变过来后,可以继续,在其他两台电脑上修改上述内容(配置JDK,修改系统环境变量操作)

四、添加新用户(三台机器上都要操作)

ES启动必须使用非Root用户启动,所以我们需要创建一个新用户用于启动

groupadd supermap
useradd -m supermap -g supermap -p supermap
passwd supermap

新添加完成后切换到新创建的用户

su supermap

五、安装ES

5.1 将ES压缩包放到/home/supermap 目录下并解压ES安装包,(三台机器上都要操作)

tar -zxvf elasticsearch-6.1.3.tar.gz

并创建存储ES的数据目录和日志目录

mkdir /home/supermap/elasticsearch-6.1.3/data
mkdir /home/supermap/elasticsearch-6.1.3/logs

5.2 修改ES配置文件 (下文只保留所需内容)

vi /home/supermap/elasticsearch-6.1.3/config/elasticsearch.yml
# ---------------------------------- Cluster -----------------------------------

cluster.name : my-cluster

# ------------------------------------ Node ------------------------------------

node.name : node-1

# ----------------------------------- Paths ------------------------------------

path.data: /home/supermap/elasticsearch-6.1.3/data

path.logs: /home/supermap/elasticsearch-6.1.3/logs

# ----------------------------------- Memory -----------------------------------

bootstrap.memory_lock: true

# ---------------------------------- Network -----------------------------------

network.host: 192.168.2.132

http.port: 9200

node.master: true

node.data: true

# --------------------------------- Discovery ----------------------------------

discovery.zen.ping.unicast.hosts: ["192.168.2.132", "192.168.2.133","192.168.2.134"]

discovery.zen.minimum_master_nodes: 2

# ---------------------------------- Gateway -----------------------------------

gateway.recover_after_nodes: 3

其他节点(其他两台机器)slave1和slave2可复制上述内容,并修改其他几个关键信息,其他同上述master一致。

node.name: node-2

node.master: true

node.data: true

network.host: 192.168.2.133
node.name: node-3

node.master: false

node.data: true

network.host: 192.168.2.134

5.3 启动ES集群

运行三个节点顺序无关,但是必须得用普通用户启动。

cd /home/supermap/elasticsearch-6.1.3/bin

./elasticsearch

或者后台方式运行,如果以后台方式运行,将来查看进程命令:ps aux | grep elasticsearch

./elasticsearch -d

5.4 访问ES

可以使用IP地址加9200端口进行访问

当其他机器集群启动起来后,可以使用2种方法查看集群的健康度

方法一:curl 'http://IP:9200/_cat/health?v'

epoch      timestamp cluster    status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1573459172 15:59:32  my-cluster green           3         3      0   0    0    0        0             0                  -                100.0%

方法二:浏览器访问http://IP:9200/_cat/health?v

epoch      timestamp cluster    status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1573459526 16:05:26  my-cluster green           3         3      0   0    0    0        0             0                  -                100.0%

六、常见错误

6.1 uncaught exception in thread [main] org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root

不能以root用户启动

6.2 ERROR: bootstrap checks failed memory locking requested for elasticsearch process but memory is not locked

内存锁定失败,切换到root用户,修改limits.conf配置文件,vim /etc/security/limits.conf
添加* soft memlock unlimited / * hard memlock unlimited
(ubutnu需要写root soft memlock unlimited / root hard memlock unlimited)
临时取消:ulimit -l unlimited

6.3 max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

最大虚拟内存太小,切换到root用户下,修改配置文件sysctl.conf

sudo vim /etc/sysctl.conf
添加下面配置: vm.max_map_count=655360
并执行命令: sysctl -p

6.4 max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

按照上述所说的准备里修改limits.conf配置文件, 修改之后查询,ulimit -a

如果没有变化,需要修改/etc/pam.d/su,将session required pam_limits.so
注释打开,保存,重启就会生效
临时修改,ulimit -n 65536
ulimit -Sn 查看的是软限制
ulimit -Hn 查看的是硬限制
ulimit -a 查看完整信息

6.5 java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER compiled in

内核太低的缘故,可以升级linux内核(可忽略)

6.6 ERROR: bootstrap checks failed system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

修改elasticsearch-6.1.3/config/elasticsearch.yml ,增加

bootstrap.system_call_filter: false

6.7跨域访问问题

修改config\elasticsearch.yml,新增加如下配置,重启ES即可

http.cors.enabled: true
http.cors.allow-origin: /.*/

(转发请注明出处:http://www.cnblogs.com/zhangyongli2011/ 如发现有错,请留言,谢谢)

posted @ 2019-11-11 16:11  非法小恋  阅读(1313)  评论(0编辑  收藏  举报