三大组件之间的关系
Logstash(收集服务器上的日志文件)
保存到 ElasticSearch(搜索引擎)
Kibana提供友好的web界面(从ElasticSearch读取数据进行展示)
Centos7.5环境
解压
mkdir /usr/local/java
tar -zxf jdk-8u181-linux-x64.tar.gz -C /usr/local/java/
配置java环境
Vi /etc/profile
追加如下内容
export JAVA_HOME=/usr/local/java/jdk1.8.0_181
export PATH=
PATH:
P
A
T
H
:
JAVA_HOME/bin
export CLASSPATH=.:
JAVAHOME/lib/tools.jar:
J
A
V
A
H
O
M
E
/
l
i
b
/
t
o
o
l
s
.
j
a
r
:
JAVA_HOME/lib/dt.jar:$CLASSPATH
source /etc/profile
验证jdk配置成功
Java -version
下载elasticsearch
wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.4.0/elasticsearch-2.4.0.tar.gz
解压
tar -xzvf elasticsearch-2.4.0.tar.gz
cd elasticsearch-2.4.0
vi config/elasticsearch.yml
配置用户和目录
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
chown -R elsearch:elsearch elasticsearch-2.4.0
mkdir /data/es
mkdir /data/logs/es
chown -R elsearch:elsearch /data/es
chown -R elsearch:elsearch /data/logs/es
也配置来实现root用户启动
修改bin目录elasticsearch.in.sh文件中追加(不过不建议)
JAVA_OPTS=”$JAVA_OPTS -Des.insecure.allow.root=true”
bin/elasticsearch -d(后台运行)
通过浏览器访问:
下载群集管理elastichsearch-head
rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
curl –silent –location https://rpm.nodesource.com/setup_5.x | bash -
yum -y install nodejs
um install git npm # npm在epel源中
git clone https://github.com/mobz/elasticsearch-head.git # 安装过程需要连接互联网
cd elasticsearch-head # git clone后会自动生成的一个目录
npm install
npm run start
现在集群健康状态哪里显示未连接,这是因为head插件没有权限获取集群节点的信息,接下来设置权限
vi /etc/elasticsearch/elasticsearch.yml
http.cors.enabled: true # elasticsearch中启用CORS
http.cors.allow-origin: “” # 允许访问的IP地址段, 为所有IP都可以访问
测试
curl -XPUT ‘172.18.68.11:9100/book’
再次通过浏览器打开,填入已经授权节(上面的两行配置)点IP地址,点击链接,就可以看到集群健康信息与测试索引的分片信息。
下载logstash
wget https://download.elastic.co/logstash/logstash/logstash-2.4.0.tar.gz
解压
tar -xzvf logstash-2.4.0.tar.gz
Cd logstash-2.4.0
创建logstash测试配置文件:vi test.conf
input {
file {
path => [“/var/opt/log/a.log”,”/var/opt/log/b.log”]
}
}
output {
elasticsearch { hosts => [“localhost:9200”] }
stdout { codec => rubydebug }
}
input{file{…}}部分指定的是日志文件的位置(可以多个文件)
output部分则是表示将日志文件的内容保存到elasticsearch,这里hosts对应的是一个数组,可以设置多个elasticsearch主机,相当于一份日志文件的内容,可以保存到多个elasticsearch中。
启动logstash
bin/logstash -f test.conf
在日志/var/opt/log/a.log中写入一点文件
会有如下输出,表示成功:
下载kibana
wget https://download.elastic.co/kibana/kibana/kibana-4.6.1-linux-x86_64.tar.gz
tar -zxf kibana-4.6.1-linux-x86_64.tar.gz
vi config/kibana.yml
将url改为当前服务器的地址
elasticsearch.url: “http://localhost:9200”
启动
nohup bin/kibana &(后台运行)