如何收集活跃的RHDS客户端IP地址?

Bash

1 前言

一个问题,一篇文章,一出故事。
笔者最近接到需要收集RHDS服务活跃的IP地址的工作任务,于是整理本文。

2 最佳实践

2.1 收集的环境

如何调整RHDS的访问日志的级别?

2.2 配置收集脚本

2.2.1 创建收集脚本

vim ~/scripts/getAccessIP.sh

加入如下配置,

#!/bin/bash

activeFile="/var/log/dirsrv/activeIPs.log"
excludeFile="/var/log/dirsrv/excludeIPs.log"
accessFile="/var/log/dirsrv/slapd-389ds/access"

nosslIPs=$(grep "connection from" "$accessFile" | grep -v "SSL" | awk -F' ' '{print $8}' | sort -u)
sslIPs=$(grep "connection from" "$accessFile" | grep "SSL" | awk -F' ' '{print $9}' | sort -u)
combinedIPs=$(echo -e "$nosslIPs\n$sslIPs" | sort -u)

if [ -f "$excludeFile" ]; then
        excludedIPs=$(cat "$excludeFile")
        filteredIPs=$(echo "$combinedIPs" | grep -v -F -x -f > "$activeFile"

if [ ! -f "$excludeFile" ]; then
        exit
fi

if [ ! -f "$activeFile" ]; then
        exit
fi

while IFS= read -r ip; do
        if grep -q "^$ip$" "$activeFile"; then
                sed -i "/^$ip$/d" "$activeFile"
        fi
done < "$excludeFile"
cat "$activeFile" | grep -v '^$' | sort -n -t . -k1,1 -k2,2 -k3,3 -k4,4 -o "$activeFile"

2.2.2 创建脚本定时任务

crontab -e

加入如下配置,

0 */1 * * * bash ~/scripts/getAccessIP.sh
没有评论

发表回复

Bash
如何用Base Shell推送华为消息?

1 前言 一个问题,一篇文章,一出故事。 今天遇到服务器推送华为消息失败,于是尝试使用curl去测试 …

Bash
如何用Tigase监控nginx服务?

1 前言 一个问题,一篇文章,一出故事。 笔者今天遇到Nginx代理的上游服务器报错,由于Nginx …

Bash
如何确定LDAP的端口通讯正常?

1 前言 一个问题,一篇文章,一出故事。 今天遇到nc测试ldap的389,范例如下, ncat – …