ELK Elasticsearch 集群部署

ELK Elasticsearch 集群部署

数据流向:1、后台服务器产生的日志由filebeat收集通过logstasg进行标准化处理,传输给es1、es2(两个是一个主备的关系,数据都是一致的),然后传输给可视化设备。

有了flebeat可以节省资源,可以通过filebeat和logstash实现远程数据收集。

filereat不能对数据进行标准输出,不能输出为ES格式的数据,所以需要logstasg把filebeat数据做标准化处理

less 复制代码
192.168.11.150  ELK1  node1 (es1) 设置Java环境、部署 Elasticsearch、 Elasticsearch-head、node、 phantomjs
192.168.11.151  ELK2  node2 (es2) 设置Java环境、部署 Elasticsearch、 Elasticsearch-head、node、 phantomjs
192.168.11.152  ELK3  部署     kibana-6.7.2-x86_64.rpm  logstash-6.7.2.rpm
192.168.11.144  后台服务器     Apache、MySQL、Nginx、部署Logstash    

E LK1 ELK2 部署

less 复制代码
1.环境准备
#设置Java环境
java -version								#如果没有安装,yum -y install java

2.部署 Elasticsearch 软件
(1)安装elasticsearch---rpm包
#上传elasticsearch-6.7.2.rpm到/opt目录下
cd /opt
rpm -ivh elasticsearch-6.7.2.rpm

(2)修改elasticsearch主配置文件
cp /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml.bak
vim /etc/elasticsearch/elasticsearch.yml
--17--取消注释,指定集群名字
cluster.name: my-elk-cluster
--23--取消注释,指定节点名字:Node1节点为node1,Node2节点为node2
node.name: node1
node.master: true		#是否master节点,false为否
node.data: true			#是否数据节点,false为否
--34--取消注释,指定数据存放路径
path.data: /var/lib/elasticsearch
--38--取消注释,指定日志存放路径
path.logs: /var/log/elasticsearch
--43--注释,避免es使用swap交换分区,可以不注释
# bootstrap.memory_lock: true
--55--取消注释,设置监听地址,0.0.0.0代表所有地址
network.host: 0.0.0.0
--59--取消注释,ES 服务的默认监听端口为9200
http.port: 9200					#指定es集群提供外部访问的接口
transport.tcp.port: 9300		#指定es集群内部通信接口
--68--取消注释,集群发现通过单播实现,指定要发现的节点
discovery.zen.ping.unicast.hosts: ["192.168.11.150:9300", "192.168.11.151:9300"]
 91 http.cors.enabled: true
 92 http.cors.allow-origin: "*"

grep -v "^#" /etc/elasticsearch/elasticsearch.yml 

(3)启动elasticsearch是否成功开启
systemctl start elasticsearch.service
systemctl enable elasticsearch.service
netstat -antp | grep 9200

(5)查看节点信息
浏览器访问  http://192.168.11.150:9200  、 http://192.168.11.151:9200 查看节点 Node1、Node2 的信息。
浏览器访问 http://192.168.11.150:9200/_cluster/health?pretty  、 http://192.168.11.150:9200/_cluster/health?pretty查看群集的健康情况,可以看到 status 值为 green(绿色), 表示节点健康运行。
浏览器访问 http://192.168.11.150:9200/_cluster/state?pretty  检查群集状态信息。


3.安装 Elasticsearch-head 插件
(1)编译安装 node
#上传软件包 node-v8.2.1.tar.gz 到/opt
yum install gcc gcc-c++ make -y
cd /opt
tar zxvf node-v8.2.1.tar.gz

cd node-v8.2.1/
./configure
make -j 4 && make install

(2)安装 phantomjs
#上传软件包 phantomjs-2.1.1-linux-x86_64.tar.bz2 到
cd /opt
tar jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2
cd /opt/phantomjs-2.1.1-linux-x86_64/bin
cp phantomjs /usr/local/bin

(3)安装 Elasticsearch-head 数据可视化工具
#上传软件包 elasticsearch-head-master.zip 到/opt
cd /opt
unzip elasticsearch-head-master.zip
cd elasticsearch-head-master/

#速度慢,可以指定为淘宝镜像
npm config set registry http://registry.npm.taobao.org/  
npm install

(4)修改 Elasticsearch 主配置文件
vim /etc/elasticsearch/elasticsearch.yml

--末尾添加以下内容--
http.cors.enabled: true				#开启跨域访问支持,默认为 false
http.cors.allow-origin: "*"			#指定跨域访问允许的域名地址为所有
systemctl restart elasticsearch

