nxlog日志采集

一、nxlog 简介

  nxlog 是一个模块化、多线程、高性能的日志管理解决方案,支持多平台,可实现各类操作系统及其中间件的日志采集和管理

二、nxlog官网下载地址

2.1 社区版官网下载地址:NXLog Community Edition - Downloads | nxlog.co

2.2  下载相应的系统版本

1) Centos 6.x

wget --no-check-certificate https://nxlog.co/system/files/products/files/348/nxlog-ce-2.10.2150-1_rhel6.x86_64.rpm

2)Centos 7.x

wget --no-check-certificate https://nxlog.co/system/files/products/files/348/nxlog-ce-3.0.2272-1_rhel7.x86_64.rpm

3)Centos 8.x

wget --no-check-certificate https://nxlog.co/system/files/products/files/348/nxlog-ce-3.0.2272_rhel8.x86_64.rpm

4) Ubuntu 18.04

wget  --no-check-certificate https://nxlog.co/system/files/products/files/348/nxlog-ce_3.0.2272_ubuntu_bionic_amd64.deb

三、安装nxlog及依赖环境

3.1 Centos 6.x 

yum install apr  libdbi* -y    #安装依赖环境(yum源不可用转步骤四)
rpm -ivh nxlog-ce-2.10.2150-1_rhel6.x86_64.rpm  #安装rpm包

3.2 Centos 7.x 

yum install apr libdbi  libpython3.6m.so.1.0 -y  #安装依赖环境
rpm -ivh  nxlog-ce-3.0.2272-1_rhel7.x86_64.rpm  #安装rpm包

3.3 Centos 8.x 

yum install apr libdbi*  libperl.so.5.26  -y  #安装依赖环境(yum源不可用转步骤四)
rpm -ivh  nxlog-ce-3.0.2272-1_rhel7.x86_64.rpm  #安装rpm包

3.4 Ubuntu 18.04

sudo dpkg -i nxlog-ce_3.0.2272_ubuntu_bionic_amd64.deb  #安装deb包,提示需依赖环境
sudo apt-get --fix-broken install  #解决并安装依赖环境
sudo dpkg -i nxlog-ce_3.0.2272_ubuntu_bionic_amd64.deb #再次安装deb包

* Centos6.x 8.x 官方yum源已下线。如系统本身yum源失效, 不能安装依赖环境,需更换第三方源或搭建本地yum源。

四、解决Centos6.x 8.x yum源失效问题

4.1 Centos6.x 更换阿里云yum源

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo  #更换阿里yum源
yum clean all   #清除缓存
yum makecache  #重新建立缓存

4.2 Centos 8.x  更换阿里云yum源

mv /etc/yum.repos.d /etc/yum.repos.d.bak  #备份原有yum源目录
mkdir -p /etc/yum.repos.d                #创建新的yum源目录
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo   #更换阿里yum源
curl -o /etc/yum.repos.d/epel-archive-8.repo https://mirrors.aliyun.com/repo/epel-archive-8.repo    #添加阿里epel yum源
yum clean all   #清除缓存
yum makecache  #重新建立缓存

五、nxlog 服务管理及卸载

5.1 Centos 6.x

service nxlog start    #启动
service nxlog stop    #停止
service nxlog restart  #重启
service nxlog status  #查看运行状态

5.2 Centos 7.x 8.x

systemctl start nxlog     #启动
systemctl stop nxlog     #停止
systemctl restart nxlog   #重启
systemctl status nxlog   #查看运行状态

5.3 Ubuntu

sudo systemctl start nxlog   #启动
sudo systemctl stop nxlog   #启动
sudo systemctl restart nxlog  #重启
sudo systemctl status nxlog   #查看运行状态

5.4 配置及日志文件

/etc/nxlog.conf          #Centos6.x      默认配置文件路径
/etc/nxlog nxlog.conf     #Centos7.x 8.x ubuntu 默认配置文件路径 
/var/log/nxlog/nxlog.log   #nxlog本身日志默认存放路径,用于调试和排错

5.6 卸载nxlog

yum remove 'nxlog-*'  -y  #Centos6.x 7.x 8.x
sudo apt-get remove '^nxlog*' -y  #Ubuntu

六、防火墙放行nxlog服务

6.1 Centos 6.x

iptables -I INPUT -p udp --dport 514 -j ACCEPT    #放行udp 514端口
iptables -I OUTPUT -p udp --sport 514 -j ACCEPT    #放行udp 514端口
service iptables save            #保存防火墙规则
service iptables restart            #重启防火墙

 6.2 Centos 7.x 8x

firewall-cmd --zone=public --add-port=514/udp --permanent   #放行udp 514端口
firewall-cmd --reload                   #重新加载防火墙策略
firewall-cmd --zone=public --list-ports     #查看放行的端口
systemctl restart firewalld               #重启防火墙

6.3 Ubuntu

udo ufw allow 514   #放行udp 514端口
sudo ufw status     #查看放行的端口及规则
sudo ufw reload     #重新加载防火墙策略

七、nxlog 采集Apache错误日志示例

编辑nxlog配置文件   在Modules模块  <Input apache_error_in>  </Input>   和 <Output Apache_error_out>  中分别填写apache错误日志文件路径和输出的日志服务器地址及端口。Routes模块添加Path参数。 (红色部分名称自定义)

########################################
# Global directives                    #
########################################
User nxlog
Group nxlog

LogFile /var/log/nxlog/nxlog.log
LogLevel INFO
Nocache True
########################################
# Modules                              #
########################################
<Extension _syslog>
    Module      xm_syslog
</Extension>


<Input apache_error_in>
    SavePos  false
    Readfromlast false
    Module  im_file
    File        "/var/log/apache/error.log"
</Input>


<Output apache_error_out>
    Module  om_tcp
    Host    10.19.21.100
    Port    514
</Output>

########################################
# Routes                               #
########################################
#
<Route apache_error_route>
    Path    apache_error_in => apache_error_out
</Route>

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值