rsyslog配置以及原理

rsyslog

日志由程序產生,在內存中產生。通過Rsyslog來將內存中程序產生的日志持久化到硬盤,并且支持udp、tcp等協議來進行不同服務器的日志同步。

/var/log/messages:大多數系統日志信息紀錄在此/var/log/secure:安全和身份認證相關的消息和錯誤的日志文件/var/log/maillog:與郵件服務器相關的日志文件/var/log/cron:與定時任務相關的日志文件/var/log/boot.log:與系統啟動有關的日志文件pam:在linux中執行某些程序,這些程序在執行前要對啟動它的用戶進行認證,符合一定要求后才允許執行,例如login、su等,在linux中進行身份驗證或是狀態的驗證程序由pam來進行。pam即可動態加載驗證模塊,因為可以按需要動態的對驗證的內容進行變更,大大提高驗證的靈活性。Linux-pam:是一套共享庫,使本地系統管理員可以隨意選擇程序的認證方式。使用配置/etc/pam.d/下的文件來管理對程序的認證方式。應用程序調用相應的配置文件,從而調用本地的認證模塊,模塊放置在/lib/secureity下,以加載動態庫的形式進行,像我們使用su命令時,系統提示你輸入root用戶的密碼,這就是su命令通過調用PAM模塊實現的。日志類型分為:auth:pam產生的日志authpriv:ssh,ftp等登陸信息的驗證信息cron:時間任務相關kern:內核lpr:打印mail:郵件mark(syslog)-rsyslog:服務內部的信息,時間標識news:新聞組user:用戶程序產生的相關信息uucp:unix to unix copy,unix主機之間相關的通訊local 1-7:自定義的日志設備日志級別:(由上到下,級別由低到高,記錄信息越來越少)debug:有調試信息的,日志信息最多info:一般信息的日志,最常用notice:具有重要性的普通條件的信息warning:警告級別err:錯誤級別,阻止某個功能或者模塊不能正常工作的信息crit:嚴重級別,阻止整個系統或者整個軟件不能正常運行的信息alert:需要立刻修改的信息emerg:內核崩潰等嚴重信息none:什么都不記錄

配置

test1 作為日志服務器收集日志
test4 作為客戶端

test1配置

1.安裝
yum install rsyslog -y
2.更改配置文件
vim /etc/rsyslog.conf
#這四行去掉注釋
$ModLoad imudp          收集udp日志,并開啟端口
$UDPServerRun 514$ModLoad imtcp          收集tcp日志,并開啟端口
$InputTCPServerRun 514#添加$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat#表示收集的日志存放在/var/log/rsyslog/下,收集那個機器的日志就以那個機器ip命名
$template RemoteLogs,"/var/log/rsyslog/%fromhost-ip%/%fromhost-ip%_%$YEAR%-%$MONTH%-%$DAY%.log"#不收集本機的日志
:fromhost-ip, !isequal, "127.0.0.1" ?RemoteLogs
& ~
3.重啟服務
systemctl restart rsyslog.service

2.test4客戶端配置

1.安裝
yum install rsyslog -y
2.配置
# 無論什么級別的日志都收集到 /var/log/messages*.*;mail.none;authpriv.none;cron.none                /var/log/messages#*.info;mail.none;authpriv.none;cron.none                /var/log/messages  只收集info以上的日志
#在最底部添加
*.* @@192.168.134.25:514  #@@兩個代表收集tcp的日志    
*.* @192.168.134.25:514   #@代表收集udp的日志#192.168.206.25是日志服務器的地址
3.重啟服務
systemctl restart rsyslog.service

3.測試

