一、环境

安装环境:win10

JDK:1.8

elasticsearch:8.11.1

kibana:8.11.1

下载地址1(elasticsearch+kibana):Past Releases of Elastic Stack Software | Elastic

i下载地址2(k分词器):Releases · infinilabs/analysis-ik · GitHub

二、ElasticSearch

 (主要参考:Windows安装Elasticsearch8.x保姆级教程

1、elastic与JDK关系

elasticsearch与JDK版本

2、环境变量配置

1)进入:WIN键搜索并点击 编辑系统环境变量 --> 点击环境变量 --->点击系统变量下新建按钮。

2)输入:变量名输入ES_HOME,变量值为ES的安装目录(bin目录的上级)

3)添加:双击PATH变量--->点击新建—>输入%ES_HOME%\bin

4)输入:变量名输入ES_JAVA_HOME,变量值为JDK目录的路径(与bin目录同级)

3、修改配置文件

1)解决启动日志乱码问题。进入config目录--->打开jvm.options 文件

//文档末尾追加
-Dfile.encoding=GBK

2)修改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: D:/java/software/elasticsearch-8.11.1/data
#
# Path to log files:
#
#设置日志文件的存储路径
path.logs: D:/java/software/elasticsearch-8.11.1/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 -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
#设置ES监听地址,默认为192.168.0.1; 0.0.0.0: 任意机器都可访问
network.host: 0.0.0.0
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
#设置对外服务的http端口,默认为9200
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"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Allow wildcard deletion of indices:
#
#action.destructive_requires_name: false

#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically      
# generated to configure Elasticsearch security features on 29-09-2024 06:06:36
#
# --------------------------------------------------------------------------------

3)添加ik分词器

选择与下载的es版本一致的下载,并且在plugins目录下新建ik目录,并且将下载压缩包内容复制到ik目录下,最后终端输入命令。

elasticsearch-plugin list

4、启动服务

终端输入命令elasticsearch.bat,首次启动会输出默认用户名密码。

Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  rhPUKvPExr+fN-tPDcbp
-> Elasticsearch security features have been automatically configured!
-> Authentication is enabled and cluster connections are encrypted.

->  Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  rhPUKvPExr+fN-tPDcbp

->  HTTP CA certificate SHA-256 fingerprint:
  4831e55d892d7e7d2a9fde48d15683e704ffb82c155d5bbc2f75fb859ddb15c2

->  Configure Kibana to use this cluster:
* Run Kibana and click the configuration link in the terminal when Kibana starts.
* Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
  eyJ2ZXIiOiI4LjExLjEiLCJhZHIiOlsiMTAuMjM4LjExMi4xOTc6OTIwMCJdLCJmZ3IiOiI0ODMxZTU1ZDg5MmQ3ZTdkMmE5ZmRlNDhkMTU2ODNlNzA0ZmZiODJjMTU1ZDViYmMyZjc1ZmI4NTlkZGIxNWMyIiwia2V5IjoiTlM5a1BKSUJINWx3M3Nsa0oyQzM6dEt2eHlPRUZURUtIOVM5VG9MT0ZzZyJ9

-> Configure other nodes to join this cluster:
* Copy the following enrollment token and start new Elasticsearch nodes with `bin/elasticsearch --enrollment-token <token>` (valid for the next 30 minutes):
  eyJ2ZXIiOiI4LjExLjEiLCJhZHIiOlsiMTAuMjM4LjExMi4xOTc6OTIwMCJdLCJmZ3IiOiI0ODMxZTU1ZDg5MmQ3ZTdkMmE5ZmRlNDhkMTU2ODNlNzA0ZmZiODJjMTU1ZDViYmMyZjc1ZmI4NTlkZGIxNWMyIiwia2V5IjoiTmk5a1BKSUJINWx3M3Nsa0oyQzM6aGxKZlkwejhSNVN0a1VlUHBQRFVVQSJ9

  If you're running in Docker, copy the enrollment token and run:
  `docker run -e "ENROLLMENT_TOKEN=<token>" docker.elastic.co/elasticsearch/elasticsearch:8.11.1`

访问:http://localhost:9200/,输入控制台输出的默认用户名密码则,启动成功。

5、创建新用户以及授权

//添加:终端输入,添加新用户xinuser,并设置密码
//必须先运行ES,elasticsearch不能使用root用户启动,所以我们创建一个新的用户
elasticsearch-8.11.1\bin>elasticsearch-users useradd xinuser
Enter new password:
Retype new password:

权限:终端输入,设置xinuser为超级管理员
elasticsearch-8.11.1\bin>elasticsearch-users roles -a superuser xinuser

权限:终端输入,设置xinuser为kibana用户
elasticsearch-8.11.1\bin>elasticsearch-users roles -a kibana_system xinuser

注意:

1)、随机生成密码(一定要先运行ES)

//终端输入命令
elasticsearch-reset-password -u elastic

New value字段的值就是新的密码,用于忘记密码的情况

2)、指定账号密码(一定要先运行ES):

//终端输入命令
elasticsearch-reset-password --username elastic -i

注:密码至少要六个字符,新密码xxxxxxx

3)、安全配置

elasticsearch.yml 文件运行服务自动生成下列配置:

# 设置是否开启xpack的安全功能,默认true/开启---以xpack开头的配置项都会开启
xpack.security.enabled: false
# 设置是否开启节点的安全注册功能---ChatGPT询问xpack.security.enrollment
xpack.security.enrollment.enabled: true

# 配置X-Pack安全功能中 与 HTTP 通信相关的 SSL 设置
xpack.security.http.ssl:
  # 设置是否开启 HTTP API 客户端连接加密功能---如 Kibana  
  enabled: true
  keystore.path: certs/http.p12
  
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
  # 设置是否启用集群节点之间的加密和相互身份验证功能
  enabled: true
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12`

xpack.security.enabled
● 默认true:必须使用账号连接ES
● 若为false:必须使用http://localhost:9200/访问ES服务+启动Kibana服务会失败+使用Spring Data ES和elasticsearch-java依赖,不需要使用账号连接,但必须使用HTTP连接
xpack.security.http.ssl.enabled
● 默认true:必须使用https://localhost:9200/访问ES服务+无论使用Spring Data ES还是elasticsearch-java依赖,都需要使用账号连接+必须使用HTTPS连接
● 若为false:必须使用http://localhost:9200/访问ES服务+启动Kibana服务会失败+使用Spring Data ES和elasticsearch-java依赖,都需要使用账号连接,但必须使用HTTP连接

4)界面可视(未验证过)

下载:点击https://github.com/1340691923/ElasticView/releases/tag/v1.8.7``-->选择win

三、Kibana

1、修改配置文件config/kibana.yml

server.port: 5601

server.host: "localhost"

elasticsearch.hosts: ["http://localhost:9200"]

elasticsearch.username: "xinuser"

#新建的用户密码
elasticsearch.password: "xxxxxxxxx"

i18n.locale: "zh-CN"  

2、启动bin/kibana.bat。

3、访问http://localhost:5601/,输入账号xinuser和密码,即可登录。

四、问题

1、kibana使用ES认用户elastic访问,会无法访问。所以需要创建新用户。创建过程参考第二节的第5小节。

2、提示服务器尚未准备就绪

注意检查下server.host: "localhost" 该属性不能配置为localhost,可以配置为server.host: "0.0.0.0"server.host: "127.0.0.1"

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部