自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

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

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

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

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

Graylog 2 的組件

Graylog 2 有 4 個(gè)基本組件:

  • Graylog Server:這個(gè)服務(wù)負(fù)責(zé)接收和處理日志/消息,并且和其他組件溝通。
  • Elasticsearch:存儲(chǔ)所有的日志,它的性能依賴內(nèi)存和硬盤IO。
  • MongoDB:存儲(chǔ)數(shù)據(jù)。
  • Web接口:用戶接口。

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

 

安裝和配置 Graylog 2

環(huán)境依賴

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

  • 一臺(tái) 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 是最小化安裝的,還需要提前安裝以下軟件包:

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

安裝 Java JDK

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

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

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

  1. update-alternatives --config java 

安裝 Elasticsearch

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

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

編輯 Elasticsearch 配置文件:

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

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

  1. $ sudo systemctl daemon-reload 
  2.  
  3. $ sudo systemctl restart elasticsearch.service  

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

  1. $ sudo systemctl enable elasticsearch.service 

測試 Elastisearch 工作是否正常

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

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

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

  1. $ curl -XGET 'http://localhost:9200/_cluster/health?pretty=true' 
  2. "cluster_name" : "graylog"
  3. "status" : "green"
  4. "timed_out" : false
  5. "number_of_nodes" : 1, 
  6. "number_of_data_nodes" : 1, 
  7. "active_primary_shards" : 0, 
  8. "active_shards" : 0, 
  9. "relocating_shards" : 0, 
  10. "initializing_shards" : 0, 
  11. "unassigned_shards" : 0, 
  12. "delayed_unassigned_shards" : 0, 
  13. "number_of_pending_tasks" : 0, 
  14. "number_of_in_flight_fetch" : 0, 
  15. "task_max_waiting_in_queue_millis" : 0, 
  16. "active_shards_percent_as_number" : 100.0 
  17.  

安裝 MongoDB

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

  1. $ sudo apt-get install mongodb-server 

啟動(dòng) MongoDB 服務(wù)

  1. $ sudo systemctl start mongodb 

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

  1. $ sudo systemctl enable mongodb 

安裝 Graylog Server

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

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

編輯 Graylog Server 配置文件:

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

  1. $ pwgen -N 1 -s 96 
  2. 1jfPjMRn5XRsCdVWArjy1nulgXbUJJ8khuW0xQGrqUvJ1iXefhqSh12xsp1dZgkKVsOwiOuDLArh6TYafQE8QFDjEzUIU1tS  

修改 password_secret 參數(shù)值:

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

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

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

  1. $ echo -n 000000 | sha256sum 
  2. 91b4d142823f7d20c5f08df69122de43f35f057a988d9619f6d3138485c9a203  

修改 root_password_sha2 參數(shù)值:

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

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

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

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

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

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

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

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

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

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

  1. elasticsearch_index_prefix = graylog 
  2. elasticsearch_connect_timeout = 10s 
  3. elasticsearch_max_docs_per_index = 20000000 
  4. elasticsearch_max_total_connections = 20 
  5. elasticsearch_max_number_of_indices = 20 
  6. elasticsearch_shards = 1 
  7. elasticsearch_replicas = 0  

安裝 Graylog Web 接口

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

配置 Graylog Web 接口

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

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

啟動(dòng) Graylog Server 服務(wù):

  1. $ sudo systemctl daemon-reload 
  2.  
  3. $ sudo systemctl start graylog-server.service  

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

  1. $ sudo systemctl enable graylog-server.service 

訪問 Graylog Web

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

 

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

創(chuàng)建 Syslog UDP 輸入

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

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

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

  • Node: 在列表中選擇你的 Graylog Server 服務(wù)器
  • Title: Linux Server Logs
  • Port: 8514
  • Bind address: 0.0.0.0
  • 點(diǎn)擊 Save

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

 

本次測試采用同一臺(tái)服務(wù)器做演示,所以綁定到所有網(wǎng)卡接口。如只在特定網(wǎng)絡(luò)中訪問,請(qǐng)按實(shí)際情況填寫 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,請(qǐng)按以下格式配置:

  1. *.* @graylog_server_ip:8514;RSYSLOG_SyslogProtocol23Format 

如果你的 rsyslog 版本 < 5.10,請(qǐng)按以下格式配置:

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

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

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

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

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

  1. $ sudo systemctl restart rsyslog 

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

 

搜素 Graylog

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

 

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

 

一些常用的搜索語法

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

更詳細(xì)搜索語法可參考官方文檔: http://docs.graylog.org/en/2.3/pages/queries.html

到此為止,就完成了一個(gè)基本的可以從其它服務(wù)器收集日志的 Graylog 服務(wù)器部署。當(dāng)然 Graylog 還提供了其它一系列的豐富功能,比如儀表板、警報(bào)和流等功能,期待我們下次進(jìn)一步的探索吧。

參考文檔

  • http://www.google.com
  • http://blog.topspeedsnail.com/archives/6670
  • http://docs.graylog.org/en/2.3/pages/installation/os/ubuntu.html
  • https://marketplace.graylog.org/addons/a47beb3b-0bd9-4792-a56a-33b27b567856
  • https://www.digitalocean.com/community/tutorials/how-to-manage-logs-with-graylog-2-on-ubuntu-16-04 
責(zé)任編輯:龐桂玉 來源: 運(yùn)維之美
相關(guān)推薦

2017-08-03 10:36:08

UbuntuCertbotNGINX

2017-10-17 11:10:45

UbuntuSQL Server

2013-10-22 10:59:37

Ubuntu 13.1Linux Linux服務(wù)器部署

2017-05-08 16:52:40

UbuntuApacheJenkins

2009-12-08 12:23:15

UbuntuFTP服務(wù)器

2014-04-03 16:36:46

Ubuntu ServCacti服務(wù)器監(jiān)控

2021-09-16 07:52:18

FTP服務(wù)器Linux

2011-02-25 15:38:58

2014-12-16 10:17:01

RHEL6.5samba

2016-09-30 13:48:25

UbuntuPython報(bào)警系統(tǒng)

2021-06-10 09:48:48

Ubuntu 16.0FreeRADIUSDaloradius

2010-05-25 09:45:06

SVN服務(wù)器環(huán)境配置

2012-05-15 17:35:57

操作系統(tǒng)Ubuntu

2016-12-29 10:52:09

LinuxUbuntu郵件服務(wù)器

2017-01-09 08:59:17

Ubuntu郵件服務(wù)器

2013-07-16 14:44:43

Ubuntutftp服務(wù)器

2011-08-29 14:20:00

Ubuntusamba

2011-08-29 15:23:11

Ubuntuapache

2017-03-17 14:05:48

LinuxUbuntuFTP服務(wù)器

2010-05-24 10:12:41

Ubuntu流媒體服務(wù)器
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)