ElasticSearch7.6 -安装

1.Es 的安装

注意es 不能用root 来启动 必须要用普通用户来启动安装

1.创建elasticsearch 用户组
[root@node01 es]# groupadd es
2.创建用户并且设置密码:
[root@node01 es]# useradd wudles
3.修改密码:  wudles--用户   123456 是wudles 的密码
[root@node01 es]# echo '123456'|passwd --stdin wudles
更改用户 wudles 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@node01 es]# 
4. 创建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. 给普通的用户赋值最高的用户权限

执行命令: 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三台节点

master 01 节点

[wudles@node01 config]$ vi elasticsearch.yml 

# 集群名称必须相同
cluster.name: wudl-es
# # 节点名称
node.name: esMaster01
# # 是否是master节点
node.master: true
# # 是否允许该节点存储索引数据
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"]
# # 启动全新的集群时需要此参数,再次重新启动时此参数可免
cluster.initial_master_nodes: ["esMaster01"]
bootstrap.system_call_filter: false
bootstrap.memory_lock: false
# # 是否开启跨域访问
#http.cors.enabled: true
# # 开启跨域访问后的地址限制,*表示无限制
#http.cors.allow‐origin: "*"

slave01 节点:

[wudles@node02 config]$ vi elasticsearch.yml 

# 集群名称必须相同
cluster.name: wudl-es
# 节点名称
node.name: esSlave01
# 是否是master节点
node.master: false
# 是否允许该节点存储索引数据
node.data: true
# 绑定地址
network.host: node02.com
# http端口
http.port: 9200
# 集群主机列表
discovery.seed_hosts: ["node01.com:9300","node02.com:9300","node03.com:9300"]
# 启动全新的集群时需要此参数,再次重新启动时此参数可免
cluster.initial_master_nodes: ["esSlave01"]
# 是否开启跨域访问
http.cors.enabled: true
# 开启跨域访问后的地址限制,*表示无限制
http.cors.allow-origin: "*"

slave02 节点

[wudles@node03 config]$ vi elasticsearch.yml 

# 集群名称必须相同
cluster.name: wudl-es
# 节点名称
node.name: esSlave02
# 是否是master节点
node.master: false
# 是否允许该节点存储索引数据
node.data: true
# 绑定地址
network.host: node03.com
# http端口
http.port: 9200
# 集群主机列表
discovery.seed_hosts: ["node01.com:9300","node02.com:9300","node03.com:9300"]
# 启动全新的集群时需要此参数,再次重新启动时此参数可免
cluster.initial_master_nodes: ["esSlave02"]
# 是否开启跨域访问
http.cors.enabled: true
# 开启跨域访问后的地址限制,*表示无限制
http.cors.allow-origin: "*"

2.2 修改jvm.option

修改jvm.option配置文件,调整jvm堆内存大小

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 修改普通用户可以创建的最大线程数

[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. 普通用户调大虚拟内存

[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 .启动

注意启动要用之前创建的用户进行启动 -- 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

添加环境变量

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创建索引

#  创建索引
PUT /wudl_dbes

6.2 创建mapper 映射

#创建mapping
PUT /wudl_dbes/_mapping
{
    
     
  "properties": {
    
    
    "name": {
    
    
      "type": "text",
	  "index": true
    },
    "sex": {
    
    
      "type": "text",
	  "index": false
    },
    "age": {
    
    
      "type": "long",
      "index": false
    }
  }
}

6.3 插入数据

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
        }
      }
    ]
  }
}


浏览数据
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/wudonglianga/article/details/119980562