Ubuntu16.04下如何部署Graylog日志服務(wù)器

這篇文章主要介紹Ubuntu 16.04下如何部署Graylog日志服務(wù)器,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!

公司主營業(yè)務(wù):成都網(wǎng)站建設(shè)、成都做網(wǎng)站、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。成都創(chuàng)新互聯(lián)是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊有機(jī)會用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)推出羅平免費做網(wǎng)站回饋大家。

Graylog 是一個開源的日志管理系統(tǒng),集中式收集、索引、分析其它服務(wù)器發(fā)來的日志。它是由 Java 語言編寫的,能夠接收 TCP、UDP、AMQP  協(xié)議發(fā)送的日志信息,并且使用 MongoDB 做為后臺數(shù)據(jù)庫。它還有一個使用 Ruby 編寫的 Web 管理接口,可以輕松管理 Graylog  和查詢?nèi)罩尽?/p>

Graylog  可以收集監(jiān)控多種不同應(yīng)用的日志。本文只是會為了示范說明,會把用到的組件全部安裝到一個單獨的服務(wù)器上。對于大型、生產(chǎn)系統(tǒng)你可以把組件分開安裝在不同的服務(wù)器上,這樣可以提高效率。

Graylog 2 的組件

Graylog 2 有 4 個基本組件:

  • Graylog Server:這個服務(wù)負(fù)責(zé)接收和處理日志/消息,并且和其他組件溝通。

  • Elasticsearch:存儲所有的日志,它的性能依賴內(nèi)存和硬盤IO。

  • MongoDB:存儲數(shù)據(jù)。

  • Web接口:用戶接口。

下面是 Graylog 2 各組件之間的關(guān)系圖

Ubuntu 16.04下如何部署Graylog日志服務(wù)器

安裝和配置 Graylog 2

環(huán)境依賴

Graylog 2 需要以下環(huán)境依賴:

  • 一臺 Ubuntu 16.04 服務(wù)器,至少有 2 GB 的 RAM。

  • Elasticsearch (>= 2.x,推薦使用***穩(wěn)定版本。)

  • MongoDB (>= 2.4,推薦使用***穩(wěn)定版本。)

  • Oracle Java SE 或 OpenJDK (>= 8,推薦使用***穩(wěn)定版本。)

如果你的 Ubuntu Server 是最小化安裝的,還需要提前安裝以下軟件包:

$ sudo apt-get install apt-transport-https uuid-runtime pwgen

安裝 Java JDK

Elasticsearch 是基于 Java 的應(yīng)用,我們首先需要安裝 OpenJDK 或 Oracle JDK。這里我們選擇安裝 OpenJDK  8:

$ sudo apt-get update && sudo apt-get install openjdk-8-jdk

如果你的系統(tǒng)上存在多個 Java 版本,可使用以下指令設(shè)置默認(rèn)使用版本。

$ update-alternatives --config java

安裝 Elasticsearch

Elasticsearch 是 Graylog 一個主要的組件,負(fù)責(zé)分析和索引日志。Graylog 2.3.x 開始支持 Elasticsearch  5.x, 這里我們就安裝 Elasticsearch 5.x 版本。

# 添加 GPG 簽名密鑰 $ wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - # 添加 Eleasticsearch 源 $ echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list # 安裝 Elasticsearch $ sudo apt-get update && sudo apt-get install elasticsearch

編輯 Elasticsearch 配置文件:

$ sudo vim /etc/elasticsearch/elasticsearch.yml # 把 cluster.name 設(shè)置為 graylog。 cluster.name: graylog

修改配置后,你需要重啟 Elasticsearch:

$ sudo systemctl daemon-reload  $ sudo systemctl restart elasticsearch.service

如果要把 Elasticsearch 服務(wù)加入隨系統(tǒng)啟動,可以執(zhí)行以下命令:

$ sudo systemctl enable elasticsearch.service

測試 Elastisearch 工作是否正常

Elastisearch 默認(rèn)使用 9200 端口接收 http 請求,這里使用 curl 指令進(jìn)行一個簡單的請求測試。

$ curl -X GET http://localhost:9200 { "name" : "V8jWSvJ", "cluster_name" : "graylog", "cluster_uuid" : "8cnTgvEzRZ2U81LTYq5nEw", "version" : { "number" : "5.6.3", "build_hash" : "1a2f265", "build_date" : "2017-10-06T20:33:39.012Z", "build_snapshot" : false, "lucene_version" : "6.6.1" }, "tagline" : "You Know, for Search" }

查看 Elasticsearch 的健康狀態(tài)

