欢迎投稿

今日深度:

Linux centos7.6 安装elasticsearch8.x (es8) 教程,

Linux centos7.6 安装elasticsearch8.x (es8) 教程,


系列-Linux centos7.6 安装elasticsearch8.x (es8) 教程

Linux centos7.6 安装elasticsearch8.x (es8) 教程_言之有李LAX的博客-CSDN博客

系列-linux安装elasticsearch-head (es可视化界面)

linux安装elasticsearch-head (es可视化界面)_言之有李LAX的博客-CSDN博客

目录

安装elasticsearch

启动

常见错误

1.内存不足

2.can not run elasticsearch as root

启动成功

访问

通过ip:9200 进行访问

设置es启动脚本:

重置密码

 es默认重置密码

es自定义重置密码

下载安装

我的安装目录为 /usr/local

cd /usr/local

# 下载压缩包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.4.3-linux-x86_64.tar.gz

#解压
tar -zxvf ./elasticsearch-8.4.3-linux-x86_64.tar.gz

启动

cd /usr/local/elasticsearch-8.4.3/bin
./elasticsearch

常见错误

1.内存不足

error='Not enough space' (errno=12) 该异常表示内存不足以支撑es运行,一般如果是个人买的小服务器会容易出现该问题,直接修改es运行配置即可

#首先查询服务的内存大小
[root@VM-4-12-centos config]# cat /proc/meminfo | grep MemTotal
MemTotal:        3782868 kB

#然后进入es的配置中修改
cd /usr/local/elasticsearch-8.4.3/config
vim jvm.options

#在配置文件中添加如下配置,保存退出即可(108m)
-Xms108m
-Xmx108m

2.can not run elasticsearch as root

无法以root身份运行elasticserch :can not run elasticsearch as root

此时我们需要创建一个单独的用户给es使用

[root@VM-4-12-centos ~]# groupadd esgroup
[root@VM-4-12-centos ~]# useradd esroot -p 123456
#赋权限
[root@VM-4-12-centos ~]# chown -R esroot:esgroup /usr/local/elasticsearch-8.4.3
#切换账户
[root@VM-4-12-centos ~]# su esroot
#再次启动
[esroot@VM-4-12-centos elasticsearch-8.4.3]$ cd /usr/local/elasticsearch-8.4.3/bin/
[esroot@VM-4-12-centos bin]$ ./elasticsearch

启动成功

启动后日志打印出了配置信息如下:

解释一下:注意#备注的地方 第一步中已经返回了用户名和密码

elastic / IAcYJctxO39fixwiV7V1  后面会教怎么修改自定义密码

✅ Elasticsearch security features have been automatically configured!
✅ Authentication is enabled and cluster connections are encrypted.

#es用户信息密码,并且可以通过bin/elasticsearch-reset-password -u elastic重置
ℹ️  Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  IAcYJctxO39fixwiV7V1

ℹ️  HTTP CA certificate SHA-256 fingerprint:
  3f2e9d6e24f2b713cf84c8e70ab97acb929dec566444b6f62ce036c6d225b5ed

#kibana初始化与es链接SSl的token 有效期30分钟 过期使用bin/elasticsearch-create-enrollment- token -s kibana 再次创建
ℹ️  Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
  eyJ2ZXIiOiI4LjQuMyIsImFkciI6WyIxMC4wLjQuMTI6OTIwMCJdLCJmZ3IiOiIzZjJlOWQ2ZTI0ZjJiNzEzY2Y4NGM4ZTcwYWI5N2FjYjkyOWRlYzU2NjQ0NGI2ZjYyY2UwMzZjNmQyMjViNWVkIiwia2V5IjoiajZ3c3dZUUJGbjczWjE4NFBXSVI6Wk95MkplbU9TNnU3cDFaUXFJbHlSUSJ9

ℹ️  Configure other nodes to join this cluster:
• On this node:
  ⁃ Create an enrollment token with `bin/elasticsearch-create-enrollment-token -s node`.
  ⁃ Uncomment the transport.host setting at the end of config/elasticsearch.yml.
  ⁃ Restart Elasticsearch.
