第3步:安装MongoDB

将MongoDB存储库键添加到Ubuntu:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

添加密钥后,请执行以下命令以添加存储库 Ubuntu 18.04

echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

如果是Ubuntu 16.04

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

运行以下命令以安装包。

sudo apt update
sudo apt install mongodb-org

安装MongoDB后,下面的命令可用于停止,启动MongoDB服务和使MongoDB在系统启动时自动启动。

sudo systemctl stop mongod.service
sudo systemctl start mongod.service
sudo systemctl enable mongod.service

默认情况下,MongoDB的侦听端口27017。

查看MongoDB的状态:

sudo systemctl status mongod

输出示例:

mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2016-02-27 18:07:55 CST; 12s ago
     Docs: https://docs.mongodb.org/bananaal
 Main PID: 6273 (mongod)
   CGroup: /system.slice/mongod.service
           └─6273 /usr/bin/mongod --config /etc/mongod.conf
Nov 27 18:07:55 ubuntu1804 systemd[1]: Started MongoDB Database Server.

第2步:安装Elasticsearch

要运行Graylog,我们需要安装Elasticsearch。

添加Elasticsearch GPG密钥:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add 

将其包存储库添加到Ubuntu:

sudo sh -c 'echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" > /etc/apt/sources.list.d/elastic-6.x.list'

更新APT包列表并安装Elasticsearch:

sudo apt update
sudo apt install elasticsearch

安装Elasticsearch包后,您可以使用下面的命令确保服务器启动时自动启动,并立即启动。

sudo systemctl start elasticsearch.service
sudo systemctl enable elasticsearch.service

要检查Elasticsearch的状态,请运行以下命令:

sudo systemctl status elasticsearch.service

输出示例:

elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2016-02-27 18:03:04 CST; 20s ago
     Docs: http://www.elastic.co
 Main PID: 4524 (java)
    Tasks: 52 (limit: 4666)
   CGroup: /system.slice/elasticsearch.service
           ├─4524 /usr/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.networkaddres
           └─4588 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller
Nov 27 18:03:04 ubuntu1804 systemd[1]: Started Elasticsearch.
Nov 27 18:03:04 ubuntu1804 elasticsearch[4524]: warning: Falling back to java on path. This behavior is deprecated. Specify JAVA_HOME

如果我们正在运行单个主机服务器和从同一服务器连接的客户端,则无需配置。
如果客户端将从远程系统连接,则我们需要允许外部客户端。

打开 elasticsearch.yml配置文件:

sudo nano /etc/elasticsearch/elasticsearch.yml

我们需要将配置文件中显示的群集名称设置为 graylog

然后搜索包含network.host行,将其取消注释,值更改为0.0.0.0

# ---------------------------------- Cluster --------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: graylog
#
# Use a descriptive name for the node:
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0    
#
# Set a custom port for HTTP:

保存文件并退出。

重新启动ElasticSearch服务:

sudo systemctl restart elasticsearch.service

第4步:安装Graylog

下载并安装Graylog

cd /tmp
wget https://packages.graylog2.org/repo/packages/graylog-3.0-repository_latest.deb
sudo dpkg -i graylog-3.0-repository_latest.deb
sudo apt update
sudo apt install graylog-server

输出示例:

Graylog does NOT start automatically!
Please run the following commands if you want to start Graylog automatically on system boot:
    sudo systemctl enable graylog-server.service
    sudo systemctl start graylog-server.service

接下来,我们需要设置密码或者密码以保护服务器。

安装pwgen用于生成64个字符的密码。

sudo apt install pwgen

然后运行以下命令以在下面的配置文件中生成密码:
pwgen -N 1 -s 96

复制输出密码并将其用作配置文件中的 password_secret

hFvp8sWsnNgYa0WuS6ZFkq8aFfQ5tGLBrqSyhvFMTpC1DX1jGsCgzBpi02J6WVlhJN4JiF2Xi9R42q43bpvxaEJCPgAGUvB3

运行下面的命令将管理员密码转换为哈希值。

echo -n your_password_here | shasum -a 256

输出示例:

af65fdd1457c6e3136a14c6b3338fce31181ceaa7efb51c40a86d436fb06dafdf39234

