25.3. 使用 runlabels 运行 rsyslog
发出 rhel9/rsyslog
容器镜像以运行 rsyslogd
守护进程的容器化版本。rsyslog
镜像包含以下 runlabels:install
、run
和 uninstall
。以下流程介绍了安装、运行和卸载 rsyslog
镜像的步骤:
先决条件
-
container-tools
元数据包已安装。
流程
拉取
rsyslog
镜像:# podman pull registry.redhat.io/rhel9/rsyslog
为
rsyslog
显示install
runlabel:# podman container runlabel install --display rhel9/rsyslog command: podman run --rm --privileged -v /:/host -e HOST=/host -e IMAGE=registry.redhat.io/rhel9/rsyslog:latest -e NAME=rsyslog registry.redhat.io/rhel9/rsyslog:latest /bin/install.sh
此时该命令会为主机打开权限,将主机 root 文件系统挂载到容器中的
/host
,并运行install.sh
脚本。为
rsyslog
运行install
runlabel:# podman container runlabel install rhel9/rsyslog command: podman run --rm --privileged -v /:/host -e HOST=/host -e IMAGE=registry.redhat.io/rhel9/rsyslog:latest -e NAME=rsyslog registry.redhat.io/rhel9/rsyslog:latest /bin/install.sh Creating directory at /host//etc/pki/rsyslog Creating directory at /host//etc/rsyslog.d Installing file at /host//etc/rsyslog.conf Installing file at /host//etc/sysconfig/rsyslog Installing file at /host//etc/logrotate.d/syslog
这会在
rsyslog
镜像稍后要使用的主机系统上创建文件。为
rsyslog
显示run
runlabel:# podman container runlabel run --display rhel9/rsyslog command: podman run -d --privileged --name rsyslog --net=host --pid=host -v /etc/pki/rsyslog:/etc/pki/rsyslog -v /etc/rsyslog.conf:/etc/rsyslog.conf -v /etc/sysconfig/rsyslog:/etc/sysconfig/rsyslog -v /etc/rsyslog.d:/etc/rsyslog.d -v /var/log:/var/log -v /var/lib/rsyslog:/var/lib/rsyslog -v /run:/run -v /etc/machine-id:/etc/machine-id -v /etc/localtime:/etc/localtime -e IMAGE=registry.redhat.io/rhel9/rsyslog:latest -e NAME=rsyslog --restart=always registry.redhat.io/rhel9/rsyslog:latest /bin/rsyslog.sh
这表明,在启动
rsyslog
容器来运行rsyslogd
守护进程时,该命令会向主机开放特权,并在容器内挂载来自主机的特定的文件和目录。为
rsyslog
执行run
runlabel:# podman container runlabel run rhel9/rsyslog command: podman run -d --privileged --name rsyslog --net=host --pid=host -v /etc/pki/rsyslog:/etc/pki/rsyslog -v /etc/rsyslog.conf:/etc/rsyslog.conf -v /etc/sysconfig/rsyslog:/etc/sysconfig/rsyslog -v /etc/rsyslog.d:/etc/rsyslog.d -v /var/log:/var/log -v /var/lib/rsyslog:/var/lib/rsyslog -v /run:/run -v /etc/machine-id:/etc/machine-id -v /etc/localtime:/etc/localtime -e IMAGE=registry.redhat.io/rhel9/rsyslog:latest -e NAME=rsyslog --restart=always registry.redhat.io/rhel9/rsyslog:latest /bin/rsyslog.sh 28a0d719ff179adcea81eb63cc90fcd09f1755d5edb121399068a4ea59bd0f53
rsyslog
容器会开放特权,挂载其需要的来自主机的内容,并在后台(-d
)运行rsyslogd
守护进程。rsyslogd
守护进程开始收集日志消息,并将信息定向到/var/log
目录中的文件。显示
rsyslog
的uninstall
runlabel:# podman container runlabel uninstall --display rhel9/rsyslog command: podman run --rm --privileged -v /:/host -e HOST=/host -e IMAGE=registry.redhat.io/rhel9/rsyslog:latest -e NAME=rsyslog registry.redhat.io/rhel9/rsyslog:latest /bin/uninstall.sh
为
rsyslog
运行uninstall
runlabel:# podman container runlabel uninstall rhel9/rsyslog command: podman run --rm --privileged -v /:/host -e HOST=/host -e IMAGE=registry.redhat.io/rhel9/rsyslog:latest -e NAME=rsyslog registry.redhat.io/rhel9/rsyslog:latest /bin/uninstall.sh
在这种情况下, uninstall.sh
脚本只删除 /etc/logrotate.d/syslog
文件。它不会清理配置文件。