基本上有3种方式,
1 yum安装
2 rpm安装
3 docker安装html
yum安装,参照官方文档是最好的:
http://docs.graylog.org/en/3.0/pages/installation/os/centos.html
#没有安装jdk,则先安装jdk:
$ sudo yum install java-1.8.0-openjdk-headless.x86_64
#安装MongoDB
#修改yum源 /etc/yum.repos.d/mongodb-org.repo
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
sudo yum install mongodb-org
$ sudo chkconfig --add mongod
$ sudo systemctl daemon-reload
$ sudo systemctl enable mongod.service
$ sudo systemctl start mongod.service
#安装ES
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
#修改yum源 /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/oss-6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
#安装
sudo yum install elasticsearch-oss
#配置 /etc/elasticsearch/elasticsearch.yml
cluster.name: graylog
action.auto_create_index: false
#启动
$ sudo chkconfig --add elasticsearch
$ sudo systemctl daemon-reload
$ sudo systemctl enable elasticsearch.service
$ sudo systemctl restart elasticsearch.service
#安装Graylog 服务器
$ sudo rpm -Uvh https://packages.graylog2.org/repo/packages/graylog-3.0-repository_latest.rpm
$ sudo yum install graylog-server
#配置,安装好以后须要修改配置,/etc/graylog/server/server.conf 添加: password_secret、root_password_sha2
# root_password_sha2 经过下面的命令生成, 其中输入的密码就是admin的密码,也就是登陆时候的密码
echo -n "Enter Password: " && head -1 </dev/stdin | tr -d '\n' | sha256sum | cut -d" " -f1
# Generate one by using for example: pwgen -N 1 -s 96
# password_secret 是能够随便写的,可是要求长度64位,能够经过pwgen 来生成。可是安装pwgen,pwgen须要安装。比较麻烦。
# 参照网上博客,执行 wget http://sourceforge.net/projects/pwgen,能够下载,发现没法解压,执行tar zxvf pwgen,报错说不是正确格式。
# 因而继续尝试经过 yum。 直接 yum install pwgen是不行的。须要先执行 yum install epel-release 而后 yum install pwgen。 不知道为何 须要 epel-release
有些值是可使用默认值的,有些不行。特别是须要设置 ip。 也就是 http_bind_address, 是毫不能使用默认值的, 我开始使用默认值,死活不能经过宿主机访问,改成实际ip就行了。 另外 http_publish_uri 默认是 http_bind_address, 是不须要设置的。可是若是设置则须要设置正确。 elasticsearch_hosts 可使用默认值:elasticsearch_hosts = http://127.0.0.1:9200; mongodb_uri 也是。Email transport 什么的能够先无论。 后面有须要再改。
#启动。
$ sudo chkconfig --add graylog-server
$ sudo systemctl daemon-reload
$ sudo systemctl enable graylog-server.service
$ sudo systemctl start graylog-server.service
启动好了后, 能够grep一下mongo,elasticsearch,graylog。 特别须要注意的是, 配置graylog的时候, publish_url 须要一个实际的ip,而不能是 127.0.0.1 。
java
Docker安装的话,其实更简单。
yum install docker
systemctl start docker
cat /etc/docker/daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
准备一个文件 docker-compose.yml ,放/opt 目录下
version: '2'
services:
# MongoDB: https://hub.docker.com/_/mongo/
mongodb:
image: mongo:3
# Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/6.6/docker.html
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.6.1
environment:
- http.host=0.0.0.0
- transport.host=localhost
- network.host=0.0.0.0
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
mem_limit: 1g
# Graylog: https://hub.docker.com/r/graylog/graylog/
graylog:
image: graylog/graylog:3.0
environment:
# CHANGE ME (must be at least 16 characters)!
- GRAYLOG_PASSWORD_SECRET=somepasswordpepper
# Password: admin
- GRAYLOG_ROOT_PASSWORD_SHA2=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918
- GRAYLOG_HTTP_EXTERNAL_URI=http://127.0.0.1:9000/ ## 须要修改
links:
- mongodb:mongo
- elasticsearch
depends_on:
- mongodb
- elasticsearch
ports:
# Graylog web interface and REST API
- 9000:9000
# Syslog TCP
- 1514:1514
# Syslog UDP
- 1514:1514/udp
# GELF TCP
- 12201:12201
# GELF UDP
- 12201:12201/udp
而后 docker-compose up 就行了!
特别须要注意的是,上面的 GRAYLOG_HTTP_EXTERNAL_URI 须要一个实际的ip, 不然其余机器是没法访问的!会出现上面状况呢? 就是其余机器能够Telnet graylog, 可是web访问显示一片空白。
经过curl 获得下面的结果:
# curl http://192.168.11.183:9000
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="robots" content="noindex, nofollow">
<meta charset="UTF-8">
<title>Graylog Web Interface</title>
<link rel="shortcut icon" href="http://127.0.0.1:9000/assets/favicon.png">
</head>
<body>
<script src="http://127.0.0.1:9000/config.js"></script>
<script src="http://127.0.0.1:9000/assets/vendor.4024e2a8db732781a971.js"></script>
<script src="http://127.0.0.1:9000/assets/polyfill.a5e2fb591e8fd54ee4ef.js"></script>
<script src="http://127.0.0.1:9000/assets/builtins.a5e2fb591e8fd54ee4ef.js"></script>
<script src="http://127.0.0.1:9000/assets/plugin/org.graylog.plugins.threatintel.ThreatIntelPlugin/plugin.org.graylog.plugins.threatintel.ThreatIntelPlugin.b864ba54b438ac0bdc48.js"></script>
<script src="http://127.0.0.1:9000/assets/plugin/org.graylog.plugins.collector.CollectorPlugin/plugin.org.graylog.plugins.collector.CollectorPlugin.bcc87290018e859a8a9e.js"></script>
<script src="http://127.0.0.1:9000/assets/plugin/org.graylog.aws.AWSPlugin/plugin.org.graylog.aws.AWSPlugin.8ae7cb13983ce33eeb5b.js"></script>
<script src="http://127.0.0.1:9000/assets/app.a5e2fb591e8fd54ee4ef.js"></script>
</body>
</html>
开始没有发现问题,后面才知道 上面的html所有都是经过 js动态加载的, 其中的 script src="http://127.0.0.1:9000/ 其实就是一个问题的根由。 很明显上面的src 是 本地的,是其余机器没法正常访问的!
改了以后,再观察,就正常了!(注意下面的src )
# curl http://192.168.11.183:9000
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="robots" content="noindex, nofollow">
<meta charset="UTF-8">
<title>Graylog Web Interface</title>
<link rel="shortcut icon" href="http://192.168.11.127:9000/assets/favicon.png">
</head>
<body>
<script src="http://192.168.11.127:9000/config.js"></script>
<script src="http://192.168.11.127:9000/assets/vendor.4024e2a8db732781a971.js"></script>
<script src="http://192.168.11.127:9000/assets/polyfill.a5e2fb591e8fd54ee4ef.js"></script>
<script src="http://192.168.11.127:9000/assets/builtins.a5e2fb591e8fd54ee4ef.js"></script>
<script src="http://192.168.11.127:9000/assets/plugin/org.graylog.plugins.threatintel.ThreatIntelPlugin/plugin.org.graylog.plugins.threatintel.ThreatIntelPlugin.b864ba54b438ac0bdc48.js"></script>
<script src="http://192.168.11.127:9000/assets/plugin/org.graylog.plugins.collector.CollectorPlugin/plugin.org.graylog.plugins.collector.CollectorPlugin.bcc87290018e859a8a9e.js"></script>
<script src="http://192.168.11.127:9000/assets/plugin/org.graylog.aws.AWSPlugin/plugin.org.graylog.aws.AWSPlugin.8ae7cb13983ce33eeb5b.js"></script>
<script src="http://192.168.11.127:9000/assets/app.a5e2fb591e8fd54ee4ef.js"></script>
</body>
</html>
实际上,9000 能够访问,可是web显示一片空白, 其实能够经过F12 观察到的。 F12 看到不少的500 404, 那就是在 强烈指明是 服务端的问题了!!
graylog 的9000 web界面能够访问了,可是如今还看不到日志。而后java 也须要配置一下,这个很容易,logback增长一个GELF就行了。不过仍是不行的,graylog 还须要手动配置input。 这一点上,和ELK是很大不一样的! 刚开始接触的时候就一直卡在了这里,真是坑。es6
配置GELF的时候,注意旋转 GELF TCP或者GELF UDP,我开始的时候想固然的认为java web,而后http,而后选择了HTTP,结果不行,后面才明白是端口问题。graylog是默认开启了 12201 的tcp和udp端口 。web
graylog的使用实际上是很简单的,通过前面的简单配置,graylog已经能够正式使用了。不一样于ELK, ELK配置logstash的grok 要折腾死不少脑细胞。
界面方便跟elk差很少,可是明显,易用多了!mongodb
若是 点开Search界面看不到任何的日志,要么就是没有配置input,要么就是时间不对,要么就是没有日志进来。docker
一些注意事项:json
The search syntax is very close to the Lucene syntax. By default all message fields are included in the search if you don’t specify a message field to search in.
es6以后,
Elasticsearch 2.x and 5.x split queries on whitespace, so the query type:(ssh login) was equivalent to type:(ssh OR login). This is no longer the case in Elasticsearch 6.0 and you must now include an OR operator between each term.
—— 我在kibana中测试,好像不是这样的。。
Elasticsearch 2.x allows to use _missing_:type instead of NOT _exists_:type. This query syntax has been removed in Elasticsearch 5.0.
多个field之间,能够不用加AND OR,直接空格就好, 默认是OR?
Note that AND, OR, and NOT are case sensitive and must be typed in all upper-case. 必须全大写
—— 若是想查询包含and 关键字的呢?
Note that leading wildcards are disabled to avoid excessive memory consumption! You can enable them in your Graylog configuration file:
allow_leading_wildcard_searches = true
allow_leading_wildcard_searches 默认是false !
Numeric fields support range queries. Ranges in square brackets are inclusive, curly brackets are exclusive and can even be combined:
数字类型field支持range查询
Escaping 转义!
The following characters must be escaped with a backslash:
&& || : \ / + - ! ( ) { } [ ] ^ " ~ * ?
示例:
level_name:ERROR —————— 这里的ERROR 是不能变形的,也就是说不能小写,不能大小写混合! 这点和kibana不一样,估计是由于graylog中level_name是enum类型?
参考:
https://www.jianshu.com/p/97fcb10c3556
https://www.cnblogs.com/yuhuLin/p/7018858.html
https://blog.csdn.net/dongshaoshuai/article/details/54583668
https://blog.csdn.net/weixin_41004350/article/details/87253316
centos