因为es不能用root用户直接启动。需要单独创建用户
# 创建用户
useradd es
# 设置密码
passwd
# 切换用户
su - es
(1)修改最大虚拟内存区域 vm.max_map_count
vim /etc/sysctl.conf
文件最后添加一行
#增加这样一条配置,一个进程在VMAs(虚拟内存区域)创建内存映射最大数量
vm.max_map_count=262144
重启生效
sysctl -p
注:如果不修改,Elasticsearch启动时候出现vm.max_map_count异常的处理方法
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
(2)修改配置文件可限制文件打开数,系统进程等资源
vim /etc/security/limits.conf
//追加下面的内容
* soft nofile 65536
* hard nofile 131072
* soft nproc 4096
* hard nproc 4096
//重启服务器生效配置
shutdown -r now
不配置会报如下错误:
[1]:max file descriptors [4096] for elasticsearch process is too low, increase to at least[65536]
每个进程最大同时打开文件数太小
如不方便重启服务器生效配置,可以先配置,在用临时生效
ulimit -u 4096(将用户进程数最大值修改为4096)
ulimit -n 65536
https://www.elastic.co/cn/downloads/past-releases#elasticsearch
或:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.3.3-linux-x86_64.tar.gz
mkdir -p /opt/software/elasticsearch
tar -zxvf elasticsearch-8.3.3-linux-x86_64.tar.gz -C /opt/software/elasticsearch
进入解压目录
cd /opt/software/elasticsearch/elasticsearch-8.3.3/bin
打开elasticsearch,加入下面的命令,可以使用es的默认jdk
vim elasticsearch
############## 添加配置解决jdk版本问题 ##############
# 将jdk修改为es中自带jdk的配置目录
export JAVA_HOME=/opt/software/elasticsearch/elasticsearch-8.3.3/jdk
export PATH=$JAVA_HOME/bin:$PATH
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="/opt/software/elasticsearch/elasticsearch-8.3.3/jdk/bin/java"
else
JAVA=`which java`
fi
进入config目录
cd /opt/software/elasticsearch/elasticsearch-8.3.3/config/
根据配置的内存设置,修改文件jvm.options
-Xms8g
-Xmx8g
Elasticsearch有两个级别的通信:传输层通信和HTTP层通信。传输协议用于Elasticsearch节点之间的内部通信,HTTP协议用于从客户端到Elasticsearch集群的通信。由于Elasticsearch集群中的每个节点都是客户端和集群中其他节点的服务器,因此所有传输证书都必须是客户端和服务器证书。
Elasticsearch附带了一个名为elasticsearch-certutil的实用程序,可用于生成加密Elasticsearch集群内部通信的自签名证书,证书生成命令如下:
输入密码那一块直接回车,不要设置密码 假如在生成证书的时候设置了密码,会导致无法启动ES
bin/elasticsearch-certutil ca
ENTER ENTER
bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
ENTER ENTER ENTER
将生成的elastic-certificates.p12文件,放到
/opt/software/elasticsearch/elasticsearch-8.3.3/config的certs文件夹下
vim /opt/software/elasticsearch/elasticsearch-8.3.3/config/elasticsearch.yml
#节点名称
node.name: node-1
#允许所有ip访问
network.host: 0.0.0.0
#端口(默认9200)
http.port: 9200
#日志信息输出目录(按需求修改)
path.data: /datalog/es/data
path.logs: /datalog/es/logs
# 集群发现种子节点列表(集群部署配多个),默认["127.0.0.1"]
discovery.seed_hosts: ["localhost"]
# 手动指定可以成为 mater 的所有节点的 name 或者 ip,这些配置将会在第一次选举中进行计算(可配多>个)
cluster.initial_master_nodes: ["node-1"]
#自动写入的安全配置
#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
# The following settings, TLS certificates, and keys have been automatically
# generated to configure Elasticsearch security features on 16-06-2022 06:41:20
# --------------------------------------------------------------------------------
# Enable security features
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
enabled: false
keystore.path: certs/elastic-certificates.p12
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
enabled: true
verification_mode: certificate
keystore.path: certs/elastic-certificates.p12
truststore.path: certs/elastic-certificates.p12
进入 es 用户,执行以下操作
#启动
sh /opt/software/elasticsearch/elasticsearch-8.3.3/bin/elasticsearch
#后台启动
sh /opt/software/elasticsearch/elasticsearch-8.3.3/bin/elasticsearch -d
运行后,等待一会,会出现下面的auth信息,可以把密码保存下 或者到时候重置
Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
tJIXQCjnPGP7IvY9C1nP
修改内置用户密码
修改密码需要在es启动,并cd到es的bin目录下执行:
cd /opt/software/elasticsearch/elasticsearch-8.3.3/bin
1.重置密码并在控制台显示新密码(密码是自动生成的复杂度较高)
./elasticsearch-reset-password -u 用户名
例:重置 elastic 用户的密码 ./elasticsearch-reset-password -u elastic
2.自定义密码**==
./elasticsearch-reset-password -u elastic -i admin123
#方式1
jps
5288 org.elasticsearch.bootstrap.Elasticsearch
#方式2
ps aux | grep elasticsearch
查看访问是否成功
http://ip:9200/
用户名:elastic
密码:_=4xM2y8_oSZYMWJ5gp6
然后就登录成功了
#查看防火墙状态 :(active是绿的running表示防火墙开启)
systemctl status firewalld.service
#启动防火墙 :
systemctl start firewalld.service
#防火墙随系统开启启动 :
systemctl enable firewalld.service
#查询已经开放的端口 :
firewall-cmd --list-port
#开启端口 :
firewall-cmd --zone=public --add-port=9200/tcp --permanent
#重启防火墙 :
firewall-cmd --reload
cd /usr/lib/system/system/
新建 elasticsearch.service
[Unit]
Description=elasticsearch
After=network.target
[Service]
Type=forking
User=user-es
ExecStart=/opt/software/elasticsearch/elasticsearch-8.3.3/bin/elasticsearch -d
PrivateTmp=true
# 指定此进程可以打开的最大文件数
LimitNOFILE=65535
# 指定此进程可以打开的最大进程数
LimitNPROC=65535
# 最大虚拟内存
LimitAS=infinity
# 最大文件大小
LimitFSIZE=infinity
# 超时设置 0-永不超时
TimeoutStopSec=0
# SIGTERM是停止java进程的信号
KillSignal=SIGTERM
# 信号只发送给给JVM
KillMode=process
# java进程不会被杀掉
SendSIGKILL=no
# 正常退出状态
SuccessExitStatus=143
[Install]
WantedBy=multi-user. Target
执行设置开机启动
systemctl enable elasticsearch.service
# 启动服务
systemctl start elasticsearch.service
# 重启服务
systemctl restart elasticsearch.service
# 停止服务
systemctl stop elasticsearch.service
# 禁止开机启动
systemctl disable elasticsearch.service
# 启用开机启动
systemctl enable elasticsearch.service
https://github.com/1340691923/ElasticView