使用Puppet配置Graylog服务器

时间:2020-03-21 11:42:57  来源:igfitidea点击:

我们将使用Puppet来安装和配置Graylog服务器。

测试环境

我们已经安装了CentOS 7 VM,我们希望将其配置为Graylog服务器:

syslog.igi.local(10.11.1.14)带有Apache前端的Graylog/Elasticsearch/MongoDB

SELinux设置为强制模式。

请参见下图,以确定本文适用的homelab部分。

用Puppet配置

Puppet Master 在Katello服务器上运行。

Puppet模块

我们使用graylog-graylog Puppet模块来配置服务器。

该模块仅管理Graylog本身。
我们需要其他模块来安装所需的依赖项,例如Java,MongoDB,Elasticsearch和Apache(作为反向代理):

  • puppetlabs-java
  • 弹性-弹性搜索
  • monmongodb
  • Puppet实验室
  • saz-rsyslog

请参阅每个模块的文档以获取支持的功能和可用的配置选项。

Katello存储库

Katello提供了Graylog,Elasticsearch和MongoDB的存储库(我们在此处配置了它们)。

请注意,Graylog 2.4不适用于Elasticsearch 6.x,因此我们将使用Elasticsearch5.x。

安装MongoDB

class { 'mongodb::globals':
  ## Use Katello repository
  manage_package_repo => false,
}->
class { 'mongodb::server':
  ensure     => 'present',
  restart    => true,
  bind_ip    => ['127.0.0.1'],
  port

=> 27017,
  smallfiles => true,
}

安装Elasticsearch

class { 'elasticsearch':
  ensure => 'present',
  status => 'enabled',
  ## Use Katello repository
  manage_repo => false,
  restart_on_change => true,
}->
elasticsearch::instance { 'graylog':
  config => {

'cluster.name' => 'graylog',

'network.host' => '127.0.0.1',
  },
  jvm_options => [

'-Xms512m',

'-Xmx512m'
  ]
}

安装Java和Graylog

include ::java
class { 'graylog::server':
  enable => true,
  ensure => 'running',
  config => {

'is_master'  => true,

'password_secret' => '3jC93bTD...OS7F7H87O',

'root_password_sha2' => '008e3a245354b...f0d9913325f26b',

'web_enable' => true,

'web_listen_uri' => 'http://syslog.igi.local:9000/',

'rest_listen_uri' => 'http://syslog.igi.local:9000/api/',

'rest_transport_uri' => 'http://syslog.igi.local:9000/api/',

'root_timezone' => 'GMT',
  }
}->## Use a script to automatically create 
## UDP Syslog/GELF inputs via Graylog API. file { '/root/syslog_inputs.sh':
  ensure => file,
  source => 'puppet:///homelab_files/syslog_inputs.sh',
  owner  => '0',
  group  => '0',
  mode   => '0700',
  notify => Exec['create_syslog_inputs'],
}
exec {'create_syslog_inputs':
  command     => '/root/syslog_inputs.sh',
  refreshonly => true,
}

文件“ syslog_inputs.sh”的内容可以在下面看到。

我们创建了两个Graylog输入,一个用于syslog绑定到UDP 1514,另一个用于GELF。
请参阅以下部分,了解从UDP 514到UDP 1514的端口重定向,因为Graylog除非以root身份运行,否则无法绑定到UDP 514.