(5) 启动 elasticsearch-head 服务
#必须在解压后的 elasticsearch-head 目录下启动服务,进程会读取该目录下的 gruntfile.js 文件,否则可能启动失败。
cd /opt/elasticsearch-head-master
npm run start &
netstat -natp |grep 9100

ELK3 日志收集装置部署

有了flebeat可以节省资源,可以通过filebeat和logstash实现远程数据收集。

filereat不能对数据进行标准输出,不能输出为ES格式的数据,所以需要logstasg把filebeat数据做标准化处理

LESS 复制代码
1.更改主机名
hostnamectl set-hostname ELK3
bash
2.安装Apahce服务(httpd)
yum -y install httpd
systemctl start httpd

3.安装Java环境
yum -y install java
java -version

4.安装logstash
#上传软件包 logstash-6.7.2.rpm 到/opt目录下
cd /opt
rpm -ivh logstash-6.7.2.rpm                          
systemctl start logstash.service                      
systemctl enable logstash.service

ln -s /usr/share/logstash/bin/logstash /usr/local/bin/

logstash -e 'input { stdin{} } output { stdout{} }'
logstash -e 'input { stdin{} } output { stdout{ codec=>rubydebug } }'

logstash -e 'input { stdin{} } output { elasticsearch { hosts=>["192.168.11.150:9200","192.168.11.151:9200"] } }'  --path.data /opt/test1

ELK3 日志可视化部署

less 复制代码
[root@apache-elk3 opt]#cd /opt/
[root@apache-elk3 opt]#rpm -ivh kibana-6.7.2-x86_64.rpm  
[root@apache-elk3 conf.d]# vim /etc/kibana/kibana.yml
 2 server.port: 5601
 7 server.host: "0.0.0.0"
 28 elasticsearch.hosts: ["http://192.168.11.150:9200","http://192.168.11.151:9200"]
指向ELK1  ELK2   
 37 kibana.index: ".kibana"
 96 logging.dest: /var/log/kibana.log
 113 i18n.locale: "zh-CN"
[root@apache-elk3 opt]#  systemctl restart kibana.service 
[root@apache-elk3 opt]#  systemctl enable  kibana.service 
[root@apache-elk3 opt]#  netstat -antp | grep 5601
[root@apache-elk3 opt]# chmod 777 /var/log/messages

浏览器访问:192.168.11.152:5601

#配置接收日志脚本
cd /etc/logstash/conf.d
vim xhg.conf 

input {
   beats { port => "5046"}
}

output {
         if "nginx" in [tags] {

        elasticsearch {
               hosts => ["192.168.11.150:9200","192.168.11.151:9200"]
               index=> "%{[fields][service_name]}-%{+YYYY.MM.dd}"
          }
        }
      if "httpd" in [tags] {
               elasticsearch {
               hosts => ["192.168.11.150:9200","192.168.11.151:9200"]
               index => "%{[fields][service_name]}-%{+YYYY.MM.dd}"
          }
}
       if "mysql" in [tags] {
           elasticsearch {
               hosts=>["192.168.11.150:9200","192.168.11.151:9200"]
              index=> "%{[fields][service_name]}-%{+YYYY.MM.dd}"
          }
       }
}

logstash -f xhg.conf --path.data /opt/test9 &   #先执行

主机配置1

主机有Apache、httpd、nginx服务,将三个服务产生的日志通过ELK3收集,过滤、分析、汇总、再以标准格式输出到ELK1、ELK2,通过kiabana可视化进行查看

有了flebeat可以节省资源,可以通过filebeat和logstash实现远程数据收集。

filereat不能对数据进行标准输出,不能输出为ES格式的数据,所以需要logstasg把filebeat数据做标准化处理

less 复制代码
yum install -y httpd
yum install -y nginx
yum install -y mysqld   (可以编译安装)
-------------------------------确定每个服务的日志保存的绝对路径-----------------------------------------
find / -name  nginx
find / -name  http   #查找日志路径
mysql日志路径: general_log_file=/usr/local/mysql/data/mysql_general.log
nginx 日志路径:     - /usr/local/nginx/logs/access.log
                    - /usr/local/nginx/logs/error.log
httpd日志路径: /var/log/httpd/access_log
               /var/log/httpd/access_log