$ curl -XGET 'http://localhost:9200/_cluster/health?pretty=true' { "cluster_name" : "graylog", "status" : "green", "timed_out" : false, "number_of_nodes" : 1, "number_of_data_nodes" : 1, "active_primary_shards" : 0, "active_shards" : 0, "relocating_shards" : 0, "initializing_shards" : 0, "unassigned_shards" : 0, "delayed_unassigned_shards" : 0, "number_of_pending_tasks" : 0, "number_of_in_flight_fetch" : 0, "task_max_waiting_in_queue_millis" : 0, "active_shards_percent_as_number" : 100.0 }

安裝 MongoDB

Ubuntu 16.04 默認(rèn)安裝源中包含的 MongoDB (目前版本是 2.6.10) 是支持 Graylog 2.3.x 或更高版本的。

$ sudo apt-get install mongodb-server

啟動 MongoDB 服務(wù)

$ sudo systemctl start mongodb

如果要把 MongoDB 服務(wù)加入隨系統(tǒng)啟動,可以執(zhí)行以下命令:

$ sudo systemctl enable mongodb

安裝 Graylog Server

Graylog Server 負(fù)責(zé)接收和處理日志。

# 下載安裝 Graylog Server 倉庫 $ wget https://packages.graylog2.org/repo/packages/graylog-2.3-repository_latest.deb $ sudo dpkg -i graylog-2.3-repository_latest.deb  # 安裝 Graylog Server $ sudo apt-get update && sudo apt-get install graylog-server

編輯 Graylog Server 配置文件:

設(shè)置 password_secret,首先使用 pwgen 命令生成密碼:

$ pwgen -N 1 -s 96 1jfPjMRn5XRsCdVWArjy1nulgXbUJJ8khuW0xQGrqUvJ1iXefhqSh22xsp1dZgkKVsOwiOuDLArh7TYafQE8QFDjEzUIU1tS

修改 password_secret 參數(shù)值:

$ sudo vim /etc/graylog/server/server.conf password_secret = 1jfPjMRn5XRsCdVWArjy1nulgXbUJJ8khuW0xQGrqUvJ1iXefhqSh22xsp1dZgkKVsOwiOuDLArh7TYafQE8QFDjEzUIU1tS

設(shè)置 Graylog Server 管理員密碼 root_password_sha2,這個密碼用來登錄 Web 管理頁面。

假如你要把密碼設(shè)置為 000000 ,可以使用 sha256sum 命令來生成:

$ echo -n 000000 | sha256sum 91b4d142823f7d20c5f08df69122de43f35f057a988d9619f6d3138485c9a203

修改 root_password_sha2 參數(shù)值:

$ sudo vim /etc/graylog/server/server.conf root_password_sha2 = 91b4d142823f7d20c5f08df69122de43f35f057a988d9619f6d3138485c9a203

注:password_secret 和 root_password_sha2 參數(shù)是必須設(shè)定的,否則 Graylog Server 將無法啟動。

如果你要設(shè)置管理員郵箱和時區(qū),可以使用以下參數(shù)值:

$ sudo vim /etc/graylog/server/server.conf root_email = "admin@hi-linux.com" root_timezone = UTC

設(shè)置 Elasticsearch 節(jié)點:

$ sudo vim /etc/graylog/server/server.conf # Default: http://127.0.0.1:9200 elasticsearch_hosts = http://192.168.100.212:9200

如果需要配置多個 Elasticsearch 節(jié)點或是需要認(rèn)證的節(jié)點,可按以下格式配置:

elasticsearch_hosts = http://node1:9200,http://user:password@node2:19200

注:如不配置,默認(rèn)是連接到本機(jī)的 Elasticsearch 節(jié)點。

其它一些和 Elasticsearch 的相關(guān)設(shè)置:

elasticsearch_index_prefix = graylog elasticsearch_connect_timeout = 10s elasticsearch_max_docs_per_index = 20000000 elasticsearch_max_total_connections = 20 elasticsearch_max_number_of_indices = 20 elasticsearch_shards = 1 elasticsearch_replicas = 0

安裝 Graylog Web 接口

從 Graylog 2.x 版本開始,Graylog 已經(jīng)默認(rèn)集成了 Web 接口。

配置 Graylog Web 接口

$ sudo vim /etc/graylog/server/server.conf # 配置rest Api 的 URI rest_listen_uri = http://your_ip_or_domain:9001/ # 配置 Web 界面的 URI web_listen_uri = http://your_ip_or_domain:9000/

注: your_ip_or_domain 為你實際服務(wù)器 IP 或域名。

啟動 Graylog Server 服務(wù):

