centos 7 下编译 rsyslog 8.24.0 (二)

这篇博客介绍了测试工具syslog_caller,用于向系统日志发送不同严重级别的消息,支持自定义数量和格式选项。通过`syslog_caller -s [severity] -m [messages]`命令进行测试,例如发送14条严重级别从0到7循环的消息。

测试程序:

rsyslog-8.24.0/tests/syslog_caller.c

/* A testing tool that just emits a number of
 * messages to the system log socket.
 *
 * Options
 *
 * -s severity (0..7 accoding to syslog spec, r "rolling", default 6)
 * -m number of messages to generate (default 500)
 * -C liblognorm-stdlog channel description
 * -f message format to use
 *
 * Part of the testbench for rsyslog.
 *
 * Copyright 2010-2014 Rainer Gerhards and Adiscon GmbH.
 *
 * This file is part of rsyslog.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 *       -or-
 *       see COPYING.ASL20 in the source distribution
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <errno.h>
#include <string.h>

#ifdef HAVE_LIBLOGGING_STDLOG
#include <liblogging/stdlog.h>
#endif

static enum { FMT_NATIVE, FMT_SYSLOG_INJECT_L, FMT_SYSLOG_INJECT_C
	} fmt = FMT_NATIVE;

static void usage(void)
{
	fprintf(stderr, "usage: syslog_caller num-messages\n");
	exit(1);
}


#ifdef HAVE_LIBLOGGING_STDLOG
/* buffer must be large "enough" [4K?] */
static void
genMsg(char *buf, const int sev, const int iRun)
{
	switch(fmt) {
	case FMT_NATIVE:
		sprintf(buf, "test message nbr %d, severity=%d", iRun, sev);
		break;
	case FMT_SYSLOG_INJECT_L:
		sprintf(buf, "test\n");
		break;
	case FMT_SYSLOG_INJECT_C:
		sprintf(buf, "test 1\t2");
		break;
	}
}
#endif

