ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口操作ES,也可以利用Java API。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。
我们建立一个网站或应用程序,并要添加搜索功能,但是想要完成搜索工作的创建是非常困难的。我们希望搜索解决方案要运行速度快,我们希望能有一个零配置和一个完全免费的搜索模式,我们希望能够简单地使用JSON通过HTTP来索引数据,我们希望我们的搜索服务器始终可用,我们希望能够从一台开始并扩展到数百台,我们要实时搜索,我们要简单的多租户,我们希望建立一个云的解决方案。因此我们利用Elasticsearch来解决所有这些问题及可能出现的更多其它问题。
安装软件
[root@eslocalhost ~]# yum -y install vim??net-tools wget??lrzsz
关闭selinux和防火墙
[root@eslocalhost ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#?????enforcing - SELinux security policy is enforced.
#?????permissive - SELinux prints warnings instead of enforcing.
#?????disabled - No SELinux policy is loaded.
SELINUX=disabled??#设置成disabled
# SELINUXTYPE= can take one of three two values:
#?????targeted - Targeted processes are protected,
#?????minimum - Modification of targeted policy. Only selected processes are protected.?
#?????mls - Multi Level Security protection.
SELINUXTYPE=targeted
关闭防火墙
[root@eslocalhost ~]# systemctl stop firewalld
[root@eslocalhost ~]# systemctl disable firewalld
安装jdk环境
[root@eslocalhost ~]# mkdir -p /usr/local/java/
[root@eslocalhost ~]# cd /usr/local/java/
[root@eslocalhost java]#?
[root@eslocalhost java]# rz????#敲回车找到jdk的路径并上传
[root@eslocalhost java]# tar -xvf jdk1.8.0_181-cloudera.tar.gz??#解压缩文件
[root@eslocalhost java]# ls
jdk1.8.0_181-cloudera??jdk1.8.0_181-cloudera.tar.gz??#已解压缩完成
[root@eslocalhost java]# vim /etc/profile??#设置环境变理
把以下内容贴到此文件的最下方
# java environment
export JAVA_HOME=/usr/local/java/jdk1.8.0_181-cloudera
export JRE_HOME=$JAVA_HOME/jre
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
[root@eslocalhost java]# java -version???查看java版本
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
https://www.elastic.co/cn/start
?
点击linux下载最新的是7.11.2版本
首先把它上传到一个目录(data目录),可以用lrzsz工具(如果没有,执行yum -y install lrzsz进行安装)上传。
[root@eslocalhost java]# cd /data
[root@eslocalhost data]# rz
[root@eslocalhost data] tar -xvf elasticsearch-7.11.2-linux-x86_64.tar.gz
[root@eslocalhost data] mv elasticsearch-7.11.2-linux??elasticsearch??#更改解压后的文件夹名字
[root@eslocalhost data]# ll??#查看解压后的文件
总用量?560584
drwxr-xr-x??10 es???es????????4096 3月??19 18:02 elasticsearch
-rwxrwxrwx.??1 root root 322857683 3月??19 15:14 elasticsearch-7.11.2-linux-x86_64.tar.gz
创建个新用户
[root@eslocalhost data] useradd es
把目录的权限设置为新用户
[root@eslocalhost data] chown -R es:es /data/elasticsearch/
修改sysctl文件
[root@eslocalhost ~]# vim /etc/sysctl.conf?
添加或修改如下内容
vm.max_map_count=655360
[root@eslocalhost ~]# sysctl -p
修改句柄数
[root@eslocalhost ~]# vim /etc/security/limits.conf
添加内容如下:
* soft nofile 65536
* hard nofile 65536
* soft nproc 2048
* hard nproc 4096
此文件修改后需要重新登录用户,才会生效
登录后使用ulimit -S -n和ulimit -H -n查看
[root@eslocalhost ~]# ulimit -n
65536
修改elasticsearch的yml配置文件
[root@eslocalhost ~]# vim /data/elasticsearch/config/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: my-application
#
# ------------------------------------ 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: /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: 192.168.200.88??#修改成服务器的iP
#
# Set a custom port for HTTP:
#
http.port: 9200??#需要开启的端口
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["eslocalhost"]??#修改成主机名
#
# For more information, consult the discovery and cluster formation 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
启动elasticsearch
[root@eslocalhost ~]# cd /data/elasticsearch/bin/
[root@eslocalhost bin]# ./elasticsearch -d???#启动??-d表示在后台启动,如果不加-d是窗口启动,可以先不加-d查看报错日志。
测试服务是否正常启动
[root@eslocalhost bin]# curl http://192.168.200.88:9200
{
??"name" : "eslocalhost",
??"cluster_name" : "elasticsearch",
??"cluster_uuid" : "mkHgdVD5RoSYCVH9slepPg",
??"version" : {
????"number" : "7.11.2",
????"build_flavor" : "default",
????"build_type" : "tar",
????"build_hash" : "3e5a16cfec50876d20ea77b075070932c6464c7d",
????"build_date" : "2021-03-06T05:54:38.141101Z",
????"build_snapshot" : false,
????"lucene_version" : "8.7.0",
????"minimum_wire_compatibility_version" : "6.8.0",
????"minimum_index_compatibility_version" : "6.0.0-beta1"
??},
??"tagline" : "You Know, for Search"
}
出现以上信息表示服务正常启动。
FAQ报错处理
1.es?异常
ERROR: [5] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [1024] for user [es] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[4]:? failed to install; check the logs and fix your configuration or disable system call filters at your own risk
[5]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
[2019-04-09T09:51:29,228][INFO ][o.e.n.Node?????????????? ] [localhost.localdomain] stopping ...
[2019-04-09T09:51:29,264][INFO ][o.e.n.Node?????????????? ] [localhost.localdomain] stopped
[2019-04-09T09:51:29,265][INFO ][o.e.n.Node?????????????? ] [localhost.localdomain] closing ...
[2019-04-09T09:51:29,320][INFO ][o.e.n.Node?????????????? ] [localhost.localdomain] closed
[2019-04-09T09:51:29,323][INFO ][o.e.x.m.p.NativeController] [localhost.localdomain] Native controller process has stopped - no new native processes can be started
解决方案
切换root用户修改句柄数
[root@eslocalhost ~]# vim /etc/security/limits.conf
添加内容如下:
* soft nofile 65536
* hard nofile 65536
* soft nproc 2048
* hard nproc 4096
2.ERROR: [3] bootstrap checks failed
[1]: max number of threads [1024] for user [es] is too low, increase to at least [4096]
[2]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
[3]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
解决方案:
[root@eslocalhost ~]#vim /etc/security/limits.d/90-nproc.conf
修改
*??????????soft????nproc?????1024
为
*??????????soft????nproc?????4096
ERROR: [2] bootstrap checks failed
[1]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
[2]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
解决方案:
在?elasticsearch.yml中添加配置项:bootstrap.system_call_filter为false:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
重启es?异常
ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
解决方案:
修改
elasticsearch.yml
取消注释保留一个节点
cluster.initial_master_nodes: ["node-1"]
这个的话,这里的node-1是上面一个默认的记得打开就可以了
重启?正常
下载并上传到服务器的data目录下
[root@eslocalhost ~]# cd /data
[root@eslocalhost data]# ls kibana-7.11.2-linux-x86_64.tar.gz?
kibana-7.11.2-linux-x86_64.tar.gz
[root@eslocalhost data]# tar -xvf kibana-7.11.2-linux-x86_64.tar.gz???#解压
[root@eslocalhost data]# ll
drwxr-xr-x??10 root root??????4096 3月??25 14:13 kibana-7.11.2-linux-x86_64
[root@eslocalhost data]# chown -R es:es kibana-7.11.2-linux-x86_64??#给es用户授权
[root@eslocalhost data]# sudo su - es??#切换到es用户
[es@eslocalhost ~]$ cd /data
[es@eslocalhost data]$?
[es@eslocalhost data]$ mv kibana-7.11.2-linux-x86_64 kibana??重命名
配置kibana的yml文件
[es@eslocalhost data]$ vim??kibana/config/kibana.yml?
代码如下:
# Kibana is served by a back end server. This setting specifies the port to use.
server.port: 5601??#kibana的端口打开
# Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
# The default is ‘localhost‘, which usually means remote machines will not be able to connect.
# To allow connections from remote users, set this parameter to a non-loopback address.
server.host: "192.168.200.88" #改成服务器的iP
# Enables you to specify a path to mount Kibana at if you are running behind a proxy.
# Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath
# from requests it receives, and to prevent a deprecation warning at startup.
# This setting cannot end in a slash.
#server.basePath: ""
# Specifies whether Kibana should rewrite requests that are prefixed with
# `server.basePath` or require that they are rewritten by your reverse proxy.
# This setting was effectively always `false` before Kibana 6.3 and will
# default to `true` starting in Kibana 7.0.
#server.rewriteBasePath: false
# Specifies the public URL at which Kibana is available for end users. If
# `server.basePath` is configured this URL should end with the same basePath.
#server.publicBaseUrl: ""
# The maximum payload size in bytes for incoming server requests.
#server.maxPayloadBytes: 1048576
# The Kibana server‘s name.??This is used for display purposes.
server.name: "eslocalhost"??#改成服务器的主机名
# The URLs of the Elasticsearch instances to use for all your queries.
elasticsearch.hosts: ["http://192.168.200.88:9200"] #改成es的接口地址
# Kibana uses an index in Elasticsearch to store saved searches, visualizations and
# dashboards. Kibana creates a new index if the index doesn‘t already exist.
kibana.index: ".kibana"??#kibana的访问主页打开
# The default application to load.
#kibana.defaultAppId: "home"
# If your Elasticsearch is protected with basic authentication, these settings provide
# the username and password that the Kibana server uses to perform maintenance on the Kibana
# index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
# is proxied through the Kibana server.
#elasticsearch.username: "kibana_system"
#elasticsearch.password: "pass"
# Enables SSL and paths to the PEM-format SSL certificate and SSL key files, respectively.
# These settings enable SSL for outgoing requests from the Kibana server to the browser.
#server.ssl.enabled: false
#server.ssl.certificate: /path/to/your/server.crt
#server.ssl.key: /path/to/your/server.key
# Optional settings that provide the paths to the PEM-format SSL certificate and key files.
# These files are used to verify the identity of Kibana to Elasticsearch and are required when
# xpack.security.http.ssl.client_authentication in Elasticsearch is set to required.
#elasticsearch.ssl.certificate: /path/to/your/client.crt
#elasticsearch.ssl.key: /path/to/your/client.key
# Optional setting that enables you to specify a path to the PEM file for the certificate
# authority for your Elasticsearch instance.
#elasticsearch.ssl.certificateAuthorities: [ "/path/to/your/CA.pem" ]
# To disregard the validity of SSL certificates, change this setting‘s value to ‘none‘.
#elasticsearch.ssl.verificationMode: full
# Time in milliseconds to wait for Elasticsearch to respond to pings. Defaults to the value of
# the elasticsearch.requestTimeout setting.
#elasticsearch.pingTimeout: 1500
# Time in milliseconds to wait for responses from the back end or Elasticsearch. This value
# must be a positive integer.
#elasticsearch.requestTimeout: 30000
# List of Kibana client-side headers to send to Elasticsearch. To send *no* client-side
# headers, set this value to [] (an empty list).
#elasticsearch.requestHeadersWhitelist: [ authorization ]
# Header names and values that are sent to Elasticsearch. Any custom headers cannot be overwritten
# by client-side headers, regardless of the elasticsearch.requestHeadersWhitelist configuration.
#elasticsearch.customHeaders: {}
# Time in milliseconds for Elasticsearch to wait for responses from shards. Set to 0 to disable.
#elasticsearch.shardTimeout: 30000
# Logs queries sent to Elasticsearch. Requires logging.verbose set to true.
#elasticsearch.logQueries: false
# Specifies the path where Kibana creates the process ID file.
#pid.file: /run/kibana/kibana.pid
# Enables you to specify a file where Kibana stores log output.
#logging.dest: stdout
# Set the value of this setting to true to suppress all logging output.
#logging.silent: false
# Set the value of this setting to true to suppress all logging output other than error messages.
#logging.quiet: false
# Set the value of this setting to true to log all events, including system usage information
# and all requests.
#logging.verbose: false
# Set the interval in milliseconds to sample system and process performance
# metrics. Minimum is 100ms. Defaults to 5000.
#ops.interval: 5000
# Specifies locale to be used for all localizable strings, dates and number formats.
# Supported languages are the following: English - en , by default , Chinese - zh-CN .
i18n.locale: "zh-CN"??#主页显示中文名字
启动kibana服务
[es@eslocalhost data]$ cd kibana/bin/
[es@eslocalhost bin]$ ./kibana &??加&表示在后台启动服务,不加是在窗口启动,关掉后服务就停止了。
验证是否启动成功
?
?
原文:https://blog.51cto.com/u_1602069/2839592