Centos7上安装Elasticsearch和kibana(非集群模式)
一、实验物料
Linux操作系统(Centos7),elasticsearch-7.11.1-linux-x86_64.tar.gz,kibana-7.11.1-linux-x86_64
下载地址:
软件名称 | 下载地址 |
---|---|
elasticsearch-7.11.1-linux-x86_64.tar.gz | https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.1-linux-x86_64.tar.gz |
kibana-7.11.1-linux-x86_64 | https://artifacts.elastic.co/downloads/kibana/kibana-7.11.1-linux-x86_64.tar.gz |
二、安装过程
1.安装Elasticsearch
1、上传elaticsearch软件包及解压
将下载好的elasticsearch-7.11.1-linux-x86_64.tar.gz上传的linux服务器上,然后执行加压缩操作:
tar -xzf elasticsearch-7.11.1-darwin-x86_64.tar.gz
解压完成后
2、为elaticsearch创建用户并赋予相应权限
因为如果用root用户执行命令,会报错
创建方法:
adduser es
passwd es
chown -R es:es elasticsearch-7.11.1/
chmod 770 elasticsearch-7.11.1/
3、配置elasticsearch.yml
配置文件的目录位置:
在elasticsearch的安装目录下的config目录下,如我的elasticsearch的安装目录是:/usr/local/elasticsearch-7.11.1,那么elasticsearch.yml文件所在位置就是:/usr/local/elasticsearch-7.11.1/config。
执行命令:
vim 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):
# 解决其他机器无法访问9200端口的问题
network.host: 0.0.0.0
#
# 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: ["127.0.0.1", "[::1]"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
# 配置单机非集群模式下的master节点
cluster.initial_master_nodes: ["node-1"]
#
# 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
4、修改liunx服务器的配置
如果我们不做提前的配置,那么Elasticsearch在启动的时候就会抛出异常,导致程序终止:
解决方式:
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]。
这是说每个进程最大同时打开文件数太小,可通过下面2个命令查看当前数量
ulimit -Hn
ulimit -Sn
修改/etc/security/limits.conf文件,增加配置,用户退出后重新登录生效
* soft nofile 65536
* hard nofile 65536
[2]: max number of threads [3860] for user [es] is too low, increase to at least [4096]
问题同上,最大线程个数太低。修改配置文件/etc/security/limits.conf(和问题1是一个文件),增加配置
* soft nproc 4096
* hard nproc 4096
可通过命令查看
ulimit -Hu
ulimit -Su
修改后的文件:
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
修改/etc/sysctl.conf文件,增加配置vm.max_map_count=262144
vi /etc/sysctl.conf
sysctl -p
执行命令sysctl -p生效
[4]: 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中配置,上面我们已经做了
discovery.seed_hosts: ["0.0.0.0", "[::1]"]
cluster.initial_master_nodes: ["node-1"]
5、启动Elasticsearch
在Elasticsearch安装目录中,执行
./bin/elasticsearch
如果想要后台方式启动,执行如下操作:
./bin/elasticsearch -d
这样就启动成功了。
6、验证
我们在浏览器上请求如下地址:
http://192.168.15.62:9200/
出现如下内容:
Elasticsearch就安装完成了。如果无法访问,那么看一下自己linux上防火墙是否关闭了命令如下:
systemctl status firewalld.service
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
2.安装kibana
1、上传kibana软件包及解压
将下载好的kibana-7.11.1-linux-x86_64.tar.gz上传的linux服务器上,然后执行加压缩操作:
tar -xzf kibana-7.11.1-linux-x86_64.tar.gz
解压完成后
2、配置kibana.yml
配置文件的目录位置:
在kibana的安装目录下的config目录下,如我的kibana的安装目录是:/usr/local/kibana-7.11.1-linux-x86_64,那么kibana.yml文件所在位置就是:/usr/local/kibana-7.11.1-linux-x86_64/config。
执行命令:
vim kibana.yml
主要修改一下配置:
# Kibana is served by a back end server. This setting specifies the port to use.
# 配置访问端口
server.port: 5601
# 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: "0.0.0.0"
# 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: "your-hostname"
# The URLs of the Elasticsearch instances to use for all your queries.
# 指定一个Elasticsearch 的连接地址
elasticsearch.hosts: ["http://192.168.15.61:9200"]
# 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"
# 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: "en"
3、启动kibana
在kibana安装目录中,执行
./bin/kibana
或者后台方式启动:
nohup ./bin/kibana &
注意:这里也不要用root用户,最好单独建一个账号,方式和上面Elasticsearch安装时建立账号的方式一致。
这样就启动成功了。
4、验证
我们在浏览器上请求如下地址:
http://192.168.15.64:5601/
出现如下内容:
这样kibana就安装完成了。
5、停止服务
通常情况下,我们关闭服务都是使用 ps -ef|grep kibana ,但是这个命令现在却查不到进程的,主要原因大概是因为 kibana 是node 写的。所以kibana 运行的时候是运行在node 里面。我们知道 kibana 是 5601 对外的 tcp 端口,所以使用 netstat -tunlp|grep 5601 就可以查到进程id 了 。
三、小结
本文主要是介绍了最简单的Elasticsearch和kibana的暗转过程,基本都是采用的默认配置,没有做其他的配置更改。