#此時再看服務端就有ip對應的日志
[root@test1 ~]# tail -f /var/log/rsyslog/192.168.134.28/192.168.134.28_2023-12-1
192.168.134.28_2023-12-11.log  192.168.134.28_2023-12-12.log
1.此時我們讓test4的nginx報錯
[root@test4 ~]# grep http  /etc/nginx/nginx.conf
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/
http ;{'$status $body_bytes_sent "$http_referer" '
2.重啟nginx,此時test1服務端就有日志產生
[root@test1 ~]# tail -f /var/log/rsyslog/192.168.134.28/192.168.134.28_2023-12-1
192.168.134.28_2023-12-11.log  192.168.134.28_2023-12-12.log
[root@test1 ~]# tail -f /var/log/rsyslog/192.168.134.28/192.168.134.28_2023-12-12.log
Dec 12 08:56:49 test4 polkitd[528]: Unregistered Authentication Agent for unix-process:9285:162270604 (system bus name :1.1063, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
Dec 12 08:56:49 test4 polkitd[528]: Unregistered Authentication Agent for unix-process:9285:162270604 (system bus name :1.1063, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
Dec 12 09:01:01 test4 systemd[1]: Started Session 512 of user root.
Dec 12 09:01:01 test4 systemd[1]: Started Session 512 of user root.
Dec 12 09:01:01 test4 systemd: Started Session 512 of user root.
Dec 12 09:01:01 test4 systemd: Started Session 512 of user root.
Dec 12 09:01:01 test4 CROND[9326]: (root) CMD (run-parts /etc/cron.hourly)
Dec 12 09:01:01 test4 CROND[9326]: (root) CMD (run-parts /etc/cron.hourly)
Dec 12 09:01:01 test4 CROND[9326]: (root) CMD (run-parts /etc/cron.hourly)
Dec 12 09:01:01 test4 CROND[9326]: (root) CMD (run-parts /etc/cron.hourly)Dec 12 09:36:42 test4 polkitd[528]: Registered Authentication Agent for unix-process:9860:162509910 (system bus name :1.1068 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
Dec 12 09:36:42 test4 polkitd[528]: Registered Authentication Agent for unix-process:9860:162509910 (system bus name :1.1068 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
Dec 12 09:36:42 test4 polkitd[528]: Registered Authentication Agent for unix-process:9860:162509910 (system bus name :1.1068 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
Dec 12 09:36:42 test4 polkitd[528]: Registered Authentication Agent for unix-process:9860:162509910 (system bus name :1.1068 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
Dec 12 09:36:42 test4 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Dec 12 09:36:42 test4 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Dec 12 09:36:42 test4 systemd: Starting The nginx HTTP and reverse proxy server...
Dec 12 09:36:42 test4 systemd: Starting The nginx HTTP and reverse proxy server...
Dec 12 09:36:42 test4 nginx[9867]: nginx: [emerg] directive "http" has no opening "{" in /etc/nginx/nginx.conf:17
Dec 12 09:36:42 test4 nginx[9867]: nginx: configuration file /etc/nginx/nginx.conf test failed
Dec 12 09:36:42 test4 nginx: nginx: [emerg] directive "http" has no opening "{" in /etc/nginx/nginx.conf:17
Dec 12 09:36:42 test4 nginx[9867]: nginx: [emerg] directive "http" has no opening "{" in /etc/nginx/nginx.conf:17
Dec 12 09:36:42 test4 nginx[9867]: nginx: configuration file /etc/nginx/nginx.conf test failed
Dec 12 09:36:42 test4 nginx: nginx: [emerg] directive "http" has no opening "{" in /etc/nginx/nginx.conf:17
Dec 12 09:36:42 test4 nginx: nginx: configuration file /etc/nginx/nginx.conf test failed
Dec 12 09:36:42 test4 nginx: nginx: configuration file /etc/nginx/nginx.conf test failed
Dec 12 09:36:42 test4 systemd[1]: nginx.service: control process exited, code=exited status=1
Dec 12 09:36:42 test4 systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Dec 12 09:36:42 test4 systemd[1]: Unit nginx.service entered failed state.
Dec 12 09:36:42 test4 systemd[1]: nginx.service failed.
Dec 12 09:36:42 test4 systemd: nginx.service: control process exited, code=exited status=1
Dec 12 09:36:42 test4 systemd: Failed to start The nginx HTTP and reverse proxy server.
Dec 12 09:36:42 test4 systemd: Unit nginx.service entered failed state.
Dec 12 09:36:42 test4 systemd: nginx.service failed.
Dec 12 09:36:42 test4 systemd[1]: nginx.service: control process exited, code=exited status=1
Dec 12 09:36:42 test4 systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Dec 12 09:36:42 test4 systemd[1]: Unit nginx.service entered failed state.
Dec 12 09:36:42 test4 systemd[1]: nginx.service failed.
Dec 12 09:36:42 test4 systemd: nginx.service: control process exited, code=exited status=1
Dec 12 09:36:42 test4 systemd: Failed to start The nginx HTTP and reverse proxy server.
Dec 12 09:36:42 test4 systemd: Unit nginx.service entered failed state.
Dec 12 09:36:42 test4 systemd: nginx.service failed.
Dec 12 09:36:42 test4 polkitd[528]: Unregistered Authentication Agent for unix-process:9860:162509910 (system bus name :1.1068, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
Dec 12 09:36:42 test4 polkitd[528]: Unregistered Authentication Agent for unix-process:9860:162509910 (system bus name :1.1068, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
Dec 12 09:36:42 test4 polkitd[528]: Unregistered Authentication Agent for unix-process:9860:162509910 (system bus name :1.1068, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
Dec 12 09:36:42 test4 polkitd[528]: Unregistered Authentication Agent for unix-process:9860:162509910 (system bus name :1.1068, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/215555.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/215555.shtml
英文地址,請注明出處:http://en.pswp.cn/news/215555.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

HTTP詳解

1. web 1.1 web相關概念 軟件架構 C /S:客戶端/服務器端 需要安裝客戶端應用 B/S:瀏覽器/服務器端 不需要安裝客戶端應用,對于用戶來說只需要記住域名訪問就可以,高效,客戶端零維護 資源分類 靜態資源:所有用戶訪問后&#x…

數據庫系統原理與實踐 筆記 #12

文章目錄 數據庫系統原理與實踐 筆記 #12事務管理和并發控制與恢復(續)并發控制SQL-92中的并發級別基于鎖的協議基于鎖的協議的隱患鎖的授予封鎖協議兩階段封鎖協議多粒度粒度層次的例子意向鎖類型相容性矩陣多粒度封鎖模式基于時間戳的協議基于時間戳協議的正確性基于有效性檢…

怎樣在PPT中加入音頻文件?記好這4個簡單操作!

“我要制作一個比較專業的PPT來匯報工作成果,想在PPT里加一段音樂,但是不知道應該如何操作,有沒有朋友可以指導一下呢?” PPT作為一種常用的文件形式,很多用戶會將其用于工作匯報,期末總結以及各種演講。在…

HTML---基礎

文章目錄 前言一、pandas是什么?二、使用步驟 1.引入庫2.讀入數據總結 前言 一.HTML概述 HTML(超文本標記語言)是一種用于創建網絡頁面的標記語言。它以標記的形式編寫,該標記描述了文檔的結構和內容。HTML文件由一系列標記&#…

六級高頻詞組2

目錄 詞組 參考鏈接 詞組 51. arise from(be caused by) 由…引起。 52. arrange for sb.sth. to do sth. 安排…做… 53. arrive on 到達; arrive at 到達某地(小地方);得出,作出&#x…

zookeeper基礎內容

文章目錄 Zookeeper基礎概述數據結構Zookeeper節點操作zookeeper節點操作命令數據模型 znode 結構 zookeeper java客戶端ZooKeeper原生APICuratorzkClient對比總結 Zookeeper基礎 概述 zookeeper(分布式協調服務) 本質:小型的文件存儲系統監…

寄存器、緩存、內存、硬盤、存儲器的理解

https://blog.csdn.net/heixiaolong7/article/details/51226378 只要能存儲數據的器件都可以稱之為存儲器,它的含義覆蓋了寄存器,緩存,內存,硬盤。cpu訪問快慢的速度依次為 寄存器-> 緩存->內存->硬盤 寄存器是中央處…

Springboot內置Tomcat線程數優化

Springboot內置Tomcat線程數優化 # 等待隊列長度,默認100。隊列也做緩沖池用,但也不能無限長,不但消耗內存,而且出隊入隊也消耗CPU server.tomcat.accept-count1000 # 最大工作線程數,默認200。(4核8g內存…

Spring 的緩存機制【記錄】

一、背景 在最近的業務需求開發過程中遇到了“傳說中”的循環依賴問題,在之前學習Spring的時候經常會看到Spring是如何解決循環依賴問題的,所謂循環依賴即形成了一個環狀的依賴關系,這個環中的某一個點產生不穩定變化都會導致整個鏈路產生不…

OpenCV-opencv下載安裝和基本操作

文章目錄 一、實驗目的二、實驗內容三、實驗過程OpenCV-python的安裝與配置python下載和環境配置PIP鏡像安裝Numpy安裝openCV-python檢驗opencv安裝是否成功 openCV-python的基本操作圖像輸入和展示以及寫出openCV界面編程單窗口顯示多圖片鼠標事件鍵盤事件滑動條事件 四、實驗…

唯創知音WTN6080-8S語音芯片在咖啡機中的應用:增添聲音魅力,提升用戶體驗

在快節奏的現代生活中,咖啡機已成為許多家庭和辦公室的必備設備,為人們提供了便捷和高品質的咖啡享受。然而,對于很多用戶來說,操作咖啡機可能是一項復雜而棘手的任務。為了解決這一難題,唯創知音WTN6080-8S語音芯片被…

Altman作了多少惡?排擠首席科學家出GPT5開發、離間董事會、PUA員工

在山姆奧特曼(Sam Altman)被OpenAI董事會突然解職后的幾天里,這個消息在科技圈引發轟動,該公司內部員工和許多科技界人士甚至將此舉比作一場政變。 奧特曼被解雇后立即傳出的說法是,OpenAI的廣大員工都很喜歡他&#x…

一入一出模擬量兩線制無源 4-20mA隔離變送器

一入一出模擬量兩線制無源 4-20mA隔離變送器 特征與應用: ◆薄體積,低成本,國際標準 DIN35mm 導軌安裝方式 ◆兩端隔離(輸入、輸出間相互隔離) ◆單通道輸入單通道輸出 ◆高精度等級(0.1%,0.2% F.S) ◆高線性度(0.1% F.S) ◆高隔離電壓(3000…

32位ADC布局的指導方針

接地必須是一個低阻抗連接,以使回流電流不受干擾地流回各自的源。接地面連接盡量短且直。使用過孔連接接地線時,應并聯多個過孔,以減小對地阻抗。 混合信號布局有時包含在一個位置捆綁在一起的單獨的模擬和數字地平面;但是,當模擬…

活動回顧 | 菊風亮相 GTC2023 全球流量大會

2023年12月5日-12月6日,由白鯨出海主辦的【GTC2023 全球流量大會】在中國深圳盛大召開。 本次大會薈聚海內外優質企業品牌,以專業的“展會”形式,全方位呈現跨境出海的成果,探索多元化的跨境商業模式,大會涵蓋社交娛樂…

【Jeecg Boot 3 - 第二天】1.1、后端 docker-compose 部署 JEECGBOOT3

一、場景 二、實戰 ? 2.1 修改配置文件 > 目的一:將 dev 變更為生產環境 prod > 目的二:方便spring項目調用docker同個network下的redis和mysql ? 2.2 編寫dockerfile ? 2.3 編寫docker-compose.yaml ? 2.4 打…

Qt/C++音視頻開發59-使用mdk-sdk組件/原qtav作者力作/性能兇殘/超級跨平臺

一、前言 最近一個月一直在研究mdk-sdk音視頻組件,這個組件是原qtav作者的最新力作,提供了各種各樣的示例demo,不僅限于支持C,其他各種比如java/flutter/web/android等全部支持,性能上也是杠杠的,目前大概…

cadence中如何在更新原理圖封裝

cadence中如何在更新原理圖封裝 一、更改原理圖封裝 當原理圖畫好后,如果我們發現某個封裝錯了,需要改動,需要找到你最初畫Library中器件封裝文件打開,進行修改,修改好后保存。 二、更新封裝 保存好后,…

C/C++ 有效的字母異位詞

題目: 給定兩個字符串s和t,編寫一個函數來判斷t是否是s的字母異位詞。 注:若s和t中每個字符出現的次數都相同,則稱s和t互為字母異位詞。 示例 1: 輸入: s "anagram", t "nagaram" 輸出: true …