我写的这篇文档的时候,是临时安装的最新版本:7.8.1
kibana和es和被监控的nginx是三台机器
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && yum makecache
yum -y install epel-release && yum clean all && yum makecache
yum install lrzsz screen -y
systemctl stop firewalld && systemctl disable firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config && /usr/sbin/setenforce 0
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
vim /etc/sysctl.conf
vm.max_map_count=655360
sysctl -p
vim /etc/security/limits.conf
添加如下内容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 65535
* hard nproc 65535
[root@elk ~]# crontab -l
#update time
*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1
详细安装java参考https://www.cnblogs.com/sxdcgaq8080/p/7492426.html
yum install java -y
yum install java-1.8.0-openjdk* -y
rpm -ivh jdk-8u231-linux-x64.rpm
java -version
rpm -ivh elasticsearch-7.8.1.rpm
cat >/etc/elasticsearch/elasticsearch.yml <<EOF
#cluster.name : my-application #这里不需要开启
node.name: node-1
path.data: /data/elasticsearch
path.logs: /var/log/elasticsearch
bootstrap.memory_lock: true
network.host: 你的es地址,127.0.0.1
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
cluster.initial_master_nodes: ["node-1"]
EOF
第17行: 17 #cluster.name : my-application #集群名称
第23行: 23 #node.name : node-1 #节点名称
第33行: 33 #path.data : #数据存放路径
第37行: 37 #path.logs : #日志存放路径
第55行: 55 #network.host : #这个地址要修改为elasticsearch所在的地址
第59行: 59 #http.port : 9200 #通信端口
mkdir -p /data/elasticsearch
chown -R elasticsearch.elasticsearch /data/elasticsearch
sed -i "s/\-Xms1g/\-Xms2g/g" /etc/elasticsearch/jvm.options
sed -i "s/\-Xmx1g/\-Xmx2g/g" /etc/elasticsearch/jvm.options
mkdir /etc/systemd/system/elasticsearch.service.d
Ps:可以用curl -X GET "localhost:9200/_nodes?filter_path=**.mlockall" 来查看。如果"mlockall": false说明请求失败。日志里面还会有警告信息:memory locking requested for elasticsearch process but memory is not locked。可能是因为运行es的用户没有锁定内存的权限。
如果es是用tar或者zip包安装:
#ulimit -l unlimited,或者
#/etc/security/limits.conf添加
elasticsearch - nofile 65536
rpm包安装的:我们这里采用的此项
cat >/etc/systemd/system/elasticsearch.service.d/override.conf<<EOF
[Service]
LimitMEMLOCK=infinity
EOF
systemctl daemon-reload
systemctl enable elasticsearch.service --now
http://你的es地址:9200
已经成功访问,如果出现打不开请检查防火墙,安全组,使用netstat -tunlp查看端口情况
[root@elk ~]# rpm -ivh jdk-8u231-linux-x64.rpm
[root@elk ~]# rpm -ivh kibana-7.8.1-x86_64.rpm
[root@elk ~]# rpm -qc kibana
/etc/kibana/kibana.yml
[root@elk ~]# grep "^[a-Z]" /etc/kibana/kibana.yml
server.port: 5601
server.host: "kibana地址"
server.name: "elk"
elasticsearch.hosts: ["http://你的es地址:9200"]
kibana.index: ".kibana"
[root@kibana ~]# systemctl enable kibana.service --now
[root@elk ~]# netstat -tulnp | grep 5601
tcp 0 0 kibana地址:5601 0.0.0.0:* LISTEN 20501/node
http://你的kibana地址:5601
出现Kibana server is not ready yet,需要稍等片刻,因为启动非常慢,没有启动完成
cat >/etc/yum.repos.d/nginx.repo<<EOF
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/\$releasever/\$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF
yum clean all
yum makecache
yum -y install nginx httpd-tools
systemctl enable nginx --now && systemctl status nginx
rpm -ivh filebeat-7.8.1-x86_64.rpm
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
output.elasticsearch:
hosts: ["你的es地址:9200"]
systemctl enable filebeat.service --now
[root@nginx-1 ~]# ab -c 100 -n 100 http://你的本机nginx的ip/
[root@nginx-1 ~]# wc -l /var/log/nginx/access.log
100 /var/log/nginx/access.log
可以用命令查看es索引数据,也可以通过es-head图形化插件来查看
[root@es ~]#curl -X GET 'http://localhost:9200/_cat/indices?v'
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open .monitoring-kibana-7-2020.08.18 vRSBTqYSQ7igH3DR58mNQA 1 0 7340 0 1.4mb 1.4mb
green open .apm-custom-link Qsc0y6-UQc2ssBqsOgGWcA 1 0 0 0 208b 208b
green open .kibana_task_manager_1 RUjDClBaTl20JR7iGCjjGg 1 0 5 1 48.6kb 48.6kb
green open .apm-agent-configuration UI5JbkzkRo-rtbJEsguTGA 1 0 0 0 208b 208b
green open .monitoring-es-7-2020.08.18 r4Ka_-ErQmO6ltdZyMQlVg 1 0 88118 58680 33.4mb 33.4mb
green open .monitoring-es-7-2020.08.19 Zp9zD8siR2SS-xj8-wKPkA 1 0 10480 7440 5.4mb 5.4mb
green open .kibana_1 yCHKaAJ9TfquvKwj7mzDtQ 1 0 45 0 29.9kb 29.9kb
green open .kibana-event-log-7.8.1-000001 0E4zS4R8RK6BjyUZ_NkaSg 1 0 1 0 5.3kb 5.3kb
green open .monitoring-kibana-7-2020.08.19 sTN1T6zTS5aioCUKTudqKw 1 0 746 0 238.3kb 238.3kb
yellow open filebeat-7.8.1-2020.08.19-000001 1GzNvk4rQjWyW8eHVGMMQA 1 1 100 0 33.2kb 33.2kb