一、软件版本
1.jdk-8u211-linux-x64.rpm
2.elasticsearch-6.8.1.rpm
3.logstash-6.8.1.rpm
4.kibana-6.8.1-x86_64.rpm
5.winlogbeat-6.8.4-windows-x86_64 在windows服务器安装配置
说明:elasticsearch做集群 主机1:192.168.1.102 主机2:192.168.1.104
logstash和kibana安装在主机1上
二、安装软件
2.1 主机1和主机2:jdk-8u211-linux-x64.rpm和elasticsearch-6.8.1.rpm 并配置elasticsearch
说明:elasticsearch依赖jdk环境,所以先安装jdk-8u211-linux-x64.rpm
yum -y localinstall jdk-8u211-linux-x64.rpm
yum -y localinstall elasticsearch-6.8.1.rpm
创建数据目录和日志目录及权限修改
[root@linux-elk1 ~]# mkdir -p /elk/{data,logs}
[root@linux-elk1 ~]# chown elasticsearch.elasticsearch /elk/ -R
修改内存限制,内存锁定需要进行配置需要2g以上内存,否则会导致无法启动elasticsearch。
[root@linux-elk1 ~]# vim /usr/lib/systemd/system/elasticsearch.service
在[Service]下加入下面这行内容
LimitMEMLOCK=infinity
[root@linux-elk1 ~]# vim /etc/elasticsearch/jvm.options
-Xms2g
-Xmx2g #最小和最大内存限制.
编辑配置文件:vim /etc/elasticsearch/elasticsearch.yml
[root@logsystem src]# grep -v "^#" /etc/elasticsearch/elasticsearch.yml
cluster.name: my-log
node.name: node-1
path.data: /elk/data
path.logs: /elk/logs
network.host: 192.168.1.102
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.168.1.102","192.168.1.104"]
设置开机启动
systemctl enable elasticsearch.service
systemctl daemon-reload
systemctl start elasticsearch.service
查看状态
systemctl status elasticsearch.service
正在运行,查看端口
ss -tnl
查看信息,也是一种检测。若能出现如下信息,则说明配置正确
curl http://192.168.1.102:9200
集群有状态: green ,red , yellow
绿色表示一切是好的(集群功能齐全)
黄色意味着所有数据是可用的,但是一些副本尚未分配(集群功能齐全)
红色意味着一些数据不可用
即使一个集群是红色的,它仍然是部分功能(即它将继续搜索请求从服务可用的碎片)但是你可能需要尽快修复它,因为你有缺失的数据。
Restful API:
四类API
1. 检查集群,节点,索引等健康与否,以及获取其相应状态
2.管理集群,节点,索引及元数据
3.执行CRUD操作
4.执行高级操作,如paging ,filtering等
ES访问接口:9200/tcp
语法:
curl -X<VERB> \'<PROTOCOL>://host:port/<PATH>?QUERY_STRING/\' -d \'<BODY>\'
查看elasticsearch相关信息 json格式的
[root@logsystem ~]# curl http://192.168.1.102:9200/_cluster/health?pretty=true
{
"cluster_name" : "elasticsearch",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}
[root@logsystem ~]# curl -X GET http://192.168.1.102:9200/_cat/nodes?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.1.102 7 95 1 0.00 0.01 0.05 mdi * node-1
[root@logsystem ~]# curl -X GET http://192.168.1.102:9200/_cat/indices?help
[root@logsystem ~]# curl -X GET \'http://192.168.1.102:9200/_cluster/state/version?pretty\'
{
"cluster_name" : "elasticsearch",
"cluster_uuid" : "qKuBK9TlQ3G-Rj6IFAXzTQ",
"version" : 16,
"state_uuid" : "SzhdF4PvRIGFbwlI_PD_cg"
}
2.2主机1: logstash-6.8.1.rpm 并配置
wget https://artifacts.elastic.co/downloads/logstash/logstash-6.8.1.rpm
yum -y localinstall logstash-6.8.1.rpm
[root@logsystem ~]cd /etc/logstash/conf/
vim system-log.conf
input{
beats{
add_field => {"myid"=>"windows_log"}
port => 5044
}
beats {
add_field => {"myid"=>"nginx_log"}
port => 5400
}
stdin{}
}
output{
if [myid] == "windows_log"{
elasticsearch{
hosts=>"192.168.1.102:9200"
index=>"%{type}-%{+YYYY-MM-dd}"
}
}
if [myid] == "nginx_log"{
elasticsearch{
hosts=>"192.168.1.102:9200"
index=>"nginx_pj_log-%{+YYYY-MM-dd}"
}
}
stdout{ codec=>rubydebug }
}
启动logstash:
[root@logsystem src]# nohup logstash -f /etc/logstash/conf.d/server_log.conf &
测试配置文件是否有语法错误:
[root@logsystem ~]logstash -f /etc/logstash/conf/system-log.conf
数据类型
Array: [item1,item2,...]
Boolean: true,false
Bytes:
Codec: 编码器
Hash: key=>value
Number:
Password:
Path:文件系统路径
String:字符串
字段引用 []
条件判断: == ,!=,<,>, in ,not in ,and,or ....
常用imput Plugin
imput插件:
File :从指定的文件中读取事件流,按行来标记一个事件。
使用FileWatch(Ruby开发)来监听文件是否变化; .sincedb保存文件的相关信息数据库中。
[root@logsystem logstash]# rpm -ql logstash |grep "patterns" 查找pattern
elasticsearch服务收到数据验证:
2.3主机1:安装配置kibana
[root@logsystem src]# wget https://artifacts.elastic.co/downloads/kibana/kibana-6.8.1-x86_64.rpm
安装
[root@logsystem src]# yum localinstall kibana-6.8.1-x86_64.rpm -y
配置
[root@logsystem src]# vim /etc/kibana/kibana.yml
server.port: 5601 #监听端口
server.host: "192.168.1.102" #监听地址
elasticsearch.hosts: ["http://192.168.1.102:9200"] #elasticsearch服务器地址
i18n.locale: "zh-CN" #修改中文
[root@logsystem src]# systemctl start kibana
[root@logsystem src]# systemctl enable kibana
查看服务
访问:http://192.168.1.102:5601
2.4 收集服务器日志上安装winlogbeat-6.8.4-windows-x86_64
解压到 C:\Program Files
重新命名文件夹为winlogbeat
用管理员身份打开windows的 powershell
运行以下命令来安装服务
PS C:\Users\Administrator> cd \'C:\Program Files\Winlogbeat\'
PS C:\Program Files\Winlogbeat> .\install-service-winlogbeat.ps1
不能安装时,令来关闭一些安全防护,输入命令后按Y确认
PS C:\Program Files\Winlogbeat> set-executionpolicy remotesigned
PS C:\Program Files\Winlogbeat> set-executionpolicy Bypass
winlogbeat.yml 配置文件修改:
winlogbeat.event_logs:
- name: Application #应用程序事件;
ignore_older: 8h #忽略8小时后的日志,初次启用传日志很有用;
provider: #过虑源yml列表
- Application Error
- Application Hang
- Windows Error Reporting
- name: Security #安全日志
ignore_older: 8h
event_id: 4624, 4625, 4700-4800, -4735 #事件ID 匹配中事件ID发送
- name: System #系统日志
ignore_older: 8h
检查配置语法
. \winlogbeat.exe test config -c .\winlogbeat.yml -e
启动winlogbeat
C:\Program Files\Winlogbeat> Start-Service winlogbeat
Windlogbeat基本配置
1.配置发送日志到logstash
output.logstash:
# The Logstash hosts
hosts: ["10.10.10.10:5044"]
2.配置发送日志到elasticsearch
output.elasticsearch:
hosts: ["10.10.10.10:9200"]
template.name: "winlogbeat"
template.path: "winlogbeat.template.json"
template.overwrite: false
坑1:插件存放路径
报错:
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: Property [elasticsearch.version] is missing for plugin [head]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:89) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82) ~[elasticsearch-5.2.2.jar:5.2.2]
原因:新版本的elasticsearch不允许插件放入/usr/share/elasticsearch/plugins 目录下。(插件bigdesk,head ...)
解决:把插件移到其它目录即可