建站不啰嗦,上手跟我做(三十一)Elasticsearch 安装

安装包下载

Elasticsearch 下载官网地址:https://www.elastic.co/cn/downloads/elasticsearch

jdk 支持

CentOS 7 安装与配置 jdk1.8

安装

[root@localhost ~]# cd /opt
[root@localhost opt]# ls
elasticsearch-6.8.16.tar.gz
[root@localhost opt]# tar -zxvf elasticsearch-6.8.16.tar.gz 
elasticsearch-6.8.16/
elasticsearch-6.8.16/bin/
elasticsearch-6.8.16/config/
elasticsearch-6.8.16/plugins/
elasticsearch-6.8.16/NOTICE.txt
elasticsearch-6.8.16/logs/
elasticsearch-6.8.16/lib/
elasticsearch-6.8.16/README.textile
elasticsearch-6.8.16/LICENSE.txt

启动

[root@localhost elasticsearch-6.8.16]# bin/elasticsearch
[2021-06-19T20:55:36,763][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-6.8.16.jar:6.8.16]
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-6.8.16.jar:6.8.16]
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.8.16.jar:6.8.16]
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.8.16.jar:6.8.16]
	at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.8.16.jar:6.8.16]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116) ~[elasticsearch-6.8.16.jar:6.8.16]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.8.16.jar:6.8.16]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.8.16.jar:6.8.16]
	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.8.16.jar:6.8.16]
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.8.16.jar:6.8.16]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-6.8.16.jar:6.8.16]
	... 6 more
创建 elasticsearch 的启动用户
[root@localhost elasticsearch-6.8.16]# passwd es
Changing password for user es.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost elasticsearch-6.8.16]# cd ..
[root@localhost opt]# ls
elasticsearch-6.8.16  elasticsearch-6.8.16.tar.gz
[root@localhost opt]# chown -R es:es elasticsearch-6.8.16
[root@localhost opt]# su es
[es@localhost opt]$ ls
elasticsearch-6.8.16  elasticsearch-6.8.16.tar.gz
[es@localhost opt]$ cd elasticsearch-6.8.16
[es@localhost elasticsearch-6.8.16]$ bin/elasticsearch
[2021-06-19T21:03:57,608][INFO ][o.e.e.NodeEnvironment    ] [ZtDziuD] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [3.9gb], net total_space [6.1gb], types [rootfs]
修改 elasticsearch 配置
[es@localhost elasticsearch-6.8.16]$ ls
bin     data  LICENSE.txt  modules     plugins
config  lib   logs         NOTICE.txt  README.textile
[es@localhost elasticsearch-6.8.16]$ cd config
[es@localhost config]$ ls
elasticsearch.keystore  jvm.options        role_mapping.yml  users
elasticsearch.yml       log4j2.properties  roles.yml         users_roles
[es@localhost config]$ vim jvm.options 
[es@localhost config]$ vim jvm.options 

## JVM configuration

################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

#-Xms1g
#-Xmx1g
-Xms256M
-Xmx256M
[es@localhost config]$ vim elasticsearch.yml

#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
#
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# Use a descriptive name for the node:
#
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
#
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
#
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
#
#
#path.data: /path/to/data
path.data: /home/es/elasticsearch/data
#
# Path to log files:
#
#path.logs: /path/to/logs
path.logs: /home/es/elasticsearch/logs
#
# 数据目录位置
path.data: /home/es/elasticsearch/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#日志目录位置
path.logs: /home/es/elasticsearch/logs
#
#
# Lock the memory on startup:
#
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
## 绑定到0.0.0.0,允许任何ip来访问(默认是只有本机访问)
# Set a custom port for HTTP:默认端口9200,这里可以修改为其它的端口
http.port: 9200
#
# For more information, consult the network module documentation.
#
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
[root@localhost opt]# vim /etc/security/limits.conf
# End of file
*               soft    nofile          100000

*               hard    nofile          100000

*               soft    nproc           100000

