記錄在linux上單機elasticsearch8和kibana8

2022-10-30 21:00:22

1、背景

此處簡單記錄一下,elasticsearch8kibana8Centos7下的單機安裝步驟。

2、es對jdk和作業系統的要求等

不同版本的esjdk作業系統的要求不等,我們選擇合適的版本,可以通過如下 https://www.elastic.co/cn/support/matrix進行確認。

3、安裝步驟

3.1 下載對應版本的es


下載地址:https://www.elastic.co/cn/downloads/elasticsearch

3.2 建立es賬戶

需要為es單獨建立一個使用者,使用root賬戶啟動es會報錯。

[root@appbasic ~]# useradd es
[root@appbasic ~]# passwd es
[root@appbasic es]# tar -zxf elasticsearch-8.4.3-linux-aarch64.tar.gz
[root@appbasic es]# chown es -R elasticsearch-8.4.3
[root@appbasic es]# su - es
Last login: Sun Oct 30 11:13:55 CST 2022 from 192.168.121.1 on pts/1
[es@appbasic ~]$ cd /usr/local/es/elasticsearch-8.4.3
[es@appbasic elasticsearch-8.4.3]$ mkdir datas
[es@appbasic elasticsearch-8.4.3]$

3.3 修改es設定

3.3.1 修改es設定

vim config/elasticsearch.yml

# 叢集名
cluster.name: es-cluster
# 節點名
node.name: es-node01
# 資料目錄
path.data: /usr/local/es/elasticsearch-8.4.3/datas
# 紀錄檔目錄
path.logs: /usr/local/es/elasticsearch-8.4.3/logs
# es繫結到的地址
network.host: 192.168.121.138
# es啟動後前端存取的埠
http.port: 9200

http.cors.enabled: true
http.cors.allow-origin: "*"


3.3.3 修改jvm設定

vim config/jvm.options

可以根據實際情況 修改一下 -Xms 和 -Xmx 等引數

3.4 修改系統設定

3.4.1 修改使用者開啟的檔案數限制

  1. 通過 ulimit -n 檢視當前使用者可開啟的檔案數
  2. 修改使用者可開啟的檔案數限制

vim /etc/security/limits.conf

es               soft    nofile          65536
es               hard    nofile          65536

參考連結: https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-system-settings.html

3.4.2 禁用swap

/etc/fstab
註釋掉所有行中存在 swap 的行。

# /dev/mapper/cl_fedora-swap none      swap    defaults        0 0

參考連結: https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html

3.4.3 修改虛擬記憶體

vim /etc/sysctl.conf

在此檔案的最後一行增加 vm.max_map_count=262144

參考連結:https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html

3.4.4 提高執行緒數

vim /etc/security/limits.conf

es               soft     nproc          65536
es               hard    nproc          65536

參考檔案:https://www.elastic.co/guide/en/elasticsearch/reference/current/max-number-of-threads.html

以上設定設定完之後,重啟一下系統,使系統設定生效。

3.5 放開9200埠

firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload

4、啟動es

需要使用非root賬戶啟動。

bin/elasticsearch 前臺啟動
bin/elasticsearch -d 後臺啟動

5、重置 elastic 賬戶密碼

[es@appbasic elasticsearch-8.4.3]$ bin/elasticsearch-reset-password --username elastic -i
warning: ignoring JAVA_HOME=/usr/local/jdk8; using bundled JDK
WARNING: Group of file [/usr/local/es/elasticsearch-8.4.3/config/users] used to be [root], but now is [es]
WARNING: Group of file [/usr/local/es/elasticsearch-8.4.3/config/users_roles] used to be [root], but now is [es]
This tool will reset the password of the [elastic] user.
You will be prompted to enter the password.
Please confirm that you would like to continue [y/N]y


Enter password for [elastic]:
Re-enter password for [elastic]:
Password for the [elastic] user successfully reset.
[es@appbasic elasticsearch-8.4.3]$

6、存取 es


出現如下資訊,說明存取成功。


  "name": "es-node01",
  "cluster_name": "es-cluster",
  "cluster_uuid": "OJsQ_w1ZTKWepM-u8-U-tg",
  "version": {
    "number": "8.4.3",
    "build_flavor": "default",
    "build_type": "tar",
    "build_hash": "42f05b9372a9a4a470db3b52817899b99a76ee73",
    "build_date": "2022-10-04T07:17:24.662462378Z",
    "build_snapshot": false,
    "lucene_version": "9.3.0",
    "minimum_wire_compatibility_version": "7.17.0",
    "minimum_index_compatibility_version": "7.0.0"
  },
  "tagline": "You Know, for Search"
}

7、kibana連線到es

7.1 修改kibana設定

vim /usr/local/kibana/kibana-8.4.3/config/kibana.yml

server.port: 5601
server.host: "192.168.121.138"
# elasticsearch.hosts: ["https://192.168.121.138:9200"] 和 es使用者民密碼都不用設定

注意:
如果上方的設定中增加了 如下設定 ( elasticsearch.usernameelasticsearch.password) 或者 elasticsearch.hosts) 則可能出現如下異常

`[2022-10-30T18:31:29.858+08:00][ERROR][elasticsearch-service] Unable to retrieve version information from Elasticsearch nodes. self signed certificate in certificate chain`

解決方案:
執行如下命令

bin/kibana-setup --enrollment-token <enrollment-token>

<enrollment-token>通過如下命令獲取:bin/elasticsearch-create-enrollment-token --scope kibana

參考連結:https://www.elastic.co/guide/en/elasticsearch/reference/current/configuring-stack-security.html

7.2 啟動kibana

bin/kibana


從上圖中可以 存取地址為 http://192.168.121.138:5601/?code=634917

7.3 設定kibana


點選藍色的按鈕,就開始設定 elastic 了。

8、參考連結

  1. https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html
  2. https://www.elastic.co/guide/en/elasticsearch/reference/current/system-config.html
  3. https://www.elastic.co/guide/en/elasticsearch/reference/current/configuring-stack-security.html