使用 yum 安装 Elasticsearch
Elasticsearch 官方文档地址https://www.elastic.co/guide/en/elasticsearch/reference/8.0/rpm.html#rpm-repo
下载并安装公钥
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
创建yum源配置文件
vi /etc/yum.repos.d/elasticsearch.repo
[elasticsearch]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
yum安装
yum install --enablerepo=elasticsearch elasticsearch
es服务命令
# 启动
systemctl start elasticsearch.service
# 关闭
systemctl stop elasticsearch.service
# 重启
systemctl restart elasticsearch.service
es默认文件路径
- 安装目录路径 /usr/share/elasticsearch
- 配置文件路径 /etc/elasticsearch
- 日志文件路径 /var/log/elasticsearch
初始化账号密码
#auto 自动生成密码 interactive手动创建密码
/usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
启动异常解决方案
当修改es配置文件elasticsearch.yml的network.host: 0.0.0.0重启会提示
[root@dev ~]# systemctl restart elasticsearch
Job for elasticsearch.service failed because the control process exited with error code. See "systemctl status elasticsearch.service" and "journalctl -xe" for details.
查看日志文件提示需要修复一下四个问题
[root@dev ~]# tail -f /var/log/elasticsearch/elasticsearch.log
[4] bootstrap checks failed. You must address the points described in the following [4] lines before starting Elasticsearch.
bootstrap check failure [1] of [4]: initial heap size [268435456] not equal to maximum heap size [536870912]; this can cause resize pauses
bootstrap check failure [2] of [4]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
bootstrap check failure [3] of [4]: Transport SSL must be enabled if security is enabled. Please set [xpack.security.transport.ssl.enabled] to [true] or disable security by setting [xpack.security.enabled] to [false]
bootstrap check failure [3] of [4]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
第一个问题bootstrap check failure [1] of [3]: initial heap size [268435456] not equal to maximum heap size [536870912]; this can cause resize pauses是初始化堆内存和最大堆内存不一致导致的需修改/etc/elasticsearch/jvm.options配置文件将最大和最小值改成一样
第二个问题bootstrap check failure [2] of [3]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured 提示必须设置三个配置中的一个
vi /etc/elasticsearch/elasticsearch.yml
修改以下配置
discovery.seed_hosts: ["0.0.0.0"]
第三个问题bootstrap check failure [3] of [3]: Transport SSL must be enabled if security is enabled. Please set [xpack.security.transport.ssl.enabled] to [true] or disable security by setting [xpack.security.enabled] to [false]需配置安全证书,偷懒方法就是临时把xpack安全设置为false
vi /etc/elasticsearch/elasticsearch.yml
# Enable security features
xpack.security.enabled: false
第四个问题bootstrap check failure [3] of [4]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]需要修改服务器内核参数
vi /etc/sysctl.conf
添加以下配置
vm.max_map_count=655360
让内核参数立即生效
sysctl -p