[root@elk-node1 ~]# yum install -y java-1.8.0
[root@elk-node1 ~]# java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
[root@elk-node1 ~]# rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
[root@elk-node1 ~]# vim /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-5.x]
name=Elasticsearch repository for5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
[root@elk-node1 ~]# echo "192.168.217.131 elk-node1" >> /etc/hosts
[root@elk-node1 ~]# echo "192.168.217.132 elk-node1" >> /etc/hosts
[root@elk-node1 ~]# yum install elasticsearch -y
[root@elk-node1 ~]# systemctl daemon-reload
[root@elk-node1 ~]# systemctl enable elasticsearch.service //添加开机自启
[root@elk-node1 ~]# grep -v ^# /etc/elasticsearch/elasticsearch.yml
cluster.name: elk //集群名
node.name: elk-node-1 //节点名
path.data: /var/lib/elasticsearch //data存储路径
path.logs: /var/log/elasticsearch //log存储路径
network.host: 0.0.0.0 //监听地址
http.port: 9200 //监听端口
discovery.zen.ping.unicast.hosts: ["192.168.217.131", "192.168.217.132"] //集群节点发现列表
discovery.zen.minimum_master_nodes: 2 //集群可做master的最小节点数
http.cors.enabled: true
http.cors.allow-origin: "*"
[root@elk-node1 ~]# wget https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar
[root@elk-node1 ~]# tar -xvf node-v6.9.5-linux-x64.tar -C /usr/local/
[root@elk-node1 ~]# ln -s node-v6.9.5-linux-x64/bin/node /usr/bin/node
[root@elk-node1 ~]# ln -s node-v6.9.5-linux-x64/bin/npm /usr/bin/npm
[root@elk-node1 ~]# node -v
v6.9.5
[root@elk-node1 ~]# npm -v
3.10.10
[root@elk-node1 ~]# npm install -g grunt-cli
[root@elk-node1 ~]# ln -s node-v6.9.5-linux-x64/lib/node_modules/grunt-cli/bin/grunt /usr/bin/grunt
[root@elk-node1 ~]# cd /var/lib/elasticsearch
[root@elk-node1 elasticsearch]# yum install -y git
[root@elk-node1 elasticsearch]# git clone git://github.com/mobz/elasticsearch-head.git
[root@elk-node1 elasticsearch]# chown -R elasticsearch:elasticsearch elasticsearch-head/
[root@elk-node1 elasticsearch]# cd /var/lib/elasticsearch/elasticsearch-head/
[root@elk-node1 elasticsearch-head]# npm install
[root@elk-node1 elasticsearch-head]# cd /var/lib/elasticsearch/elasticsearch-head/_site/
[root@elk-node1 _site]# cp app.js app.js.bak
[root@elk-node1 _site]# vim app.js
init: function(parent) {
this._super();
this.prefs = services.Preferences.instance();
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://192.168.217.131:9200"; //修改4328行
[root@elk-node1 _site]# cd /var/lib/elasticsearch/elasticsearch-head/
[root@elk-node1 elasticsearch-head]# cp Gruntfile.js Gruntfile.js.bak
[root@elk-node1 elasticsearch-head]# vim Gruntfile.js
connect: {
server: {
options: {
hostname: "0.0.0.0", //添加这一行
port: 9100,
base: '.',
keepalive: true
}
}
}
[root@elk-node1 elasticsearch-head]# systemctl start elasticsearch.service
[root@elk-node1 elasticsearch-head]# grunt server &
[root@elk-node1 elasticsearch-head]# netstat -anplut //检查9200,9300,9100端口
访问http://192.168.217.131:9200/进行验证
访问http://192.168.217.131:9100/进行验证
没安装logstash和kibana时,划红线部分是空白。
[root@elk-node1 ~]# yum isntall -y logstash
[root@elk-node1 ~]# cd /etc/logstash/
[root@elk-node1 logstash]# grep -v "#" logstash.yml
path.data: /var/lib/logstash
path.config: /etc/logstash/conf.d
path.logs: /var/log/logstash
[root@elk-node1 logstash]# cd /etc/logstash/conf.d/
[root@elk-node1 conf.d]# vim messages.conf
input {
file {
path => "/var/log/messages"
}
}
output {
elasticsearch {
hosts => ["192.168.217.131:9200","192.168.217.132:9200"]
index => "messages-%{+YYYY.MM.dd}"
}
stdout {
# codec => rubydebug
}
}
[root@elk-node1 conf.d]# cd ..
[root@elk-node1 logstash]# chown -R logstash:logstash conf.d/
[root@elk-node1 logstash]# chmod 644 /var/log/messages
1)启动测试
[root@elk-node1 logstash]# cd /usr/share/logstash/
[root@elk-node1 logstash]# bin/logstash -e 'input { stdin { } } output { stdout {} }'
WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults
Could not find log4j2 configuration at path /usr/share/logstash/config/log4j2.properties. Using default config which logs to console
[root@elk-node1 logstash]# mkdir -p /usr/share/logstash/config/
[root@elk-node1 logstash]# ln -s /etc/logstash/* /usr/share/logstash/config
[root@elk-node1 logstash]# chown -R logstash:logstash /usr/share/logstash/config/
[root@elk-node1 logstash]# bin/logstash -e 'input { stdin { } } output { stdout {} }'
2)启动logstash并验证
[root@elk-node1 ~]#
systemctl start logstash
[root@elk-node1 ~]# systemctl enable logstash.service
Created symlink from /etc/systemd/system/multi-user.target.wants/logstash.service to /etc/systemd/system/logstash.service.
[root@elk-node1 ~]# netstat -anplut
//查看9600端口
访问http://192.168.217.131:9100/
[root@elk-node1 ~]# yum install -y kinaba
[root@elk-node1 ~]# cd /etc/kibana
[root@elk-node1 kibana]# grep -v ^# /etc/kibana/kibana.yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: "http://192.168.217.131:9200"
[root@elk-node1 kibana]# systemctl start kibana
[root@elk-node1 kibana]# netstat -anplut |grep :5601
tcp 0 0 0.0.0.0:5601 0.0.0.0:* LISTEN 4335/node
访问http://192.168.217.131:5601/
在红线部分添加messages-*,然后点击Discover,如果不能显示图形,请把时间选择一小时或更长。