安徽网站优化,建设网站的公司排名,百度开放平台,源码下载工具一、组件介绍1、Elasticsearch#xff1a;2 、Logstash3、Kibana4、Kafka#xff1a;5、Filebeat: 二、 Elasticsearch集群部署服务器创建用户安装ES修改配置文件创建数据和日志目录设置JVM堆大小 #7.0默认为4G修改安装目录及存储目录权限系统优化#xff08;1#xff09;增… 一、组件介绍1、Elasticsearch2 、Logstash3、Kibana4、Kafka5、Filebeat: 二、 Elasticsearch集群部署服务器创建用户安装ES修改配置文件创建数据和日志目录设置JVM堆大小 #7.0默认为4G修改安装目录及存储目录权限系统优化1增加最大文件打开数2增加最大进程数3增加最大内存映射数 启动ES 三、安装配置head监控插件安装node下载head插件安装grunt修改head配置文件下载head必要的插件浏览器访问测试 四、Kibana部署安装配置Kibana启动 五、安装配置Nginx反向代理(1配置YUM源(2) 配置反向代理(3)启动nginx 六、Logstash部署1.安装配置Logstash启动 一、组件介绍
1、Elasticsearch
是基于一个Lucene的搜索引擎提供搜索分析。存储数据三大功能他提供了一个分布式多用户能力的全文搜索引擎基于RESTful web接口Elasticsearch是用Java开发的并作为Apache许可条款下的开放源码发布是当前流行的企业级搜索引擎。设计用于云计算中能够达到实时搜索稳定可靠快速安装使用方便
2 、Logstash
主要是用来日志的搜集、分析、过滤日志的工具。用于管理日志和事件的工具你可以用它去收集日志、转换日志、解析日志并将他们作为数据提供给其它模块调用例如搜索、存储等。
3、Kibana
是一个优秀的前端日志展示框架它可以非常详细的将日志转化为各种图表为用户提供强大的数据可视化支持,它能够搜索、展示存储在 Elasticsearch 中索引数据。使用它可以很方便的用图表、表格、地图展示和分析数据。
4、Kafka
数据缓冲队列。作为消息队列解耦合处理过程同时提高了可扩展性。具有峰值处理能力使用消息队列能够使关键组件顶住突发的访问压力而不会因为突发的超负荷的请求而完全崩溃。
1.发布和订阅记录流类似于消息队列或企业消息传递系统。2.以容错持久的方式存储记录流。3.处理记录发生的流。
5、Filebeat:
隶属于Beats,轻量级数据收集引擎。基于原先 Logstash-fowarder 的源码改造出来。换句话说Filebeat就是新版的 Logstash-fowarder也会是 ELK Stack 在 Agent 的第一选择,目前Beats包含四种工具
1.Packetbeat搜集网络流量数据2.Metricbeat搜集系统、进程和文件系统级别的 CPU 和内存使用情况等数据。通过从操作系统和服务收集指标帮助您监控服务器及其托管的服务。3.Filebeat搜集文件数据4.Winlogbeat搜集 Windows 事件日志数据
二、 Elasticsearch集群部署
服务器
注以下为环境所需所有服务器配置为测试环境配置。
主机名IP地址系统版本配置Elk192.168.20.153centos7.5.18042核4GEs1192.168.20.157centos7.5.18042核4GEs2192.168.20.159centos7.5.18042核4G
创建用户
#创建用户
[rootelk ~]# useradd es
[rootelk ~]# echo 123456 | passwd --stdin es
更改用户 es 的密码 。
passwd所有的身份验证令牌已经成功更新。安装ES
#上传解压安装包
[rootelk ~]# tar -xf elasticsearch-7.13.2-linux-x86_64.tar.gz -C /usr/local
[rootelk ~]# cd /usr/local
[rootelk local]# mv elasticsearch-7.13.2/ es修改配置文件
[rootelk local]# cd es/config
[rootelk config]# cp elasticsearch.yml elasticsearch.yml.back
[rootelk config]# vim /usr/local/es/config/elasticsearch.ymlcluster.name: zxjqcluster.initial_master_nodes: [192.168.20.153,192.168.20.157, 192.168.20.159]node.name: elk01node.master: truenode.data: truepath.data: /data/elasticsearch/datapath.logs: /data/elasticsearch/logsbootstrap.memory_lock: falsebootstrap.system_call_filter: falsenetwork.host: 0.0.0.0http.port: 9200transport.tcp.port: 9300discovery.seed_hosts: [192.168.20.157, 192.168.20.159]discovery.zen.minimum_master_nodes: 2discovery.zen.ping_timeout: 150sdiscovery.zen.fd.ping_retries: 10client.transport.ping_timeout: 60shttp.cors.enabled: truehttp.cors.allow-origin: *cluster.name 集群名称各节点配成相同的集群名称。 cluster.initial_master_nodes 集群ip默认为空如果为空则加入现有集群第一次需配置 node.name 节点名称各节点配置不同。 node.master 指示某个节点是否符合成为主节点的条件。 node.data 指示节点是否为数据节点。数据节点包含并管理索引的一部分。 path.data 数据存储目录。 path.logs 日志存储目录。 bootstrap.memory_lock 内存锁定是否禁用交换测试环境建议改为false。 bootstrap.system_call_filter 系统调用过滤器。 network.host 绑定节点IP。 http.port rest api端口。 discovery.seed_hosts 提供其他 Elasticsearch 服务节点的单点广播发现功能这里填写除了本机的其他ip discovery.zen.minimum_master_nodes 集群中可工作的具有Master节点资格的最小数量官方的推荐值是(N/2)1其中N是具有master资格的节点的数量。 discovery.zen.ping_timeout 节点在发现过程中的等待时间。 discovery.zen.fd.ping_retries 节点发现重试次数。 http.cors.enabled 是否允许跨源 REST 请求用于允许head插件访问ES。 http.cors.allow-origin 允许的源地址 创建数据和日志目录
[rootelk config]# mkdir -p /data/elasticsearch/data
[rootelk config]# mkdir -p /data/elasticsearch/logs设置JVM堆大小 #7.0默认为4G
[rootelk config]# sed -i s/## -Xms4g/-Xms4g/ /usr/local/es/config/jvm.options
[rootelk config]# sed -i s/## -Xmx4g/-Xmx4g/ /usr/local/es/config/jvm.options修改安装目录及存储目录权限
[rootelk config]# chown -R es.es /data/elasticsearch
[rootelk config]# chown -R es.es /usr/local/es确保堆内存最小值Xms与最大值Xmx的大小相同防止程序在运行时改变堆内存大小。 如果系统内存足够大将堆内存最大和最小值设置为31G因为有一个32G性能瓶颈问题。 堆内存大小不要超过系统内存的50% 系统优化
1增加最大文件打开数
永久生效方法
[rootelk ~]# echo * soft nofile 65536 /etc/security/limits.conf2增加最大进程数
[rootelk ~]# echo * soft nproc 65536 /etc/security/limits.conf更多的参数调整可以直接用这个 3增加最大内存映射数
[rootelk ~]# echo vm.max_map_count262144 /etc/sysctl.conf
[rootelk ~]# sysctl -p
[rootelk ~]# vim /etc/security/limits.conf
* hard nofile 65536启动ES
[rootelk config]# su - es
上一次登录五 11月 24 17:56:53 CST 2023pts/0 上
[eselk ~]$ cd /usr/local/es
[eselk es]$ ./bin/elasticsearch三台机器做相同操作 三、安装配置head监控插件
只在第一台es部署
主机名IP地址系统版本配置Elk192.168.20.153centos7.5.18042核4G
安装node
[rootelk ~]# tar -xf node-v10.24.1-linux-x64.tar.gz -C /usr/local
[rootelk ~]# cd /usr/local
[rootelk local]# mv node-v10.24.1-linux-x64/ node
[rootelk local]# vim /etc/profile.d/node.sh
NODE_HOME/usr/local/node
PATH$NODE_HOME/bin:$PATH
[rootelk local]# source /etc/profile.d/node.sh
[rootelk ~]# node --version
v10.24.1下载head插件
[rootelk ~]# wget https://github.com/mobz/elasticsearch-head/archive/master.zip
[rootelk ~]# unzip –d /usr/local elasticsearch-head-master.zip安装grunt
[rootelk ~]# cd /usr/local/elasticsearch-head-master
[rootelk elasticsearch-head-master]# ls
crx elasticsearch-head.sublime-project index.html plugin-descriptor.properties _site
Dockerfile Gruntfile.js LICENCE proxy src
Dockerfile-alpine grunt_fileSets.js package.json README.textile test
[rootelk elasticsearch-head-master]# npm install -g grunt-cli
/usr/local/node/bin/grunt - /usr/local/node/lib/node_modules/grunt-cli/bin/gruntgrunt-cli1.4.3
added 59 packages from 69 contributors in 21.93s
[rootelk elasticsearch-head-master]# grunt -version
grunt-cli v1.4.3修改head配置文件
[rootelk ~]#vi /usr/local/elasticsearch-head-master/Gruntfile.js 95
[rootelk ~]# vim /usr/local/elasticsearch-head-master/_site/app.js 4373
下载head必要的插件
[rootelk ~]# yum -y install bzip2
[rootelk ~]# mkdir /tmp/phantomjs
[rootelk ~]# mv phantomjs-2.1.1-linux-x86_64.tar.bz2 /tmp/phantomjs/
[rootelk ~]# chmod 777 /tmp/phantomjs -R
[rootelk ~]# cd /usr/local/elasticsearch-head-master/
[rootelk elasticsearch-head-master]# npm install
[rootelk elasticsearch-head-master]# nohup grunt server
执行错误可以再次执行npm install phantomjs-prebuilt2.1.16 --ignore-scripts
浏览器访问测试
访问http://192.168.20.153:9100
四、Kibana部署
主机名IP地址系统版本配置Elk192.168.20.153centos7.5.18042核4G
安装配置Kibana
[rootelk ~]# tar zxf kibana-7.13.2-linux-x86_64.tar.gz -C /usr/local/
[rootelk ~]# vim /usr/local/kibana-7.13.2-linux-x86_64/config/kibana.yml
server.port: 5601
server.host: 192.168.20.153
elasticsearch.hosts: [http://192.168.20.153:9200]
kibana.index: .kibana
i18n.locale: zh-CNserver.port kibana服务端口默认5601 server.host kibana主机IP地址默认localhost elasticsearch.url 用来做查询的ES节点的URL默认http://localhost:9200 kibana.index kibana在Elasticsearch中使用索引来存储保存的searches, visualizations和dashboards默认.kibana 启动
[rootelk ~]# cd /usr/local/kibana-7.13.2-linux-x86_64/
[rootelk ~]# nohup ./bin/kibana --allow-root
[rootelk kibana-7.13.2-linux-x86_64]# ss -nplt |grep 5601
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 192.168.20.153:5601 *:* users:((node,pid2236,fd18)) 五、安装配置Nginx反向代理
(1配置YUM源
[rootelk ~]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm(2) 配置反向代理
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65535;events {worker_connections 65535;use epoll;
}http {include mime.types;default_type application/octet-stream;log_format main $remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for;access_log /var/log/nginx/access.log main;server_names_hash_bucket_size 128;autoindex on;sendfile on;tcp_nopush on;tcp_nodelay on;keepalive_timeout 120;fastcgi_connect_timeout 300;fastcgi_send_timeout 300;fastcgi_read_timeout 300;fastcgi_buffer_size 64k;fastcgi_buffers 4 64k;fastcgi_busy_buffers_size 128k;fastcgi_temp_file_write_size 128k;#gzip模块设置gzip on; #开启gzip压缩输出gzip_min_length 1k; #最小压缩文件大小gzip_buffers 4 16k; #压缩缓冲区gzip_http_version 1.0; #压缩版本默认1.1前端如果是squid2.5请使用1.0gzip_comp_level 2; #压缩等级gzip_types text/plain application/x-javascript text/css application/xml; #压缩类型默认就已经包含textml所以下面就不用再写了写上去也不会有问题但是会有一个warn。gzip_vary on;#开启限制IP连接数的时候需要使用#limit_zone crawler $binary_remote_addr 10m;#tips:#upstream bakend{#定义负载均衡设备的Ip及设备状态}{# ip_hash;# server 127.0.0.1:9090 down;# server 127.0.0.1:8080 weight2;# server 127.0.0.1:6060;# server 127.0.0.1:7070 backup;#}#在需要使用负载均衡的server中增加 proxy_pass http://bakend/;server {listen 80;server_name 192.168.20.153;#charset koi8-r;# access_log /var/log/nginx/host.access.log main;access_log off;location / { auth_basic Kibana; #可以是string或off任意string表示开启认证off表示关闭认证。auth_basic_user_file /etc/nginx/passwd.db; #指定存储用户名和密码的认证文件。proxy_pass http://192.168.20.153:5601;proxy_set_header Host $host:5601; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Via nginx; }location /status { stub_status on; #开启网站监控状态 access_log /var/log/nginx/kibana_status.log; #监控日志 auth_basic NginxStatus; } location /head/{auth_basic head;auth_basic_user_file /etc/nginx/passwd.db;proxy_pass http://192.168.20.153:9100/;proxy_set_header Host $host:9100;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header Via nginx;} # redirect server error pages to the static page /50x.htmlerror_page 500 502 503 504 /50x.html;location /50x.html {root html;}}
}[rootelk ~]# yum install -y nginx httpd-tools
[rootelk ~]# htpasswd -cm /etc/nginx/passwd.db kibana
New password:
Re-type new password:
Adding password for user kibana
[rootelk ~]# htpasswd -m /etc/nginx/passwd.db head
New password:
Re-type new password:
Adding password for user head(3)启动nginx
[rootelk ~]# systemctl start nginxhttp://192.168.20.153/head/
六、Logstash部署
主机名IP地址系统版本配置Elk192.168.20.153centos7.5.18042核4G
1.安装配置Logstash
1安装
[rootelk ~]# tar -xf logstash-7.13.2-linux-x86_64.tar.gz -C /usr/local2配置
[rootelk ~]# cd /usr/local/logstash-7.13.2/
[rootelk logstash-7.13.2]# mkdir conf
[rootelk logstash-7.13.2]# cd conf
[rootelk conf]# vim input.conf
input {stdin {}
}
[rootelk conf]# vim output.conf
output {stdout {codec rubydebug}elasticsearch {hosts [192.168.20.153,192.168.20.157,192.168.20.159]index logstash-debug-%{YYYY-MM-dd}}
}启动
[rootelk logstash-7.13.2]# ./bin/logstash -f /usr/local/logstash-7.13.2/conf --config.reload.automatic
......
[2023-11-25T11:49:50,132][INFO ][logstash.agent ] Pipelines running {:count1, :running_pipelines[:main], :non_running_pipelines[]}
hello
{message hello,timestamp 2023-11-25T03:50:03.069Z,version 1,host elk
}
xiao
{message xiao,timestamp 2023-11-25T03:52:17.647Z,version 1,host elk
}
zhang
{message zhang,timestamp 2023-11-25T03:52:22.251Z,version 1,host elk}