es8.15单机部署
1.下载需要的安装版本
我这里下载的是8.15.1,elasticsearch-8.15.1-linux-x86_64.tar.gz
下载地址:
https://www.elastic.co/cn/downloads/past-releases#elasticsearch
2.创建中间件安装目录和数据文件、日志文件目录
[root@hadoop-slave1 soft]# mkdir -p /usr/local/services
[root@hadoop-slave1 soft]# mkdir -p /home/middle/elasticsearch/data
[root@hadoop-slave1 soft]# mkdir -p /home/middle/elasticsearch/logs
3.创建用户和用户组
[root@pg1 elasticsearch]# groupadd -g 1500 elasticsearch
[root@pg1 elasticsearch]# useradd -u 1500 -g elasticsearch elasticsearch
[root@pg1 elasticsearch]# passwd elasticsearch
4.上传到服务器
解压缩并创建数据目录
[root@hadoop-slave1 soft]# tar -xvf elasticsearch-8.15.1-linux-x86_64.tar.gz
[root@localhost soft]# mv elasticsearch-8.15.1 /usr/local/services/elasticsearch
5.将elasticsearch目录权限修改为elasticsearch
[root@hadoop-slave1 config]# cd /usr/local/services
[root@hadoop-slave1 services]# chown -R elasticsearch:elasticsearch ./elasticsearch
同时修改数据文件和日志文件目录给到elasticsearch
[root@hadoop-slave1 services]# cd /home/middle
[root@hadoop-slave1 middle]# chown -R elasticsearch:elasticsearch ./elasticsearch
6.创建备份目录
su - elasticsearch
mkdir -p /home/middle/esbak
7.修改配置文件
[root@hadoop-slave1 middle]# su - elasticsearch
[elasticsearch@hadoop-slave1 ~]$ cd /usr/local/services/elasticsearch/config
[elasticsearch@hadoop-slave1 config]$ vi elasticsearch.yml
node.name: node01
path.data: /home/middle/elasticsearch/data
path.logs: /home/middle/elasticsearch/logs
network.host: 192.168.1.102
http.port: 19200
path.repo: /home/middle/esbak
##cluster.initial_master_nodes: ["node01"]
discovery.seed_hosts: ["192.168.1.102"]
##安全认证
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
##第三方中间件配置参数,看情况需要
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
8.修改jvm参数( /usr/local/services/elasticsearch/config/jvm.options )
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## The heap size is automatically configured by Elasticsearch
## based on the available memory in your system and the roles
## each node is configured to fulfill. If specifying heap is
## required, it should be done through a file in jvm.options.d,
## which should be named with .options suffix, and the min and
## max should be set to the same value. For example, to set the
## heap to 4 GB, create a new file in the jvm.options.d
## directory containing these lines:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/8.15/heap-size.html
## for more information
##
################################################################
-Xms3g
-Xmx3g
9.系统参数设置
每个节点上都要执行,这里确保每台机器都能启动
[root@rac01 middle]# su - elasticsearch
[elasticsearch@rac01 ~]$ ulimit -Hn
65536
检查是否是65536,不是的话修改修改
/etc/security/limits.conf,该文件最后加入
* soft nofile 65536
* hard nofile 65536
报错的话:
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
在/etc/sysctl.conf 文件最后添加一行
[root@localhost ~]#vm.max_map_count=262144
[root@localhost ~]#sysctl -p
10.启动
su - elasticsearch
[elasticsearch@hadoop-slave1 ~]$ cd /usr/local/services/elasticsearch/bin
./elasticsearch -d
报错:
[2024-09-14T15:01:13,383][ERROR][o.e.b.Elasticsearch ] [master] fatal exception while booting Elasticsearchorg.elasticsearch.ElasticsearchSecurityException: invalid SSL configuration for xpack.security.transport.ssl - server ssl configuration requires a key and certificate, but these have not been configured; you must set either [xpack.security.transport.ssl.keystore.path], or both [xpack.security.transport.ssl.key] and [xpack.security.transport.ssl.certificate]
生成证书:
su - elasticsearch
[elasticsearch@rac01 bin]$ cd /usr/local/services/elasticsearch/bin
[elasticsearch@master bin]$ ./elasticsearch-certutil ca
一路回车
[elasticsearch@rac01 bin]$./elasticsearch-certutil cert --ca elastic-stack-ca.p12
一路回车
[elasticsearch@master elasticsearch]$ pwd
/usr/local/services/elasticsearch
[elasticsearch@master elasticsearch]$ ls
bin elastic-certificates.p12 jdk LICENSE.txt modules plugins
config elastic-stack-ca.p12 lib logs NOTICE.txt README.asciidoc
这个时候会生成 elastic-certificates.p12 和 elastic-stack-ca.p12 这2个文件
将这两个文件拷贝到config目录下面
[elasticsearch@master elasticsearch]$ cd /usr/local/services/elasticsearch
[elasticsearch@master elasticsearch]$ mv elastic-certificates.p12 ./config/
[elasticsearch@master elasticsearch]$ mv elastic-stack-ca.p12 ./config/
修改配置文件:
[root@rac01 middle]# su - elasticsearch
vi /usr/local/services/elasticsearch/config/elasticsearch.yml
添加如下配置项
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
最后的配置文件如下:
node.name: node01
path.data: /home/middle/elasticsearch/data
path.logs: /home/middle/elasticsearch/logs
network.host: 192.168.1.102
http.port: 19200
path.repo: /home/middle/esbak
##cluster.initial_master_nodes: ["node01"]
discovery.seed_hosts: ["192.168.1.102"]
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
重新启动
su - elasticsearch
[elasticsearch@hadoop-slave1 ~]$ cd /usr/local/services/elasticsearch/bin
./elasticsearch -d
11.验证
这个时候登陆会报错误
[elasticsearch@master bin]$ curl http://192.168.1.102:19200/?pretty
{
"error" : {
"root_cause" : [
{
"type" : "security_exception",
"reason" : "missing authentication credentials for REST request [/?pretty]",
"header" : {
"WWW-Authenticate" : [
"Basic realm=\"security\", charset=\"UTF-8\"",
"ApiKey"
]
}
}
],
"type" : "security_exception",
"reason" : "missing authentication credentials for REST request [/?pretty]",
"header" : {
"WWW-Authenticate" : [
"Basic realm=\"security\", charset=\"UTF-8\"",
"ApiKey"
]
}
},
"status" : 401
}
12.安装安全认证(我这里密码全部设置为 elastic)
[elasticsearch@master bin]$ cd /usr/local/services/elasticsearch/bin
[elasticsearch@master bin]$ ./elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y
13.再次验证
[elasticsearch@master bin]$ curl -u elastic:elastic http://192.168.1.102:19200/?pretty
{
"name" : "node01",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "dIn0vF6SSQWvyUJ5wqqKwA",
"version" : {
"number" : "8.15.1",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "253e8544a65ad44581194068936f2a5d57c2c051",
"build_date" : "2024-09-02T22:04:47.310170297Z",
"build_snapshot" : false,
"lucene_version" : "9.11.1",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}