使用kubernetes的日志收集,需要使用ELK。 如有问题,请加QQ群讨论:839421316
说明
由三台虚拟机安装集群。
服务名 | IP | 操作系统 |
---|---|---|
server01 | 192.168.3.150 | Centos 7 |
server02 | 192.168.3.151 | Centos 7 |
server03 | 192.168.3.152 | Centos 7 |
系统版本信息:
[root@server01 ~]# uname -a
Linux server01 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
安装包信息:
Elasticsearch安装包下载地址:https://www.elastic.co/downloads/elasticsearch
[elasticsearch@server01 ~]$ ls
elasticsearch-6.5.3.tar.gz
准备
添加用户
添加elasticsearch用户:
useradd elasticsearch
echo "elasticsearch" | passwd --stdin elasticsearch
usermod -G wheel elasticsearch
系统配置
在/etc/security/limits.conf中加入以下内容:
elasticsearch soft memlock unlimited
elasticsearch hard memlock unlimited
elasticsearch soft nofile 655350
elasticsearch hard nofile 655350
elasticsearch soft nproc 655350
elasticsearch soft nproc 655350
在/etc/sysctl.conf加入:
vm.max_map_count=655360
停用防火墙,在生产请配置防火墙。
systemctl stop firewalld
systemctl disable firewalld
停用Selinux,在生产请配置SElinux
setenforce 0
JDK安装
yum install -y java-1.8.0-openjdk-devel
Elasticsearch安装
当前包位置
[elasticsearch@server01 ~]$ pwd
/home/elasticsearch
[elasticsearch@server01 ~]$ ls
elasticsearch-6.5.3.tar.gz
创建安装目录
sudo mkdir /opt/elasticsearch
sudo chown elasticsearch:elasticsearch /opt/elasticsearch/
将包解压后,放到/opt/elasticsearch/中。
[elasticsearch@server01 elasticsearch-6.5.3]$ pwd
/opt/elasticsearch/elasticsearch-6.5.3
[elasticsearch@server01 elasticsearch-6.5.3]$ ls
bin config lib LICENSE.txt logs modules NOTICE.txt plugins README.textile
创建日志和数据目录。
/opt/elk/data
/opt/elk/log
sudo mkdir -pv /opt/elk/{data,log}
sudo chown elasticsearch:elasticsearch -R /opt/elk
在三台服务器中都要执行以上操作。
配置
在elasticsearch中有以下目录:
bin
config
lib
logs
modules
plugins
配置文件在elasticsearch的conf目录 中。
elasticsearch.yml
jvm.options
log4j2.properties
role_mapping.yml
roles.yml
users
users_roles
elasticsearch.yml : elasticsearch主配置文件
jvm.options: JVM 配置文件
log4j2.properties: 日志配置文件
修改配置文件elasticsearch.yml。
在默认的配置文件elasticsearch.yml中,所有的配置都是被注释的。接下来,我们会重新写一个配置文件。
mv elasticsearch.yml elasticsearch.yml.bak
touch elasticsearch.yml
将以下内容写入到配置文件中:
server01,192.168.3.150中内容:
# ---------------------------------- Cluster -----------------------------------
cluster.name: elasticsearch-cluster
# ------------------------------------ Node ------------------------------------
node.name: server01
node.attr.rack: elasticsearch01
node.master: true
# ----------------------------------- Paths ------------------------------------
path.data: /opt/elk/data
path.logs: /opt/elk/log
# ---------------------------------- Network -----------------------------------
network.host: 192.168.3.150
transport.tcp.port: 9301
http.port: 9200
# --------------------------------- Discovery ----------------------------------
discovery.zen.ping.unicast.hosts: ["192.168.3.150", "192.168.3.151", "192.168.3.152"]
discovery.zen.minimum_master_nodes: 2
cluster.name: 集群名
node.name: 节点名
node.attr.rack: 节点自定义属性
path.data: 数据文件
path.logs: 日志文件
network.host: 当前节点IP地址
transport.tcp.port: 内部通讯端口
http.port: http端口
discovery.zen.ping.unicast.hosts: 集群内主机
discovery.zen.minimum_master_nodes: 最小运行数量
server02,192.168.3.151中内容:
# ---------------------------------- Cluster -----------------------------------
cluster.name: elasticsearch-cluster
# ------------------------------------ Node ------------------------------------
node.name: server02
node.attr.rack: elasticsearch02
node.master: true
# ----------------------------------- Paths ------------------------------------
path.data: /opt/elk/data
path.logs: /opt/elk/log
# ---------------------------------- Network -----------------------------------
network.host: 192.168.3.151
transport.tcp.port: 9301
http.port: 9200
# --------------------------------- Discovery ----------------------------------
discovery.zen.ping.unicast.hosts: ["192.168.3.150", "192.168.3.151", "192.168.3.152"]
discovery.zen.minimum_master_nodes: 2
server03,192.168.3.152中内容:
# ---------------------------------- Cluster -----------------------------------
cluster.name: elasticsearch-cluster
# ------------------------------------ Node ------------------------------------
node.name: server03
node.attr.rack: elasticsearch03
node.master: true
# ----------------------------------- Paths ------------------------------------
path.data: /opt/elk/data
path.logs: /opt/elk/log
# ---------------------------------- Network -----------------------------------
network.host: 192.168.3.152
transport.tcp.port: 9301
http.port: 9200
# --------------------------------- Discovery ----------------------------------
discovery.zen.ping.unicast.hosts: ["192.168.3.150", "192.168.3.151", "192.168.3.152"]
discovery.zen.minimum_master_nodes: 2
启动:
cd /opt/elasticsearch/elasticsearch-6.5.3/bin/
./elasticsearch
测试: