CentOS Stream 9 + geoipupdate + Python 3.11をインストール
FreeBSDサーバーでやったことを CentOS Streamサーバーの環境でも行っているときの覚書。
Gemini 2.5 Proと対話。
環境: CentOS Stream 9, Python 3.9.23, Python 3.11.13
1. geoipupdateをインストール
CentOS Streamの環境では公式リポジトリにgeoipupdateがない。
# dnf search geoip
RPMをGitHubからダウンロードしてインストールするのが公式。
参考: maxmind/geoipupdate: GeoIP update client code
GitHubのReleasesに掲載してあるURLを確認してダウンロード。
-OはURLのファイル名でダウンロード。-Lはリダイレクトを許可。
# curl -OL https://github.com/maxmind/geoipupdate/releases/download/v7.1.1/geoipupdate_7.1.1_linux_amd64.rpm
dnfが依存関係を自動で解決してインストールしてくれる。
# dnf install ./geoipupdate_7.1.1_linux_amd64.rpm
Account IDとLicense Keyを設定ファイルに記述。
国別データベースの場合は GeoLite2-Countryを指定。
# less /etc/GeoIP.conf
AccountID 1234567LicenseKey 08MzPb....pe_mmkEditionIDs GeoLite2-Country
動作確認。
# geoipupdate -v
geoipupdate version 7.1.1 (6664d8b9, 2025-07-09T20:46:45Z, linux-amd64)Using config file /etc/GeoIP.confUsing database directory /usr/share/GeoIPInitializing file lock at /usr/share/GeoIP/.geoipupdate.lockAcquired lock file at /usr/share/GeoIP/.geoipupdate.lockCalculated MD5 sum for /usr/share/GeoIP/GeoLite2-Country.mmdb: 849e7667913e375bb3873f8778e8fb17Updates available for GeoLite2-CountryDatabase GeoLite2-Country successfully updated: bab...9a5efdLock file /usr/share/GeoIP/.geoipupdate.lock successfully released
保存場所確認。
# ls -l /usr/share/GeoIP
ダウンロードしたrpm削除
# rm -f geoipupdate_7.1.1_linux_amd64.rpm
2. GeoLite2-Country.mmdbのメタデータを確認
python用ライブラリをインストール。
# dnf install python3-maxminddb
前に作ったスクリプトをCentOS向けに修正して実行。
Gist: Check metadata of mmdb file. Generate by Gemini 2.5 Pro
# cd /home/software/server-utility/
# vi check_mmdb_meta.py
# python3 check_mmdb_meta.py
■■■ GeoIPデータベース メタデータ情報 ■■■データベースファイル: /usr/share/GeoIP/GeoLite2-Country.mmdb--------------------------------------------------【ビルド日時】ビルドエポックタイム: 1756201338ビルド日時 (UTC): 2025-08-26 09:42:18 UTCビルド日時 (ローカル): 2025-08-26 18:42:18 JST【データベース仕様】データベース種別: GeoLite2-Country説明: GeoLite2 Country database対応IPバージョン: IPv6ノード数: 1,585,231レコードサイズ: 24 bits
3. Python3.11をインストール
Gemini先生が作ったスクリプトがPython3.9で動作しなかったので、Python3.11をインストール。
# dnf install python3.11 python3.11-pip
alternativesに登録されたか確認。→ 登録されない。
# alternatives --list
PythonからMaxMind(MMDB)形式を扱えるライブラリをインストール。
# python3.11 -m pip install maxminddb
4. cronで定期実行
geoipupdateのパス確認。
# whereis geoipupdate
cronに登録する。
# cd /etc/cron.d/
# less server-maintenance
#----------------------------------------------------------------------# 実行時刻: 毎週日曜日 午前3時00分# 説 明: MaxMindのGeoIPデータベースを更新します。# 更新・Nginxリロード・メタデータ確認を行います。#----------------------------------------------------------------------0 3 * * 0 root /usr/bin/geoipupdate -v && /home/software/server-utility/update_geoip_rules.sh
▼ 関連記事
- FreeBSD14 + Nginx + GeoIP2の設定とIPアドレスを自動更新
- 日本国以外からのPOSTを拒否するNginx設定をGeoIPで自動化
- Python3.6と3.9を共存させようとして結局3.6はアンインストール