• On other nodes:
  ⁃ Start Elasticsearch with `bin/elasticsearch --enrollment-token <token>`, using the enrollment token that you generated.

访问

通过ip:9200 进行访问

同时记得开启防火墙

#将9200加入白名单
firewall-cmd --zone=public --add-port=9200/tcp --permanent
#刷新防火墙
systemctl restart firewalld.service

 如果是阿里云、腾讯云等线上服务器,记得在服务防火墙中规则中添加9200

此时通过浏览器直接访问会提示失败:

 原因是elasticsearch开启了认证和http加密

解决:

1.首先关闭认证进行测试

#切换到root用户
su root
#进入config文件夹
cd /usr/local/elasticsearch-8.4.3/config
#修改elasticsearch.yml 配置信息
vi elasticsearch.yml


关闭xpack认证 
xpack.security.enabled: true 改成 false
与客户端http链接是否加密,先选择不加密
xpack.security.http.ssl: true 改成 false
保存退出


#却换用户
su esuser
#进入elasticsearch  bin目录下面
cd /usr/local/elasticsearch-8.4.3/bin
#启动
./elasticsearch

 此时访问即可查询到内容:

设置es启动脚本:

ES_HOME记得修改成自己的路径

su esuser :记得修改成自己的linux上面设置的es启动用户名

#切换root用户
su root
#进入到目录
cd /etc/init.d   
#创建elasticsearch系统启动服务文件   
vi elasticsearch

#!/bin/bash
#chkconfig: 345 63 37
#description: elasticsearch
#processname: elasticsearch-8.4.3
# 这个目录是你Es所在文件夹的目录
export ES_HOME=/usr/local/elasticsearch-8.4.3
case $1 in
start)
    su esuser<<!
    cd $ES_HOME
    ./bin/elasticsearch -d -p pid
    exit
!
    echo "elasticsearch is started"
    ;;
stop)
    pid=`cat $ES_HOME/pid`
    kill -9 $pid
    echo "elasticsearch is stopped"
    ;;
restart)   
    pid=`cat $ES_HOME/pid`
    kill -9 $pid
    echo "elasticsearch is stopped"
    sleep 1
    su esuser<<!
    cd $ES_HOME
    ./bin/elasticsearch -d -p pid
    exit
!
    echo "elasticsearch is started"
    ;;
*)
    echo "start|stop|restart"
    ;;
esac
exit 0
 


给elasticsearch 文件赋权限
chmod 777 elasticsearch


# 添加系统服务
chkconfig --add elasticsearch   执行这一步
# 删除系统服务
chkconfig --del elasticsearch

# 启动服务
service elasticsearch start
# 停止服务
service elasticsearch stop
# 重启服务
service elasticsearch restart


# 开启开机自动启动服务
chkconfig elasticsearch on  执行这一步
# 关闭开机自动启动服务
chkconfig elasticsearch off

刚才为了测试,关闭的xpac认证,此时还原

#进入elaticsearch config目录下面
cd /usr/local/elasticsearch-8.4.3/config
#修改配置文件
vi elasticsearch.yml

xpack.security.enabled: 修改为 true  然后退出保存

重新启动

service elasticsearch restart

重置密码

此时再进行访问会提示需要输入密码:

 es默认重置密码

刚才启动打印的地方已经提示用户名密码了,直接输入即可

如果忘记可以进行重置密码

#进入elaticsearch bin目录下面
cd /usr/local/elasticsearch-8.4.3/bin
#设置密码 elastic是默认用户名
./elasticsearch-reset-password -u elastic

es自定义重置密码

如果密码太长记不住 则可以使用下面的命令进行自定义密码

 #设置自己想设置的密码
./elasticsearch-reset-password -u elastic -i

 

 最后再通过ip:9200访问,输入用户名密码即可看到信息

www.htsjk.Com true http://www.htsjk.com/Elasticsearch/45935.html NewsArticle Linux centos7.6 安装elasticsearch8.x (es8) 教程, 系列-Linux centos7.6 安装elasticsearch8.x (es8) 教程 Linux centos7.6 安装elasticsearch8.x (es8) 教程_言之有李LAX的博客-CSDN博客 系列-linux安装elasticsearch-head e...
评论暂时关闭