温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Ubuntu18.04 LTS如何安装Rsyslog

发布时间:2022-01-24 15:03:09 来源:亿速云 阅读:210 作者:iii 栏目:开发技术

今天小编给大家分享一下Ubuntu18.04  LTS如何安装Rsyslog的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

Rsyslog 是一个 syslogd 的多线程增强版。它提供高性能、极好的安全功能和模块化设计。虽然它基于常规的 syslogd,但 rsyslog 已经演变成了一个强大的工具。

Ubuntu18.04  LTS如何安装Rsyslog

准备

  • 两个运行Ubuntu 18.04 LTS版本的虚拟机下载地址:http://mirror.freethought-internet.co.uk/ubuntu-releases/18.04.3/ubuntu-18.04.3-live-server-amd64.iso
  • 在Rsylog服务端配置静态IP地址192.168.0.101,在Rsylog客户端配置192.1680.102。
  • 在两个服务器上都设置root密码。

安装Rsyslog

默认情况下,Rsyslog安装在Ubuntu 18.04服务器上。如果没有安装,您可以通过运行以下命令来安装它:

linuxprobe@ubuntu-18-04-lts:~$ apt-get install rsyslog -y

在安装Rsyslog之后,您可以使用以下命令检查Rsyslog的版本:

linuxprobe@ubuntu-18-04-lts:~$ rsyslogd -v
rsyslogd 8.32.0, compiled with:
PLATFORM:    x86_64-pc-linux-gnu
PLATFORM (lsb_release -d):  
FEATURE_REGEXP:    Yes
GSSAPI Kerberos 5 support:  Yes
FEATURE_DEBUG (debug build, slow code): No
32bit Atomic operations supported: Yes
64bit Atomic operations supported: Yes
memory allocator:   system default
Runtime Instrumentation (slow code): No
uuid support:    Yes
systemd support:   Yes
Number of Bits in RainerScript integers: 64

See http://www.rsyslog.com for more information.

还可以用这个命令检查Rsyslog的状态:

linuxprobe@ubuntu-18-04-lts:~$ systemctl status rsyslog
? rsyslog.service - System Logging Service
  Loaded: loaded (/lib/systemd/system/rsyslog.service; enabled; vendor preset: enabled)
  Active: active (running) since Thur 2020-01-16 11:20:32 CST; 1min 31s ago
    Docs: man:rsyslogd(8)
Main PID: 724 (rsyslogd)
   Tasks: 4 (limit: 1114)
  CGroup: /system.slice/rsyslog.service
          ??724 /usr/sbin/rsyslogd -n

Jan 16 04:28:53 ubuntu-18-04-lts systemd[1]: Starting System Logging Service...
Jan 16 04:28:54 ubuntu-18-04-lts rsyslogd[724]: imuxsock: Acquired UNIX socket '/run/systemd/journal/syslog' (fd 3) from systemd.  [v8.32.0]
Jan 16 04:28:54 ubuntu-18-04-lts rsyslogd[724]: rsyslogd's groupid changed to 106
Jan 16 04:28:54 ubuntu-18-04-lts rsyslogd[724]: rsyslogd's userid changed to 102
Jan 16 04:28:54 ubuntu-18-04-lts rsyslogd[724]:  [origin software="rsyslogd" swVersion="8.32.0" x-pid="724" x-info="http://www.rsyslog.com"] start
Jan 16 04:28:55 ubuntu-18-04-lts systemd[1]: Started System Logging Service.

配置Rsyslog服务端

linuxprobe@ubuntu-18-04-lts:~$ vim /etc/rsyslog.conf

取消这几行前面的注释,同事使用UDP和TCP协议的514端口

$ModLoad imudp$UDPServerRun 514$ModLoad imtcp$InputTCPServerRun 514

指定子网、IP或域名来限制访问,如下所示:

$AllowedSender TCP, 127.0.0.1, 192.168.0.0/24, *.example.com$AllowedSender UDP, 127.0.0.1, 192.168.0.0/24, *.example.com

创建一个模板来告诉Rsyslog如何存储传入的syslog消息。在GLOBAL DIRECTIVES部分之前添加以下几行:

$template remote-incoming-logs,"/var/log/%HOSTNAME%/%PROGRAMNAME%.log"*.* ?remote-incoming-logs

用以下命令检查Rsyslog配置信息是否有语法错误:

linuxprobe@ubuntu-18-04-lts:~$ rsyslogd -f /etc/rsyslog.conf -N1
rsyslogd: version 8.32.0, config validation run (level 1), master config /etc/rsyslog.conf
rsyslogd: End of config validation run. Bye.

重新启动Rsyslog:

linuxprobe@ubuntu-18-04-lts:~$ systemctl restart rsyslog

验证Rsyslog正在使用以下命令监听TCP/UDP:

linuxprobe@ubuntu-18-04-lts:~$ netstat -4altunp | grep 514tcp        0      0 0.0.0.0:514             0.0.0.0:*               LISTEN      1332/rsyslogd      udp        0      0 0.0.0.0:514             0.0.0.0:*                           1332/rsyslogd

配置Rsyslog客户端

配置Rsyslog客户端来向远程服务端发送系统日志消息。登录客户端,打开/etc/rsyslog.conf添加如下信息:

linuxprobe@ubuntu-18-04-lts:~$ vim /etc/rsyslog.conf##Enable sending of logs over UDP add the following line:*.* @192.168.0.101:514##Enable sending of logs over TCP add the following line:*.* @@192.168.0.101:514##Set disk queue when rsyslog server will be down:$ActionQueueFileName queue$ActionQueueMaxDiskSpace 1g$ActionQueueSaveOnShutdown on$ActionQueueType LinkedList$ActionResumeRetryCount -1

重新启动Rsyslog:

linuxprobe@ubuntu-18-04-lts:~$ systemtcl restart rsyslog

查看日志

此时,Rsyslog客户端被配置为将它们的日志发送到Rsyslog服务端。 现在,登录到Rsyslog服务器并检查/var/log目录。看到客户端机器的主机名,包括几个日志文件:

linuxprobe@ubuntu-18-04-lts:~$ ls /var/log/rsyslog-client/
CRON.log  kernel.log  rsyslogd-2039.log  rsyslogd.log  sudo.log  wpa_supplicant.log

以上就是“Ubuntu18.04  LTS如何安装Rsyslog”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI