CentOS 7安裝NXLog服務


NXLog是一個跨平台日志傳輸插件,支持linux、windows平台的大部分系統日志及常見的web日志,支持tcp、udp、http(s)等協議傳輸。本文介紹NXLog在CentOS 7服務器上的安裝,以及運行om_dbi/im_dbi所需插件的安裝。

操作系統環境:CentOS Linux release 7.6.1810 (Core)

NXLog版本:nxlog-ce-2.10.2150

 

一、安裝NXLog

由於yum中沒有直接提供NXLog,因此需要在https://nxlog.co/products/nxlog-community-edition/download下載對應操作系統的rpm后,上傳至服務器進行安裝,當然也可以直接利用wget下載安裝。。

//下載路徑
# cd /usr/local/

//下載rpm
# wget https://nxlog.co/system/files/products/files/348/nxlog-ce-2.10.2150-1_rhel7.x86_64.rpm

NXLog安裝依賴apr和libdbi,如果未安裝會報如下錯誤。

# rpm -ivh nxlog-ce-2.10.2150-1_rhel7.x86_64.rpm 
錯誤:依賴檢測失敗:
    apr >= 1.2 被 nxlog-ce-2.10.2150-1.x86_64 需要
    libapr-1.so.0()(64bit) 被 nxlog-ce-2.10.2150-1.x86_64 需要
    libdbi >= 0.8.1 被 nxlog-ce-2.10.2150-1.x86_64 需要
    libdbi.so.0()(64bit) 被 nxlog-ce-2.10.2150-1.x86_64 需要

通過yum安裝apr和libdbi

# yum install apr
軟件包 apr.x86_64.0.1.4.8-5.el7 將被 安裝
...

# yum install libdbi
軟件包 libdbi.x86_64.0.0.8.4-6.el7 將被 安裝
...

依賴組件安裝完成后,再安裝NXLog就成功了

# rpm -ivh nxlog-ce-2.10.2150-1_rhel7.x86_64.rpm 
准備中...                          ################################# [100%]
正在升級/安裝...
   1:nxlog-ce-2.10.2150-1             ################################# [100%]

安裝完成后,查看程序安裝路徑位於/usr/bin/nxlog,配置文件位於/etc/nxlog.conf,至此就安裝完畢了。

# whereis nxlog
nxlog: /usr/bin/nxlog /etc/nxlog.conf /usr/libexec/nxlog

 

二、libdbi及驅動的安裝

本文的實際場景需要將通過syslog獲取的日志同時存儲到文件和數據庫MySQL,同時需要轉發到其他的syslog服務器,因此需要在配置文件中使用到im_udp、om_file、om_udp和om_dbi幾個模塊。根據官方文檔說明, 在linux系統中,im_dbi和om_dbi模塊依賴於libdbi庫,而在windows環境下im_odbc和om_odbc模塊可提供原生的數據庫訪問,但是只有NXLog的企業版才支持(CE版不支持)。

libdbi需要通過數據庫驅動程序來訪問對應的數據庫,而在CentOS環境下,雖然已經安裝了libdbi,但是其中並不包含有任何驅動,因此需要進行安裝。

The im_dbi and om_dbi modules support GNU/Linux only because of the libdbi library. The im_odbc and om_odbc modules provide native database access on Windows (available only in NXLog Enterprise Edition).
libdbi needs drivers to access the database engines. These are in the libdbd-* packages on Debian and Ubuntu. CentOS 5.6 has a libdbi-drivers RPM package, but this package does not contain any driver binaries under /usr/lib64/dbd. The drivers for both MySQL and PostgreSQL are in libdbi-dbd-mysql. If these are not installed, NXLog will return a libdbi driver initialization error.

# yum install mysql-connector-odbc mysql-devel libdbi-dbd-mysql

 

三、修改配置文件,啟動NXLog

NXLog的配置文件位於/etc/nxlog.conf,可參考官方手冊對其中的各個模塊進行編輯。

配置完成后,通過以下方法啟動、停止服務。

systemctl start nxlog   //啟動服務
systemctl stop nxlog    //停止服務
systemctl enable nxlog  //開機啟動服務
systemctl status nxlog  //查看服務狀態,顯示active(running)表明服務已經運行了

 

四、防火牆中加入514端口(UDP/TCP)

# firewall-cmd --permanent --add-port=514/udp
# firewall-cmd --permanent --add-port=514/tcp

如果用不到tcp可以不添加tcp的,添加端口后需要重啟防火牆。 

 

五、關於libdbi及驅動安裝的彎路

因為需要安裝libdbi的驅動,之前通過yum安裝的libdbi的版本為0.8.4,在sourceforge上查詢到其最新版本為0.9.0,因此想更新一下。

而將文件包下載后放到服務器上,在./configure時,一直提示“Invalid libdbi directory - include files not found.”。查找了幾種可能性:

可能性1:autoconf的版本太高,libdbi只支持autoconf-2.13版本,在其官方文檔末尾 http://libdbi-drivers.sourceforge.net/docs/dbd_mysql.pdf 中有提及。

可能性2:dbd_mysql.c的第154行中的錯誤代碼,在 https://sourceforge.net/p/libdbi/mailman/libdbi-users/ 的用戶郵件中有反應這個問題。

然而上述2種方法都沒有奏效,最后還是在參考資料4中找到了類似安裝libdbis mysql drivers的方法,成功解決。

 

參考資料:

1. Centos7安裝nxlog-2.9 

2. libdbi-users — General libdbi discussion and support

3. libdbi-drivers

4. Centos7安裝Typecho詳細教程

5. NXLog - Forwarding and Storing Logs


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM