Filebeat是个很轻量级的工具,主要干这么三件事:
监听本机指定日志文件的新增条目,类似 tail -f
做最原始的过滤和处理
发送到Logstash,或者Elastic Search,又或者其他地方
直接复制2.X的elasticsearch.yml配置文件会有大量报错
1)”node settings must not contain any index level settings” 不支持索引级别设置
2)不支持脚本设置script。
3)bootstrap.mlockall 改为了 bootstrap.memory_lock。
所以直接在5.0的elasticsearch.yml进行参数设定。
bootstrap checks failed
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
解决方法:
vi /etc/sysctl.conf
vm.max_map_count=262144
解决方法:
# tail -n 2 /etc/security/limits.conf
es soft memlock unlimited
es hard memlock unlimited
[root@es-0 ~]# cat /etc/hosts
....
192.168.1.10 es-0
192.168.1.11 es-1
192.168.1.12 es-2
192.168.1.13 es-3
此处将通过es-0 节点直接切换到其他节点进行操作免去输入密码
[root@es-0 ~]# ssh-keygen -t rsa [一路回车]
[root@es-0 ~]# cd .ssh && cat id_rsa.pub > authorized_keys
[root@es-0 ~]# chmod 0600 .ssh/authorized_keys
[root@es-0 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@es-1
[root@es-0 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@es-2
[root@es-0 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@es-3
[root@es-0 ~]# tree /home/maintenance/
/home/maintenance/
├── config
│ └── config.sh
├── docmdoncluster.sh
└── updatefiletocluster.sh
1 directory, 3 files
[root@es-0 ~]# vim /etc/profile
export PATH=/home/maintenance:$PATH
[root@es-0 ~]# vim /home/maintenance/config/config.sh
#!/bin/bash
file_ips="es-1 es-2 es-3"
command_ips="localhost $file_ips"
port=22
[root@es-0 ~]# updatefiletocluster.sh /etc/hosts
file dir is /etc
==================starting rsync file /etc/hosts to es-1=====================
remote dir is existed!
sending incremental file list
host
sent 76 bytes received 31 bytes 214.00 bytes/sec
total size is 4 speedup is 0.04
==================starting rsync file /etc/hosts to es-2=====================
remote dir is existed!
sending incremental file list
host
sent 76 bytes received 31 bytes 214.00 bytes/sec
total size is 4 speedup is 0.04
==================starting rsync file /etc/hosts to es-3=====================
remote dir is existed!
sending incremental file list
host
sent 76 bytes received 31 bytes 214.00 bytes/sec
total size is 4 speedup is 0.04
*****************finished!!!*******************
[root@es-0 ~]# ls /opt/
jdk1.8.0_74
[root@es-0 ~]# ln -s /opt/jdk1.8.0_74 /opt/jdk
添加变量:
[root@es-0 ~]# vim /etc/profile
export JAVA_HOME=/opt/jdk
export PATH=${JAVA_HOME}/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/jre/lib/dt.jar:$JAVA_HOME/lib/tools.jar
[root@es-0 ~]# cat sys_init.sh
# /etc/security/limits.conf
echo -e "* soft nproc unlimited" >> /etc/security/limits.conf
echo -e "* hard nproc unlimited" >> /etc/security/limits.conf
echo -e "* soft nofile 655350" >> /etc/security/limits.conf
echo -e "* hard nofile 655350" >> /etc/security/limits.conf
# /etc/proflie
echo -e "ulimit -SHn 655350" >> /etc/profile
echo -e "ulimit -SHu unlimited" >> /etc/profile
echo -e "ulimit -SHd unlimited" >> /etc/profile
echo -e "ulimit -SHm unlimited" >> /etc/profile
echo -e "ulimit -SHs unlimited" >> /etc/profile
echo -e "ulimit -SHt unlimited" >> /etc/profile
echo -e "ulimit -SHv unlimited" >> /etc/profile
# /etc/sysctl.conf (踩坑记录)
echo -e "vm.max_map_count=262144" >> /etc/sysctl.conf
[root@es-0 ~]# source /etc/profile
[root@es-0 ~]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 126606
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 655350
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) unlimited
cpu time (seconds, -t) unlimited
max user processes (-u) unlimited
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
[root@es-0 ~]# tail -n 2 /etc/security/limits.conf (踩坑记录)
es soft memlock unlimited
es hard memlock unlimited
注: es 为用户名,稍后会创建es用户
/opt/source
目录下并 link
到/opt/下[root@es-0 ~]# useradd es
[root@es-0 ~]# chown -R es:es /opt/source/
[es@es-0 ~]$ grep -v "^#" /opt/es/config/elasticsearch.yml
cluster.name: test-elk
node.name: node-0 [需修改]
node.master: true [数据节点需修改为false]
node.data: true
path.data: /home/es/es-data
path.logs: /home/es/logs
bootstrap.memory_lock: true
network.publish_host: es-0 [需修改]
network.bind_host: es-0 [需修改]
discovery.zen.minimum_master_nodes: 3
discovery.zen.ping.unicast.hosts: ["es-0", "es-1", "es-2", "es-3"]
discovery.zen.fd.ping_timeout: 120s
discovery.zen.fd.ping_retries: 6
discovery.zen.fd.ping_interval: 30s
client.transport.ping_timeout: 60s
discovery.zen.ping_timeout: 120s
xpack.security.enabled: false #关闭es认证 与kibana对应
[es@es-0 ~]$ updatefiletocluster.sh /opt/es/config/elasticsearch.yml
注
:各节点只需要修改上面所标记 需修改
的参数项即可[es@es-0 ~]$ cd /opt/es/ && ./bin/elasticsearch-plugin install file:///opt/source/x-pack-5.1.1.zip
[es@es-0 ~]$ cd /opt/es/ && ./bin/elasticsearch -d [后台进程启动]
$ curl http://es-0:9200/_cat/nodes
192.168.1.11 29 93 0 0.21 0.36 0.40 mdi - node-1
192.168.1.10 70 95 1 0.28 0.37 0.40 mdi * node-0
192.168.1.12 61 93 1 0.25 0.31 0.37 mdi - node-2
192.168.1.13 34 97 0 0.57 0.46 0.42 di - node-3
[es@es-0 ~]$ curl http://es-0:9200/_cat/health?v
[es@es-0 ~]$ curl http://es-0:9200/_cat/plugins
node-3 x-pack 5.1.1
node-1 x-pack 5.1.1
node-0 x-pack 5.1.1
node-2 x-pack 5.1.1
[root@es-3 ~]# cat /opt/logstash/conf/nginx.conf
input {
file {
path => "/tmp/nginx/access*.log"
start_position => beginning
}
}
filter {
grok {
match => { "message" => "%{COMBINEDAPACHELOG} %{QS:x_forwarded_for}"}
}
date {
match => [ "timestamp", "UNIX" ]
}
geoip {
source => "clientip"
}
}
output {
elasticsearch {
hosts => "es-0:9200"
index => "nginx-%{+YYYY.MM.dd}"
}
stdout { codec => rubydebug }
}
.....
output {
elasticsearch {
hosts => "es-0:9200"
index => "nginx-%{+YYYY.MM.dd}"
user => "elastic"
password => "changeme"
}
....
}
[root@es-3 ~]# cd /opt/logstash && nohup ./bin/logstash -f config/nginx -l logs/nginx.log &
[root@es-0 ~]# egrep -v "^#|^$" /opt/kibana/config/kibana.yml
server.host: "kibana"
server.name: "test-kibana"
elasticsearch.url: "http://es-0:9200"
logging.dest: ./kibana.log
xpack.security.enabled: false
[root@es-0 ~]# cd /opt/kibana && ./bin/kibana-plugin install file:///opt/source/x-pack-5.1.1.zip
[root@es-0 ~]# cd /opt/kibana && nohup ./bin/kibana &
文本示例未开启安全认证功能
elasticsearch.username: "user"
elasticsearch.password: "password"
注: 默认kibana会使用初始用户名密码连接 elasticsearch
curl -XPUT -u elastic:password 'http://:/_xpack/license' -d @license.json
@license.json 申请得到的json文件,复制文件中的所有内容,粘贴在此。
如果提示需要acknowledge,则设置为true
curl -XPUT -u elastic:password 'http://:/_xpack/license?acknowledge=true' -d @license.json
查看安装结果信息
curl -XGET -u elastic:password 'http://:/_license'
不同版本功能
https://www.elastic.co/subscriptions
elastic
默认密码 changeme
前面有一再的说明;修改elastic用户的密码:
$ curl -XPUT -u elastic 'localhost:9200/_xpack/security/user/elastic/_password' -d '{
"password" : "123456"
}'
修改kibana用户的密码:
$ curl -XPUT -u elastic 'localhost:9200/_xpack/security/user/kibana/_password' -d '{
"password" : "123456"
}'
创建用户组和角色,创建所属用户
创建 `admin` 用户组,该用户组对 `nginx*` 有all权限,对.kibana*有manage,read,index权限
$ curl -XPOST -u elastic 'localhost:9200/_xpack/security/role/admin' -d '{
"indices" : [
{
"names" : [ "nginx*" ],
"privileges" : [ "all" ]
},
{
"names" : [ ".kibana*" ],
"privileges" : [ "manage", "read", "index" ]
}
]
}'
创建 test 用户,密码是 passwd
$ curl -XPOST -u elastic 'localhost:9200/_xpack/security/user/test' -d '{
"password" : "passwd",
"full_name" : "test",
"email" : "[email protected]",
"roles" : [ "admin" ]
}'
./bin/elasticsearch-plugin remove x-pack
./bin/kibana-plugini remove x-pack