ELK是elasticsearch、logstash、kibana、filebeat等一套软件的集合,通过这套软件可以在企业服务器搭建日志搜集系统。
下载elasticsearch、logstash、kibana三个软件安装包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.3.tar.gz
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.5.3-linux-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/logstash/logstash-6.5.3.tar.gz
解压安装包
tar -zxvf elasticsearch-6.5.3.tar.gz -C /usr/local/bin
配置master主机上的elasticsearch,vim /etc/elasticsearch/elasticsearch.yml
cluster.name: es-cluster # 集群中的名称
node.name: master-node # 该节点名称
node.master: true # 意思是该节点为主节点
node.data: false # 表示这不是数据节点
network.host: 192.168.134.129
http.port: 9200 # es服务的端口号
discovery.zen.ping.unicast.hosts: ["192.168.134.129", "192.168.134.130"]
配置slave主机上的elasticsearch,vim /etc/elasticsearch/elasticsearch.yml
cluster.name: es-cluster
node.name: data-node1
node.master: false
node.data: true
network.host: 192.168.134.130
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.168.134.129", "192.168.134.130"]
先启动主节点上,再依次启动其他节点
elasticsearch可能出现的错误:
【ERROR】max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
【ERROR】max number of threads [1024] for user [hadoop] is too low, increase to at least [2048]
【ERROR】max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
编辑系统配置文件,vim /etc/security/limits.conf
添加
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
vim /etc/security/limits.d/20-nproc.conf,添加
* soft nproc 4096
root soft nproc unlimited
vim /etc/sysctl.conf,添加
vm.max_map_count=655360
加载配置,sysctl -p
查看es集群情况,curl '192.168.134.129:9200/_cluster/health?pretty'
status为green则代表健康没问题,如果是yellow或者red则是集群有问题。
查看集群的详细信息:curl '192.168.134.129:9200/_cluster/state?pretty'
安装kibana
添加kibana配置文件
server.port: 5601 # 配置kibana的端口
server.host: 192.168.77.128 # 配置监听ip
elasticsearch.url: "http://192.168.77.128:9200"
logging.dest: /var/log/kibana.log
创建日志文件:
[root@master-node ~]# touch /var/log/kibana.log; chmod 777 /var/log/kibana.log
启动kibana服务,并检查进程和监听端口:
[root@master-node ~]# systemctl start kibana
[root@master-node ~]# ps aux |grep kibana
kibana 3083 36.8 2.9 1118668 112352 ? Ssl 17:14 0:03 /usr/share/kibana/bin/../node/bin/node --no-warnings /usr/share/kibana/bin/../src/cli -c /etc/kibana/kibana.yml
root 3095 0.0 0.0 112660 964 pts/0 S+ 17:14 0:00 grep --color=auto kibana
[root@master-node ~]# netstat -lntp |grep 5601
tcp 0 0 192.168.77.128:5601 0.0.0.0:* LISTEN 3083/node
[root@master-node ~]#
注:由于kibana是使用node.js开发的,所以进程名称为node
然后在浏览器里进行访问,如:http://192.168.77.128:5601/ ,由于我们并没有安装x-pack,所以此时是没有用户名和密码的,可以直接访问的:
到此我们的kibana就安装完成了,很简单,接下来就是安装logstash,不然kibana是没法用的。