Rocky Linuxをインストールした Raspberry Pi 4 Model B に、webalizerをインストールした記録です。
Rocky Linuxにはwebalizerのパッケージが有りませんので、ソース・ファイルをコンパイルしました。
BerkeleyDBをインストールする。
ソースを展開する。
1 2 3 4 5 6 7 8 9 10 11 12 |
# tar xvfz db-4.8.30.tar.gz db-4.8.30/ db-4.8.30/btree/ db-4.8.30/btree/bt_compress.c db-4.8.30/btree/bt_compact.c db-4.8.30/btree/bt_compare.c : db-4.8.30/txn/txn_rec.c db-4.8.30/txn/txn_region.c db-4.8.30/txn/txn_stat.c db-4.8.30/txn/txn_util.c # |
configureを実行する。
ライブラリを/usr/local/libにインストールするため、「–prefix=/usr/local」を指定する。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# cd db-4.8.30/build_unix/ # ../dist/configure --prefix=/usr/local --enable-shared --build=arm --enable-cxx --disable-replication --with-pic --enable-pthread_api --enable-cxx checking build system type... arm-unknown-none checking host system type... arm-unknown-none checking if building in the top-level or dist directories... no checking if --disable-cryptography option specified... no checking if --disable-hash option specified... no : configure: creating ./config.status config.status: creating Makefile config.status: creating db_cxx.h config.status: creating db_int.h config.status: creating clib_port.h config.status: creating include.tcl config.status: creating db.h config.status: creating db_config.h config.status: executing libtool commands # |
makeする。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# make ./libtool --mode=compile cc -c -I. -I../dist/.. -O3 ../dist/../mutex/mut_pthread.c libtool: compile: cc -c -I. -I../dist/.. -O3 ../dist/../mutex/mut_pthread.c -o mut_pthread.o ./libtool --mode=compile cc -c -I. -I../dist/.. -O3 ../dist/../btree/bt_compare.c libtool: compile: cc -c -I. -I../dist/.. -O3 ../dist/../btree/bt_compare.c -o bt_compare.o ./libtool --mode=compile cc -c -I. -I../dist/.. -O3 ../dist/../btree/bt_compress.c libtool: compile: cc -c -I. -I../dist/.. -O3 ../dist/../btree/bt_compress.c -o bt_compress.o : ./libtool --mode=compile cc -c -I. -I../dist/.. -O3 ../dist/../db_verify/db_verify.c libtool: compile: cc -c -I. -I../dist/.. -O3 ../dist/../db_verify/db_verify.c -o db_verify.o ./libtool --mode=link cc -O3 -o db_verify \ db_verify.o util_cache.o util_sig.o libdb-4.8.a -lpthread libtool: link: cc -O3 -o db_verify db_verify.o util_cache.o util_sig.o libdb-4.8.a -lpthread : db_verify # |
インストールする。
–enable-sharedを指定しているが、動的ライブラリ(*.so)が作成されていない(なぜ?)・
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# make install Installing DB include files: /usr/local/include ... Installing DB library: /usr/local/lib ... libtool: install: cp -p libdb-4.8.a /usr/local/lib/libdb-4.8.a libtool: install: chmod 644 /usr/local/lib/libdb-4.8.a libtool: install: ranlib /usr/local/lib/libdb-4.8.a libtool: install: cp -p libdb.a /usr/local/lib/libdb.a libtool: install: chmod 644 /usr/local/lib/libdb.a libtool: install: ranlib /usr/local/lib/libdb.a Installing DB utilities: /usr/local/bin ... libtool: install: cp -p db_archive /usr/local/bin/db_archive libtool: install: cp -p db_checkpoint /usr/local/bin/db_checkpoint libtool: install: cp -p db_deadlock /usr/local/bin/db_deadlock libtool: install: cp -p db_dump /usr/local/bin/db_dump libtool: install: cp -p db_hotbackup /usr/local/bin/db_hotbackup libtool: install: cp -p db_load /usr/local/bin/db_load libtool: install: cp -p db_printlog /usr/local/bin/db_printlog libtool: install: cp -p db_recover /usr/local/bin/db_recover libtool: install: cp -p db_sql /usr/local/bin/db_sql libtool: install: cp -p db_stat /usr/local/bin/db_stat libtool: install: cp -p db_upgrade /usr/local/bin/db_upgrade libtool: install: cp -p db_verify /usr/local/bin/db_verify Installing documentation: /usr/local/docs ... # |
ライブラリ参照設定
動的ライブラリが作成されていないが、作成できることを考慮して作成しておく。動的ライブラリが作成された時は、更新します。
1 2 3 4 5 6 |
# vi /etc/ld.so.conf.d/usr_local_lib.conf # cat /etc/ld.so.conf.d/usr_local_lib.conf /usr/local/lib/ # # ldconfig # |
webalizerをインストールする。
DNSの逆引きを利用しなければ、エラーとなりません。が、DNSの逆引きを利用するならソースファイルを修正しないと利用できません。
webalizerを取得する。
ソースファイルが見つけにくいのでここ置きました。
ソースを展開する。
1 2 3 4 5 6 7 8 9 10 |
# tar xvfz webalizer-2.23-08-src.tgz webalizer-2.23-08/ webalizer-2.23-08/CHANGES webalizer-2.23-08/COPYING webalizer-2.23-08/Copyright : webalizer-2.23-08/lang/webalizer_lang.thai webalizer-2.23-08/lang/webalizer_lang.turkish webalizer-2.23-08/lang/webalizer_lang.ukrainian # |
configureを実行する。
GeoIPをパッケージを含めてコンパイルしました。ただし、webalizerで正確な国の情報が必要とは思えない。アクセスされた情報が重要と思われる。
Raspberry pi:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
./configure --enable-dns --with-dblib=/usr/lib64 --enable-bz2 --enable-geoip -with-langage=japanese --build=arm root@raspberrypi webalizer-2.23-08]# [root@raspberrypi webalizer-2.23-08]# ./configure --enable-dns --with-dblib=/usr/lib64 --enable-bz2 --enable-geoip -with-langage=japanese --build=arm checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... : checking for language file... yes - english configure: creating ./config.status config.status: creating Makefile config.status: linking ./lang/webalizer_lang.english to webalizer_lang.h configure: Done. Type 'make' to continue with build. # |
Intel PC:
1 |
# ./configure --enable-dns --with-dblib=/usr/lib64 --enable-bz2 -with-langage=japanese --build=i686-linux |
※-with-langage=japanese を指定しいますが、langディレクトリの配下のファイルは内容が英語なので指定不要です。
※–build=XXX を指定していますが、アーキテクチャのチェックが無いので指定不要です。
make する(が、エラーとなる)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# make gcc -fsigned-char -Wall -O2 -DETCDIR=\"/usr/local/etc\" -DGEODB_LOC=\"/usr/share/GeoDB\" -DPACKAGE_NAME=\"webalizer\" -DPACKAGE_TARNAME=\"webalizer\" -DPACKAGE_VERSION=\"V2.23\" -DPACKAGE_STRING=\"webalizer\ V2.23\" -DPACKAGE_BUGREPORT=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_GETOPT_H=1 -DHAVE_MATH_H=1 -DHAVE_SYS_SOCKET_H=1 -DUSE_GEOIP -DUSE_BZIP -DUSE_DNS -c webalizer.c webalizer.c: 関数 ‘main’ 内: webalizer.c:748:43: 警告: 書式 ‘%llu’ は引数の型が ‘long long unsigned int’ であると予期されますが、第 5 引数の型は ‘u_int64_ ’ {aka ‘long unsigned int’} です [-Wformat=] 748 | fprintf(stderr,"%s: %s [%llu]", | ~~~^ | | | long long unsigned int | %lu 749 | msg_bad_date,log_rec.datetime,total_rec); | ~~~~~~~~~ | | | u_int64_t {aka long unsigned int} webalizer.c:979:49: 警告: 書式 ‘%llu’ は引数の型が ‘long long unsigned int’ であると予期されますが、第 4 引数の型は ‘u_int64_ ’ {aka ‘long unsigned int’} です [-Wformat=] : /usr/bin/ld: dns_resolv.o:(.bss+0x1e58): multiple definition of `buffer'; webalizer.o:(.bss+0x5c20): first defined here /usr/bin/ld: dns_resolv.o:(.bss+0xe58): multiple definition of `tmp_buf'; webalizer.o:(.bss+0x4c20): first defined here /usr/bin/ld: dns_resolv.o:(.bss+0x2e58): multiple definition of `host_table'; hashtab.o:(.bss+0x0): first defined here /usr/bin/ld: dns_resolv.o:(.bss+0xcd0): multiple definition of `system_info'; webalizer.o:(.bss+0x940): first defined here collect2: エラー: ld はステータス 1 で終了しました make: *** [Makefile:47: webalizer] エラー 1 # |
「定義が複数ある」と怒っています。
※webalizer.cに同様のchar定義があるので、こちらを先にlinkerが見つけたと思われる。
ソースを修正する。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# cp -p dns_resolv.c dns_resolv.c_org # vi dns_resolv.c # diff -c dns_resolv.c_org dns_resolv.c *** dns_resolv.c_org 2013-02-26 14:37:27.000000000 +0900 --- dns_resolv.c 2024-02-14 20:44:20.440310744 +0900 *************** *** 78,88 **** struct dns_child child[MAXCHILD]; /* DNS child pipe data */ ! DNODEPTR host_table[MAXHASH]; /* hostname/ip hash table */ ! char buffer[BUFSIZE]; /* log file record buffer */ ! char tmp_buf[BUFSIZE]; /* used to temp save above */ ! struct utsname system_info; /* system info structure */ int raiseSigChild = 1; --- 78,88 ---- struct dns_child child[MAXCHILD]; /* DNS child pipe data */ ! extern DNODEPTR host_table[MAXHASH]; /* hostname/ip hash table */ ! extern char buffer[BUFSIZE]; /* log file record buffer */ ! extern char tmp_buf[BUFSIZE]; /* used to temp save above */ ! extern struct utsname system_info; /* system info structure */ int raiseSigChild = 1; # |
この定義は、「他のソースに同様の定義がある」と宣言します。
再度makeする。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# make gcc -fsigned-char -Wall -O2 -DETCDIR=\"/usr/local/etc\" -DGEODB_LOC=\"/usr/share/GeoDB\" -DPACKAGE_NAME=\"webalizer\" -DPACKAGE_TARNAME=\"webalizer\" -DPACKAGE_VERSION=\"V2.23\" -DPACKAGE_STRING=\"webalizer\ V2.23\" -DPACKAGE_BUGREPORT=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_GETOPT_H=1 -DHAVE_MATH_H=1 -DHAVE_SYS_SOCKET_H=1 -DUSE_GEOIP -DUSE_BZIP -DUSE_DNS -c dns_resolv.c dns_resolv.c: 関数 ‘dns_resolver’ 内: dns_resolv.c:319:18: 警告: 書式 ‘%llu’ は引数の型が ‘long long unsigned int’ であると予期されますが、第 2 引数の型は ‘u_int64_t’ {aka ‘long unsigned int’} です [-Wformat=] 319 | printf("%llu %s ",listEntries, msg_addresses); | ~~~^ ~~~~~~~~~~~ | | | | | u_int64_t {aka long unsigned int} | long long unsigned int | %lu : wcmgr.c: 関数 ‘add_rec’ 内: wcmgr.c:764:13: 警告: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 764 | strncpy(name,addr,strlen(addr)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcc -L/usr/lib64 -o wcmgr wcmgr.o -ldb # |
正常にmakeできた。
インストールする。
インストール先は、configureコマンドで指定しないため「/usr/local」配下になります。
設定ファイルは、「/usr/local/etc/webalizer.conf」です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
]# make install mkdir -p /usr/local/bin mkdir -p /man/man1 mkdir -p /usr/local/etc /usr/bin/install -c webalizer /usr/local/bin/webalizer /usr/bin/install -c wcmgr /usr/local/bin/wcmgr rm -f /usr/local/bin/webazolver ln -s webalizer /usr/local/bin/webazolver /usr/bin/install -c -m 644 webalizer.1 /man/man1/webalizer.1 /usr/bin/install -c -m 644 wcmgr.1 /man/man1/wcmgr.1 rm -f /man/man1/webazolver.1 ln -s webalizer.1 /man/man1/webazolver.1 /usr/bin/install -c -m 644 sample.conf /usr/local/etc/webalizer.conf.sample # |
WEBサーバのログを切り替え(ローテイト)させる。
日付が変わった時点でWEBサーバのログを切り替えることにより、日単位でのログになるので管理が便利である。
また、ログを切り替えてすぐに圧縮してしまうと、webalizerで読み込ませる前に解凍が必要になるので、圧縮処理は一日ずら様にする。
他のログの切り替えの説明であるがここを参考にしてください。
webalizerを実行するシェルを作成し実行する。
以下に参考シェルを示します。
1 2 3 4 5 6 7 8 9 10 |
# cat /usr/local/sbin/webalizer.sh #!/bin/bash # 前日ログが当日日付でアーカイブされる DATE=`date "+%Y%m%d"` /usr/local/bin/webalizer -c /usr/local/etc/webalizer.conf /var/log/nginx/access.log-${DATE} # # chmod 755 /usr/local/sbin/webalizer.sh # |
crontabに登録する。
1 2 |
# crontab -e 5 0 * * * /usr/local/sbin/webalizer.sh |
手動でシェルを実行し、シェルが正しく動作するか確認する。また、webalizer.confファイルの設定が正しいか確認する。
webalizer.confファイルの修正
数日実行すると結果表示サイトに「Total URLs」の情報が色々表示される。
*.xmlや*.webpのファイル情報や、/wp-admin/*や/wp-content/plugins/*などの情報が表示されるが投稿URLのみ表示させたいので非表示にする必要がある。
よって、webalizer.confファイルの修正が必要になる。
1 2 3 4 5 6 7 8 9 10 |
# Usually you want to hide these : HideURL *.svg HideURL *.xml HideURL *.webp IgnoreURL /wp-content/plugins/* IgnoreURL /feed/* IgnoreURL /wp-admin/* IgnoreURL /wp-json/* |
設定する項目は、自サイトの表示結果で判断してください。
国別のアクセスデータに国旗を表示する。
webalizer.confを修正
国旗の画像はどうなっているのだろうと思いながらwebalizer.confファイルを修正する。
以下が設定内容です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
CountryGraph yes # CountryFlags allows flags to be displayed in the top country # table in monthly reports. Values can be 'yes' or 'no', with # the default being 'no'. CountryFlags yes # FlagDir specifies the location of flag graphics which will be # used in the top country table. If not specified, the default # is to look in the 'flags' directory directly under the output # directory being used for the reports. If this option is used, # the display of flag graphics will be enabled by default. #FlagDir flags |
結果表示htmlファイルの確認
FlagDirをコメントアウトすると、webalizerの結果を出力するフォルダ(webで表示するデータのフォルダ)配下のflagsフォルダに国旗ファイルがある想定で表示用htmlファイルが作成される。
ブラウザで表示された統計情報のhtmlソースを確認すると「IMG SRC=”flags/jp.png”」が確認できる。これが国旗の画像情報で、flagsディレクトリ配下のpngファイルを表示する設定であることが判明する。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<TD ALIGN=left NOWRAP><<span style="color: #ff0000;"><strong>IMG SRC="flags/jp.png"</strong></span> ALT="Japan" WIDTH=18 HEIGHT=12> <FONT SIZE="-1">Japan</FONT></TD></TR> <TR><TD ALIGN=center><FONT SIZE="-1"><B>3</B></FONT></TD> <TD ALIGN=right><FONT SIZE="-1"><B>1735</B></FONT></TD> <TD ALIGN=right><FONT SIZE="-2">16.48%</FONT></TD> <TD ALIGN=right><FONT SIZE="-1"><B>947</B></FONT></TD> <TD ALIGN=right><FONT SIZE="-2">14.52%</FONT></TD> <TD ALIGN=right><FONT SIZE="-1"><B>86197</B></FONT></TD> <TD ALIGN=right><FONT SIZE="-2">14.91%</FONT></TD> <TD ALIGN=left NOWRAP><IMG SRC="flags/us.png" ALT="United States" WIDTH=18 HEIGHT=12> <FONT SIZE="-1">United States</FONT></TD></TR> <TR><TD ALIGN=center><FONT SIZE="-1"><B>4</B></FONT></TD> <TD ALIGN=right><FONT SIZE="-1"><B>720</B></FONT></TD> <TD ALIGN=right><FONT SIZE="-2">6.84%</FONT></TD> <TD ALIGN=right><FONT SIZE="-1"><B>501</B></FONT></TD> <TD ALIGN=right><FONT SIZE="-2">7.68%</FONT></TD> <TD ALIGN=right><FONT SIZE="-1"><B>88296</B></FONT></TD> |
国旗ファイルをWEBからダインロード
無料でダウンロードできる世界の国旗の画像 | Sekainokokki.jpから国旗のpngファイルをダウンロードして、flagsディレクトリを作成してディレクトリ配下で解凍する。
動作確認
国旗が表示できた。
国旗が表示されない国がある。
・European Union(EU)は国か?と思ったが、EUのpngファイルをwebからダウンロードしてflagsディレクトリに置いた。
・United KingdomはGreat Britain(UK)を含むため、こちらに国旗が表示されるべきではと思いながら、gb.pngファイルのリンクファイルとしてuk.pngファイルを作成して表示させた。
まとめ
何度がwebalizerを設定したが、今回国旗表示を行ってみた。WEBを検索すると国旗を表示する設定情報は存在するが、国旗をダウンロードして特定のディレクトリに置くとの情報が無い。
常識なのだろうか。