elasticsearch-6.8.5单机部署(当生产环境使用)
前提条件安装java 1.8,否则启动的时候报错误
the minimum required Java version is 8; your Java version from [/opt/develop/jdk1.7.0_79/jre] does not meet this requirement
安装请参考
https://www.cnblogs.com/hxlasky/p/14775706.html
1.下载需要的安装版本
我这里下载的是6.8.5,elasticsearch-6.8.5.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-6.8.5.tar.gz
[root@localhost soft]# mv elasticsearch-6.8.5 /usr/local/services/elasticsearch
[root@localhost soft]#cd /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/elasticsearch/esbak
7.修改配置文件
[root@hadoop-slave1 middle]# su - elasticsearch
[elasticsearch@hadoop-slave1 ~]$ cd /usr/local/services/elasticsearch/config
[elasticsearch@hadoop-slave1 config]$ vi elasticsearch.yml
注意修改如下几项:
path.data: /home/middle/elasticsearch/data
path.logs: /home/middle/elasticsearch/logs
network.host: 192.168.1.63
http.port: 19200
path.repo: /home/elasticsearch/esbak
##安全认证
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)
## 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
-Xms8g
-Xmx8g
9.修改/usr/local/services/elasticsearch/bin/elasticsearch
# ES_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/elasticsearch
export ES_HEAP_SIZE=8g
10.系统参数设置
每个节点上都要执行,这里确保每台机器都能启动
[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
11.启动
su - elasticsearch
[hxl@hadoop-slave1 ~]$ cd /usr/local/services/elasticsearch/bin
./elasticsearch -d
12.验证
这个时候登陆会报错误
[hxl@hadoop-slave1 bin]$ curl http://192.168.1.63:19200/?pretty
{
"error" : {
"root_cause" : [
{
"type" : "security_exception",
"reason" : "missing authentication token for REST request [/?pretty]",
"header" : {
"WWW-Authenticate" : "Basic realm=\"security\" charset=\"UTF-8\""
}
}
],
"type" : "security_exception",
"reason" : "missing authentication token for REST request [/?pretty]",
"header" : {
"WWW-Authenticate" : "Basic realm=\"security\" charset=\"UTF-8\""
}
},
"status" : 401
}
13.安装安全认证(我这里密码全部设置为 hxldev123)
[elasticsearch@hadoop-slave1 ~]$ cd /usr/local/services/elasticsearch/bin
[elasticsearch@localhost 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
Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana]:
Reenter password for [kibana]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
14.再次验证
curl -u elastic:sdrdev123 http://192.168.1.63:19200/?pretty
{
"name" : "Jzm_fbR",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "igZpEAg9T5uF1PGdit6dVQ",
"version" : {
"number" : "6.8.5",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "78990e9",
"build_date" : "2019-11-13T20:04:24.100411Z",
"build_snapshot" : false,
"lucene_version" : "7.7.2",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
14.设置开机自启动
/etc/systemd/system/elasticsearch.service
在/etc/systemd/system目录下创建 elasticsearch.service 文件
root下操作
vi /etc/systemd/system/elasticsearch.service
[Unit]
Description=elasticsearch
[Service]
User=elasticsearch
LimitNOFILE=100000
LimitNPROC=100000
ExecStart=/usr/bin/su - elasticsearch -c "/usr/local/services/elasticsearch/bin/elasticsearch -d -p pid"
[Install]
WantedBy=multi-user.target
设置开机自启
systemctl enable elasticsearch
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?