CentOS7安装Elasticsearch8.5.3(ik分词器 + 单节点模式)+ Kibana8.5.3
2023/01/14
Linux
Elasticsearch
Kibana
# Elasticsearch > 官方教程:[Install Elasticsearch from archive on Linux or MacOS](https://www.elastic.co/guide/en/elasticsearch/reference/8.5/targz.html) ## 下载 ### Elasticsearch 全版本下载地址:<https://www.elastic.co/cn/downloads/past-releases#elasticsearch> > 因为 `Spring Boot 3.0.1` 对应的 `Spring Data Elasticsearch 5.0.0` 对应的 `Elasticsearch` 的版本为 `8.5.3` ,所以本文以此版本为例 1. 打开下载地址 2. `Versions` 选择 `8.5.3` 3. 点击 `Download` 4. 分两种 1. **点击** `LINUX X86_64` 下载至本地,下载完成后上传至服务器 2. **右击** `LINUX X86_64` 复制链接,在服务器上使用 `wget` 命令执行下载 PS:为啥不用 `rpm` 包?因为 `rpm` 包安装好之后文件散落在不同的文件夹内,虽然官方详细介绍了各个文件夹在哪以及干嘛用的。 `rpm` 包官方教程:[Install Elasticsearch with RPM](https://www.elastic.co/guide/en/elasticsearch/reference/8.5/rpm.html) ### elasticsearch-analysis-ik > ik中文分词器,推荐必装 下载地址:<https://github.com/medcl/elasticsearch-analysis-ik/releases> 也需要下载对应的 `8.5.3` 版本 `zip` 包。注意!是`zip`包!下载完成后上传至服务器 PS:由于作者未更新至 `8.5.3` ,所以只能下载 `8.5.2` 的包 ## 安装 ### 创建用户 ```bash # 新建用户(建议不设置密码,后面直接使用su切换用户) useradd es ``` ### 安装 Elasticsearch ```bash # 解压 tar -zxf elasticsearch-8.5.3-linux-x86_64.tar.gz # 移动 mv elasticsearch-8.5.3/ /usr/local/elasticsearch # 删除压缩包 rm -rf elasticsearch-8.5.3-linux-x86_64.tar.gz # 修改文件所有者 chown -R es:es /usr/local/elasticsearch/ ``` ### 安装 ik 分词器 ```bash # 安装解压工具(若已安装,则忽略此步) yum -y install zip unzip # 创建插件文件夹 mkdir /usr/local/elasticsearch/plugins/ik # 解压 unzip elasticsearch-analysis-ik-8.5.2.zip -d /usr/local/elasticsearch/plugins/ik/ # 删除 rm -rf elasticsearch-analysis-ik-8.5.2.zip # 修改 ik 分词器的配置 vim /usr/local/elasticsearch/plugins/ik/plugin-descriptor.properties # 将文档结尾的 elasticsearch.version=8.5.2 改为 elasticsearch.version=8.5.3 并保存 # 修改文件所有者 chown -R es:es /usr/local/elasticsearch/plugins/ik/ ``` ## 配置 ### Linux系统配置 官方教程:[Important System Configuration](https://www.elastic.co/guide/en/elasticsearch/reference/8.5/system-config.html) #### 关闭 swap > 若已关闭则忽略 临时关闭 ```bash swapoff -a ``` 永久关闭 ```bash #编辑配置文件 vim /etc/fstab # 在/etc/fstab中swap分区这行前加 # # /dev/mapper/centos-swap swap swap defaults 0 0 ``` #### 修改 limits.conf 临时生效 ```bash # 指定同一时间最多可开启的文件数 ulimit -n 65536 # 用户最多可开启的程序数目 ulimit -u 4096 ``` 永久生效 ```bash # 编辑配置文件(注:该文件有设置介绍) vim /etc/security/limits.conf # 添加如下设置 # 1. 同一时间最多可开启的文件数 es soft nofile 65536 es hard nofile 65536 # 2. 进程开启多少个线程 es soft nproc 4096 es hard nproc 4096 ``` #### 修改 sysctl.conf ```bash # 编辑匹配值文件 vim /etc/sysctl.conf # 添加如下设置 # 1. 虚拟内存 vm.max_map_count=262144 # 2. TCP超时重传 net.ipv4.tcp_retries2=5 # 保存后执行以下命令立即生效 sysctl -p ``` ### 设置开机自启 ```bash # 编辑开机自启文件 vim /etc/rc.d/rc.local # 在文件结尾添加如下内容(-d代表后台运行,elasticsearch自带运行参数) su es -c "/usr/local/elasticsearch/bin/elasticsearch -d" # 允许该文件执行 chmod +x /etc/rc.d/rc.local ``` ### Elasticsearch配置 ```bash # 切换至 es !!! su es # 进入文件夹 cd /usr/local/elasticsearch/ ``` #### Elasticsearch配置文件 ```bash # 编辑配置文件 vim config/elasticsearch.yml # 修改如下设置 # 1. 节点名称(名称任意即可,若不设置则为系统的hostname) node.name: node-1 # 2. 允许远程访问 network.host: 0.0.0.0 # 3. 设置单节点启动(在文件结尾添加) discovery.type: single-node # 4. 关闭IP信息下载(在文件结尾添加) ingest.geoip.downloader.enabled: false ``` #### jvm配置 ```bash # 编辑配置文件 vim config/jvm.options # 默认使用jvm内存为1G,最小可以设置为256m,最大看情况,设置时,两个值必须相当 -Xms512m -Xmx512m ``` > 设置为`256m`的配置我已经在服务器上跑了很久了,没有问题,实际内存占用不超过`500m`。 > PS:我的数据量不大,并发几乎没有 ## 启动 ```bash # 当期步骤路径为 /usr/local/elasticsearch/ 且继续使用 es ./bin/elasticsearch & ``` 启动后可能需要过一会才能看到启动信息,需要耐心等待,第一次启动完成会看到如下类似信息: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ✅ 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`): 0ulo5u5sHpC3HEYvHDGT ℹ️ HTTP CA certificate SHA-256 fingerprint: 435dc68aadf9f6b2e34ada29fad18b45b0324939c9c0763ac8864886cb86633e ℹ️ 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): eyJ2ZXIiOiI4LjUuMyIsImFkciI6WyIxOTIuMTY4LjIyMC4xMDE6OTIwMCJdLCJmZ3IiOiI0MzVkYzY4YWFkZjlmNmIyZTM0YWRhMjlmYWQxOGI0NWIwMzI0OTM5YzljMDc2M2FjODg2NDg4NmNiODY2MzNlIiwia2V5IjoieGZmVG5vVUJKUUQ5eTFydmdacFE6SnZwSXNSZjNUdW1jVmRYbzlWSmx5ZyJ9 ℹ️ 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): eyJ2ZXIiOiI4LjUuMyIsImFkciI6WyIxOTIuMTY4LjIyMC4xMDE6OTIwMCJdLCJmZ3IiOiI0MzVkYzY4YWFkZjlmNmIyZTM0YWRhMjlmYWQxOGI0NWIwMzI0OTM5YzljMDc2M2FjODg2NDg4NmNiODY2MzNlIiwia2V5IjoieFBmVG5vVUJKUUQ5eTFydmdacE46X2d2WEJjcXVTUGUtcTlMQ3JHUU1RZyJ9 If you're running in Docker, copy the enrollment token and run: `docker run -e "ENROLLMENT_TOKEN=<token>" docker.elastic.co/elasticsearch/elasticsearch:8.5.3` ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 注意:上文信息中有两个比较重要的信息 1. `Password for the elastic user ...` 下面的一串字符,即默认用户 `elastic` 的密码 2. `Configure Kibana to use this cluster ...` 下面额一长串字符,下文配置 `Kibana` 会用到,请临时保存 ## 访问 浏览器访问:`https://[ip]:9200`,注意是 `https` 协议,默认用户名为 `elastic` ,密码在上文的启动成功的信息中显示 注:密码只会在控制台输出,不会在日志中记录,如需重置密码,请在 `es` 用户下执行 `/usr/local/elasticsearch/bin/elasticsearch-reset-password -u elastic` ,根据提示输入 `y` 并回车,新密码将在控制台显示 访问成功后可以看到如下类似信息 ```json { "name" : "node-1", "cluster_name" : "elasticsearch", "cluster_uuid" : "nKSdFiOTSrevU7_e4JNzCw", "version" : { "number" : "8.5.3", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "4ed5ee9afac63de92ec98f404ccbed7d3ba9584e", "build_date" : "2022-12-05T18:22:22.226119656Z", "build_snapshot" : false, "lucene_version" : "9.4.2", "minimum_wire_compatibility_version" : "7.17.0", "minimum_index_compatibility_version" : "7.0.0" }, "tagline" : "You Know, for Search" } ``` 此时就可以命令行中执行 `exit` 回到 `root` 用户 # Kibana > 官方教程:[Install Kibana from archive on Linux or macOS](https://www.elastic.co/guide/en/kibana/8.5/targz.html) ## 下载 全版本下载地址:<https://www.elastic.co/cn/downloads/past-releases#kibana> 1. 打开下载地址 2. `Versions` 选择 `8.5.3` 3. 点击 `Download` 4. 分两种 1. 点击 `LINUX X86_64` 下载至本地,下载完成后上传至服务器 2. 右击 `LINUX X86_64` 复制链接,在服务器上使用 `wget` 命令执行下载 PS:为啥不用 `rpm` 包?因为 `rpm` 包安装好之后文件散落在不同的文件夹内,虽然官方详细介绍了各个文件夹在哪以及干嘛用的。 `rpm` 包官方教程:[Install Elasticsearch with RPM](https://www.elastic.co/guide/en/kibana/8.5/rpm.html) ## 安装 ```bash ## 此时是 root 用户 # 解压 tar -zxf kibana-8.5.3-linux-x86_64.tar.gz # 移动 mv kibana-8.5.3/ /usr/local/kibana # 删除压缩包 rm -rf kibana-8.5.3-linux-x86_64.tar.gz # 修改文件所有者 chown -R es:es /usr/local/kibana/ ``` ## 配置 ### 设置开机自启 ```bash # 编辑开机自启文件 vim /etc/rc.d/rc.local # 在文件结尾添加如下内容(-d代表后台运行,elasticsearch自带运行参数) su es -c "/usr/local/kibana/bin/kibana" # 允许该文件执行(如果在同一台服务器上,则无需重复执行) chmod +x /etc/rc.d/rc.local ``` ### Kibana配置 ```bash # 切换至 es !!! su es # 进入文件夹 cd /usr/local/kibana/ ``` #### Kibana配置文件 ```bash # 编辑配置文件 vim config/kibana.yml # 修改如下配置 # 1. 允许远程访问 server.host: 0.0.0.0 ``` #### token配置 首先,确保上文中 `Elasticsearch` 启动成功后的 `token` 已经获取到且在半小时内( `token` 有效期为半小时) 如果忘记 `token` 或者超时了,在 `es` 用户下执行 `/usr/local/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana` 重新生成即可 ```bash # 执行初始化设置 ./bin/kibana-setup # 将上文中的 token 粘贴进去并回车 ``` 此时会提示 `Kibana configured successfully.` ,此时查看 `config/kibana.yml` 文件末尾会有一些 `elasticsearch` 的相关信息 ## 启动 ```bash # 当期步骤路径为 /usr/local/kibana/ 且继续使用 es ./bin/kibana & ``` 启动后,看到 `[status] Kibana is now available (was degraded)` 即代表启动成功 ## 访问 浏览器访问:`http://[ip]:5601`,注意是 `http` 协议,默认用户名为 `elastic` ,密码是上文中对应的密码
1