Nginx Log
n5321 | 2025年6月11日 23:52
goaccess can track request.
但是记录的ip地址不知道是哪里的。
尝试方式一:命令行加 --enable-geoip
和 --enable-geo-resolver
安装:
sudo apt install geoip-bin geoip-database
无效。
用nano写script
#!/bin/bash
echo "🔍 正在检查 GoAccess 是否安装..."
if ! command -v goaccess &> /dev/null; then
echo "❌ 未检测到 GoAccess,正在安装旧版本..."
sudo apt update
sudo apt install -y goaccess
fi
echo "✅ GoAccess 已安装,检测版本和 GeoIP 支持情况..."
goaccess --version | grep -q "GeoIP2 support"
if [ $? -eq 0 ]; then
echo "🎉 当前 GoAccess 已支持 GeoIP2,无需修复。"
exit 0
else
echo "⚠️ 当前 GoAccess 未启用 GeoIP 支持,准备自动编译带 GeoIP2 的版本..."
fi
# 安装编译依赖
echo "📦 安装依赖中..."
sudo apt update
sudo apt install -y build-essential libncursesw5-dev libgeoip-dev \
libmaxminddb-dev libtokyocabinet-dev git autotools-dev automake
# 克隆源码
echo "📥 下载 GoAccess 最新源代码..."
cd ~
rm -rf goaccess # 避免旧版本冲突
git clone https://github.com/allinurl/goaccess.git
cd goaccess
echo "🔧 开始编译 GoAccess with GeoIP2 支持..."
autoreconf -fi
./configure --enable-utf8 --enable-geoip=mmdb
make -j$(nproc)
sudo make install
# 检查是否成功
echo "✅ 编译完成,检查 GeoIP2 支持:"
goaccess --version | grep GeoIP2 && echo "✅ 成功安装带 GeoIP2 支持的 GoAccess!" || echo "❌ 安装失败,请手动检查"
# 提示用户数据库位置
echo ""
echo "📍 你需要下载 MaxMind 的 GeoLite2-City.mmdb 数据库:"
echo "1. 访问:https://dev.maxmind.com/geoip/geolite2/"
echo "2. 注册账号,下载 GeoLite2-City.mmdb"
echo "3. 保存到例如:/usr/local/share/GeoIP/GeoLite2-City.mmdb"
echo ""
echo "📊 之后你可以这样运行 goaccess:"
echo " zcat /var/log/nginx/access.log.*.gz | goaccess \\"
echo " --log-format=COMBINED \\"
echo " --geoip-database /usr/local/share/GeoIP/GeoLite2-City.mmdb \\"
echo " -o report.html"
download GeoLite2-City.mmdb
sudo mkdir -p /usr/local/share/GeoIP
sudo cp GeoLite2-City.mmdb /usr/local/share/GeoIP/
sudo chmod 644 /usr/local/share/GeoIP/GeoLite2-City.mmdb
搞定
14天的hits!