#!/bin/bash
GRAYLOG_URL="http://admin:Hyman@theitroad:9000/api/system/inputs";
GRAYLOG_INPUT_SYSLOG_UDP='
{
  "global": "true",
  "title": "Syslog UDP",
  "configuration": {

"port": 1514,

"bind_address": "0.0.0.0"
  },
  "type": "org.graylog2.inputs.syslog.udp.SyslogUDPInput"
}';
GRAYLOG_INPUT_GELF_UDP='
{
  "global": "true",
  "title": "Gelf UDP",
  "configuration": {

"port": 12201,

"bind_address": "0.0.0.0"
  },
  "type": "org.graylog2.inputs.gelf.udp.GELFUDPInput"
}';
curl -s -X POST -H "Content-Type: application/json" -d "${GRAYLOG_INPUT_SYSLOG_UDP}" ${GRAYLOG_URL} >/dev/null;
curl -s -X POST -H "Content-Type: application/json" -d "${GRAYLOG_INPUT_GELF_UDP}" ${GRAYLOG_URL} >/dev/null;
exit 0;

配置防火墙

配置防火墙以允许WebUI,系统日志和GELF通信。
还要配置端口重定向,因为Graylog除非以root身份运行,否则无法绑定到UDP 514.

firewall { '007 allow Graylog HTTP/S':
  dport  => [80, 443, 9000],
  source => '10.11.1.0/24',
  proto  => tcp,
  action => accept,
}->
firewall { '008 allow Syslog':
  dport  => ['514', '1514'],
  source => '10.11.1.0/24',
  proto  => udp,
  action => accept,
}->
firewall { '009 redirect Syslog 514 to Graylog 1514':
  chain    => 'PREROUTING',
  jump     => 'REDIRECT',
  proto    => 'udp',
  dport    => '514',
  toports  => '1514',
  table    => 'nat',
}->
firewall { '010 allow Gelf':
  dport  => ['12201'],
  source => '10.11.1.0/24',
  proto  => udp,
  action => accept,
}

带有TLS的Apache反向代理

安装Apache作为Graylog的反向代理。

class { 'apache':
  default_vhost     => false,
  default_ssl_vhost => false,
  default_mods

=> false,
  mpm_module

=> 'prefork',
  server_signature  => 'Off',
  server_tokens     => 'Prod',
  trace_enable

=> 'Off',
}
include apache::mod::proxy
include apache::mod::proxy_http
include apache::mod::rewrite
include apache::mod::ssl
include apache::mod::headers
apache::vhost { 'graylog_http':
  port => 80,
  servername => 'syslog.igi.local',
  rewrites => [

{ rewrite_rule => ['(.*) https://%{HTTP_HOST}%{REQUEST_URI}'],

rewrite_cond => ['%{HTTPS} off'],

},
  ],
  docroot => false,
  manage_docroot => false,
  suphp_engine => 'off',
}
apache::vhost { 'graylog_https':
  port => 443,
  servername => 'syslog.igi.local',
  docroot => false,
  manage_docroot => false,
  suphp_engine => 'off',
  ssl => true,
  ssl_cert => '/etc/pki/tls/certs/hl.crt',
  ssl_key  => '/etc/pki/tls/private/hl.key',
  ssl_protocol => ['all', '-SSLv2', '-SSLv3'],
  ssl_cipher => 'HIGH:!aNULL!MD5:!RC4',
  ssl_honorcipherorder => 'On',
  ## Pass a string of custom configuration directives
  custom_fragment => '

ProxyRequests Off

<Proxy *>

Require ip 10.11.1.0/24

</Proxy>

<Location

RequestHeader set X-Graylog-Server-URL "https://syslog.igi.local/api/"

ProxyPass http://syslog.igi.local:9000/

ProxyPassReverse http://syslog.igi.local:9000/

</Location>
  ',
}

在所有服务器上配置日志转发

我们要配置所有homelab服务器以将syslog转发到Graylog。

这需要进入主环境列表文件“ /etc/puppetlabs/code/environments/homelab/manifests/site.pp”,以便将配置应用于所有服务器。

class { 'rsyslog::client':
  log_remote => true,
  log_local => true,
  remote_servers => false,
  server => 'syslog.igi.local',
  port => '1514',
  remote_type => 'udp',
  remote_forward_format => 'RSYSLOG_SyslogProtocol23Format',
}

所有服务器将日志转发到Graylog。