想了解ELK,从安装开始吧,本文档着重介绍以RPM的方式安装JAVA与ELK相关组件,操作系统为CentOS 7。
JAVA 11 RPM安装
前置条件-JAVA环境安装(必须)
大部分安装失败的情况多为JAVA环境缺失,所以JAVA安装必不可少。
- 检查openjdk版本,需要jdk11的版本
rpm -qa | grep jdk
- 卸载相关其他版本
rpm -e --nodeps java-x.x.x-openjdk-headless-1.7.0.111-2.6.7.2.el7_2.x86_64
- 再次检查openjdk所有版本是否卸载完毕
rpm -qa | grep jdk
- 查询JAVA RPM安装包(版本11)
yum search java-11 | grep -i --color JDK
- 安装JAVA RPM包
yum install -y java-11-openjdk.x86_64 java-11-openjdk-devel.x86_64
- 查看JAVA rpm包安装目录
ls -l /usr/lib/jvm
- 设置环境变量(一次性生效,仅针对当前用户)
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.3.7-0.el7_6.x86_64
- 设置环境变量(永久生效针对系统所有用户)
vim /etc/profile
- 在末尾添加(重点是:JAVA_HOME目录设置正确)
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.3.7-0.el7_6.x86_64
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
- 使profile配置文件生效
source /etc/profile
- 验证java是否安装成功
java --version
openjdk 11.0.1 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)
a. echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk-11.0.3.7-0.el7_6.x86_64
b. echo $CLASSPATH
.:/usr/lib/jvm/java-11-openjdk-11.0.3.7-0.el7_6.x86_64/lib/dt.jar:/usr/lib/jvm/java-11-openjdk-11.0.3.7-0.el7_6.x86_64/lib/tools.jar
c. echo $PATH
/root/.py3/bin:/usr/lib/jvm/java-11-openjdk-11.0.3.7-0.el7_6.x86_64/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/opennms/bin:/root/bin
ELK组件安装
1、导入官网秘钥
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
2、向elasticsearch.repo文件添加安装所需内容
(这里安装7.x是软件版,7.x为目前最新,如有需要可更改其他老版本如:6.x)
cat>/etc/yum.repos.d/elasticsearch.repo<<EOF
[elasticsearch-7.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF
4、清除yum缓存
yum clean all
5、安装elasticsearch logstash kibana三个组件
yum install elasticsearch logstash kibana -y
6、配置文件存放目录
cd /etc/logstash/
cp logstash-sample1.conf logstash.conf
7、启用服务
systemctl start logstash
systemctl start elasticsearch
systemctl start kibana