首页 > 其他分享 >ElasticSearch+Kibana+Filebeat+Head搭建日志采集系统

ElasticSearch+Kibana+Filebeat+Head搭建日志采集系统

时间:2023-01-29 14:03:02浏览次数:250  
标签:node Filebeat log Head Kibana elasticsearch usr local es


安装步骤如下:
1.进入elasticsearch官网下载:
​​​https://www.elastic.co/downloads/elasticsearch​​​ cd /usr/local/
wget ​​https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.4.tar.gz​

解压 tart -zxvf elasticsearch-6.5.4.tar.gz
重命名
mv elasticsearch-6.5.4 elasticsearch
创建数据存放路径(应将设置配置为在Elasticsearch主目录之外定位数据目录,以便在不删除数据的情况下删除主目录!)
mkdir -p /usr/local/elasticsearch/data
创建日志存放路径(已存在不用创建)
mkdir -p /usr/local/elasticsearch/logs
2.建立用户并授权(es不能用root运行)

useradd es

3.赋予文件夹权限
chown -R es:es /usr/local/elasticsearch/

elasticsearch.yml如下:

4.修改elasticsearch配置文件
vim /usr/local/elasticsearch/config/elasticsearch.yml

#集群的名称
​​​cluster.name​​​: es6.5.4
#节点名称,其余两个节点分别为node-2 和node-3
​​​node.name​​​: node-1
#指定该节点是否有资格被选举成为master节点,默认是true,es是默认集群中的第一台机器为master,如果这台机挂了就会重新选举master
node.master: true
#允许该节点存储数据(默认开启)
node.data: true
#索引数据的存储路径
path.data: /opt/elasticsearch/data
#日志文件的存储路径
path.logs: /opt/elasticsearch/logs
#设置为true来锁住内存。因为内存交换到磁盘对服务器性能来说是致命的,当jvm开始swapping时es的效率会降低,所以要保证它不swap
bootstrap.memory_lock: true
#绑定的ip地址
network.host: 0.0.0.0
#设置对外服务的http端口,默认为9200
http.port: 9200
#设置节点间交互的tcp端口,默认是9300
transport.tcp.port: 9300
#Elasticsearch将绑定到可用的环回地址,并将扫描端口9300到9305以尝试连接到运行在同一台服务器上的其他节点。
#这提供了自动集群体验,而无需进行任何配置。数组设置或逗号分隔的设置。每个值的形式应该是host:port或host
#(如果没有设置,port默认设置会transport.profiles.default.port 回落到transport.tcp.port)。
#请注意,IPv6主机必须放在括号内。默认为127.0.0.1, [::1]
discovery.zen.ping.unicast.hosts: [“192.168.0.45:9300”, “192.168.0.69:9300”, “192.168.0.76:9300”]
#如果没有这种设置,遭受网络故障的集群就有可能将集群分成两个独立的集群 - 分裂的大脑 - 这将导致数据丢失
discovery.zen.minimum_master_nodes: 1
discovery.type: single-node
http.cors.enabled: true
http.cors.allow-origin: “*”
http.cors.allow-credentials: true

修改完之后使用命令查看具体修改了哪些值
grep ‘​​​1​​​’ /usr/local/elasticsearch/config/elasticsearch.yml
添加索引数据的存储路径日志文件的存储路径

mkdir -p /opt/elasticsearch/data && mkdir -p /opt/elasticsearch/logs

chown -R es:es /opt/elasticsearch/data && chown -R es:es /opt/elasticsearch/logs

5.调整jvm内存

vim /usr/local/elasticsearch/config/jvm.options
#默认是1g官方建议对jvm进行一些修改,不然很容易出现OOM,参考官网改参数配置最好不要超过内存的50%
-Xms1g
-Xmx1g

6.启动以及启动遇到问题的解决方法
注意:请使用es用户启动 su - es
/usr/local/elasticsearch/bin/elasticsearch -d