*               hard    nproc           100000
[root@localhost opt]# vim /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).
vm.max_map_count=262144
[root@localhost opt]# /sbin/sysctl -p
vm.max_map_count = 262144
[es@localhost ~]$ mkdir -p /home/es/elasticsearch/logs
[es@localhost ~]$ ls
elasticsearch
[es@localhost ~]$ cd /opt/elasticsearch-6.8.16/
[es@localhost elasticsearch-6.8.16]$ bin/elasticsearch
[2021-06-19T21:20:17,518][INFO ][o.e.e.NodeEnvironment    ] [Z2PtPM6] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [3.9gb], net total_space [6.1gb], types [rootfs]
[2021-06-19T21:20:17,523][INFO ][o.e.e.NodeEnvironment    ] [Z2PtPM6] heap size [247.6mb], compressed ordinary object pointers [true]
[2021-06-19T21:20:17,569][INFO ][o.e.n.Node               ] [Z2PtPM6] node na
#浏览器访问http://192.168.8.102:9200/
{
  "name" : "Z2PtPM6",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "a2HvtLaxTLWsV5irf4G8-Q",
  "version" : {
    "number" : "6.8.16",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "1f62092",
    "build_date" : "2021-05-21T19:27:57.985321Z",
    "build_snapshot" : false,
    "lucene_version" : "7.7.3",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

日志查看

[root@localhost ~]# cd /opt/elasticsearch-6.8.16/
[root@localhost elasticsearch-6.8.16]# ls
bin  config  data  lib  LICENSE.txt  logs  modules  NOTICE.txt  plugins  README.textile
[root@localhost elasticsearch-6.8.16]# cd logs
[root@localhost logs]# ls
elasticsearch_access.log  elasticsearch_deprecation.log             elasticsearch_index_search_slowlog.log  gc.log.0.current
elasticsearch_audit.log   elasticsearch_index_indexing_slowlog.log  elasticsearch.log
[root@localhost logs]# tail -f -n 200 elasticsearch.log 
[2021-06-19T12:12:59,982][ERROR][o.e.b.Bootstrap          ] [unknown] Exception
java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.8.16.jar:6.8.16]
	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.8.16.jar:6.8.16]
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) [elasticsearch-6.8.16.jar:6.8.16]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) [elasticsearch-6.8.16.jar:6.8.16]
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) [elasticsearch-6.8.16.jar:6.8.16]
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) [elasticsearch-6.8.16.jar:6.8.16]
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) [elasticsearch-cli-6.8.16.jar:6.8.16]
	at org.elasticsearch.cli.Command.main(Command.java:90) [elasticsearch-cli-6.8.16.jar:6.8.16]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116) [elasticsearch-6.8.16.jar:6.8.16]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) [elasticsearch-6.8.16.jar:6.8.16]
[2021-06-19T12:12:59,991][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] uncaught exception in thread [main]

后台启动

[root@localhost elasticsearch-6.8.16]$ su es
[es@localhost elasticsearch-6.8.16]# ls
elasticsearch               elasticsearch-croneval.bat  elasticsearch-saml-metadata        elasticsearch-sql-cli             x-pack
elasticsearch.bat           elasticsearch-env           elasticsearch-saml-metadata.bat    elasticsearch-sql-cli-6.8.16.jar  x-pack-env
elasticsearch-certgen       elasticsearch-env.bat       elasticsearch-service.bat          elasticsearch-sql-cli.bat         x-pack-env.bat
elasticsearch-certgen.bat   elasticsearch-keystore      elasticsearch-service-mgr.exe      elasticsearch-syskeygen           x-pack-security-env
elasticsearch-certutil      elasticsearch-keystore.bat  elasticsearch-service-x64.exe      elasticsearch-syskeygen.bat       x-pack-security-env.bat
elasticsearch-certutil.bat  elasticsearch-migrate       elasticsearch-setup-passwords      elasticsearch-translog            x-pack-watcher-env
elasticsearch-cli           elasticsearch-migrate.bat   elasticsearch-setup-passwords.bat  elasticsearch-translog.bat        x-pack-watcher-env.bat
elasticsearch-cli.bat       elasticsearch-plugin        elasticsearch-shard                elasticsearch-users
elasticsearch-croneval      elasticsearch-plugin.bat    elasticsearch-shard.bat            elasticsearch-users.bat
[es@localhost elasticsearch-6.8.16]# ./bin/elasticsearch -d

插件安装

head 插件

head 插件是一个 Elasticsearch 的集群管理工具,它完全由 html5 编写。

下载地址

