本文档简单介绍安装过程,可以参考graylog2官方文档http://docs.graylog.org/en/2.4/此安装过程在CentOS7 64 中进行。


第一部分:    Server端的部署

一. 安装dockerdocker-compose

1、使用yum直接安装 yum -y install docker

2、安装完成后启动docker服务 sudo service docker start

3、安装compose可以使用不同方式

  ①、直接使用Python-pip安装 pip install docker-compose

  ②、下载脚本执行安装

      $ sudo curl -L --fail https://github.com/docker/compose/releases/download/1.21.2/run.sh -o /usr/local/bin/docker-compose

      $ sudo chmod +x /usr/local/bin/docker-compose

        $ docker-compose -version查看是否安装成功

Ps:镜像加速

鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,我们可以需要配置加速器来解决,我使用的是网易的镜像地址:http://hub-mirror.c.163.com

新版的 Docker 使用 /etc/docker/daemon.json(Linux) 或者 %programdata%\docker\config\daemon.json(Windows) 来配置 Daemon。

请在该配置文件中加入(没有该文件的话,请先建一个):

  {"registry-mirrors": ["http://hub-mirror.c.163.com"]}

 

二. 准备graylog2相关配置文件

1mkdir -p /graylog/config

2cd /graylog/config

3wget https://raw.githubusercontent.com/Graylog2/graylog2-images/2.0/docker/config/graylog.conf

4wget https://raw.githubusercontent.com/Graylog2/graylog2-images/2.0/docker/config/log4j2.xml

三. 新建docker-compose.yml文件,下载并运行相关镜像

配置文件如下:

version: '2'

services:

  mongodb:

    image: mongo:3

  elasticsearch:

    image: elasticsearch:5.6.3

    environment:

      - http.host=0.0.0.0

      - transport.host=localhost

      - network.host=0.0.0.0

      - xpack.security.enabled=false

      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"

    ulimits:

      memlock:

        soft: -1

        hard: -1

    mem_limit: 1g

  graylog:

    image: graylog/graylog:2.4.0-1

    environment:

      - GRAYLOG_PASSWORD_SECRET=somepasswordpepper

      - GRAYLOG_ROOT_PASSWORD_SHA2=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918

      - GRAYLOG_WEB_ENDPOINT_URI=http://192.168.148.67:9000/api

    links:

      - mongodb:mongo

      - elasticsearch

    depends_on:

      - mongodb

      - elasticsearch

    ports:

      - 9000:9000

      - 1514:1514/udp

      - 5044:5044/udp

      - 12201:12201/udp

      - 12202:12202/udp

配置文件中有几个注意的地方:

①、对密码进行加盐处理,例如

md5(md5(password)+salt)和SHA512(SHA512(password)+salt) 方式,这里使用pwgen生成密码:pwgen -N 1 -s 96

root_password_sha2    

8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918

graylog-web登录的用户密码,使用 sha256sum进行加密。

密码加密命令:echo -n yourpassword | sha256sum

②、将配置文件中的GRAYLOG_WEB_ENDPOINT_URI修改成自己的server-Ip

②、ports配置的端口是后面采集日志使用的,可以后面再统一

保存文件后:直接执行docker-compose up

如要在后台运行 -d

运行后可以执行docker -ps查看相关镜像运行情况

 

运行成功后访问http://127.0.0.1:9000查看web服务。

如使用上面的配置,可以admin/admin登录系统。

 


第二部分:    Collector端的部署

四. Graylog Collector Sidecar是一种用于采集日志的轻量级配置管理系统,也称为后端,作为守护进程运行。

             

Sidecar支持NxlogFilebeatWinlogbeat。支持的功能几乎相同,可以在web界面进行切换,对于所有收集器,可以使用带有SSL加密的GELF输出。

在服务器端,您可以与多个收集器共享输入,例如,所有FilebeatWinlogbeat实例都可以将日志发送到单个Graylog-Beats输入。

这里Nxlog作为后端来进行配置。

五. 开始配置日志收集端。

1、安装collector-sidecaryum源不提供所以只能到官方下载,这里有不同环境的下载地址https://github.com/Graylog2/collector-sidecar/releases

①、下载安装包  

$ wget https://github.com/Graylog2/collector-sidecar/releases/download/0.1.6/collector-sidecar-0.1.6-1.x86_64.rpm

②、安装服务并启动

$ rpm -i collector-sidecar-0.1.6-1.x86_64.rpm

