Graylog 分布式日志管理系统-集群搭建
简介
Graylog是一个开源的日志聚合、分析、审计、展现和预警工具。低成本,高性能。
Graylog与ELK对比
Graylog需要把日志源采集到graylog-server,经过处理后的数据,使用ES进行存储。
Graylog提供了Web端,相当于Kibana。
集群架构分配参考
官方文档架构图:https://docs.graylog.org/en/3.3/pages/architecture.html
部署节点
IP | 作用 |
192.168.122.71 | Graylog、MongoDB,Nginx |
192.168.122.72 | Graylog、MongoDB |
192.168.122.73 | Graylog、MongoDB |
192.168.122.74 | Elasticsearch |
192.168.122.75 | Elasticsearch |
192.168.122.76 | Elasticsearch |
前置工作
sudo systemctl status firewalld
…
cat /etc/selinux/config
java -version
sudo yum install epel-release pwgen -y
搭建MongoDB集群
sudo touch /etc/yum.repos.d/mongodb-org.repo
sudo vim /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
安装MongoDB
sudo yum install -y mongodb-org
sudo mongod --config /etc/mongod.conf
关闭MongoDB
mongo
use admin
db.shutdownServer()
创建文件
mkdir -p /work/mongo/data mkdir -p /work/mongo/log touch /work/mongo/log/mongod.log
备份并编辑配置
sudo cp /etc/mongod.conf /etc/mongod.conf.bak
sudo vim /etc/mongod.conf
编辑 mongod.conf 配置
systemLog: destination: file logAppend: true path: /work/mongo/log/mongod.log #path: /var/log/mongodb/mongod.log storage: dbPath: /work/mongo/data #dbPath: /var/lib/mongo journal: enabled: true #配置远程连接 net: port: 27017 bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting. #replication(集群配置): replication: replSetName: rs0
mongoDB重启,参考上面先关闭mongoDB,再启动。
mongo >rs.initiate( { _id : "rs0", members: [ { _id : 0, host : "192.168.122.71:27017" } ] }) exit
mongo
rs0:PRIMARY> rs.conf()
rs0:PRIMARY> rs.add("192.168.122.72") rs0:PRIMARY> rs.add("192.168.122.73") rs0:PRIMARY> rs.status()
rs0:PRIMARY> use graylog switched to db graylog rs0:PRIMARY> db.createUser( { user: "graylog", pwd: "xxxxx", roles: [ { role: "readWrite", db: "graylog" } ] }); rs0:PRIMARY> db.grantRolesToUser( "graylog" , [ { role: "dbAdmin", db: "graylog" } ]) rs0:PRIMARY> show users rs0:PRIMARY> db.auth("graylog","xxxxx")
Elasticsearch集群部署
cd /wrok wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.3.tar.gz tar -zxf elasticsearch-6.4.3.tar.gz
mkdir -p /work/elasticsearch-6.4.3/data
sudo vim /work/elasticsearch-6.4.3/config/elasticsearch.yml
#graylog01: cluster.name: graylog node.name: graylog01 node.master: true node.data: true bootstrap.memory_lock: false bootstrap.system_call_filter: false path.data: /work/elasticsearch-6.4.3/data path.logs: /work/elasticsearch-6.4.3/logs network.host: 0.0.0.0 http.port: 9200 discovery.zen.ping.unicast.hosts: ["192.168.122.74:9300", "192.168.122.75:9300","192.168.122.76:9300"] #graylog02 cluster.name: graylog node.name: graylog02 node.master: true node.data: true bootstrap.memory_lock: false bootstrap.system_call_filter: false path.data: /work/elasticsearch-6.4.3/data path.logs: /work/elasticsearch-6.4.3/logs network.host: 0.0.0.0 http.port: 9200 discovery.zen.ping.unicast.hosts: ["192.168.122.74:9300", "192.168.122.75:9300","192.168.122.76:9300"] #graylog03 cluster.name: graylog node.name: graylog03 node.master: true node.data: true bootstrap.memory_lock: false bootstrap.system_call_filter: false path.data: /work/elasticsearch-6.4.3/data path.logs: /work/elasticsearch-6.4.3/logs network.host: 0.0.0.0 http.port: 9200 discovery.zen.ping.unicast.hosts: ["192.168.122.74:9300", "192.168.122.75:9300","192.168.122.76:9300"]
bin/elasticsearch -d
[2020-09-09T15:27:08,646][ERROR][o.e.b.Bootstrap ] [graylog01] node validation exception [2] bootstrap checks failed [1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536] [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
sudo vim /etc/security/limits.conf
* - nofile 65536 * - memlock unlimited 或者 * soft nofile 65536 * hard nofile 65536 * soft nproc 4096 * hard nproc 4096
sudo vi /etc/sysctl.conf
Graylog集群安装
sudo rpm -Uvh https://packages.graylog2.org/repo/packages/graylog-3.0-repository_latest.rpm
pwgen -N 1 -s 96 M39BrdTsF7EmzLc1x0iejVoCn3QAYuvgSc5OkitRspJBmBCL2XasAK2LgW5uvok0v2QT3gM8hgaNbNTED1UOjAgCSQVPznLy
echo -n admin | sha256sum 8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918
sudo vim /etc/graylog/server/server.conf
#主节点is_master = true,其他两个节点的配置文件中设置为is_master = false is_master = true #密钥 password_secret = M39BrdTsF7EmzLc1x0iejVoCn3QAYuvgSc5OkitRspJBmBCL2XasAK2LgW5uvok0v2QT3gM8hgaNbNTED1UOjAgCSQVPznLy #加密后的登陆密码 root_password_sha2 = 8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918 #时区 root_timezone = Asia/Shanghai # 网络访问相关,重要 http_bind_address = 0.0.0.0:9000 # 配置Nginx代理的外网地址 http_publish_uri = http://192.168.122.71:9100/ #高亮 allow_highlighting = true # ES 连接配置 elasticsearch_hosts = http://192.168.122.74:9200,http://192.168.122.75:9200,http://192.168.122:9200 # mongodb 连接配置,设置验证 mongodb_uri = mongodb://graylog:graylog@192.168.122.71:27017,192.168.122.71:27017,192.168.122:27017/graylog # 或者,不设置验证 mongodb_uri = mongodb://192.168.122.71:27017,192.168.122.71:27017,192.168.122:27017/graylog
sudo chkconfig --add graylog-server sudo systemctl daemon-reload sudo systemctl enable graylog-server.service sudo systemctl start graylog-server.service sudo systemctl status graylog-server.service sudo systemctl restart graylog-server.service
安装Nginx
./configure \
--prefix=/work/graylog-nginx
配置Graylog 负载均衡
sudo vim /work/nginx/conf/nginx.conf
upstream graylog_servers { least_conn; server 192.168.122.71:9000 max_fails=3 fail_timeout=30s; server 192.168.122.72:9000 max_fails=3 fail_timeout=30s; server 192.168.122:9000 max_fails=3 fail_timeout=30s; } server { listen 9100; server_name 192.168.122.71:9100; location / { proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Graylog-Server-URL http://$server_name/; proxy_pass http://graylog_servers; } }
在线加载配置 cd /work/nginx/sbin sudo nginx -s reload 查看版本 nginx -v 停止nginx服务 sudo nginx -s stop 检查配置文件语法是否有误 sudo nginx -t 查看nginx 安装了哪些模块 nginx -V
cd /var/log/graylog-server/server.log
如何使用Logstash 转发到 Graylog?
bin/logstash-plugin install logstash-output-gelf
output { gelf { host => "graylog_ip_address" port => 12201 } stdout { codec => rubydebug } }
Graylog-Inputs 配置为GELF UDP,监听端口12201