它将用于配置文件中的root_password_sha2

打开Graylog Server配置文件:

sudo nano /etc/graylog/server/server.conf

填入刚才生成的加密密码:

# You MUST set a secret to secure/pepper the stored user passwords here. Use at least 64 characters.
# Generate one by using for example: pwgen -N 1 -s 96
password_secret = hFvp8sWsnNgYa0WuS6ZFkq8aFfQ5tGLBrqSyhvFMTpC1DX1jGsCgzBpi02J6WVlhJN4JiF2Xi9R42q43bpvxaEJCPgAGUvB3
# The default root user is named 'admin'
#root_username = admin
# You MUST specify a hash password for the root user (which you only need to initially set up the
# system and in case you lose connectivity to your authentication backend)
# This password cannot be changed using the API or via the web interface. If you need to change it,
# modify it in this file.
# Create one by using for example: echo -n yourpassword | shasum -a 256
# and put the resulting hash value into the following line
root_password_sha2 = af65fdd1457c6e3136a14c6b3338fce31181ceaa7efb51c40a86d436fb06dafdf39234
# The email address of the root user.

同时添加下面内容到配置文件中。

root_email = "admin@example.com"
http_bind_address = 127.0.0.1:9000

保存文件并退出,然后重新启动Graylog服务器。

sudo systemctl restart graylog-server

要检查Graylog Service的状态,请运行以下命令:

sudo systemctl status graylog-server

输出示例:

Loaded: loaded (/usr/lib/systemd/system/graylog-server.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2016-02-27 18:14:40 CST; 13s ago
     Docs: http://docs.graylog.org/
 Main PID: 8163 (graylog-server)
    Tasks: 86 (limit: 4666)
   CGroup: /system.slice/graylog-server.service
           ├─8163 /bin/sh /usr/share/graylog-server/bin/graylog-server
           └─8164 /usr/bin/java -Xms1g -Xmx1g -XX:NewRatio=1 -server -XX:+ResizeTLAB -XX:+UseConcMarkSweepGC -XX:+CMSConcurrentMTEnabled -XX:+CMSClassUnloadingEn
Nov 27 18:14:40 ubuntu1804 systemd[1]: Stopped Graylog server.
Nov 27 18:14:40 ubuntu1804 systemd[1]: Started Graylog server.

使用浏览器,打开Graylog服务器主页:
http://example.com:9000

使用默认的管理员用户名和上面创建的密码登录。

开始设置环境

Graylog节点通过输入接受数据。
从系统 - >输入页面启动或者终止我们想要的许多输入。

第一步是创建输入。
输入定义了Graylog收集日志的方法。
Graylog支持多种收集日志的方法,包括:

  • Syslog(TCP,UDP,AMQP,Kafka)
  • GEL(TCP,UDP,AMQP,KAFKA,HTTP)
  • AWS - AWS日志,流程,CloudTrail
  • Beats/logstash.
  • CEF(TCP,UDP,AMQP,Kafka)
  • 来自HTTP API的JSON路径
  • netflow(UDP)
  • 普通/原始文本(TCP,UDP,AMQP,Kafka)

要创建输入,请在顶部菜单中打开系统==>输入页面,单击下拉字段中的箭头,选择输入类型,然后单击标记为启动新输入的绿色按钮。

通常,默认设置是正确的。
某些输入类型可能需要身份验证或者特定于该源的其他信息。

如何在Ubuntu上安装Graylog

Graylog是一个开源日志管理软件,可从集中式服务器跨网络系统提供监视和分析。
它可以监视,搜索和分析大量数据,(尤其是在较大的环境中)以简单的格式,以便我们可以轻松读取和摘要。

第1步:安装OpenJDK

要运行Elasticsearch,我们必须安装Java。

要安装Java的开源版本,请运行以下命令:

sudo apt update
sudo apt-get install openjdk-8-jre-headless apt-transport-https uuid-runtime dirmngr

安装Java后,下面的命令可用于查看其版本

java -version

输出示例:

openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-8u242-b08-0ubuntu3~18.04-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
日期:2020-07-07 20:55:55 来源:oir作者:oir