https://github.com/mobz/elasticsearch-head

nodejs 支持

建站不啰嗦,上手跟我做(十九)在 Linux 系统安装 Nodejs

[root@localhost nodejs]# cnpm install -g grunt-cli
Downloading grunt-cli to /opt/nodejs/lib/node_modules/grunt-cli_tmp
Copying /opt/nodejs/lib/node_modules/grunt-cli_tmp/_grunt-cli@1.4.3@grunt-cli to /opt/nodejs/lib/node_modules/grunt-cli
Installing grunt-cli's dependencies to /opt/nodejs/lib/node_modules/grunt-cli/node_modules
[1/5] grunt-known-options@~2.0.0 installed at node_modules/_grunt-known-options@2.0.0@grunt-known-options
[2/5] interpret@~1.1.0 installed at node_modules/_interpret@1.1.0@interpret
[3/5] nopt@~4.0.1 installed at node_modules/_nopt@4.0.3@nopt
[4/5] liftup@~3.0.1 installed at node_modules/_liftup@3.0.1@liftup
[5/5] v8flags@~3.2.0 installed at node_modules/_v8flags@3.2.0@v8flags
All packages installed (57 packages installed from npm registry, used 5s(network 5s), speed 62.64kB/s, json 57(68.93kB), tarball 265.87kB)
[grunt-cli@1.4.3] link /opt/nodejs/bin/grunt@ -> /opt/nodejs/lib/node_modules/grunt-cli/bin/grunt
[root@localhost nodejs]# /opt/nodejs/lib/node_modules/grunt-cli/bin/grunt -version
grunt-cli v1.4.3
[root@localhost nodejs]# cd /opt/elasticsearch-6.8.16/config
[root@localhost config]# ls
elasticsearch.keystore  jvm.options        role_mapping.yml  users
elasticsearch.yml       log4j2.properties  roles.yml         users_roles
[root@localhost config]# vim elasticsearch.yml
cluster.name: my-application
node.name: node-1
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true

elasticsearch-head 解压配置

[root@localhost elasticsearch-6.8.16]# unzip elasticsearch-head-master.zip
[root@localhost elasticsearch-6.8.16]$ ls
bin  config  data  elasticsearch-head-master  lib  LICENSE.txt  logs  modules  NOTICE.txt  plugins  README.textile
[root@localhost elasticsearch-6.8.16]# cd elasticsearch-head-master
[root@localhost elasticsearch-head-master]# ls
crx                                 package.json
Dockerfile                          plugin-descriptor.properties
Dockerfile-alpine                   proxy
elasticsearch-head.sublime-project  README.textile
Gruntfile.js                        _site
grunt_fileSets.js                   src
index.html                          test
LICENCE
[root@localhost elasticsearch-head-master]# vim Gruntfile.js 
connect: {
		server: {
				options: {
						hostname: '*',
						port: 9100,
						base: '.',
						keepalive: true
				}
		}
}

[root@localhost opt]# chown -R es:es elasticsearch-6.8.16
[es@localhost elasticsearch-6.8.16]$ rm -rf elasticsearch-head-master.zip
[es@localhost elasticsearch-6.8.16]$ bin/elasticsearch -d

elasticsearch-head 启动

[es@localhost elasticsearch-head-master]# cnpm install
⠦ [0/10] Installing minimatch@~3.0.0
WARN node unsupported "node@v10.15.3" is incompatible with grunt-contrib-connect@1.0.2 › http2@^3.3.4, expected node@>=0.12.0 <9.0.0
⠇ [2/10] Installing map-obj@^1.0.0
WARN node unsupported "node@v10.15.3" is incompatible with karma@1.3.0, ex
[es@localhost elasticsearch-head-master]$ cnpm run start

> elasticsearch-head@0.0.0 start /opt/elasticsearch-6.8.16/elasticsearch-head-master
> grunt server

Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
浏览器访问http://192.168.8.102:9100/

图片.png

ES 和关系型数据库对比

关系型数据库Elasticsearch
数据库 database索引 index
表 table类型 type
数据行 row文档 document
数据列 column字段 field

上一篇 建站不啰嗦,上手跟我做(三十)scala 安装
目录
下一篇 建站不啰嗦,上手跟我做(三十二)Logstash 安装