使用ps -ef|grep elasticsearc查看进程是否启动,发现并没有启动

解决方法:
切回root用户su - root,修改配置
vim /etc/security/limits.conf

  • soft nofile 65536
  • hard nofile 131072
  • soft nproc 4096
  • hard nproc 4096
    es soft memlock unlimited
    es hard memlock unlimited
    es soft nproc 4096
    es soft nproc 4096

#我选择锁住swapping因此需要在这个配置文件下再增加两行代码
es soft memlock unlimited
es hard memlock unlimited

vim /etc/sysctl.conf

vm.max_map_count = 655360
fs.file-max = 655360

注意:之后需要执行一句命令sysctl -p使系统配置生效(使用root用户)。
再次重启,使用ps -ef|grep elasticsearch进程查看命令已启动,使用netstat -ntlp查看9200端口也被占用了。

7.Elasticsearch-head插件安装

安装node.js

①先安装,nvm,即是Node Version Manager(Node版本管理器)

wget -qO- ​​https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh​​​ | bash
②之后需要激活nvm:

source ~/.nvm/nvm.sh

③激活完成后,安装node
nvm install node

④安装完成后,切换到该版本

nvm use node

8.安装grunt

grunt是基于Node.js的项目构建工具,可以进行打包压缩、测试、执行等等的工作,head插件就是通过grunt启动
mkdir -p /usr/local/elasticsearch/elasticsearch-head
cd /usr/local/elasticsearch/elasticsearch-head
npm install -g grunt-cli

执行后会生成node_modules文件夹,grunt -version检查是否安装成功。

9.安装Head插件
cd /usr/local/elasticsearch/
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head/
npm install

①安装完成之后,修改服务器监听地址
vim /usr/local/elasticsearch/elasticsearch-head/Gruntfile.js,增加hostname属性,设置为*

connect: {
server: {
options: {
port: 9100,
hostname: ‘*’,
base: ‘.’,
keepalive: true
}
}
}
②修改连接地址
vim /usr/local/elasticsearch/elasticsearch-head/_site/app.js,把localhost修改成你es的服务器地址,如:
this.base_uri = this.config.base_uri || this.prefs.get(“app-base_uri”) || “​​​http://192.168.8.101:9200​​”;

③启动Head插件
使用 grunt server 或 npm run start 启动插件。
访问http://192.168.1.8:9100/ 出现以下画面,代表启动成功

备注:点解连接 按钮连接集群,发现无论如何点击都没有反应,还需要在es上进行以下设置,开启跨域访问支持
vim /usr/local/elasticsearch/config/elasticsearch.yml 在最后添加以下三条属性:
discovery.type: single-node
http.cors.enabled: true
http.cors.allow-origin: “*”
http.cors.allow-credentials: true

10.kibana安装与elasticsearch安装版本要一致
docker run -it -d -e ELASTICSEARCH_URL=http://192.168.0.124:9200 --name kibana -p 5601:5601 nshou/elasticsearch-kibana
#kibana链接
​​​https://www.elastic.co/downloads/kibana​

11.filebeat安装
#filebeat链接
​​​https://www.elastic.co/downloads/beats/filebeat​​ cd /opt/filebeat-6.2.3-linux-x86_64

vim filebeat.yml

需要注意,enable必须为true

  • type: log

#Change to true to enable this input configuration.
enabled: true
#指定日志路径
- /var/tomcat/log/.log
- /var/mysql/log/
.log
- /var/itpl/log/.log
- /var/vts/log/logs/
.log
- /var/log/.log
- /var/log/nginx/
.log
- /var/log/redis/*.log
#filebeat启动
sudo ./filebeat -e -c filebeat.yml


  1. a-z ↩︎


标签:node,Filebeat,log,Head,Kibana,elasticsearch,usr,local,es
From: https://blog.51cto.com/u_15943246/6025726

相关文章