1.Es 的安裝
注意es 不能用root 來啟動 必須要用普通用戶來啟動安裝
1.創(chuàng)建elasticsearch 用戶組
[root@node01 es]# groupadd es
2.創(chuàng)建用戶并且設置密碼:
[root@node01 es]# useradd wudles
3.修改密碼: wudles--用戶 123456 是wudles 的密碼
[root@node01 es]# echo '123456'|passwd --stdin wudles
更改用戶 wudles 的密碼 。
passwd:所有的身份驗證令牌已經(jīng)成功更新潜的。
[root@node01 es]#
4. 創(chuàng)建es 文件夾
[root@node01 es]# mkdir -p /opt/module/es
5. 將用戶 wudles 添加到es用戶組
usermod -G es wudles
6. 給es 目錄復制wudles 的操作用戶
chown -R wudles /opt/module/es/elasticsearch-7.6.1
7. 給普通的用戶賦值最高的用戶權限
執(zhí)行命令: visudo
visudo
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
wudles ALL=(ALL) ALL
2.修改配置文件
[root@node01 elasticsearch-7.6.1]# pwd
/opt/module/es/elasticsearch-7.6.1
[root@node01 elasticsearch-7.6.1]# mkdir log data
[root@node01 config]# rm -rf elasticsearch.yml
[root@node01 config]#
[root@node01 config]# vim elasticsearch.yml
2.1三臺節(jié)點
master 01 節(jié)點
[wudles@node01 config]$ vi elasticsearch.yml
# 集群名稱必須相同
cluster.name: wudl-es
# # 節(jié)點名稱
node.name: esMaster01
# # 是否是master節(jié)點
node.master: true
# # 是否允許該節(jié)點存儲索引數(shù)據(jù)
node.data: true
path.data: /opt/module/es/elasticsearch-7.6.1/data
path.logs: /opt/module/es/elasticsearch-7.6.1/log
# # 綁定地址
network.host: node01.com
http.port: 9200
# # 集群主機列表
# discovery.seed_hosts: ["node01.com:9300,node02.com:9300,node03.com:9300"]
# # 啟動全新的集群時需要此參數(shù)嫌拣,再次重新啟動時此參數(shù)可免
cluster.initial_master_nodes: ["esMaster01"]
bootstrap.system_call_filter: false
bootstrap.memory_lock: false
# # 是否開啟跨域訪問
#http.cors.enabled: true
# # 開啟跨域訪問后的地址限制克婶,*表示無限制
#http.cors.allow‐origin: "*"
slave01 節(jié)點:
[wudles@node02 config]$ vi elasticsearch.yml
# 集群名稱必須相同
cluster.name: wudl-es
# 節(jié)點名稱
node.name: esSlave01
# 是否是master節(jié)點
node.master: false
# 是否允許該節(jié)點存儲索引數(shù)據(jù)
node.data: true
# 綁定地址
network.host: node02.com
# http端口
http.port: 9200
# 集群主機列表
discovery.seed_hosts: ["node01.com:9300","node02.com:9300","node03.com:9300"]
# 啟動全新的集群時需要此參數(shù)簸呈,再次重新啟動時此參數(shù)可免
cluster.initial_master_nodes: ["esSlave01"]
# 是否開啟跨域訪問
http.cors.enabled: true
# 開啟跨域訪問后的地址限制,*表示無限制
http.cors.allow-origin: "*"
slave02 節(jié)點
[wudles@node03 config]$ vi elasticsearch.yml
# 集群名稱必須相同
cluster.name: wudl-es
# 節(jié)點名稱
node.name: esSlave02
# 是否是master節(jié)點
node.master: false
# 是否允許該節(jié)點存儲索引數(shù)據(jù)
node.data: true
# 綁定地址
network.host: node03.com
# http端口
http.port: 9200
# 集群主機列表
discovery.seed_hosts: ["node01.com:9300","node02.com:9300","node03.com:9300"]
# 啟動全新的集群時需要此參數(shù)扛施,再次重新啟動時此參數(shù)可免
cluster.initial_master_nodes: ["esSlave02"]
# 是否開啟跨域訪問
http.cors.enabled: true
# 開啟跨域訪問后的地址限制窟哺,*表示無限制
http.cors.allow-origin: "*"
2.2 修改jvm.option
修改jvm.option配置文件,調(diào)整jvm堆內(nèi)存大小
vi /opt/module/es/elasticsearch-7.6.1/config/jvm.options
-Xms2g
-Xmx2g
2.3 打開文件的最大限制
vi /etc/security/limits.con
加入
* soft nofile 204800
* hard nofile 204800
* soft nproc 204800
* hard nproc 204800
2.4 修改普通用戶可以創(chuàng)建的最大線程數(shù)
[root@node01 limits.d]# vi /etc/security/limits.d/20-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* soft nproc 4096
root soft nproc unlimited
2.5. 普通用戶調(diào)大虛擬內(nèi)存
[root@node02 module]# vi /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
fs.file-max = 6553560
vm.max_map_count=262144
3 .啟動
注意啟動要用之前創(chuàng)建的用戶進行啟動 -- wudles
nohup /usr/local/es/elasticsearch‐7.6.1/bin/elasticsearch 2>&1 &
```bash
[wudles@node01 bin]$ ./elasticsearch
[wudles@node02 bin]$ ./elasticsearch
[wudles@node03 bin]$ ./elasticsearch
日志:
```bash
[wudles@node01 bin]$ ./elasticsearch
future versions of Elasticsearch will require Java 11; your Java version from [/opt/module/jdk1.8.0_231/jre] does not meet this requirement
[2021-08-29T18:09:31,159][INFO ][o.e.e.NodeEnvironment ] [esMaster01] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [135.8gb], net total_space [190.9gb], types [rootfs]
[2021-08-29T18:09:31,160][INFO ][o.e.e.NodeEnvironment ] [esMaster01] heap size [1.9gb], compressed ordinary object pointers [true]
[2021-08-29T18:09:31,266][INFO ][o.e.n.Node ] [esMaster01] node name [esMaster01], node ID [3GjYrJRwSMiVDW9X01Kr2w], cluster name [wudl-es]
[2021-08-29T18:09:31,267][INFO ][o.e.n.Node ] [esMaster01] version[7.6.1], pid[37845], build[default/tar/aa751e09be0a5072e8570670309b1f12348f023b/2020-02-29T00:15:25.529771Z], OS[Linux/3.10.0-1062.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_231/25.231-b11]
[2021-08-29T18:09:31,267][INFO ][o.e.n.Node ] [esMaster01] JVM home [/opt/module/jdk1.8.0_231/jre]
[2021-08-29T18:09:31,267][INFO ][o.e.n.Node ] [esMaster01] JVM arguments [-Des.networkaddress.cache.ttl=60, -Des.networkaddress.cache.negative.ttl=10, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dio.netty.allocator.numDirectArenas=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.locale.providers=COMPAT, -Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -Djava.io.tmpdir=/tmp/elasticsearch-7000799159445262128, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -XX:MaxDirectMemorySize=1073741824, -Des.path.home=/opt/module/es/elasticsearch-7.6.1, -Des.path.conf=/opt/module/es/elasticsearch-7.6.1/config, -Des.distribution.flavor=default, -Des.distribution.type=tar, -Des.bundled_jdk=true]
[2021-08-29T18:09:32,543][INFO ][o.e.p.PluginsService ] [esMaster01] loaded module [aggs-matrix-stats]
[2021-08-29T18:09:32,543][INFO ][o.e.p.PluginsService ] [esMaster01] loaded module [analysis-common]
[2021-08-29T18:09:32,543][INFO ][o.e.p.PluginsService ] [esMaster01] loaded module [flattened]
[2021-08-29T18:09:32,546][INFO ][o.e.p.PluginsService ] [esMaster01] loaded module [x-pack-deprecation]
[2021-08-29T18:09:32,546][INFO ][o.e.p.PluginsService ] [esMaster01] loaded module [x-pack-enrich]
[2021-08-29T18:09:32,546][INFO ][o.e.p.PluginsService ] [esMaster01] loaded module [x-pack-graph]
[2021-08-29T18:09:32,546][INFO ][o.e.p.PluginsService ] [esMaster01] loaded module [x-pack-ilm]
[2021-08-29T18:09:32,546][INFO ][o.e.p.PluginsService ] [esMaster01] loaded module [x-pack-logstash]
[2021-08-29T18:09:32,546][INFO ][o.e.p.PluginsService ] [esMaster01] loaded module [x-pack-ml]
[2021-08-29T18:09:32,546][INFO ][o.e.p.PluginsService ] [esMaster01] loaded module [x-pack-monitoring]
[2021-08-29T18:09:32,547][INFO ][o.e.p.PluginsService ] [esMaster01] loaded module [x-pack-rollup]
[2021-08-29T18:09:32,547][INFO ][o.e.p.PluginsService ] [esMaster01] loaded module [x-pack-security]
[2021-08-29T18:09:32,547][INFO ][o.e.p.PluginsService ] [esMaster01] loaded module [x-pack-sql]
[2021-08-29T18:09:32,547][INFO ][o.e.p.PluginsService ] [esMaster01] loaded module [x-pack-voting-only-node]
[2021-08-29T18:09:32,547][INFO ][o.e.p.PluginsService ] [esMaster01] loaded module [x-pack-watcher]
[2021-08-29T18:09:32,548][INFO ][o.e.p.PluginsService ] [esMaster01] no plugins loaded
[2021-08-29T18:09:35,077][INFO ][o.e.x.s.a.s.FileRolesStore] [esMaster01] parsed [0] roles from file [/opt/module/es/elasticsearch-7.6.1/config/roles.yml]
[2021-08-29T18:09:35,451][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [esMaster01] [controller/37966] [Main.cc@110] controller (64 bit): Version 7.6.1 (Build 6eb6e036390036) Copyright (c) 2020 Elasticsearch BV
集群的驗證:
http://192.168.1.161:9200/_cat/nodes
4 kibana 的安裝
4.1.直接進行解壓配置
vi kibana.yml
[wudles@node01 config]$ vi 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: "192.168.1.161"
# 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
# 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.hosts: ["http://192.168.1.161:9200","http://192.168.1.162:9200","http://192.168.1.163:9200"]
4.2 啟動kibana
啟動命令: ./kibana
[wudles@node01 bin]$ pwd
/opt/module/es/kibana-7.6.1-linux-x86_64/bin
[wudles@node01 bin]$ ./kibana
啟動報錯
[wudles@node01 bin]$ ./kibana
Babel could not write cache to file: /opt/module/es/kibana-7.6.1-linux-x86_64/optimize/.babel_register_cache.json
due to a permission issue. Cache is disabled.
log [09:44:57.824] [info][plugins-service] Plugin "case" is disabled.
log [09:45:12.152] [fatal][root] Error: Unable to write Kibana UUID file, please check the uuid.server configuration value in kibana.yml and ensure Kibana has sufficient permissions to read / write to this file. Error was: EACCES
at writeUuidToFile (/opt/module/es/kibana-7.6.1-linux-x86_64/src/core/server/uuid/resolve_uuid.js:123:11)
FATAL Error: Unable to write Kibana UUID file, please check the uuid.server configuration value in kibana.yml and ensure Kibana has sufficient permissions to read / write to this file. Error was: EACCES
[wudles@node01 bin]$
解決辦法:
sudo chown -R wudles /opt/module/es/kibana-7.6.1-linux-x86_64/
5 訪問Kibana
http://192.168.1.161:5601/
` 注意每次啟動如果有問題就將 data 目錄下面的文件刪除`
sudo wget https://nodejs.org/dist/v9.9.0/node-v9.9.0-linux-x64.tar.xz
添加環(huán)境變量
export NODE_HOME=/opt/module/es/node-v9.9.0-linux-x64
export PATH=:$PATH:$NODE_HOME/bin
刷新配置
source /etc/profile
驗證:
[wudles@node01 es]$ source /etc/profile
[wudles@node01 es]$ node -v
v9.9.0
[wudles@node01 es]$ npm -v
5.6.0
[wudles@node01 es]$
elasticsearch-head-compile-after.tar.gz 上傳
[wudles@node01 es]$ sudo tar -zxvf elasticsearch-head-compile-after.tar.gz
修改配置
vim /opt/module/es/elasticsearch-head/Gruntfile.js 修改為 hostname: 'node01.com'
connect: {
server: {
options: {
hostname: 'node01.com',
port: 9100,
base: '.',
keepalive: true
}
}
}
修改第二個配置
[wudles@node01 elasticsearch-head]$ sudo vim /opt/module/es/elasticsearch-head/_site/app.js
修改Wie自己的ip
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://node01.com:9200";
啟動
[wudles@node01 bin]$ pwd
/opt/module/es/elasticsearch-head/node_modules/grunt/bin
[wudles@node01 bin]$ ./grunt server
訪問地址:
http://node01.com:9100
6. 簡單的操作
6.1創(chuàng)建索引
# 創(chuàng)建索引
PUT /wudl_dbes
6.2 創(chuàng)建mapper 映射
#創(chuàng)建mapping
PUT /wudl_dbes/_mapping
{
"properties": {
"name": {
"type": "text",
"index": true
},
"sex": {
"type": "text",
"index": false
},
"age": {
"type": "long",
"index": false
}
}
}
6.3 插入數(shù)據(jù)
PUT /wudl_dbes/_doc/1
{
"name":"HFDS",
"sex":"男",
"age":18
}
PUT /wudl_dbes/_doc/2
{
"name":"HIVE",
"sex":"女",
"age":20
}
PUT /wudl_dbes/_doc/3
{
"name":"Flink",
"sex":"女",
"age":18
}
6.4 查詢
GET /wudl_dbes/_doc/1
**************************************************
{
"_index" : "wudl_dbes",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"_seq_no" : 0,
"_primary_term" : 1,
"found" : true,
"_source" : {
"name" : "HFDS",
"sex" : "男",
"age" : 18
}
}
GET /wudl_dbes/_search
********************************************
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "wudl_dbes",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"name" : "HFDS",
"sex" : "男",
"age" : 18
}
},
{
"_index" : "wudl_dbes",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"name" : "HIVE",
"sex" : "女",
"age" : 20
}
},
{
"_index" : "wudl_dbes",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"name" : "Flink",
"sex" : "女",
"age" : 18
}
}
]
}
}
瀏覽數(shù)據(jù)