【日志服务CLS】快速采集Linux日志到日志服务CLS

什么是日志服务CLS?

日志服务(Cloud Log Service,CLS)提供一站式的日志数据解决方案。您无需关注扩缩容等资源问题,五分钟快速便捷接入,即可享受从日志采集、日志存储到日志内容搜索、统计分析等全方位稳定可靠的日志服务。帮助您轻松解决业务问题定位,指标监控、安全审计等日志问题。大大降低日志运维门槛。

日志服务提供了多种采集方式:

API方式采集:通过调用日志服务API上传结构化日志至日志服务

SDK方式采集:通过SKD的方式采集日志

LogListener 客户端采集:通过部署安装部署 LogListener,可以方便快速地接入日志服务,无需修改应用程序运行逻辑,是一种对应用服务无侵入式的采集方式。

本文【快速采集Linux日志到日志服务CLS】将通过LogListener客户端采集Linux的日志。

使用 LogListener 采集日志的流程如下图所示:

下面开始此次教程

1.开通腾讯云日志服务CLS

日志服务产品地址:https://cloud.tencent.com/product/cls

点击立即开通

开通后进入概览页面,在此页面的左上角可以切换地域

2.安装专用日志采集器LogListener

安装环境:LogListener 仅支持64位 Linux 操作系统环境(暂不支持 Windows),并适配主流 Linux 操作系统版本

1.首先下载并安装LogListener:

运行以下命令(默认安装在/usr/local/目录):

wget https://loglistener-1254077820.cos.ap-shanghai.myqcloud.com/loglistener-linux-x64-2.5.8.tar.gz && tar -zxvf loglistener-linux-x64-2.5.8.tar.gz -C /usr/local && cd /usr/local/loglistener-2.5.8/tools && ./loglistener.sh install

出现以下提示即代表安装成功

3.LogListener采集配置

到腾讯云日志服务CLS控制台首页,点击Linux/Unix文本日志

填写相关参数

点击新建机器组

填写机器组名称,选择配置机器标识并填写机器标识

勾选刚刚创建的机器组

配置参数

./loglistener.sh init -secretid AKIDPEtPyKabfW8Z3Uspdz83xxxxxxxxxxx -secretkey whHwQfjdLnzzCE1jIf09xxxxxxxxxxxx -region ap-xxxxxx

绿色加粗部分需自省替换(默认使用内网方式访问服务)

如果使用外网请使用:

./loglistener.sh init -secretid AKIDPEtPyKabfW8Z3Uspdz83xxxxxxxxxxx -secretkey whHwQfjdLnzzCE1jIf09xxxxxxxxxxxx -region ap-xxxxxx -network internet

在访问管理页面 找到访问秘钥选项卡 点击新建秘钥

复制并替换刚刚的SecretId和SecretKey

SecretId和SecretKey请注意保密,您的 API 密钥代表您的账号身份和所拥有的权限,等同于您的登录密码,切勿泄露他人

打开CLS控制台 找到概况中的地域 替换刚刚的region

比如我使用了中国香港 则替换成ap-hongkong

可用地域及简称

地域

域名简称

内网域名

外网域名

北京

ap-beijing

ap-beijing.cls.tencentyun.com

ap-beijing.cls.tencentcs.com

广州

ap-guangzhou

ap-guangzhou.cls.tencentyun.com

ap-guangzhou.cls.tencentcs.com

上海

ap-shanghai

ap-shanghai.cls.tencentyun.com

ap-shanghai.cls.tencentcs.com

成都

ap-chengdu

ap-chengdu.cls.tencentyun.com

ap-chengdu.cls.tencentcs.com

南京

ap-nanjing

ap-nanjing.cls.tencentyun.com

ap-nanjing.cls.tencentcs.com

重庆

ap-chongqing

ap-chongqing.cls.tencentyun.com

ap-chongqing.cls.tencentcs.com

中国香港

ap-hongkong

ap-hongkong.cls.tencentyun.com

ap-hongkong.cls.tencentcs.com

硅谷

na-siliconvalley

na-siliconvalley.cls.tencentyun.com

na-siliconvalley.cls.tencentcs.com

弗吉尼亚

na-ashburn

na-ashburn.cls.tencentyun.com

na-ashburn.cls.tencentcs.com

新加坡

ap-singapore

ap-singapore.cls.tencentyun.com

ap-singapore.cls.tencentcs.com

泰国

ap-bangkok

ap-bangkok.cls.tencentyun.com

ap-bangkok.cls.tencentcs.com

孟买

ap-mumbai

ap-mumbai.cls.tencentyun.com

ap-mumbai.cls.tencentcs.com

法兰克福

eu-frankfurt

eu-frankfurt.cls.tencentyun.com

eu-frankfurt.cls.tencentcs.com

东京

ap-tokyo

ap-tokyo.cls.tencentyun.com

ap-tokyo.cls.tencentcs.com

首尔

ap-seoul

ap-seoul.cls.tencentyun.com

ap-seoul.cls.tencentcs.com

莫斯科

eu-moscow

eu-moscow.cls.tencentyun.com

eu-moscow.cls.tencentcs.com

深圳金融

ap-shenzhen-fsi

ap-shenzhen-fsi.cls.tencentyun.com

ap-shenzhen-fsi.cls.tencentcs.com

上海金融

ap-shanghai-fsi

ap-shanghai-fsi.cls.tencentyun.com

ap-shanghai-fsi.cls.tencentcs.com

北京金融

ap-beijing-fsi

ap-beijing-fsi.cls.tencentyun.com

ap-beijing-fsi.cls.tencentcs.com

如下图,配置成功

启动LogListener客户端

/etc/init.d/loglistenerd start

然后就可以在机器组管理中看到刚刚添加的服务器

到这里LogListener客户端的安装就完毕了

4.创建日志主题

找到日志主题选项卡,点击创建日志主题并填写相关信息

5.设置采集配置

点击刚刚创建的日志集,找到采集配置选项卡,点击Linux/Unix文本日志

勾选机器组

配置采集路径 /var/log

点击提交

然后到检索选项卡就可以看到相关日志

本站文章资源均来源自网络,除非特别声明,否则均不代表站方观点,并仅供查阅,不作为任何参考依据!
如有侵权请及时跟我们联系,本站将及时删除!
如遇版权问题,请查看 本站版权声明
THE END
分享
二维码
海报
【日志服务CLS】快速采集Linux日志到日志服务CLS
LogListener 客户端采集:通过部署安装部署 LogListener,可以方便快速地接入日志服务,无需修改应用程序运行逻辑,是一种对应用服务无侵入式的采...
<<上一篇
下一篇>>