1.Elasticsearch集群搭建

1.Elasticsearch简介
ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。
2.下载安装包
这里我们下载的是elasticsearch-6.7.2,目前7.0.1版本已经出来了,网上有相关的文章介绍,做了很大的升级。
3.Elasticsearch集群安装
1).这里我们准备三台虚拟机:

IPhttp porttcp port
10.xxx.xx.4082008300
10.xxx.xx.4182018301
10.xxx.xx.4282028302

2).解压安装包

$ tar -zxvf elasticsearch-6.7.2.tar.gz

3).进入安装目录config修改elasticsearch.yml
note-master配置:

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: yrz-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
# 节点名称
node.name: node-master
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
# 本机地址
network.host: 10.xxx.xx.40
#
# Set a custom port for HTTP:
# http端口
http.port: 8200
# tcp通讯端口
transport.tcp.port: 8300
# 是否作为主机
node.master: true
# 是否作为数据节点
node.data: false
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
# 集群信息,默认的通讯接口是9300
discovery.zen.ping.unicast.hosts: ["10.xxx.xx.40:8300", "10.xxx.xx.41:8301","10.xxx.xx.42:8302"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

# 开启跨域访问支持,默认为false
http.cors.enabled: true
# 跨域访问允许的域名地址,(允许所有域名)以上使用正则
http.cors.allow-origin: /.*/  

node-data1:

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: yrz-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
# 节点名称
node.name: node-data1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
# 本机地址
network.host: 10.xxx.xx.41
#
# Set a custom port for HTTP:
# http端口
http.port: 8201
# tcp通讯端口
transport.tcp.port: 8301
# 是否作为主机
node.master: false
# 是否作为数据节点
node.data: true
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
# 集群信息,默认的通讯接口是9300
discovery.zen.ping.unicast.hosts: ["10.xxx.xx.40:8300", "10.xxx.xx.41:8301","10.xxx.xx.42:8302"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

# 开启跨域访问支持,默认为false
http.cors.enabled: true
# 跨域访问允许的域名地址,(允许所有域名)以上使用正则
http.cors.allow-origin: /.*/  

node-data2:

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: yrz-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
# 节点名称
node.name: node-data2
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
# 本机地址
network.host: 10.xxx.xx.42
#
# Set a custom port for HTTP:
# http端口
http.port: 8202
# tcp通讯端口
transport.tcp.port: 8302
# 是否作为主机
node.master: false
# 是否作为数据节点
node.data: true
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
# 集群信息,默认的通讯接口是9300
discovery.zen.ping.unicast.hosts: ["10.xxx.xx.40:8300", "10.xxx.xx.41:8301","10.xxx.xx.42:8302"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

# 开启跨域访问支持,默认为false
http.cors.enabled: true
# 跨域访问允许的域名地址,(允许所有域名)以上使用正则
http.cors.allow-origin: /.*/  

4.配置elasticsearch开机自动启动
新建文件

$ sudo vi /etc/init.d/elasticsearch

文件内容如下:

#!/bin/sh

export JAVA_HOME=/usr/local/nlp/java/jdk1.8.0_162
export JAVA_BIN=/usr/local/nlp/java/jdk1.8.0_162/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH

SERVICE_DIR=/usr/local/nlp/elasticsearch-6.7.2
            
SERVICE_NAME=elasticsearch
PID=$SERVICE_NAME\.pid

cd $SERVICE_DIR

case "$1" in

    start)
        nohup ./bin/elasticsearch >/dev/null 2>&1 &
        echo $! > $SERVICE_DIR/$PID
        echo "=== start $SERVICE_NAME"
        ;;

    stop)
        kill `cat $SERVICE_DIR/$PID`
        rm -rf $SERVICE_DIR/$PID
        echo "=== stop $SERVICE_NAME"

        sleep 5
		##
		## edu-service-aa.jar
		## edu-service-aa-bb.jar
        P_ID=`ps -ef | grep -w "$SERVICE_NAME" | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "=== $SERVICE_NAME process not exists or stop success"
        else
            echo "=== $SERVICE_NAME process pid is:$P_ID"
            echo "=== begin kill $SERVICE_NAME process, pid is:$P_ID"
            kill -9 $P_ID
        fi
        ;;

    restart)
        $0 stop
        sleep 2
        $0 start
        echo "=== restart $SERVICE_NAME"
        ;;

    *)
        ## restart
        $0 stop
        sleep 2
        $0 start
        ;;

esac
exit 0

配置/etc/init.d/ elasticsearc可执行权限:

$ sudo chmod 755 /etc/init.d/elasticsearch
$ sudo chmod +x /etc/init.d/elasticsearch

注册系统服务:

$ sudo chkconfig --add elasticsearch

启动elasticsearch:

$ service elasticsearch start

1.启动时出现如下异常:
[2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方案:
修改连接数:
vi /etc/security/limits.conf
wxt hard nofile 1048576
wxt soft nofile 1048576
wxt soft nproc 50000
wxt hard nproc 65536
注:wxt为当前linux用户
sudo vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360 【修该项即可】
并执行命令:
sudo sysctl -p

2.提示java.lang.OutOfMemoryError: Java heap space时可以修改es默认内存大小,编辑config下的jvm.options
#Xms represents the initial size of total heap space
#Xmx represents the maximum size of total heap space

-Xms2g
-Xmx2g

5.安装elasticsearch-head
安装head前需要安装nodejs
1).解压nodejs安装包:

$ tar xf node-v8.11.2-linux-x64.tar.xz

2).安装nodejs所需相关插件

$ sudo yum -y install gcc make gcc-c++ openssl-devel wget

3).设置node和npm为全局变量

$ sudo ln -s /usr/local/nlp/node-v8.11.2-linux-x64/bin/node /usr/local/bin/node
$ sudo ln -s /usr/local/nlp/node-v8.11.2-linux-x64//bin/npm /usr/local/bin/npm

4).修改.bash_profile文件,新增如下配置

$ vi ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/nlp/node-v8.11.2-linux-x64/bin

5).执行如下命令使.bash_profile修改生效

$ source  ~/.bash_profile

6).测试nodejs是否安装成功

$ node -v
$ npm -v

7).修改elasticsearch-head下的Gruntfile.js文件
将端口改为8100

$ vim Gruntfile.js
connect: {
	server: {
		options: {
			port: 8100,
			hostname: '*',
			base: '.',
			keepalive: true
		}
	}
}

8).执行安装并启动head

npm install
npm run start

安装成功后访问:http://10.xxx.xx.40:8100/,出现如下界面则安装成功。
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值