Rocky Linuxに webalizer をインストールする

スポンサーリンク
Linux
スポンサーリンク
スポンサーリンク

概要

Rocky Linuxをインストールした Raspberry Pi 4 Model B に、webalizerをインストールした記録です。
Rocky Linuxにはwebalizerのパッケージが無いため、ソース・ファイルをコンパイルしました。
以下のパッケージをインストールする。
・BerkerayDBのインストールする。
・Webalizerをインストールする。
・国旗の画像を取得し、指摘ディレクトリに置く。

BerkeleyDBをインストールする。

ソースを展開する。

db-4.8.30を解凍して展開する。

# 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」を指定する。
デフォルトの引数設定では、共有(shared)ライブラリが生成されなかったが、「–host=arm-none-linux-gnueabi」引数を指定することにより共有ライブラリが作成できることが分かった。
また、「–build=arm」を指定しないと、「dist/config.guess」を更新しろとエラーになるため指定してください。

# cd db-4.8.30/build_unix/
# ../dist/configure --prefix=/usr/local \
--host=arm-none-linux-gnueabi \
--build=arm
checking build system type... arm-unknown-none
checking host system type... arm-none-linux-gnueabi
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する。

プログラムのコンパイルを実行する。

# make
./libtool --mode=compile cc -c -I. -I../dist/.. -D_GNU_SOURCE -D_REENTRANT -O3 ../dist/../mutex/mut_pthread.c
libtool: compile: cc -c -I. -I../dist/.. -D_GNU_SOURCE -D_REENTRANT -O3 ../dist/../mutex/mut_pthread.c -fPIC -DPIC -o .libs/mut_pthread.o
libtool: compile: cc -c -I. -I../dist/.. -D_GNU_SOURCE -D_REENTRANT -O3 ../dist/../mutex/mut_pthread.c -o mut_pthread.o >/dev/null 2>&1
./libtool --mode=compile cc -c -I. -I../dist/.. -D_GNU_SOURCE -D_REENTRANT -O3 ../dist/../btree/bt_compare.c
libtool: compile: cc -c -I. -I../dist/.. -D_GNU_SOURCE -D_REENTRANT -O3 ../dist/../btree/bt_compare.c -fPIC -DPIC -o .libs/bt_compare.o
libtool: compile: cc -c -I. -I../dist/.. -D_GNU_SOURCE -D_REENTRANT -O3 ../dist/../btree/bt_compare.c -o bt_compare.o >/dev/null 2>&1
            : 
./libtool --mode=compile cc -c -I. -I../dist/.. -D_GNU_SOURCE -D_REENTRANT -O3 ../dist/../db_verify/db_verify.c
libtool: compile: cc -c -I. -I../dist/.. -D_GNU_SOURCE -D_REENTRANT -O3 ../dist/../db_verify/db_verify.c -fPIC -DPIC -o .libs/db_verify.o
libtool: compile: cc -c -I. -I../dist/.. -D_GNU_SOURCE -D_REENTRANT -O3 ../dist/../db_verify/db_verify.c -o db_verify.o >/dev/null 2>&1
./libtool --mode=link cc -O3 -o db_verify \
db_verify.lo util_cache.lo util_sig.lo libdb-4.8.la -lpthread
libtool: link: cc -O3 -o .libs/db_verify .libs/db_verify.o .libs/util_cache.o .libs/util_sig.o ./.libs/libdb-4.8.so -lpthread
./libtool --mode=execute true db_verify
: db_verify
#

 

インストールする。

libdb-4.8.soがインストールされた。

# make install
Installing DB include files: /usr/local/include ...
Installing DB library: /usr/local/lib ...
libtool: install: cp -p .libs/libdb-4.8.so /usr/local/lib/libdb-4.8.so
libtool: install: cp -p .libs/libdb-4.8.lai /usr/local/lib/libdb-4.8.la
libtool: install: cp -p .libs/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
libtool: finish: PATH="/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/lib/jvm/java-17-openjdk-17.0.14.0.7-2.el9.x86_64/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
 /usr/local/lib
 
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
 - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
 during execution
 - add LIBDIR to the `LD_RUN_PATH' environment variable
 during linking
 - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
 - have your system administrator add LIBDIR to `/etc/ld.so.conf'
 
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Installing DB utilities: /usr/local/bin ...
libtool: install: cp -p .libs/db_archive /usr/local/bin/db_archive
libtool: install: cp -p .libs/db_checkpoint /usr/local/bin/db_checkpoint
libtool: install: cp -p .libs/db_deadlock /usr/local/bin/db_deadlock
libtool: install: cp -p .libs/db_dump /usr/local/bin/db_dump
libtool: install: cp -p .libs/db_hotbackup /usr/local/bin/db_hotbackup
libtool: install: cp -p .libs/db_load /usr/local/bin/db_load
libtool: install: cp -p .libs/db_printlog /usr/local/bin/db_printlog
libtool: install: cp -p .libs/db_recover /usr/local/bin/db_recover
libtool: install: cp -p .libs/db_sql /usr/local/bin/db_sql
libtool: install: cp -p .libs/db_stat /usr/local/bin/db_stat
libtool: install: cp -p .libs/db_upgrade /usr/local/bin/db_upgrade
libtool: install: cp -p .libs/db_verify /usr/local/bin/db_verify
Installing documentation: /usr/local/docs ...
#

 