$ sudo graylog-collector-sidecar -service install

$ sudo systemctl start collector-sidecar

③、编辑配置文件

$ vim /etc/graylog/collector-sidecar/collector_sidecar.yml

配置文件如下:

server_url: http://192.168.148.67:9000/api/

update_interval: 30

tls_skip_verify: false

send_status: true

list_log_files:

collector_id: file:/etc/graylog/collector-sidecar/collector-id

cache_path: /var/cache/graylog/collector-sidecar

log_path: /var/log/graylog/collector-sidecar

log_rotation_time: 86400

log_max_age: 604800

tags:

    - apache

backends:

    - name: nxlog

      enabled: true

      binary_path: /usr/bin/nxlog

      configuration_path: /etc/graylog/collector-sidecar/generated/nxlog.conf

    - name: filebeat

      enabled: false

      binary_path: /usr/bin/filebeat

      configuration_path: /etc/graylog/collector-sidecar/generated/filebeat.yml

2、安装nxlog,同样的yum源不提供,这里有不同环境的下载地址https://nxlog.co/products/nxlog-community-edition/download

$ w get https://nxlog.co/system/files/products/files/348/nxlog-ce-2.10.2102-1_rhel7.x86_64.rpm

$ yum localinstall nxlog-ce-2.10.2102-1_rhel7.x86_64.rpm -y

$ systemctl start nxlog

配置文件如下:

## This is a sample configuration file. See the nxlog reference manual about the

## configuration options. It should be installed locally under

## /usr/share/doc/nxlog-ce/ and is also available online at

## http://nxlog.org/docs

########################################

# Global directives                    #

########################################

User nxlog

Group nxlog

 

LogFile /var/log/nxlog/nxlog.log

LogLevel INFO

########################################

# Modules                              #

########################################

<Extension _syslog>

    Module      xm_syslog

</Extension>

<Input in>

    Module      im_file

    File   "/var/log/test.log"

    SavePos  TRUE

</Input>

<Output out>

    Module      om_udp

    Host        192.168.148.67

    Port        12201

</Output>

########################################

# Routes                               #

########################################

<Route r>

    Path        in => out

</Route>

补充一下:NXLOG分为三个模块.第一个是读取日志的路径.是input;第二个是将数据送到Remote Server.这个是output;第三个是path,定义input和output的映射.

六. 进入web界面开始配置collectorinput

①、创建一个新的collector

 

②、创建tag并更新

 

③、创建输出output,选择type,填写server ip port

 

④、创建输出input,选择file input输入,并填写日志文件,可以用*等匹配多个

 

⑤、确定collector运行正常

 

⑥、配置grayloginput

 

⑦、创建新的输入节点


⑧、填写标题,选择节点。

 

⑨、最后查看是否开始收集日志

 

 



补充:

 

1、添加Stream

点击 graylog->stream,可以直接克隆一份已有的,修改名字,并启动

 

2、设置邮件报警

点击alerts->Manage condition->Add new condition ,选择新加的stream,在condition type中选择:Message Count Alert Condition,点击add

 

点击edit,设置报警频率

 

点击Manage notifications->add new notification,选择新添加的一条stream,在type中选择Email Alert Callback,添加title,及收件人邮箱,并删掉发件人邮箱,

点击保存

 

 

3、设置邮件转发

选择error output

4、查看是否添加成功

search上搜索是否收到该项目的日志信息,name:项目名称

若有,则添加成功

 

 

搭建过程中一些记录

大致日志流向:graylog服务器里system->collector里所展示的就是所有安装了sidecar并监听到日志的服务器collector里的input用来接收日志,output用来将日志转发给graylog服务器graylog服务器里system->Input,用来接收监听转发过来的日志,再通过output发出去。

 

collector-sidecar安装好后会在/etc/graylog/collector-sidecar

可通过查看generated/filebeat.xml来查看是否接收到了项目日志

使用‘graylog-collector-sidecar -c /etc/graylog/collector-sidecar/collector_sidecar.yml’校验指定的collector-sidecar配置文件是否正确,

并查看/var/log/collector-sidecar.err‘或者‘/var/log/messages‘来获取错误详情。


可以参考:

https://blog.csdn.net/u012954706/article/details/79592060

https://blog.csdn.net/iwannarun/article/details/52604646

http://www.ywnds.com/?p=7705

https://www.cnblogs.com/elevenheart/p/7205388.html



 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