4

在 Linux 环境安装 ElasticSearch8.3 和 Kibana8.3

 1 year ago
source link: https://tianmingxing.com/2022/08/28/%E5%9C%A8Linux%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85ElasticSearch%E5%92%8CKibana/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在 Linux 环境安装 ElasticSearch8.3 和 Kibana8.3

2022-08-28 2022-08-29ElasticSearch

3

Distributor ID:	Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
  • 创建一个系统用户用来安装和运行 elasticsearch
tianmx@mydebian:[~]: sudo adduser elastic
正在添加用户"elastic"...
正在添加新组"elastic" (1002)...
正在添加新用户"elastic" (1002) 到组"elastic"...
创建主目录"/home/elastic"...
正在从"/etc/skel"复制文件...
新的 密码:
重新输入新的 密码:
passwd:已成功更新密码
正在改变 elastic 的用户信息
请输入新值,或直接敲回车键以使用默认值
全名 []: elastic
房间号码 []:
工作电话 []:
家庭电话 []:
其它 []:
这些信息是否正确? [Y/n] y
  • 切换到上面创建的 elastic 用户
tianmx@mydebian:[~]: su - elastic
密码:
elastic@mydebian:~$ pwd
/home/elastic
elastic@mydebian:~$

安装 elasticsearch

  • 下载并解压
wget -c https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.4.0-linux-x86_64.tar.gz
tar -xzf elasticsearch-8.4.0-linux-x86_64.tar.gz
cd elasticsearch-8.4.0/
  • 在本地测试安装时可以将堆内存设置小一点,默认为 4G。
vim config/jvm.options

# 在打开的文件中增加下面两项配置:
-Xms2g
-Xmx2g
  • 修改 ES 绑定的 IP,便于从其它电脑上访问
vim config/elasticsearch.yml

# 填写运行ES的机器IP,集群名称可不改。
network.host: 192.168.0.110
cluster.name: test
  • 执行 ./bin/elasticsearch 命令尝试前台启动 ES
  • 如果出现下面错误,可修改文件 sudo vim /etc/sysctl.conf,增加 vm.max_map_count=262144 配置解决。
enforcing bootstrap checks
bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
  • 如果能看到下面的日志,说明 ES 启动成功了,这些信息需要复制下来备用。
✅ 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`):
1usTQ6E+=qBmTDqSlgtF

ℹ️ HTTP CA certificate SHA-256 fingerprint:
b109a66f2f3d7ee4ed2fee52ff17dd0d49d9fec2e73e953c49ad952ca767a052

ℹ️ 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):
eyJ2ZXIiOiI4LjMuMyIsImFkciI6WyIxOTIuMTY4LjAuMTEwOjkyMDAiXSwiZmdyIjoiYjEwOWE2NmYyZjNkN2VlNGVkMmZlZTUyZmYxN2RkMGQ0OWQ5ZmVjMmU3M2U5NTNjNDlhZDk1MmNhNzY3YTA1MiIsImtleSI6ImduY1J5SUlCeWJGZlhsdFdFY09nOjNLUDkzZTJhUXZPNVlvblBQcHU5alEifQ==

ℹ️ 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):
eyJ2ZXIiOiI4LjMuMyIsImFkciI6WyIxOTIuMTY4LjAuMTEwOjkyMDAiXSwiZmdyIjoiYjEwOWE2NmYyZjNkN2VlNGVkMmZlZTUyZmYxN2RkMGQ0OWQ5ZmVjMmU3M2U5NTNjNDlhZDk1MmNhNzY3YTA1MiIsImtleSI6ImhIY1J5SUlCeWJGZlhsdFdFY094OjF0YW16TkRnVF9lNGpma0swdGVIQXcifQ==

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

安装 kibana

  • 下载并解压
wget -c https://artifacts.elastic.co/downloads/kibana/kibana-8.3.3-linux-x86_64.tar.gz
tar -xzf kibana-8.3.3-linux-x86_64.tar.gz
cd kibana-8.3.3/
  • 配置 Server 地址,便于 Kibana 找到 ES 服务
vim config/kibana.yml

# 修改server IP地址
server.name: "test"
server.host: "192.168.0.110"
  • 执行 ./bin/kibana 命令在前台启动 Kibana
  • 首次启动 kibana 时在控制台日志中会看到访问地址 http://192.168.0.110:5601/?code=545471,此时打开浏览器访问。
  • 首次访问 Kibana 管理台会提示输入 token,这可以在 ES 首次启动日志中找。如果 token 已失效或不正确,你也可以重新生成 token,进入 elasticsearch 目录执行 bin/elasticsearch-create-enrollment-token --scope kibana
  • 紧接着输入登录账号 elastic,密码也同样是从 ES 首次启动日志中找,如果密码不正确可在 ES 目录执行:bin/elasticsearch-reset-password -u elastic 进行重置。
  • 启动 ES ./bin/elasticsearch -d -p pid,其中 pid 指的是文件名称,不用修改名字,ES 启动后会将真实的 pid 号写入到 pid 文件中。如果要停止 ES 也非常简单,直接执行 pkill -F pid 即可,如果你不是在 pid 文件目录下执行,则指定下路径即可 pkill -F /home/elastic/xxx/pid
  • Kibana 本身没有后台启动功能,可以借用 nohup 命令来实现,只需要执行 nohup ./bin/kibana & 命令即可。

安装中文分词插件

如果对中文分词没有特别的需求,那么用官方提供的简单中文分词插件就行。如果对分词有特别要求并且希望做更多的定制,那可以安装 ik 分词插件,不过它的安装会比较复杂一些,我在后续文章中再分享。

tianmx@mydebian:[~/elasticsearch-8.3.3]: ./bin/elasticsearch-plugin install analysis-icu
-> Installing analysis-icu
-> Downloading analysis-icu from elastic
[=================================================] 100%
-> Installed analysis-icu
-> Please restart Elasticsearch to activate any plugins installed
tianmx@mydebian:[~/elasticsearch-8.3.3]: ./bin/elasticsearch-plugin install analysis-smartcn
-> Installing analysis-smartcn
-> Downloading analysis-smartcn from elastic
[=================================================] 100%
-> Installed analysis-smartcn
-> Please restart Elasticsearch to activate any plugins installed
tianmx@mydebian:[~/elasticsearch-8.3.3]: ./bin/elasticsearch-plugin list
analysis-icu
analysis-smartcn
tianmx@mydebian:[~/elasticsearch-8.3.3]:
  • 注意:安装插件后必须重启 ES 才能生效。

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK