玉婧媛 發表於 2020-5-17 16:31:00

CentOS 7安装NXLog服务

<p>NXLog是一个跨平台日志传输插件,支持linux、windows平台的大部分系统日志及常见的web日志,支持tcp、udp、http(s)等协议传输。本文介绍NXLog在CentOS 7服务器上的安装,以及运行om_dbi/im_dbi所需插件的安装。</p>
<p>操作系统环境:CentOS Linux release 7.6.1810 (Core)</p>
<p>NXLog版本:nxlog-ce-2.10.2150</p>
<p>&nbsp;</p>
<p><strong>一、安装NXLog</strong></p>
<p>由于yum中没有直接提供NXLog,因此需要在https://nxlog.co/products/nxlog-community-edition/download下载对应操作系统的rpm后,上传至服务器进行安装,当然也可以直接利用wget下载安装。。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">下载路径</span>
# cd /usr/local/

<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">下载rpm</span>
# wget https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">nxlog.co/system/files/products/files/348/nxlog-ce-2.10.2150-1_rhel7.x86_64.rpm<br></span></pre>
</div>
<p>NXLog安装依赖apr和libdbi,如果未安装会报如下错误。</p>
<div class="cnblogs_code">
<pre># rpm -ivh nxlog-ce-<span style="color: rgba(128, 0, 128, 1)">2.10</span>.<span style="color: rgba(128, 0, 128, 1)">2150</span>-<span style="color: rgba(0, 0, 0, 1)">1_rhel7.x86_64.rpm
错误:依赖检测失败:
    apr </span>&gt;= <span style="color: rgba(128, 0, 128, 1)">1.2</span> 被 nxlog-ce-<span style="color: rgba(128, 0, 128, 1)">2.10</span>.<span style="color: rgba(128, 0, 128, 1)">2150</span>-<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">.x86_64 需要
    libapr</span>-<span style="color: rgba(128, 0, 128, 1)">1</span>.so.<span style="color: rgba(128, 0, 128, 1)">0</span>()(64bit) 被 nxlog-ce-<span style="color: rgba(128, 0, 128, 1)">2.10</span>.<span style="color: rgba(128, 0, 128, 1)">2150</span>-<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">.x86_64 需要
    libdbi </span>&gt;= <span style="color: rgba(128, 0, 128, 1)">0.8</span>.<span style="color: rgba(128, 0, 128, 1)">1</span> 被 nxlog-ce-<span style="color: rgba(128, 0, 128, 1)">2.10</span>.<span style="color: rgba(128, 0, 128, 1)">2150</span>-<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">.x86_64 需要
    libdbi.so.</span><span style="color: rgba(128, 0, 128, 1)">0</span>()(64bit) 被 nxlog-ce-<span style="color: rgba(128, 0, 128, 1)">2.10</span>.<span style="color: rgba(128, 0, 128, 1)">2150</span>-<span style="color: rgba(128, 0, 128, 1)">1</span>.x86_64 需要</pre>
</div>
<p>通过yum安装apr和libdbi</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)"># yum install apr
软件包 apr.x86_64.</span><span style="color: rgba(128, 0, 128, 1)">0.1</span>.<span style="color: rgba(128, 0, 128, 1)">4.8</span>-<span style="color: rgba(128, 0, 128, 1)">5</span><span style="color: rgba(0, 0, 0, 1)">.el7 将被 安装
...

# yum install libdbi
软件包 libdbi.x86_64.</span><span style="color: rgba(128, 0, 128, 1)">0.0</span>.<span style="color: rgba(128, 0, 128, 1)">8.4</span>-<span style="color: rgba(128, 0, 128, 1)">6</span><span style="color: rgba(0, 0, 0, 1)">.el7 将被 安装
...</span></pre>
</div>
<p>依赖组件安装完成后,再安装NXLog就成功了</p>
<div class="cnblogs_code">
<pre># rpm -ivh nxlog-ce-<span style="color: rgba(128, 0, 128, 1)">2.10</span>.<span style="color: rgba(128, 0, 128, 1)">2150</span>-<span style="color: rgba(0, 0, 0, 1)">1_rhel7.x86_64.rpm
准备中...                        ################################# [</span><span style="color: rgba(128, 0, 128, 1)">100</span>%<span style="color: rgba(0, 0, 0, 1)">]
正在升级</span>/<span style="color: rgba(0, 0, 0, 1)">安装...
   </span><span style="color: rgba(128, 0, 128, 1)">1</span>:nxlog-ce-<span style="color: rgba(128, 0, 128, 1)">2.10</span>.<span style="color: rgba(128, 0, 128, 1)">2150</span>-<span style="color: rgba(128, 0, 128, 1)">1</span>             ################################# [<span style="color: rgba(128, 0, 128, 1)">100</span>%]</pre>
</div>
<p>安装完成后,查看程序安装路径位于/usr/bin/nxlog,配置文件位于/etc/nxlog.conf,至此就安装完毕了。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)"># whereis nxlog
nxlog: </span>/usr/bin/nxlog /etc/nxlog.conf /usr/libexec/nxlog</pre>
</div>
<p>&nbsp;</p>
<p><strong>二、libdbi及驱动的安装</strong></p>
<p>本文的实际场景需要将通过syslog获取的日志同时存储到文件和数据库MySQL,同时需要转发到其他的syslog服务器,因此需要在配置文件中使用到im_udp、om_file、om_udp和om_dbi几个模块。根据官方文档说明,&nbsp;在linux系统中,im_dbi和om_dbi模块依赖于libdbi库,而在windows环境下im_odbc和om_odbc模块可提供原生的数据库访问,但是只有NXLog的企业版才支持(CE版不支持)。</p>
<p>libdbi需要通过数据库驱动程序来访问对应的数据库,而在CentOS环境下,虽然已经安装了libdbi,但是其中并不包含有任何驱动,因此需要进行安装。</p>
<p>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).<br>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.</p>
<div class="cnblogs_code">
<pre># yum install mysql-connector-odbc mysql-devel libdbi-dbd-mysql</pre>
</div>
<p>&nbsp;</p>
<p><strong>三、修改配置文件,启动NXLog</strong></p>
<p>NXLog的配置文件位于/etc/nxlog.conf,可参考官方手册对其中的各个模块进行编辑。</p>
<p>配置完成后,通过以下方法启动、停止服务。</p>
<div class="cnblogs_code">
<pre>systemctl start nxlog   <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">启动服务</span>
systemctl stop nxlog    <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">停止服务</span>
systemctl enable nxlog<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">开机启动服务</span>
systemctl status nxlog<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">查看服务状态,显示active(running)表明服务已经运行了</span></pre>
</div>
<p>&nbsp;</p>
<p><strong>四、防火墙中加入514端口(UDP/TCP)</strong></p>
<div class="cnblogs_code">
<pre># firewall-cmd --permanent --add-port=<span style="color: rgba(128, 0, 128, 1)">514</span>/ud<span style="color: rgba(0, 0, 0, 1)">p
# firewall</span>-cmd --permanent --add-port=<span style="color: rgba(128, 0, 128, 1)">514</span>/tcp</pre>
</div>
<p>如果用不到tcp可以不添加tcp的,添加端口后需要重启防火墙。&nbsp;</p>
<p>&nbsp;</p>
<p><strong>五、关于libdbi及驱动安装的弯路</strong></p>
<p>因为需要安装libdbi的驱动,之前通过yum安装的libdbi的版本为0.8.4,在sourceforge上查询到其最新版本为0.9.0,因此想更新一下。</p>
<p><img src="https://img2020.cnblogs.com/blog/1960974/202005/1960974-20200517164012024-183481594.png"></p>
<p>而将文件包下载后放到服务器上,在./configure时,一直提示“Invalid libdbi directory - include files not found.”。查找了几种可能性:</p>
<p>可能性1:autoconf的版本太高,libdbi只支持autoconf-2.13版本,在其官方文档末尾&nbsp;http://libdbi-drivers.sourceforge.net/docs/dbd_mysql.pdf&nbsp;中有提及。</p>
<p>可能性2:dbd_mysql.c的第154行中的错误代码,在&nbsp;https://sourceforge.net/p/libdbi/mailman/libdbi-users/&nbsp;的用户邮件中有反应这个问题。</p>
<p>然而上述2种方法都没有奏效,最后还是在参考资料4中找到了类似安装libdbis mysql drivers的方法,成功解决。</p>
<p>&nbsp;</p>
<p><strong>参考资料:</strong></p>
<p>1.&nbsp;Centos7安装nxlog-2.9&nbsp;</p>
<p>2.&nbsp;libdbi-users — General libdbi discussion and support</p>
<p>3.&nbsp;libdbi-drivers</p>
<p>4.&nbsp;Centos7安装Typecho详细教程</p>
<p>5. NXLog -&nbsp;Forwarding and Storing Logs</p><br><br>
来源:https://www.cnblogs.com/yangjisen/p/12905076.html
頁: [1]
查看完整版本: CentOS 7安装NXLog服务