• 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

  • 相关阅读:
    浏览器之window对象--javascript
    CSS3盒子模型
    CSS3动画以及animation事件
    CSS3响应式布局
    原生JS实现tab切换--web前端开发
    html5表单与PHP交互
    UITableView 的坑
    多线程:Operation(二)
    多线程:Operation(一)
    GCD(Swift)
  • 原文地址:https://www.cnblogs.com/yangjisen/p/12905076.html
Copyright © 2020-2023  润新知