ライブラリ参照設定

動的ライブラリを参照可能に設定する。

# 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を取得する。

ソースファイルが見つけにくいのでここ置きました。

ソースを展開する。

 

# 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:

# ./configure --enable-dns\
--with-dblib=/usr/lib64 \
--enable-bz2 \
--enable-geoip \
--with-langage=japanese\
--build=arm \
--with-db=/usr/local \
--with-dblib=/usr/local/lib
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:

# ./configure --enable-dns \
--with-dblib=/usr/lib64 \
--enable-bz2 \
-with-langage=japanese \
--build=i686-linux \
--with-db=/usr/local \
--with-dblib=/usr/local/lib

※-with-langage=japanese を指定しいますが、langディレクトリの配下のファイルは内容が英語なので指定不要です。

make する(が、エラーとなる)。

dns_resolv.oのリンクで「定義が複数ある」と怒ってエラーとなる。
※webalizer.cに同様のchar定義があるので、こちらを先にlinkerが見つけたと思われる。

# 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の定義を参照する(extern)様に修正する。

# 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する(正常終了)。

正常にmakeできた。

# 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
#

 

インストールする。

インストール先は、configureコマンドで指定しないため「/usr/local」配下になります。
設定ファイルは、「/usr/local/etc/webalizer.conf」です。

# 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を実行するシェルを作成し実行する。

以下にcronに登録する参考のシェルを示します。
手動でシェルを実行し、シェルが正しく動作するか確認する。また、webalizer.confファイルの設定が正しいか確認する。

# 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に登録する。

# crontab -e
5 0 * * * /usr/local/sbin/webalizer.sh

 

webalizer.confファイルの修正

数日実行すると結果表示サイトに「Total URLs」の情報が色々表示される。
*.xmlや*.webpのファイル情報や、/wp-admin/*や/wp-content/plugins/*などの情報が表示されるが投稿URLのみ表示させたいので非表示にする必要がある。
よって、webalizer.confファイルの修正が必要になる。

# 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ファイルを修正する。
以下が設定内容です。

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ファイルを表示する設定であることが判明する。

<TD ALIGN=left NOWRAP><IMG SRC="flags/jp.png" ALT="Japan" WIDTH=18 HEIGHT=12> <FONT SIZE="-1">Japan</FONT></TD></TR>
<TR><TD ALIGN=center><FONT SIZE="-1"><B>2</B></FONT></TD>
<TD ALIGN=right><FONT SIZE="-1"><B>8579</B></FONT></TD>
<TD ALIGN=right><FONT SIZE="-2">16.64%</FONT></TD>
<TD ALIGN=right><FONT SIZE="-1"><B>4204</B></FONT></TD>
<TD ALIGN=right><FONT SIZE="-2">21.53%</FONT></TD>
<TD ALIGN=right><FONT SIZE="-1"><B>84325</B></FONT></TD>
<TD ALIGN=right><FONT SIZE="-2">24.57%</FONT></TD>
<TD ALIGN=left NOWRAP><FONT SIZE="-1">Commercial (com)</FONT></TD></TR>
<TR><TD ALIGN=center><FONT SIZE="-1"><B>3</B></FONT></TD>
<TD ALIGN=right><FONT SIZE="-1"><B>7215</B></FONT></TD>
<TD ALIGN=right><FONT SIZE="-2">14.00%</FONT></TD>
<TD ALIGN=right><FONT SIZE="-1"><B>180</B></FONT></TD>
<TD ALIGN=right><FONT SIZE="-2">0.92%</FONT></TD>
<TD ALIGN=right><FONT SIZE="-1"><B>4864</B></FONT></TD>
<TD ALIGN=right><FONT SIZE="-2">1.42%</FONT></TD>
<TD ALIGN=left NOWRAP><IMG SRC="flags/es.png" ALT="Spain" WIDTH=18 HEIGHT=12> <FONT SIZE="-1">Spain</FONT></TD></TR>
<TR><TD ALIGN=center><FONT SIZE="-1"><B>4</B></FONT></TD>
<TD ALIGN=right><FONT SIZE="-1"><B>5941</B></FONT></TD>
<TD ALIGN=right><FONT SIZE="-2">11.53%</FONT></TD>
<TD ALIGN=right><FONT SIZE="-1"><B>1175</B></FONT></TD>
<TD ALIGN=right><FONT SIZE="-2">6.02%</FONT></TD>
<TD ALIGN=right><FONT SIZE="-1"><B>22299</B></FONT></TD>
<TD ALIGN=right><FONT SIZE="-2">6.50%</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を検索すると国旗を表示する設定情報は存在するが、国旗画像をダウンロードして特定のディレクトリに置くの情報が無い。
ダウンロードした画像を指定ディレクトリに置いたら表示できたので良いかった。