centos7.9 搭建ES8.12 + Kibana8.12

一、ES安装

1. 下载网址

https://www.elastic.co/cn/downloads/elasticsearch

2. 安装

上传到服务器,解压

tar -xvf elasticsearch-8.12.0-linux-x86_64.tar.gz 

3. 创建用户

创建 es用户 并赋予 es安装目录 权限,这是 Elasticsearch 的一种安全措施(不能使用root用户,启动服务只能用es用户)

[root@xj ~]# useradd es
[root@xj ~]# echo "password" | passwd --stdin es

修改文件夹权限

chown -R es:es /home/es/elasticsearch-8.12.0

切换用户

su - es

4. 修改配置启动

进入到对应的 config 目录,修改配置文件 elasticsearch.yml

[es@xj elasticsearch-8.12.0]$ cd config/
[es@xj config]$ vim elasticsearch.yml

网络配置修改:最初是全部注释掉的

开启 ES 的远程连接

# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
network.host: 0.0.0.0
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
http.port: 9200
#
# For more information, consult the network module documentation.

启动

在对应的bin目录下,-d 是在后台启动,首次启动不要加 -d

[es@xj bin]$ ./elasticsearch -d

启动完成后会出现以下内容 

同上面一样,最后输出的日志非常重要,所以建议复制保存在一个文件中。最后输出的elastic用户的初始密码,你需要记录下来,登录时使用,但如果你忘了没记下来,也可以运行./bin/elasticsearch-reset-password -u elastic重新生成一个。 

5. 连接测试

启动成功后我们可以用curl连接默认端口9200测试

curl 127.0.0.1:9200

不出意外,应该会返回 curl: (52) Empty reply from server。这是因为 elasticsearch 默认开启了 xpack 认证,我们刚开始测试阶段,可以先全部关掉。进入.elasticsearch-8.13.0/config/elasticsearch.yml目录,可以看到与认证相关的配置,这段配置是启动后加上去的,我们将与 xpack 有关的配置修改为 false:

然后重启即可(先ps找到进程id,kill掉后再运行上面的启动命令) 

本机运行 curl 连接:

 公网浏览器访问http://ip:9200/(如果连接失败可检查防火墙或云服务器安全组是否开放9200端口)

6. 修改密码

新版的 ES 会自动生成用户和密码:用户名统一为 elastic,随机生成密码

通过下面命令可以修改密码

[es@xj bin]$ ./elasticsearch-reset-password -u elastic -i
This tool will reset the password of the [elastic] user.
You will be prompted to enter the password.
Please confirm that you would like to continue [y/N]y


Enter password for [elastic]: 
Re-enter password for [elastic]: 
Password for the [elastic] user successfully reset.

7. systemd 管理

这种安装方式是直接执行/bin/elasticsearch启动脚本启动的,但这样不利于系统化管理,也不能开机自启动,我们可以将进程交给systemd管理,但是我们需要自定义一个elasticsearch.service文件。在这篇博客 找到一个现成的elasticsearch.service模板可以直接用。我们需要创建/etc/systemd/system/elasticsearch.service文件,将下面内容复制到文件中,注意要修改下Service.User 和 Service.ExecStart 配置:

[root@xj ~]# vim /etc/systemd/system/elasticsearch.service
[Unit]
Description=elasticsearch
After=network.target

[Service]
Type=forking

# ============================== 注意 ================================
# 这里要替换成你自己创建的 elasticsearch 用户
User=es
# 这里要替换成你自己的 elasticsearch 安装目录
ExecStart=/usr/local/elasticsearch-8.13.0/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

 创建好 .service 文件后,依次执行下面命令生效并启动elasticsearch服务:

systemctl daemon-reload
systemctl enable elasticsearch.service
systemctl start elasticsearch.service

二、Kibana安装

1. 下载网址

https://www.elastic.co/cn/downloads/kibana

2. 安装

同样上传到服务器,并且解压

[es@xj home]$ tar -zxvf kibana-8.12.0-linux-x86_64.tar.gz

3. 创建用户

[root@xj home]# useradd kibana
[root@xj home]# echo "password" | passwd --stdin

 修改权限

[root@xj home]# chown -R kibana:kibana /home/kibana/kibana-8.12.0

 切换用户

su - kibana

4. 修改配置

修改对应config目录的kibana.yml配置文件

server.port: 5601

server.host: "0.0.0.0"

server.name: "kibana"

elasticsearch.hosts: ["https://‘es的ip’:9200"]

5. 后台启动

[kibana@xj bin]$ nohup ./kibana &

由于我们之前配置了,取消安全验证,所以启动后直接访问 http://IP地址:5601 即可

如果没有配置取消安全验证,会需要输入一个 token 和 code

猜你喜欢

转载自blog.csdn.net/2301_78183285/article/details/138523205