ELK分布式框架作为现在大数据时代分析日志的常为大家使用。现在我们就记录下单机Centos7部署ELK的过程和遇到的问题。
系统要求:Centos7(内核3.5及以上,2核4G)
elk版本:6.2.4(较新版本)
jdk版本:1.8(必须为java1.8版本)
一、下载需要软件
1、ELK下载地址
https://www.elastic.co/downloads/past-releases
2、jdk下载地址
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
3、所需软件列表
#文件默认放到/opt目录下
jdk-8u131-linux-x64.tar.gz
elasticsearch-6.2.4.rpm
kibana-6.2.4-x86_64.rpm
logstash-6.2.4.rpm
二、 安装JAVA
1、解压
tar -zxvf jdk-8u131-linux-x64.tar.gz -C /usr/local/
ln -s /usr/local/jdk1.8.0_131/ /usr/local/jdk
2、配置环境
vim /etc/profile
#最后面添加以下配置文件
export JAVA_HOME=/usr/local/jdk
export JRE_HOME=$JAVA_HOME/jre
export PATH=$PATH:$JAVA_HOME/bin
3、验证结果
source /etc/profile
java -version
#检查结果:
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
三、部署elasticsearch
1、 rpm安装
cd /opt
rpm -ivh elasticsearch-6.2.4.rpm
创建用户
groupadd elasticsearch
useradd -g elasticsearch elasticsearch
2、修改elasticsearch配置文件
2.1 vim /etc/elasticsearch/elasticsearch.yml
[root@localhost elasticsearch]# cat elasticsearch.yml | grep -v "^#" | grep -v "^$"
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: "0.0.0.0"
http.port: 9200
2.2 vim /etc/elasticsearch/jvm.options(根据自己服务器配置修改)
-Xms512m
-Xmx512m
2.3 vim /etc/sysconfig/elasticsearch
JAVA_HOME=/usr/local/jdk
3、安装x-pack插件
cd /usr/share/elasticsearch/bin
./elasticsearch-plugin install x-pack
安装时间比较长,需耐心等待......
4、启动elasticsearch
systemctl start elasticsearch
5、检查启动情况
5.1 查看启动状态
systemctl status elasticsearch
5.2 查看启动日志
cd /var/log/elasticsearch/
tail -f elasticsearch.log
5.3 检查端口情况
netstat -lntp
6、通过x-pack设置密码
cd /usr/share/elasticsearch/bin/
x-pack/setup-passwords interactive
7、登陆测试
打开浏览器访问:http://10.244.78.230:9200
可以看到对话框,输入用户名和密码就可以。默认的用户名:elastic
访问成功!!!!
四、部署kibana
1、rpm安装
cd /opt
rpm -ivh kibana-6.2.4-x86_64.rpm
2、修改配置文件
[root@localhost bin]# cat /etc/kibana/kibana.yml | grep -v "^#" | grep -v "^$"
server.port: 5601
server.host: "10.244.78.230"
elasticsearch.url: "http://10.244.78.230:9200"
elasticsearch.username: "elastic"
elasticsearch.password: "123456"
3、安装x-pack插件
cd /usr/share/kibana/bin/
./kibana-plugin install x-pack
4、启动kibana
systemctl start kibana
5、访问测试(默认端口为5601)
五、部署logstash
1、rpm安装
cd /opt
rpm -ivh logstash-6.2.4.rpm
2、修改配置文件
mkdir -p /usr/share/logstash/config
cp /etc/logstash/log4j2.properties /usr/share/logstash/config
[root@localhost logstash]# cat /etc/logstash/logstash.yml | grep -v "^#" | grep -v "^$"
node.name: logstash
path.data: /var/lib/logstash
path.config: /etc/logstash/conf.d
config.test_and_exit: True
path.logs: /var/log/logstash
3、编写测试conf
一般放在/etc/logstash/conf.d目录下
[root@localhost conf.d]# cat test.conf
input {
stdin {
}
}
output {
elasticsearch {
hosts =>["10.244.78.230:9200"]
index => "test-%{+YYYY.MM.dd}"
user => elastic
password => "123456"
}
stdout {
codec => rubydebug
}
}
4、测试运行
/usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/test.conf(用来临时做测试用)
5、打开kibana查看
6、开启kibana
后期生产环境中,只需:
1、编写好conf文件
2、启动logstash即可,systemctl start logstash
7、kibana中x-pack认证问题
显示试用期为30天。预知如何增加时间,请看下回分解。
https://www.cnblogs.com/JeremyWYL/p/9482273.html