实验前夕
systemctl stop firewalld.service //关闭防火墙
systemctl status firewalld.service //查看防火墙状态
setenforce 0 // 关闭安全系统
一,安装部署 1.环境部署 node1 ; 192.168.189.14 Elasticsearch/Kibana node2 ; 192.168.189.15 Elasticsearch apache; 192.168.189.16 httpd / Logstash 客户机 win10 3.更改主机名 hostnamectl set-hostname +主机名 4.配置elasticsearch 环境 node1 nede2 配置
echo '192.168.189.14 node1' >> /etc/hosts
echo '192.168.189.15 node2' >> /etc/hosts
cat /etc/hosts
5.安装elasticsearch软件 node1 node2
cd /opt
rpm -ivh elasticsearch-5.5.0.rpm
二,加载系统服务 systemctl daemon-reload systemctl enable elasticsearch.service
1.更改elasticsearch参数配置
cp /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml.bak
2.vim /etc/elasticsearch/elasticsearch.yml
cluster.name: my-elk-cluster
node.name: node1
path.data: /data/elk_data
path.logs: /var/log/elasticsearch
bootstrap.memory_lock: false
network.host: 0.0.0.0
http.port: 9200
discovery.zen.ping.unicast.hosts: ["node1", "node2"]
3.检验配置
grep -v "^#" /etc/elasticsearch/elasticsearch.yml
4.创建数据存放路径并授权
mkdir -p /data/elk_data
chown elasticsearch:elasticsearch /data/elk_data/
5.启动一下
systemctl start elasticsearch
6.查看一下
netstat -antp | grep 9200
7.查看节点信息
http://192.168.189.14:9200
http://192.168.189.15:9200
8.检验集群健康状态
http://192.168.189.14:9200/_cluster/health?pretty
http://192.168.189.15:9200/_cluster/health?pretty
9.查看集群状态
http://192.168.189.14:9200/_cluster/state?pretty
http://192.168.189.15:9200/_cluster/state?pretty
三,安装elasticsearch-head插件
node1 node 2 1.编译安装node组件依赖包
yum -y install gcc gcc-c++ make
cd /opt
tar xzvf node-v8.2.1.tar.gz
cd node-v8.2.1/
./configure && make && make install
2.安装安装phantomjs 前端框架 node1 node2
cd /opt
tar jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /usr/local/src/
cd /usr/local/src/phantomjs-2.1.1-linux-x86_64/bin
cp phantomjs /usr/local/bin
3.安装elasticsearch-head 数据可视化工具 node1 node2
cd /opt
tar zxvf elasticsearch-head.tar.gz -C /usr/local/src/
cd /usr/local/src/elasticsearch-head/
npm install
4.修改主机配置文件 node1 node2
vim /etc/elasticsearch/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
systemctl restart elasticsearch.service
5.启动elasticsearch-head node1 node2
在 elasticsearch-head 目录下启动服务
cd /usr/local/src/elasticsearch-head/
npm run start &
netstat -natp |grep 9100
6.使用elasticsearch-head插件查看集群状态
http://192.168.189.14:9100
在Elasticsearch 后面的栏目中输入
http://192.168.189.15:9200
http://192.168.189.15:9100
在Elasticsearch 后面的栏目中输入
http://192.168.189.14:9200
7.创建索引 node1
创建索引为index-demo,类型为test
curl -XPUT 'localhost:9200/index-demo/test/1?pretty&pret
查看数据浏览–会发现在node1上创建的索引为index-demo,类型为test, 相关的信息 8…安装logstash 收集日志输出到elasticsearch中 安装Apahce服务(httpd) apache
yum -y install httpd
systemctl start httpd
9.安装logstash apache
cd /opt
rpm -ivh logstash-5.5.1.rpm
systemctl start logstash.service
systemctl enable logstash.service
ln -s /usr/share/logstash/bin/logstash /usr/local/bin/
10.测试logstash命令 apache
logstash -e 'input { stdin{ } } output { stdout { } }'
使用rubydebug显示详细输出,codec为一种编解码器
logstash -e 'input { stdin{} } output { stdout{ codec=>rubydebug} }'
使用logstash将信息写入elasticsearch中,并查看
logstash -e 'input { stdin{} } output { elasticsearch { hosts=> ["192.168.35.40:9200"] } }'
11.使用平台收集日志
chmod o+r /var/log/messages
vim /etc/logstash/conf.d/system.conf
input {
file{
path => "/var/log/messages"
type => "system"
start_position => "beginning"
}
}
output {
elasticsearch {
hosts => ["192.168.189.14:9200"]
index => "system-%{+YYYY.MM.dd}"
}
}
systemctl restart logstash.service
四,安装kibana node1
上传kibana-5.5.1-x86_64.rpm到/usr/local/src目录
cd /usr/local/src
rpm -ivh kibana-5.5.1-x86_64.rpm
cd /etc/kibana/
cp kibana.yml kibana.yml.bak
vim kibana.yml
2 server.port: 5601
7 server.host: "0.0.0.0“ ##kibana侦听的地址
21 elasticsearch.url: "http://192.168.189.14:9200" ##和elasticsearch建立联系
30 kibana.index: ".kibana"
systemctl start kibana.service
访问5601端口:http://192.168.189.14:5601/
2.对接apache的日志(访问的、错误)
apache
cd /etc/logstash/conf.d/
vim apache_log.conf
input {
file{
path => "/etc/httpd/logs/access_log"
type => "access"
start_position => "beginning"
}
file{
path => "/etc/httpd/logs/error_log"
type => "error"
start_position => "beginning"
}
}
output {
if [type] == "access" {
elasticsearch {
hosts => ["192.168.189.14:9200"]
index => "apache_access-%{+YYYY.MM.dd}"
}
}
if [type] == "error" {
elasticsearch {
hosts => ["192.168.189.14:9200"]
index => "apache_error-%{+YYYY.MM.dd}"
}
}
}
进入kibana进入创建Apache索引appche_acess和apache_error 首页Management–Index Patterns–Create Index Pattern–选择inde name or pattern 验证索引
|