int main(int argc, char *argv[])
{
	int i;
	int opt;
	int bRollingSev = 0;
	int sev = 6;
	int msgs = 500;
#ifdef HAVE_LIBLOGGING_STDLOG
	stdlog_channel_t logchan = NULL;
	const char *chandesc = "syslog:";
	char msgbuf[4096];
#endif

#ifdef HAVE_LIBLOGGING_STDLOG
	stdlog_init(STDLOG_USE_DFLT_OPTS);
	while((opt = getopt(argc, argv, "m:s:C:f:")) != -1) {
#else
	while((opt = getopt(argc, argv, "m:s:")) != -1) {
#endif
		switch (opt) {
		case 's':	if(*optarg == 'r') {
					bRollingSev = 1;
					sev = 0;
				} else
#ifdef HAVE_LIBLOGGING_STDLOG
					sev = atoi(optarg) % 8;
#else
					sev = atoi(optarg);
#endif
				break;
		case 'm':	msgs = atoi(optarg);
				break;
#ifdef HAVE_LIBLOGGING_STDLOG
		case 'C':	chandesc = optarg;
				break;
		case 'f':	if(!strcmp(optarg, "syslog_inject-l"))
					fmt = FMT_SYSLOG_INJECT_L;
				else if(!strcmp(optarg, "syslog_inject-c"))
					fmt = FMT_SYSLOG_INJECT_C;
				else
					usage();
				break;
#endif
		default:	usage();
#ifdef HAVE_LIBLOGGING_STDLOG
				exit(1);
#endif
				break;
		}
	}

#ifdef HAVE_LIBLOGGING_STDLOG
	if((logchan = stdlog_open(argv[0], 0, STDLOG_LOCAL1, chandesc)) == NULL) {
		fprintf(stderr, "error opening logchannel '%s': %s\n",
			chandesc, strerror(errno));
		exit(1);
	}
#endif
	for(i = 0 ; i < msgs ; ++i) {
#ifdef HAVE_LIBLOGGING_STDLOG
		genMsg(msgbuf, sev, i);
		if(stdlog_log(logchan, sev, "%s", msgbuf) != 0) {
			perror("error writing log record");
			exit(1);
		}
#else
		syslog(sev % 8, "test message nbr %d, severity=%d", i, sev % 8);
#endif
		if(bRollingSev)
#ifdef HAVE_LIBLOGGING_STDLOG
			sev = (sev + 1) % 8;
#else
		sev++;
#endif
	}
	return(0);
}

测试:

        写14条日志,严重界别从0-7循坏

        ./syslog_caller -s  r  -m 14

        

        写14条日志,严重级别:0

        ./syslog_caller -s  0  -m 14

Understanding systemd-journald and how logging works with Journal in RHEL 7​​​​​​​

<think>好的,用户现在想在CentOS 7上安装特定版本的rsyslog,版本号是rsyslog-802402.0。首先我需要确认这个版本号是否真的存在,或者是否是用户输入时的笔误。因为通常rsyslog的版本号格式是类似8.2402.0这样的结构,可能用户写成了802402.0。例如,之前的回答中提到了rsyslog v8.2.0及以上支持DTLS,所以这个版本号可能应为8.24.02或者其他类似的格式。我需要先检查这一点。 接下来,用户提到的引用中有关于CentOS 7的安装和配置问题,比如引用[4]和[5]都是关于CentOS 7的网络和yum更新问题的解决方案。用户之前的问题是关于在CentOS 7上安装特定版本的rsyslog,所以需要结合这些引用中的信息,尤其是关于yum的使用和可能遇到的依赖冲突问题。 用户提供的引用[2]提到了在CentOS 7上部署rsyslog与MySQL的集成,其中涉及到了权限配置,这可能与当前问题无关,但需要注意是否有依赖关系。此外,用户之前的问题中提到了DTLS插件的配置,可能需要较高版本的rsyslog,因此用户可能希望安装较新的版本以获得特定功能。 接下来,我需要考虑在CentOS 7上安装特定版本rsyslog的方法。通常,CentOS 7的默认仓库可能不包含最新版本的rsyslog,因此可能需要添加第三方仓库,比如EPEL或者rsyslog的官方仓库。例如,rsyslog的官方文档可能提供了repo文件,可以通过yum进行安装。 另外,用户提到的版本号rsyslog-802402.0可能需要确认是否存在,如果不存在,可能需要用户确认正确的版本号。假设用户是指8.2402.0版本,那么需要检查该版本是否在可用的仓库中,或者是否需要从源代码编译安装。 在安装过程中,可能会遇到依赖问题,比如引用[5]中的yum冲突问题,需要解决可能的依赖冲突。此外,引用[3]中提到的网络配置问题可能在安装过程中需要确保网络连接正常,尤其是在使用yum安装时。 另外,用户可能希望使用特定版本的rsyslog来支持某些功能,比如DTLS插件,这可能需要在编译时启用相关选项,或者确保安装的版本包含所需模块。 总结步骤应该是:1. 检查版本号是否正确;2. 添加合适的仓库;3. 使用yum安装指定版本;4. 处理可能的依赖问题;5. 验证安装和配置。 需要确保用户了解添加第三方仓库的风险,以及如何处理依赖冲突。如果无法通过仓库安装,可能需要从源代码编译,此时需要安装编译工具和依赖库,步骤会更复杂。 最后,还需要指导用户如何验证安装是否成功,检查rsyslog的版本,并确保服务正常运行,可能还需要配置和重启服务。</think>根据您的要求,在 CentOS 7 上安装特定版本的 rsyslog(假设版本号为 **8.2402.0**,原始输入可能存在格式误差),需通过以下步骤实现: --- ### 一、版本号校验与安装路径 1. **版本号确认** - 您提到的 `rsyslog-802402.0` 可能是格式误差,官方版本命名规则为 `8.2402.0`(例如 `v8.2402.0`)[^1]。 - 验证版本是否存在: ```bash yum list rsyslog --showduplicates | grep '8.2402' # 检查仓库中是否存在该版本 ``` 2. **安装源选择** - CentOS 7 默认仓库仅提供较旧版本(如 `8.24.0-57.el7`),需通过 **第三方仓库** 获取新版本: ```bash # 添加 rsyslog 官方仓库(如适用) sudo yum install epel-release sudo yum install https://rpms.adiscon.com/v8-stable/rsyslog-rpms-release-8-stable.el7.noarch.rpm ``` --- ### 、安装指定版本 1. **通过 YUM 安装** ```bash # 清理缓存并更新仓库 sudo yum clean all sudo yum update # 安装指定版本(假设仓库中存在 8.2402.0) sudo yum install rsyslog-8.2402.0 ``` 2. **若仓库无此版本,需源码编译安装** ```bash # 安装编译依赖 sudo yum install -y gcc make libestr-devel libfastjson-devel liblogging-devel openssl-devel # 下载源码包(替换为实际版本号) wget https://www.rsyslog.com/files/download/rsyslog/rsyslog-8.2402.0.tar.gz tar -xzvf rsyslog-8.2402.0.tar.gz cd rsyslog-8.2402.0 # 编译并安装 ./configure --enable-ssl --enable-imudp --enable-omstdout # 启用 DTLS 所需模块[^2] make sudo make install ``` --- ### 三、配置与验证 1. **版本验证** ```bash rsyslogd -v # 输出应包含 "8.2402.0" ``` 2. **服务管理** ```bash # 若通过源码安装,需手动注册服务(默认路径 /usr/local/sbin/rsyslogd) sudo cp platform/redhat/rsyslog.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl start rsyslog ``` 3. **依赖冲突处理** - 若出现类似引用[^5]的 `yum conflicts` 错误,需排除冲突包: ```bash sudo yum update --exclude=initscripts # 临时跳过冲突包 ``` --- ### 四、典型问题解决 - **网络配置问题**(参考引用[^3][^4]): 确保虚拟机网卡已激活(`ONBOOT=yes`)且 DNS 配置正确,否则 yum 安装会失败。 ```bash vi /etc/sysconfig/network-scripts/ifcfg-eth0 # 修改后重启网络服务 ``` --- ### 五、卸载旧版本(如适用) ```bash sudo yum remove rsyslog sudo rm -rf /etc/rsyslog.conf /etc/rsyslog.d # 备份配置后再操作 ``` --- ### 相关问题 1. 如何为 rsyslog 8.2402.0 启用 DTLS 加密传输? 2. 源码编译安装的 rsyslog 如何与 systemd 集成? 3. 如何回滚到 CentOS 7 默认仓库的 rsyslog 版本? [^1]: rsyslog 官方版本命名规则 [^2]: rsyslog 编译选项文档
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值