备案网站负责人,坪山区住房和建设局网站,网站开发专员绩效考核,深圳营销策划ansible部署 ELK部署 ELK常见架构
#xff08;1#xff09;ElasticsearchLogstashKibana#xff1a;这种架构是最常见的一种#xff0c;也是最简单的一种架构#xff0c;这种架构通过Logstash收集日志#xff0c;运用Elasticsearch分析日志#xff0c;最后通过Kibana中… ansible部署 ELK部署 ELK常见架构
1ElasticsearchLogstashKibana这种架构是最常见的一种也是最简单的一种架构这种架构通过Logstash收集日志运用Elasticsearch分析日志最后通过Kibana中展示日志信息。
Elasticsearch是一个开源分布式搜索引擎它提供存储、分析、搜索功能。有分布式、基于reasful风格、支持海量高并发的准实时搜索场景、稳定、可靠、快速、使用方便等特点。其作用是接收搜集海量结构化日志数据并提供给Kibana查询分析。Logstash是一个开源日志搜集、分析、过滤框架支持多种数据输入输出方式。 它用于收集日志对日志进行过滤形成结构化数据并转发到Elasticsearch中。Kibana是一个开源日志报表系统对Elasticsearch以及Logstash有良好的Web页面支持。它能对Elasticsearch提供的数据进行分析展示。
2ElasticsearchLogstashFilebeatKibana在这种架构中增加了一个Filebeat模块。这个模块在上面的内容中没有对它详细介绍它是一款轻量的日志收集代理用来部署在客户端中。这个服务较Logstash来说能够节省资源一般在生产环境中大多采用这种架构但是这种架构有一个弊端那就是当Logstash出现故障后会造成日志的丢失。
3ElasticsearchLogstashlebeatRedis及其他中间件Kibana这种架构等于是上面第二种的完善通过增加中间件避免数据丢失当Logstash出现故障后日志依旧留存在中间件内当Logstash再次启动则会读取中间件中积压的日志。在出现“too many open files”报错的时候大多数情况是由于程序没有正常关闭一些资源引起的所以出现这种情况时需要检查I/O读写、socket通讯等是否正常关闭等。当然也可以通过修改参数将系统的文件句柄限制提高来缓解这一压力。
ELK部署
系统环境VMware创建的centos7.9虚拟机
节点信息如下
节点IPansible192.168.200.80node1192.168.200.81node2192.168.200.82node3192.168.200.83
环境初始化
修改当前节点主机名为ansible并修改ansible节点主机映射命令如下
[rootlocalhost ~]# hostnamectl set-hostname ansible
[rootlocalhost ~]# bash
[rootansible ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.80 ansible
192.168.200.81 node1
192.168.200.81 node2
192.168.200.81 node3配置免密访问虚拟机root用户密码为000000命令如下
[rootansible ~]# ssh-keygen
[rootansible ~]# ssh-copy-id node1
[rootansible ~]# ssh-copy-id node2
[rootansible ~]# ssh-copy-id node3将ansible节点的域名解析文件复制给安装Elasticsearch集群服务的三个节点命令如下
[rootansible ~]# scp /etc/hosts node1:/etc/
[rootansible ~]# scp /etc/hosts node2:/etc/
[rootansible ~]# scp /etc/hosts node3:/etc/关闭ansible节点的防火墙和Selinux配置如已关闭则不需要操作命令如下 [rootansible ~]# setenforce 0软件包下载及uum源配置
修将提供的Elasticsearch、Kibana以及Logstash软件包下载至ansible节点/root目录下并将相应服务的软件包拷贝至不同节点。
[rootansible ~]# curl -O http://mirrors.douxuedu.com/competition/Ansible.tar.gz
[rootansible ~]# tar -zxvf Ansible.tar.gz将Elasticsearch软件包拷贝至三个节点将Kibana软件包拷贝至node1节点将Logstash软件包拷贝至node2节点命令如下
[rootansible ~]# scp elasticsearch-6.0.0.rpm node1:/root/
[rootansible ~]# scp elasticsearch-6.0.0.rpm node2:/root/
[rootansible ~]# scp elasticsearch-6.0.0.rpm node3:/root/
[rootansible ~]# scp kibana-6.0.0-x86_64.rpm node1:/root/
[rootansible ~]# scp kibana-6.0.0-x86_64.rpm node2:/root/
[rootansible ~]# scp kibana-6.0.0-x86_64.rpm node3:/root/
[rootansible ~]# scp logstash-6.0.0.rpm node1:/root/
[rootansible ~]# scp logstash-6.0.0.rpm node2:/root/
[rootansible ~]# scp logstash-6.0.0.rpm node3:/root/将软件包ansible.tar.gz上传至ansible节点配置本地yum源并安装Ansible
[rootansible ~]# tar -zxvf ansible.tar.gz -C /opt/
[rootansible ~]# mv /etc/yum.repos.d/* /media/
[rootansible ~]# vi /etc/yum.repos.d/local.repo
[ansible]
nameansible
baseurlfile:///opt/ansible
gpgcheck0
enabled1
[rootansible ~]# yum -y install ansible配置Ansible主机映射
[rootansible ~]# mkdir example
[rootansible ~]# cd example
[rootansible example]# vi /etc/ansible/hosts
[node1]
192.168.200.81
[node2]
192.168.200.82
[node3]
192.168.200.83使用CentOS-7-x86_64-DVD-2009.iso镜像文件作为仓库源将镜像挂载至/opt/centos编写yum源文件安装vsftpd服务用于给远程主机安装Java。命令如下
[rootansible example]# curl -O http://mirrors.douxuedu.com/competition/CentOS-7-x86_64-DVD-2009.iso
[rootansible example]# mkdir /opt/centos
[rootansible example]# mount CentOS-7-x86_64-DVD-2009.iso /opt/centos/
[rootansible example]# vi /etc/yum.repos.d/local.repo
[ansible]
nameansible
baseurlfile:///opt/ansible
gpgcheck0
enabled1
[centos]
namecentos
baseurlfile:///opt/centos
gpgcheck0
enabled1
[rootansible example]# yum install -y vsftpd
[rootansible example]# vi /etc/vsftpd/vsftpd.conf
anon_root/opt
[rootansible example]# systemctl restart vsftpd
[rootansible example]# vi ftp.repo
[centos]
namecentos
baseurlftp://192.168.200.80/centos/
gpgcheck0
enabled1安装Elasticsearch获取配置文件
安装Elasticsearch服务并编写node1节点配置文件命令如下
[rootansible example]# rpm -ivh /root/elasticsearch-6.0.0.rpm
[rootansible example]# cp -rf /etc/elasticsearch/elasticsearch.yml elk1.yml
[rootansible example]# cat elk1.yml | grep -Ev ^$|^#
cluster.name: ELK
node.name: node1
node.master: true
node.data: false
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 192.168.200.81
http.port: 9200
discovery.zen.ping.unicast.hosts: [node1,node2,node3]编写node2节点配置文件命令如下
[rootansible example]# cp elk1.yml elk2.yml
[rootansible example]# cat elk2.yml | grep -Ev ^$|^#
cluster.name: ELK
node.name: node2
node.master: false
node.data: true
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 192.168.200.82
http.port: 9200
discovery.zen.ping.unicast.hosts: [node1,node2,node3]编写node3节点配置文件命令如下
[rootansible example]# cp elk1.yml elk3.yml
[rootansible example]# cat elk3.yml | grep -Ev ^$|^#
cluster.name: ELK
node.name: node3
node.master: false
node.data: true
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 192.168.200.83
http.port: 9200
discovery.zen.ping.unicast.hosts: [node1,node2,node3]安装Kibana获取配置文件
安装Kibana服务并编写配置文件命令如下
[rootansible example]# rpm -ivh /root/kibana-6.0.0-x86_64.rpm
[rootansible example]# cp -rf /etc/kibana/kibana.yml .
[rootansible example]# cat kibana.yml |grep -v ^#
server.port: 5601
server.host: 192.168.200.81
elasticsearch.url: http://192.168.200.81:9200安装Logstash获取配置文件
安装Logstash服务并获取配置文件命令如下
[rootansible example]# rpm -ivh /root/logstash-6.0.0.rpm
[rootansible example]# cp -rf /etc/logstash/logstash.yml .
[rootansible example]# vi logstash.yml
http.host: 192.168.200.82新建日志输出文件内容如下
[rootansible example]# vi syslog.conf
input {file {path /var/log/messages type systemlog start_position beginningstat_interval 3}
}
output {if [type] systemlog {elasticsearch {hosts [192.168.200.81:9200] index system-log-%{YYYY.MM.dd}}}
}编写剧本文件
安编写Playbook剧本文件命令如下
[rootansible example]# vi cscc_install.yaml
- hosts: allremote_user: roottasks:- name: rm reposhell: rm -rf /etc/yum.repos.d/*- name: copy repocopy: srcftp.repo dest/etc/yum.repos.d/- name: install javashell: yum -y install java-1.8.0-*- name: install elkshell: rpm -ivh elasticsearch-6.0.0.rpm
- hosts: node1remote_user: roottasks:- name: copy configcopy: srcelk1.yml dest/etc/elasticsearch/elasticsearch.yml- name: daemon-reloadshell: systemctl daemon-reload- name: start elkshell: systemctl start elasticsearch systemctl enable elasticsearch- name: install kibanashell: rpm -ivh kibana-6.0.0-x86_64.rpm- name: copy configtemplate: srckibana.yml dest/etc/kibana/kibana.yml- name: start kibanashell: systemctl start kibana systemctl enable kibana
- hosts: node2remote_user: roottasks:- name: copy configcopy: srcelk2.yml dest/etc/elasticsearch/elasticsearch.yml- name: daemon-reloadshell: systemctl daemon-reload- name: start elkshell: systemctl start elasticsearch systemctl enable elasticsearch- name: install logstashshell: rpm -ivh logstash-6.0.0.rpm- name: copy configcopy: srclogstash.yml dest/etc/logstash/logstash.yml- name: copy configcopy: srcsyslog.conf dest/etc/logstash/conf.d/syslog.conf
- hosts: node3remote_user: roottasks:- name: copy configcopy: srcelk3.yml dest/etc/elasticsearch/elasticsearch.yml- name: daemon-reloadshell: systemctl daemon-reload- name: start elkshell: systemctl start elasticsearch systemctl enable elasticsearch执行Playbook完成ELK集群的部署命令如下
[rootansible example]# ansible-playbook cscc_install.yaml浏览器界面访问node1节点5601端口http://192.168.200.81:5601