Linux系统之部署Rsyslog 日志服务器

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: Linux系统之部署Rsyslog 日志服务器

一、检查服务器系统版本

[root@master ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

二、在master节点上配置

1.修改/etc/rsyslog.conf

取消以下几行注释

image.png

2.开启日志服务

[root@master ~]# systemctl start rsyslog
[root@master ~]# systemctl enable rsyslog

3.查看日志服务状态

[root@master ~]# systemctl status rsyslog
● rsyslog.service - System Logging Service
   Loaded: loaded (/usr/lib/systemd/system/rsyslog.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2022-10-26 15:06:24 CST; 2h 47min ago
     Docs: man:rsyslogd(8)
           http://www.rsyslog.com/doc/
 Main PID: 7775 (rsyslogd)
   CGroup: /system.slice/rsyslog.service
           └─7775 /usr/sbin/rsyslogd -n

Oct 26 15:06:18 master systemd[1]: Starting System Logging Service...
Oct 26 15:06:24 master rsyslogd[7775]:  [origin software="rsyslogd" swVersion="8.24.0-34.el7" x-pid="7775" x-info="http://www.rsyslog.com"] start
Oct 26 15:06:24 master systemd[1]: Started System Logging Service.
Hint: Some lines were ellipsized, use -l to show in full.

4.关闭防火墙

[root@master ~]# systemctl disable firewalld
[root@master ~]# systemctl stop  firewalld

三、在node节点操作

1.编辑/etc/rsyslog.conf

将 info 级别日志传送到日志服务器

image.png

2.重启日志服务

systemctl restart rsyslog

四、在master日志服务器查看node节点日志信息

[root@master ~]# tail /var/log/messages
Oct 26 18:07:23 master systemd: Stopped System Logging Service.
Oct 26 18:07:23 master systemd: Starting System Logging Service...
Oct 26 18:07:23 master rsyslogd: [origin software="rsyslogd" swVersion="8.24.0-34.el7" x-pid="129582" x-info="http://www.rsyslog.com"] start
Oct 26 18:07:23 master systemd: Started System Logging Service.
Oct 26 18:07:16 node01 systemd: Stopping System Logging Service...
Oct 26 18:07:16 node01 rsyslogd: [origin software="rsyslogd" swVersion="8.24.0-34.el7" x-pid="129134" x-info="http://www.rsyslog.com"] exiting on signal 15.
Oct 26 18:07:16 node01 systemd: Stopped System Logging Service.
Oct 26 18:07:16 node01 systemd: Starting System Logging Service...
Oct 26 18:07:16 node01 rsyslogd: [origin software="rsyslogd" swVersion="8.24.0-34.el7" x-pid="130443" x-info="http://www.rsyslog.com"] start
Oct 26 18:07:16 node01 systemd: Started System Logging Service.

image.png

五、修改日志文件主机名为 IP 地址

1.mster节点修改/etc/rsyslog.conf

新增以下内容,注释原来默认模板
$template TraditionalFileFormat,"%TIMESTAMP% %FROMHOST-IP% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
$ActionFileDefaultTemplate TraditionalFileFormat

image.png

2.重启日志服务

systemctl restart rsyslog

4.在node节点重启ssh服务

[root@node01 ~]# systemctl restart rsyslog
[root@node01 ~]# systemctl restart sshd

5.在master日志服务器查看日志效果

[root@master ~]# tail  /var/log/messages
Oct 26 18:28:58 192.168.3.91 image-cri-shim: 2022-10-26T18:28:58 #033[34minfo#033[0m #033[34mdomain: k8s.gcr.io, imageName: pause:3.7, action: ImageStatus#033[0m
Oct 26 18:28:58 192.168.3.91 image-cri-shim: 2022-10-26T18:28:58 #033[34minfo#033[0m #033[34maddress: http://sealos.hub:5000, base64: YWRtaW46cGFzc3cwcmQ=, imageName: pause#033[0m
Oct 26 18:28:58 192.168.3.91 image-cri-shim: 2022-10-26T18:28:58 #033[34minfo#033[0m #033[34mpre image name: pause, pre image tag: 3.7#033[0m
Oct 26 18:29:21 127.0.0.1 registry: time="2022-10-26T18:29:21.527136696+08:00" level=info msg="authorized request" go.version=go1.16.15 http.request.host="sealos.hub:5000" http.request.id=6d08c26d-a4fd-454c-a850-0c5c17a53d31 http.request.method=GET http.request.remoteaddr="192.168.3.91:38332" http.request.uri="/v2/pause/tags/list" http.request.useragent="kube-probe/v0.0.0-master+unknown" vars.name=pause
Oct 26 18:29:21 127.0.0.1 registry: time="2022-10-26T18:29:21.527326642+08:00" level=info msg="response completed" go.version=go1.16.15 http.request.host="sealos.hub:5000" http.request.id=6d08c26d-a4fd-454c-a850-0c5c17a53d31 http.request.method=GET http.request.remoteaddr="192.168.3.91:38332" http.request.uri="/v2/pause/tags/list" http.request.useragent="kube-probe/v0.0.0-master+unknown" http.response.contenttype="application/json; charset=utf-8" http.response.duration=59.004744ms http.response.status=200 http.response.written=32
Oct 26 18:29:21 127.0.0.1 registry: 192.168.3.91 - - [26/Oct/2022:18:29:21 +0800] "GET /v2/pause/tags/list HTTP/1.1" 200 32 "" "kube-probe/v0.0.0-master+unknown"
Oct 26 18:28:58 192.168.3.91 image-cri-shim: 2022-10-26T18:28:58 #033[34minfo#033[0m #033[34mdata: {"name":"pause","tags":["3.7"]}
Oct 26 18:28:58 192.168.3.91 image-cri-shim: #033[0m
Oct 26 18:28:58 192.168.3.91 image-cri-shim: 2022-10-26T18:28:58 #033[34minfo#033[0m #033[34mimageTag found in registry.Tags#033[0m
Oct 26 18:28:58 192.168.3.91 image-cri-shim: 2022-10-26T18:28:58 #033[34minfo#033[0m #033[34mbegin image: k8s.gcr.io/pause:3.7, after image: sealos.hub:5000/pause:3.7, action: ImageStatus#033[0m

image.png

相关实践学习
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
相关文章
|
1月前
|
弹性计算 人工智能 前端开发
在阿里云ECS上部署n8n自动化工作流:U2实例实战
本文介绍如何在阿里云ECS的u2i/u2a实例上部署开源工作流自动化平台n8n,利用Docker快速搭建并配置定时任务,实现如每日抓取MuleRun新AI Agent并推送通知等自动化流程。内容涵盖环境准备、安全组设置、实战案例与优化建议,助力高效构建低维护成本的自动化系统。
369 5
|
1月前
|
Java Linux Apache
在CentOS服务器上编译并部署NiFi源码
部署Apache NiFi在CentOS上是一个涉及细节的过程,需要注意Java环境、源码编译、配置调整等多个方面。遵循上述步骤,可以在CentOS服务器上成功部署和配置Apache NiFi,从而高效地处理和分发数据。
154 17
|
2月前
|
运维 监控 安全
EventLog Analyzer:高效的Web服务器日志监控与审计解决方案
ManageEngine EventLog Analyzer是一款企业级Web服务器日志监控与审计工具,支持Apache、IIS、Nginx等主流服务器,实现日志集中管理、实时威胁检测、合规报表生成及可视化分析,助力企业应对安全攻击与合规挑战,提升运维效率。
172 0
|
2月前
|
弹性计算 安全 Linux
使用阿里云服务器安装Z-Blog博客网站流程,新手一键部署教程
本教程教你如何在阿里云99元服务器上,通过宝塔Linux面板一键部署Z-Blog博客。基于CentOS 7.9系统,从远程连接、安装宝塔面板、开放端口到部署Z-Blog全流程详解,操作简单,新手也能轻松搭建个人博客网站。
393 13
|
2月前
|
弹性计算 Devops Shell
用阿里云 DevOps Flow 实现 ECS 部署自动化:从准备到落地的完整指南
阿里云 DevOps Flow 是一款助力开发者实现自动化部署的高效工具,支持代码流水线构建、测试与部署至ECS实例,显著提升交付效率与稳定性。本文详解如何通过 Flow 自动部署 Bash 脚本至 ECS,涵盖环境准备、流水线搭建、源码接入、部署流程设计及结果验证,助你快速上手云上自动化运维。
231 0
|
2月前
|
Ubuntu
在Ubuntu系统上设置syslog日志轮替与大小限制
请注意,在修改任何系统级别配置之前,请务必备份相应得原始档案并理解每项变更可能带来得影响。
272 2
监控 安全 Linux
117 0
|
2月前
|
Prometheus 监控 Cloud Native
基于docker搭建监控系统&日志收集
Prometheus 是一款由 SoundCloud 开发的开源监控报警系统及时序数据库(TSDB),支持多维数据模型和灵活查询语言,适用于大规模集群监控。它通过 HTTP 拉取数据,支持服务发现、多种图表展示(如 Grafana),并可结合 Loki 实现日志聚合。本文介绍其架构、部署及与 Docker 集成的监控方案。
345 122
基于docker搭建监控系统&日志收集

热门文章

最新文章