Linux-CentOS7安装ELK-Elasticsearch-Logstash-Kibana

下载地址

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

Logstash:https://www.elastic.co/cn/downloads/logstash

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

IK分词:https://github.com/medcl/elasticsearch-analysis-ik/releases

注意版本对应
ELK三者都是Java开发的,所以在系统中需要安装JDK的版本在8以上,但是现在下载的安装包中都有jdk,所以本机没有安装JDK也是可以的。

es与spring boot对应版本
https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#repositories

# 安装的主目录
cd /usr/local/
mkdir elk

一、Elasticsearch安装

基本安装

cd elk/
tar -zxvf elasticsearch-8.5.3-linux-x86_64.tar.gz
cd elasticsearch-8.5.3/
# es因为安全问题拒绝使用root用户启动,因此新建用户
# --------新建用户-----------
# 添加用户
useradd elk
# 为用户设置密码,可以为空
# passwd elk
# 为用户设置文件夹权限(我都是整个software目录,大家根据自己的实际情况进行设置)
chown -R elk /usr/local/elk/
# 切换用户
su elk
# ----------用户结束--------
# 前台启动
./bin/elasticsearch
# 后台启动
./bin/elasticsearch -d
# 测试,返回json成功
curl http://localhost:9200
# 外部访问
vim config/elasticsearch.yml
network.host: 0.0.0.0

es启动脚本

start_elasticsearch.sh

#!/bin/sh
export JAVA_HOME=/usr/local/elk/elasticsearch-7.3.0/jdk/
export PATH=$JAVA_HOME/bin:$PATH
export ES_HOME=/usr/local/elk/elasticsearch-7.3.0/
export PATH=$ES_HOME/bin:$PATH
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit ;
fi
case $1 in
start)
su - elk -c "$ES_HOME/bin/elasticsearch -d -p pid"
echo "elasticsearch is started"
;;
stop)
pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill -9 $pid
echo "elasticsearch is stopped"
;;
restart)
pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill -9 $pid
echo "elasticsearch is stopped"
sleep 1
su - elk -c "$ES_HOME/bin/elasticsearch -d -p pid"
echo "elasticsearch is started"
;;
*)
echo "start|stop|restart"
;;
esac
exit 0

常见问题

1.exception during geoip databases update
此版本将GeoIp功能默认开启了采集。在默认的启动下是会去官网的默认地址下获取最新的Ip的GEO信息

解决:在elasticsearch.yml中添加配置

ingest.geoip.downloader.enabled: false

2.max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]

解决

vim /etc/security/limits.conf
#此处elasticsearch对应用户名,可以用*
elk soft nofile 65536
elk hard nofile 65536

3.max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]、

解决

vim /etc/sysctl.conf
# 新增配置
vm.max_map_count=262144
# 刷新
sysctl -p

4.curl localhost:9200
curl: (52) Empty reply from server
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.security.enabled: false

5.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

解决

vim config/elasticsearch.yml
#添加配置
discovery.seed_hosts: ["127.0.0.1"]
cluster.initial_master_nodes: ["node-1"]

账号密码设置

使用基本和试用许可证时,默认情况下会禁用 Elasticsearch 安全功能。 要启用它们,首先,我们必须停止所以正在运行的 Elastic Stack 软件

# 停止elk软件,或者用kill
systemctl stop kibana.service
systemctl stop elasticsearch.service
# 或者kill
# ps -ef | grep ela
vim elasticsearch-8.5.3/config/elasticsearch.yml
# 修改以下配置
# 主要关闭ssl验证,否者:curl: (52) Empty reply from server
xpack.security.http.ssl.enabled: false
# 允许head插件等访问的相关设置
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
http.cors.allow-credentials: true
# 是否启用es的安全设置,启用安全设置后es各节点、客户端的传输都会加密,并需要账号密码
xpack.security.enabled: true
# 此项不可更改,当启用安全设置后,此项必须为true
xpack.security.transport.ssl.enabled: true
# 重启es服务
bin/elasticsearch -d
# 在启动的情况下,初始化es账号密码
# bin/elasticsearch-setup-passwords interactive
# 上面命令无效则使用
bin/elasticsearch-reset-password -u elastic -i
# 测试访问
curl -u elastic:密码 'http://localhost:9200'
# 或者
curl 'http://elastic:密码@localhost:9200'

访问方式

ES开启安全密码认证后,es-head连接方式
在web界面访问时,该框由原来的
http://localhost:9100
替换为
http://localhost:9100/?auth_user=elastic&auth_password=123456

IK分词器插件安装

仔细阅读文档查看对应版本和一键安装命令,https://github.com/medcl/elasticsearch-analysis-ik

