安装部署elasticsearch
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了安装部署elasticsearch相关的知识,希望对你有一定的参考价值。
环境准备:
服务器:centos7服务器1台,IP:10.0.0.103
安装包:
elasticsearch-6.1.1.tar.gz
jdk-8u151-linux-x64.tar.gz
[[email protected] ~]# ll
-rw-r--r-- 1 root root 33783880 6月 3 11:18 elasticsearch-6.1.1.tar.gz
-rw-r--r-- 1 root root 189736377 6月 3 11:23 jdk-8u151-linux-x64.tar.gz
[[email protected] ~]#
安装JDK
elasticsearch需要依赖JDK,因此首先要安装JDK:
1、解压安装包
[[email protected]?~]#?tar xf jdk-8u151-linux-x64.tar.gz -C /usr/local/
2、安装jdk修改/etc/profile,在文件末尾加入下面几句:
export JAVA_HOME=/usr/local/jdk1.8.0_151 #根据目录和版本修改
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
3、source命令让修改后的/etc/profile生效:
[[email protected] ~]# source /etc/profile
4、检查安装正确性:
[[email protected] ~]# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
[[email protected] ~]#
安装elasticsearch
1、解压文件
[[email protected]?~]#?tar?-xf?elasticsearch-6.1.1.tar.gz?-C /usr/local??##解压
[[email protected]?~]#?cd?/usr/local/elasticsearch-6.1.1
[[email protected]?elasticsearch-6.1.1]#?ls
bin??config??lib??LICENSE.txt??modules??NOTICE.txt??plugins??README.textile
2、修改配置如下(根据实际情况调整)
[[email protected] config]# cat elasticsearch.yml
# ======================== 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: mycluster #配置ES集群名字
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1 #配置节点名字
#
# 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: /opt/elk/data #配置数据路径
#
# Path to log files:
#
path.logs: /opt/elk/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.0.0.103 ?#配置为本地ip,监听主机
#
# Set a custom port for HTTP:
#
http.port: 9200 #设置对外服务的http端口
#
# 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]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
discovery.zen.minimum_master_nodes: 1 #设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4)。我这里只有一台,所以设置为1
#
# 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
3、修改系统配置文件:
修改之前最好先备份:
[[email protected] elasticsearch-6.1.1]# cp /etc/security/limits.conf /etc/security/limits.conf.bak
[[email protected] elasticsearch-6.1.1]# cp /etc/sysctl.conf /etc/sysctl.conf.bak
vi /etc/security/limits.conf?
在文件末尾添加如下内容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
vi /etc/sysctl.conf?
添加下面配置:
vm.max_map_count=655360
并执行命令sysctl -p让其修改生效:
[[email protected] elasticsearch-6.1.1]# sysctl -p
vm.max_map_count = 655360
4、创建启动elasticsearch的用户和日志目录,修改权限:
[[email protected] elasticsearch-6.1.1]# cd /usr/local
[[email protected] local]# useradd elk
[[email protected] local]# mkdir /opt/elk/logs -p
[[email protected] local]# mkdir /opt/elk/data -p
[[email protected] local]# chown -R elk:elk /opt/elk/
[[email protected] local]# chown -R elk:elk /usr/local/elasticsearch-6.1.1
5、启动服务
[[email protected] config]# su elk
[[email protected] config]$ nohup /usr/local/elasticsearch-6.1.1/bin/elasticsearch >/dev/null 2>&1 &
6、服务验证:
1)查看进程和端口号:
[[email protected] config]# netstat -tlunp|grep 9200
tcp6 0 0 10.0.0.103:9200 :::* LISTEN 6665/java
[[email protected] config]# ps -ef|grep elasticsearch
elk 6665 1 4 15:10 pts/0 00:01:17 /usr/local/jdk1.8.0_151/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 -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/usr/local/elasticsearch-6.1.1 -Des.path.conf=/usr/local/elasticsearch-6.1.1/config -cp /usr/local/elasticsearch-6.1.1/lib/* org.elasticsearch.bootstrap.Elasticsearch
root 6769 3724 0 15:37 pts/0 00:00:00 grep --color=auto elas
2)命令行验证:
[[email protected] config]# curl http://10.0.0.103:9200
{
"name" : "node-1",
"cluster_name" : "elk",
"cluster_uuid" : "gv8DzvZeR1W-aOM_UTEdVA",
"version" : {
"number" : "6.1.1",
"build_hash" : "bd92e7f",
"build_date" : "2017-12-17T20:23:25.338Z",
"build_snapshot" : false,
"lucene_version" : "7.1.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
[[email protected] config]#
3)浏览器访问验证:
以上是关于安装部署elasticsearch的主要内容,如果未能解决你的问题,请参考以下文章