$ sudo systemctl daemon-reload  $ sudo systemctl start graylog-server.service

如果要把 Graylog Server 服務(wù)加入隨系統(tǒng)啟動,可以執(zhí)行以下命令:

$ sudo systemctl enable graylog-server.service

訪問 Graylog Web

使用瀏覽器訪問  http://your_ip_or_doamin:9000,能成功看到如下界面則表示安裝成功。默認(rèn)用戶名為:admin,密碼為:root_password_sha2  參數(shù)中設(shè)置的。

Ubuntu 16.04下如何部署Graylog日志服務(wù)器

添加一個需收集日志的服務(wù)器

創(chuàng)建 Syslog UDP 輸入

Ubuntu 系統(tǒng)自帶 Rsyslog 服務(wù)無需安裝,只需要配置一下即可。

打開 Graylog Web 頁面,選擇 System->Inputs->Syslog UDP->Launch new  input,添加一個要接收 Syslog 日志的服務(wù)器。

在彈出的窗口上輸入如下信息:

  • Node: 在列表中選擇你的 Graylog Server 服務(wù)器

  • Title: Linux Server Logs

  • Port: 8514

  • Bind address: 0.0.0.0

  • 點擊 Save

配置完成后就生成了一個監(jiān)聽在 8514 端口上的 Syslog 服務(wù)端,下面可以用它來收集其它服務(wù)器上的日志。

Ubuntu 16.04下如何部署Graylog日志服務(wù)器

本次測試采用同一臺服務(wù)器做演示,所以綁定到所有網(wǎng)卡接口。如只在特定網(wǎng)絡(luò)中訪問,請按實際情況填寫 Bind address 的 IP 地址。

現(xiàn)在,我們的 Graylog Server 服務(wù)器已經(jīng)做好了接收其它服務(wù)器發(fā)來日志的準(zhǔn)備。下面我們還需要配置需收集日志服務(wù)器,讓這些服務(wù)器給  Graylog Server 服務(wù)器發(fā)送日志。

配置服務(wù)器發(fā)送日志到 Graylog

創(chuàng)建 rsyslog 配置文件 /etc/rsyslog.d/90-graylog.conf。

如果你的 rsyslog 版本 > 5.10,請按以下格式配置:

*.* @graylog_server_ip:8514;RSYSLOG_SyslogProtocol23Format

如果你的 rsyslog 版本 < 5.10,請按以下格式配置:

$template GRAYLOGRFC5424,"<%PRI%>%PROTOCOL-VERSION% %TIMESTAMP:::date-rfc3339% %HOSTNAME% %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n" *.* @graylog_server_ip:8514;GRAYLOGRFC5424

注:把 graylog_server_ip 替換為 Graylog 服務(wù)器 IP 地址。

我這里使用的是 rsyslog 8.16 版本,修改后類似下面:

$ sudo vim /etc/rsyslog.d/90-graylog.conf  *.* @192.168.100.212:8514;RSYSLOG_SyslogProtocol23Format

重啟 rsyslog 服務(wù)使生效

$ sudo systemctl restart rsyslog

配置完成之后,回到 Graylog Web,點擊 Sources,查看是否有新添加 Rsyslog 來源的圖形。

Ubuntu 16.04下如何部署Graylog日志服務(wù)器

搜素 Graylog

在 Graylog Web 上,點擊 Search 可以訪問 Graylog 搜索頁面。 在這里可以根據(jù)條件查詢指定的日志。

Ubuntu 16.04下如何部署Graylog日志服務(wù)器

假如你要搜索 ssh 的活動日志,輸入關(guān)鍵字 sshd,點搜索圖標(biāo):

Ubuntu 16.04下如何部署Graylog日志服務(wù)器

一些常用的搜索語法

  • 搜索包含關(guān)鍵字 ssh 的信息

ssh
  • 搜索包含關(guān)鍵字 ssh 或 login 的信息

ssh login
  • 搜索包含完整關(guān)鍵字 ssh login 的信息

"ssh login"
  • 搜索字段類型包含 ssh 的信息

type:ssh
  • 搜索字段類型包含 ssh 或 login 的信息

type:(ssh login)
  • 搜索字段類型包含完整關(guān)鍵字 ssh login 的信息

type:"ssh login"

以上是“Ubuntu 16.04下如何部署Graylog日志服務(wù)器”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

本文名稱:Ubuntu16.04下如何部署Graylog日志服務(wù)器
文章出自:http://bm7419.com/article36/pcopsg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、移動網(wǎng)站建設(shè)網(wǎng)站收錄、網(wǎng)站設(shè)計、品牌網(wǎng)站建設(shè)定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司