尽量下载版本号与es版本相同的,如果没有对应版本,可以先查看以上链接找到合适版本进行安装一次,如果报错版本不一致:下载Git源码,更改pom.xml中<elasticsearch.version>你的es版本</elasticsearch.version>然后重新打包.
如果遇到本身代码错误就大胆改image
(他哥的想不明白为什么会范这种错误)
打包后将target>releases>下的zip文件用以下方式解压安装。

# 进去es插件目录
cd elasticsearch-8.5.3/plugins/
# 新建ik目录
mkdir ik
# 进入ik目录
cd ik
# ik压缩包移动到ik目录
mv /tmp/upload/elasticsearch-analysis-ik-8.5.3.zip ./
# 解压压缩包
unizp elasticsearch-analysis-ik-8.5.3.zip
# ----------配置-----------
cd config
vim IKAnalyzer.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置</comment>
<!--用户可以在这里配置自己的扩展字典 -->
<entry key="ext_dict">my.dic</entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords">mystop.dic</entry>
<!--用户可以在这里配置远程扩展字典 -->
<!-- <entry key="remote_ext_dict">words_location</entry> -->
<!--用户可以在这里配置远程扩展停止词字典-->
<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>
vim my.dic
小飞棍来咯
# 重启es

二、kibana安装

设置es的kibana通信账号

# kibana.yml中配置:elasticsearch.username: "elastic"会报错,应该直接是`kibana_system`
# 重置“ kibana_system ”用户密码;命令:
./bin/elasticsearch-reset-password -u kibana_system -i

基本安装

tar -zxvf kibana-8.3.3-linux-x86_64.tar.gz
# 修改配置,如果kibana和es在同一机器上,则不需要修改
cd kibana-8.5.3/
vim config/kibana.yml
# Kibana端口号
server.port: 5601
server.host: "0.0.0.0"
# elasticsearch的地址
elasticsearch.hosts: ["http://localhost:9200"]
# 账号密码
elasticsearch.username: "kibana_system"
elasticsearch.password: "你在es中设置的密码"
# 将目前权限给elk用户
chown -R elk /usr/local/elk/
# 使用elk用户启动
./bin/kibana
# 后台启动①
nohup ./bin/kibana &
# 后台启动②
./bin/kibana &
启动完成后输入exit退出

启动脚本

su - elk -c "/usr/local/elk/kibana-7.17.10-linux-x86_64/bin/kibana &"

进程查看

kibana使用ps -ef|grep kibana 是查不到进程的,主要原因大概是因为 kibana 是node 写的。所以kibana 运行的时候是运行在node 里面。

# 我们知道kibana是 5601 对外的 tcp 端口
netstat -tunlp|grep 5601

常见问题

1.Unable to write to UUID file at /usr/local/elk/kibana-8.5.3/data/uuid. Ensure Kibana has sufficient permissions to read / write to this file. Error was: EACCES

解决:给elk用户授予文件权限

chown -R elk /usr/local/elk/

2.Error: [config validation of [elasticsearch].username]: value of "elastic" is forbidden. This is a superuser account that cannot write to system indices that Kibana needs to function. Use a service account token instead. Learn more: https://www.elastic.co/guide/en/elasticsearch/reference/8.0/service-accounts.html

解决:kibana.yml中配置:elasticsearch.username: "elastic"会报错,看前面操作创建“ kibana_system ”用户

访问方式
浏览器:http://localhost:5601

三、Logstash安装

设置es的通信Logstash账号

如果之前没设置es账号密码这里需要设置,已经设置了就不用在执行了

./bin/elasticsearch-reset-password -u logstash_system -i

基础安装

tar -zxvf logstash-8.5.3-linux-x86_64.tar.gz
cd logstash-8.5.3/
vim ./config/test.conf

test.conf

input {
tcp {
mode => "server"
host => "100.171.xx.xx"
port => 9300
codec => json_lines
}
}
output {
stdout{
codec => rubydebug
}
elasticsearch {
hosts => "100.171.xx.xx:9200"
index => "springboot-logstash-%{+YYYY.MM.dd}"
user => "logstash_system"
password => "密码"
}
}
# 授权
chown -R elk /usr/local/elk/
# 启动①
./bin/logstash -f ./config/test.conf &
# 启动②:--config.test_and_exit选项的意思是解析配置文件并报告任何错误
bin/logstash -f config/test.conf --config.test_and_exit &
# 启动②:--config.reload.automatic选项的意思是启用自动配置加载,以至于每次你修改完配置文件以后无需停止然后重启Logstash
bin/logstash -f config/test.conf --config.reload.automatic &
# 多个启动,建议新建config.d文件夹管理
./logstash -f /etc/logstash/config.d/xxx.conf --path.data=/etc/logstash/config.d/xxx &
posted @   生生灯火半杯月  阅读(619)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示