#############注意: http服务和nginx服务所使用的端口都是80端口需要修改其中一个端口的使用##############
########修改nginx端口信息改成8888##########
[root@myslq4 nginx]# vim /etc/nginx/nginx.conf
 38     server {
 39         listen       8888;
 40         listen       [::]:8888;
 41         server_name  _;
 42         root         /usr/share/nginx/html;
 [root@myslq4 nginx]# netstat -antp | grep nginx
tcp        0      0 0.0.0.0:8888            0.0.0.0:*               LISTEN      30416/nginx: master 
tcp6       0      0 :::8888                 :::*                    LISTEN      30416/nginx: master 

主机上配置日志收集

less 复制代码
1.更改主机名
hostnamectl set-hostname 后台服务器

2.安装Apahce服务(httpd)
yum -y install httpd
systemctl start httpd

3.安装Java环境
yum -y install java
java -version

4.安装logstash
#上传软件包 logstash-6.7.2.rpm 到/opt目录下
cd /opt
rpm -ivh logstash-6.7.2.rpm                          
systemctl start logstash.service                      
systemctl enable logstash.service

ln -s /usr/share/logstash/bin/logstash /usr/local/bin/

#可以指定logstash的工作目录,默认为:/etc/logstash/conf.d
path.config: /opt/log

cd /opt
tar -xf filebeat-6.7.2-linux-x86_64.tar.gz 
mv filebeat-6.7.2-linux-x86_64 /usr/local/filebeat
cd /usr/local/filebeat/
cp filebeat.yml filebeat.yml.bak
[root@myslq4 filebeat]# pwd
/usr/local/filebeat
[root@myslq4 filebeat]# vim filebeat.yml
- type: log
  enabled: true
  paths:
    - /usr/local/nginx/logs/access.log
    - /usr/local/nginx/logs/error.log
  tags: ["nginx"]
  fields:
    service_name: 192.168.11.144_nginx
    log_type: nginx
    from: 192.168.11.144

- type: log
  enabled: true
  paths:
    - /var/log/httpd/access_log
    - /var/log/httpd/access_log

  tags: ["httpd"]
  fields:
    service_name: 192.168.11.144_httpd
    log_type: httpd
    from: 192.168.11.144


- type: log
  enabled: true
  paths:
    - /usr/local/mysql/data/mysql_general.log
  tags: ["mysql"]
  fields:
    service_name: 192.168.11.144_mysql
    log_type: mysql
    from: 192.168.11.144


 95 filebeat.config.modules:
 96   # Glob pattern for configuration loading
 97   path: ${path.config}/modules.d/*.yml
 99   # Set to true to enable config reloading
 100   reload.enabled: false
 107   setup.template.settings:
 108   index.number_of_shards: 3
 188   output.logstash:
 189   # The Logstash hosts
 190   hosts: ["192.168.11.152:5046"]

nohup ./filebeat -e -c filebeat.yml > filebeat.out &
tail -f filebeat.out 

t to true to enable config reloading

100 reload.enabled: false

107 setup.template.settings:

108 index.number_of_shards: 3

188 output.logstash:

189 # The Logstash hosts

190 hosts: ["192.168.11.152:5046"]

nohup ./filebeat -e -c filebeat.yml > filebeat.out &

tail -f filebeat.out

复制代码
相关推荐
Lill_bin2 小时前
报表生成---JFreeChart
docker·信息可视化·zookeeper·云原生·容器·jenkins
铭毅天下8 小时前
深入解密 Elasticsearch 查询优化:巧用 Profile 工具/API 提升性能
java·大数据·elasticsearch·搜索引擎·mybatis
码农小伙8 小时前
Elasticsearch之原理详解
大数据·elasticsearch·搜索引擎
Elastic 中国社区官方博客10 小时前
GenAI 用于客户支持 — 第 4 部分:调整 RAG 搜索的相关性
大数据·人工智能·elasticsearch·搜索引擎·ai·机器人·全文检索
雨声不在14 小时前
在jenkins中获取git的修改记录的方法
git·jenkins
微学AI15 小时前
内网穿透的应用-本地化部署Elasticsearch平替工具OpenObserve并实现无公网IP远程分析数据
大数据·tcp/ip·elasticsearch
wang090720 小时前
netty编程之整合es实现存储以及搜索功能
大数据·elasticsearch·搜索引擎·netty
WalsonTung21 小时前
Elasticsearch客户端Kibana使用说明
大数据·elasticsearch·搜索引擎
‍。。。1 天前
git如何设置嵌套仓库(设置子树或子模块),并解决直接将一个仓库拖拽到另一个仓库中导致的问题
大数据·git·elasticsearch
lgbisha1 天前
828华为云征文|华为云Flexus X实例docker部署jdk21最新版jenkins搭建自己的devops服务器
docker·华为云·jenkins