amegonの雑なブログ

日常的なものから技術的なものまでメモの雑記

Miracle Linux で docker と docker-compose を使える状態にする

目的

CentOS のサポート終了に伴って、環境の移行を実施中。
docker と docker-compse を CentOS で実行している環境があり、その環境の引継ぎ用に Miracle Linux へ docker、docker-compoer 環境の作成を行ってみる。

注意事項

コマンドはいろいろと調べていたので、本記事は実行コマンドと実行ログの記録のみとしています。

docker の設定

リポジトリのインストール

コマンド

sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

実行ログ

[root@test244 ~]# sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
repo の追加: https://download.docker.com/linux/centos/docker-ce.repo
[root@test244 ~]#

リポジトリの確認

コマンド

dnf repolist

実行ログ

[root@test244 ~]# dnf repolist
repo id                                          repo の名前
8-latest-AppStream                               8-latest-AppStream
8-latest-BaseOS                                  8-latest-BaseOS
docker-ce-stable                                 Docker CE Stable - x86_64
[root@test244 ~]#

docker-ce-stable が表示されていればOKとする。

docker のインストール

実行コマンド

sudo dnf -y install docker-ce

実行ログ

[root@test244 ~]# sudo dnf -y install docker-ce
Docker CE Stable - x86_64                                                4.9 kB/s |  50 kB     00:10
8-latest-BaseOS                                                          425  B/s | 4.3 kB     00:10
8-latest-BaseOS                                                          2.2 MB/s |  44 MB     00:19
8-latest-AppStream                                                       469  B/s | 4.7 kB     00:10
8-latest-AppStream                                                       2.5 MB/s |  51 MB     00:20
依存関係が解決しました。
=========================================================================================================
 パッケージ                    Arch    バージョン                              リポジトリー        サイズ
=========================================================================================================
インストール:
 docker-ce                     x86_64  3:24.0.6-1.el8                          docker-ce-stable     24 M
依存関係のインストール:
 checkpolicy                   x86_64  2.9-1.el8                               8-latest-BaseOS     346 k
 container-selinux             noarch  2:2.205.0-2.module+el8+1646+e7d22cc1    8-latest-AppStream   63 k
 containerd.io                 x86_64  1.6.24-3.1.el8                          docker-ce-stable     34 M
 docker-ce-cli                 x86_64  1:24.0.6-1.el8                          docker-ce-stable    7.2 M
 docker-ce-rootless-extras     x86_64  24.0.6-1.el8                            docker-ce-stable    4.9 M
 fuse-common                   x86_64  3.3.0-16.el8                            8-latest-BaseOS      21 k
 fuse-overlayfs                x86_64  1.11-1.module+el8+1646+e7d22cc1         8-latest-AppStream   73 k
 fuse3                         x86_64  3.3.0-16.el8                            8-latest-BaseOS      53 k
 fuse3-libs                    x86_64  3.3.0-16.el8                            8-latest-BaseOS      94 k
 libcgroup                     x86_64  0.41-19.el8                             8-latest-BaseOS      69 k
 libslirp                      x86_64  4.4.0-1.module+el8+1646+e7d22cc1        8-latest-AppStream   69 k
 policycoreutils-python-utils  noarch  2.9-19.el8                              8-latest-BaseOS     252 k
 python3-audit                 x86_64  3.0.7-2.el8.2.ML.1                      8-latest-BaseOS      86 k
 python3-libsemanage           x86_64  2.9-8.el8.ML.1                          8-latest-BaseOS     127 k
 python3-policycoreutils       noarch  2.9-19.el8                              8-latest-BaseOS     2.2 M
 python3-setools               x86_64  4.3.0-3.el8                             8-latest-BaseOS     623 k
 slirp4netns                   x86_64  1.2.0-2.module+el8+1646+e7d22cc1        8-latest-AppStream   53 k
弱い依存関係のインストール:
 docker-buildx-plugin          x86_64  0.11.2-1.el8                            docker-ce-stable     13 M
 docker-compose-plugin         x86_64  2.21.0-1.el8                            docker-ce-stable     13 M
モジュールストリームの有効化中:
 container-tools                       rhel8

トランザクションの概要
=========================================================================================================
インストール  20 パッケージ

ダウンロードサイズの合計: 100 M
インストール後のサイズ: 378 M
パッケージのダウンロード:
(1/20): docker-buildx-plugin-0.11.2-1.el8.x86_64.rpm                     1.6 MB/s |  13 MB     00:08
(2/20): docker-ce-cli-24.0.6-1.el8.x86_64.rpm                            3.8 MB/s | 7.2 MB     00:01
(3/20): docker-ce-rootless-extras-24.0.6-1.el8.x86_64.rpm                3.1 MB/s | 4.9 MB     00:01
(4/20): containerd.io-1.6.24-3.1.el8.x86_64.rpm                          2.6 MB/s |  34 MB     00:13
(5/20): docker-ce-24.0.6-1.el8.x86_64.rpm                                1.8 MB/s |  24 MB     00:13
(6/20): docker-compose-plugin-2.21.0-1.el8.x86_64.rpm                    4.8 MB/s |  13 MB     00:02
(7/20): fuse-common-3.3.0-16.el8.x86_64.rpm                              3.7 kB/s |  21 kB     00:05
(8/20): fuse3-3.3.0-16.el8.x86_64.rpm                                     10 kB/s |  53 kB     00:05
(9/20): checkpolicy-2.9-1.el8.x86_64.rpm                                  55 kB/s | 346 kB     00:06
(10/20): fuse3-libs-3.3.0-16.el8.x86_64.rpm                              1.5 MB/s |  94 kB     00:00
(11/20): libcgroup-0.41-19.el8.x86_64.rpm                                706 kB/s |  69 kB     00:00
(12/20): policycoreutils-python-utils-2.9-19.el8.noarch.rpm              2.2 MB/s | 252 kB     00:00
(13/20): python3-audit-3.0.7-2.el8.2.ML.1.x86_64.rpm                     817 kB/s |  86 kB     00:00
(14/20): python3-libsemanage-2.9-8.el8.ML.1.x86_64.rpm                   1.8 MB/s | 127 kB     00:00
(15/20): python3-setools-4.3.0-3.el8.x86_64.rpm                          4.5 MB/s | 623 kB     00:00
(16/20): container-selinux-2.205.0-2.module+el8+1646+e7d22cc1.noarch.rpm 440 kB/s |  63 kB     00:00
(17/20): libslirp-4.4.0-1.module+el8+1646+e7d22cc1.x86_64.rpm            964 kB/s |  69 kB     00:00
(18/20): fuse-overlayfs-1.11-1.module+el8+1646+e7d22cc1.x86_64.rpm       732 kB/s |  73 kB     00:00
(19/20): slirp4netns-1.2.0-2.module+el8+1646+e7d22cc1.x86_64.rpm         981 kB/s |  53 kB     00:00
(20/20): python3-policycoreutils-2.9-19.el8.noarch.rpm                   6.2 MB/s | 2.2 MB     00:00
---------------------------------------------------------------------------------------------------------
合計                                                                     3.3 MB/s | 100 MB     00:30
Docker CE Stable - x86_64                                                317  B/s | 1.6 kB     00:05
GPG 鍵 0x621E9F35 をインポート中:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
 From       : https://download.docker.com/linux/centos/gpg
鍵のインポートに成功しました
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                                                 1/1
  インストール中   : fuse3-libs-3.3.0-16.el8.x86_64                                                 1/20
  scriptletの実行中: fuse3-libs-3.3.0-16.el8.x86_64                                                 1/20
  インストール中   : docker-compose-plugin-2.21.0-1.el8.x86_64                                      2/20
  scriptletの実行中: docker-compose-plugin-2.21.0-1.el8.x86_64                                      2/20
  インストール中   : libslirp-4.4.0-1.module+el8+1646+e7d22cc1.x86_64                               3/20
  インストール中   : slirp4netns-1.2.0-2.module+el8+1646+e7d22cc1.x86_64                            4/20
  インストール中   : python3-setools-4.3.0-3.el8.x86_64                                             5/20
  インストール中   : python3-libsemanage-2.9-8.el8.ML.1.x86_64                                      6/20
  インストール中   : python3-audit-3.0.7-2.el8.2.ML.1.x86_64                                        7/20
  scriptletの実行中: libcgroup-0.41-19.el8.x86_64                                                   8/20
  インストール中   : libcgroup-0.41-19.el8.x86_64                                                   8/20
  scriptletの実行中: libcgroup-0.41-19.el8.x86_64                                                   8/20
  インストール中   : fuse-common-3.3.0-16.el8.x86_64                                                9/20
  インストール中   : fuse3-3.3.0-16.el8.x86_64                                                     10/20
  インストール中   : fuse-overlayfs-1.11-1.module+el8+1646+e7d22cc1.x86_64                         11/20
  scriptletの実行中: fuse-overlayfs-1.11-1.module+el8+1646+e7d22cc1.x86_64                         11/20
  インストール中   : checkpolicy-2.9-1.el8.x86_64                                                  12/20
  インストール中   : python3-policycoreutils-2.9-19.el8.noarch                                     13/20
  インストール中   : policycoreutils-python-utils-2.9-19.el8.noarch                                14/20
  scriptletの実行中: container-selinux-2:2.205.0-2.module+el8+1646+e7d22cc1.noarch                 15/20
  インストール中   : container-selinux-2:2.205.0-2.module+el8+1646+e7d22cc1.noarch                 15/20
  scriptletの実行中: container-selinux-2:2.205.0-2.module+el8+1646+e7d22cc1.noarch                 15/20
  インストール中   : containerd.io-1.6.24-3.1.el8.x86_64                                           16/20
  scriptletの実行中: containerd.io-1.6.24-3.1.el8.x86_64                                           16/20
  インストール中   : docker-buildx-plugin-0.11.2-1.el8.x86_64                                      17/20
  scriptletの実行中: docker-buildx-plugin-0.11.2-1.el8.x86_64                                      17/20
  インストール中   : docker-ce-cli-1:24.0.6-1.el8.x86_64                                           18/20
  scriptletの実行中: docker-ce-cli-1:24.0.6-1.el8.x86_64                                           18/20
  インストール中   : docker-ce-rootless-extras-24.0.6-1.el8.x86_64                                 19/20
  scriptletの実行中: docker-ce-rootless-extras-24.0.6-1.el8.x86_64                                 19/20
  インストール中   : docker-ce-3:24.0.6-1.el8.x86_64                                               20/20
  scriptletの実行中: docker-ce-3:24.0.6-1.el8.x86_64                                               20/20
  scriptletの実行中: container-selinux-2:2.205.0-2.module+el8+1646+e7d22cc1.noarch                 20/20
  scriptletの実行中: docker-ce-3:24.0.6-1.el8.x86_64                                               20/20
  検証             : containerd.io-1.6.24-3.1.el8.x86_64                                            1/20
  検証             : docker-buildx-plugin-0.11.2-1.el8.x86_64                                       2/20
  検証             : docker-ce-3:24.0.6-1.el8.x86_64                                                3/20
  検証             : docker-ce-cli-1:24.0.6-1.el8.x86_64                                            4/20
  検証             : docker-ce-rootless-extras-24.0.6-1.el8.x86_64                                  5/20
  検証             : docker-compose-plugin-2.21.0-1.el8.x86_64                                      6/20
  検証             : checkpolicy-2.9-1.el8.x86_64                                                   7/20
  検証             : fuse-common-3.3.0-16.el8.x86_64                                                8/20
  検証             : fuse3-3.3.0-16.el8.x86_64                                                      9/20
  検証             : fuse3-libs-3.3.0-16.el8.x86_64                                                10/20
  検証             : libcgroup-0.41-19.el8.x86_64                                                  11/20
  検証             : policycoreutils-python-utils-2.9-19.el8.noarch                                12/20
  検証             : python3-audit-3.0.7-2.el8.2.ML.1.x86_64                                       13/20
  検証             : python3-libsemanage-2.9-8.el8.ML.1.x86_64                                     14/20
  検証             : python3-policycoreutils-2.9-19.el8.noarch                                     15/20
  検証             : python3-setools-4.3.0-3.el8.x86_64                                            16/20
  検証             : container-selinux-2:2.205.0-2.module+el8+1646+e7d22cc1.noarch                 17/20
  検証             : fuse-overlayfs-1.11-1.module+el8+1646+e7d22cc1.x86_64                         18/20
  検証             : libslirp-4.4.0-1.module+el8+1646+e7d22cc1.x86_64                              19/20
  検証             : slirp4netns-1.2.0-2.module+el8+1646+e7d22cc1.x86_64                           20/20

インストール済み:
  checkpolicy-2.9-1.el8.x86_64
  container-selinux-2:2.205.0-2.module+el8+1646+e7d22cc1.noarch
  containerd.io-1.6.24-3.1.el8.x86_64
  docker-buildx-plugin-0.11.2-1.el8.x86_64
  docker-ce-3:24.0.6-1.el8.x86_64
  docker-ce-cli-1:24.0.6-1.el8.x86_64
  docker-ce-rootless-extras-24.0.6-1.el8.x86_64
  docker-compose-plugin-2.21.0-1.el8.x86_64
  fuse-common-3.3.0-16.el8.x86_64
  fuse-overlayfs-1.11-1.module+el8+1646+e7d22cc1.x86_64
  fuse3-3.3.0-16.el8.x86_64
  fuse3-libs-3.3.0-16.el8.x86_64
  libcgroup-0.41-19.el8.x86_64
  libslirp-4.4.0-1.module+el8+1646+e7d22cc1.x86_64
  policycoreutils-python-utils-2.9-19.el8.noarch
  python3-audit-3.0.7-2.el8.2.ML.1.x86_64
  python3-libsemanage-2.9-8.el8.ML.1.x86_64
  python3-policycoreutils-2.9-19.el8.noarch
  python3-setools-4.3.0-3.el8.x86_64
  slirp4netns-1.2.0-2.module+el8+1646+e7d22cc1.x86_64

完了しました!
[root@test244 ~]#

docker バージョン確認

実行コマンド

docker -v

実行ログ

[root@test244 ~]# docker -v
Docker version 24.0.6, build ed223bc
[root@test244 ~]#

docker の起動と自動起動設定

実行コマンド

systemctl status docker
sudo systemctl enable docker
sudo systemctl start docker
systemctl status docker

実行ログ

[root@test244 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: https://docs.docker.com
[root@test244 ~]#
[root@test244 ~]# sudo systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[root@test244 ~]#
[root@test244 ~]# sudo systemctl start docker
[root@test244 ~]#
[root@test244 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2023-10-02 20:25:39 EDT; 8s ago
     Docs: https://docs.docker.com
 Main PID: 3866 (dockerd)
    Tasks: 10
   Memory: 53.5M
   CGroup: /system.slice/docker.service
           mq3866 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

10月 02 20:25:37 test244 systemd[1]: Starting Docker Application Container Engine...
10月 02 20:25:37 test244 dockerd[3866]: time="2023-10-02T20:25:37.201841779-04:00" level=info msg="Start>
10月 02 20:25:37 test244 dockerd[3866]: time="2023-10-02T20:25:37.303017012-04:00" level=info msg="Loadi>
10月 02 20:25:38 test244 dockerd[3866]: time="2023-10-02T20:25:38.904783892-04:00" level=info msg="Firew>
10月 02 20:25:39 test244 dockerd[3866]: time="2023-10-02T20:25:39.108602561-04:00" level=info msg="Loadi>
10月 02 20:25:39 test244 dockerd[3866]: time="2023-10-02T20:25:39.206540486-04:00" level=info msg="Docke>
10月 02 20:25:39 test244 dockerd[3866]: time="2023-10-02T20:25:39.207181187-04:00" level=info msg="Daemo>
10月 02 20:25:39 test244 dockerd[3866]: time="2023-10-02T20:25:39.281732859-04:00" level=info msg="API l>
10月 02 20:25:39 test244 systemd[1]: Started Docker Application Container Engine.
[root@test244 ~]#

docker をユーザーで実行する場合

以下の設定を実施する。(今回は不要とした。)

sudo usermod -aG docker $USER
sudo systemctl restart docker

docker-compose の設定

最新版のインストール

インストール

実行コマンド

curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url | grep docker-compose-linux-x86_64 | cut -d '"' -f 4 | wget -qi -

実行ログ

[root@test244 ~]#
[root@test244 ~]# curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url | grep docker-compose-linux-x86_64 | cut -d '"' -f 4 | wget -qi -
[root@test244 ~]#

権限設定

実行コマンド

sudo chmod +x docker-compose-linux-x86_64

実行ログ

[root@test244 ~]#
[root@test244 ~]# sudo chmod +x docker-compose-linux-x86_64
[root@test244 ~]#

実行モジュールの移動

実行コマンド

sudo mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose

実行ログ

[root@test244 ~]#
[root@test244 ~]# sudo mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose
[root@test244 ~]#

バージョンを指定してインストール:今回は実行しておらず未検証

インストール

実行コマンド

sudo wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/v2.0.1/docker-compose-Linux-x86_64

この場合は /usr/local/bin/docker-compose を指定してダウンロード先を指定している。

権限の変更

実行コマンド

sudo chmod +x /usr/local/bin/docker-compose

docker-compose のインストールバージョンの確認

実行コマンド

docker-compose version

実行ログ

[root@test244 ~]# docker-compose version
Docker Compose version v2.22.0
[root@test244 ~]#

docker-compose でよく使用するコマンド

目的

すぐにコマンドがわからなくなるので、よく使うやつを自分用にまとめておきます。
一部 docker コマンドも記載しています。

公式

基本はここで確認しましょう。

https://docs.docker.jp/index.html

コンテナの起動

サービス用のコンテナを構築、作成、起動、アタッチする
docker-compose.yml と同ディレクトリ内で以下のコマンドを実行

docker-compose up

バックグラウンド実行する場合は -d オプションをつけて実行

docker-compose up -d

コンテナを選択して実行する場合は最後にサービス名をつけて実行

docker-compose up -d <コンテナ名>

実行例

NAME      IMAGE     COMMAND   SERVICE   CREATED   STATUS    PORTS
[root@test244 redmine]#
[root@test244 redmine]# docker-compose up -d
[+] Building 0.0s (0/0)                                              docker:default
[+] Running 2/2
 ? Container redmine-db-4.0.4  Started                                         0.1s
 ? Container redmine-4.0.4     Started                                         0.1s
[root@test244 redmine]#
[root@test244 redmine]# docker-compose ps -a
NAME               IMAGE                  COMMAND                                                                                        SERVICE            CREATED         STATUS         PORTS
redmine-4.0.4      redmine:4.0.4-alpine   "/docker-entrypoint.sh rails server -b 0.0.0.0"                                                redmine            4 seconds ago   Up 3 seconds   0.0.0.0:8080->3000/tcp, :::8080->3000/tcp
redmine-db-4.0.4   mariadb:10.8.2         "docker-entrypoint.sh mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci"   redmine-db-4.0.4   4 seconds ago   Up 3 seconds   3306/tcp
[root@test244 redmine]#

コンテナを削除せずに停止

docker-compose.yml と同ディレクトリ内で以下のコマンドを実行

docker-compose stop

コンテナを選択して実行する場合は最後にサービス名をつけて実行

docker-compose stop <コンテナ名>

実行例

[root@test244 redmine]# docker-compose ps
NAME               IMAGE                  COMMAND                                                                                        SERVICE            CREATED          STATUS          PORTS
redmine-4.0.4      redmine:4.0.4-alpine   "/docker-entrypoint.sh rails server -b 0.0.0.0"                                                redmine            25 seconds ago   Up 23 seconds   0.0.0.0:8080->3000/tcp, :::8080->3000/tcp
redmine-db-4.0.4   mariadb:10.8.2         "docker-entrypoint.sh mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci"   redmine-db-4.0.4   25 seconds ago   Up 23 seconds   3306/tcp
[root@test244 redmine]#
[root@test244 redmine]# docker-compose stop
[+] Stopping 2/2
 ? Container redmine-db-4.0.4  Stopped                                         0.9s
 ? Container redmine-4.0.4     Stopped                                         0.7s
[root@test244 redmine]#
[root@test244 redmine]# docker-compose ps
NAME      IMAGE     COMMAND   SERVICE   CREATED   STATUS    PORTS
[root@test244 redmine]#
[root@test244 redmine]# docker-compose ps -a
NAME               IMAGE                  COMMAND                                                                                        SERVICE            CREATED          STATUS                     PORTS
redmine-4.0.4      redmine:4.0.4-alpine   "/docker-entrypoint.sh rails server -b 0.0.0.0"                                                redmine            47 seconds ago   Exited (1) 8 seconds ago
redmine-db-4.0.4   mariadb:10.8.2         "docker-entrypoint.sh mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci"   redmine-db-4.0.4   47 seconds ago   Exited (0) 8 seconds ago
[root@test244 redmine]#

コンテナ停止 & コンテナ、ネットワーク、ボリューム、イメージを削除

docker-compose down

コンテナを選択して実行する場合は最後にサービス名をつけて実行

docker-compose down <コンテナ名>

実行例

[root@test244 redmine]# docker-compose ps
NAME               IMAGE                  COMMAND                                                                                        SERVICE            CREATED              STATUS          PORTS
redmine-4.0.4      redmine:4.0.4-alpine   "/docker-entrypoint.sh rails server -b 0.0.0.0"                                                redmine            About a minute ago   Up 9 seconds    0.0.0.0:8080->3000/tcp, :::8080->3000/tcp
redmine-db-4.0.4   mariadb:10.8.2         "docker-entrypoint.sh mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci"   redmine-db-4.0.4   About a minute ago   Up 10 seconds   3306/tcp
[root@test244 redmine]#
[root@test244 redmine]# docker-compose down
[+] Running 3/3
 ? Container redmine-db-4.0.4  Removed                                         0.5s
 ? Container redmine-4.0.4     Removed                                         0.4s
 ? Network redmine_default     Removed                                         0.3s
[root@test244 redmine]#
[root@test244 redmine]# docker-compose ps
NAME      IMAGE     COMMAND   SERVICE   CREATED   STATUS    PORTS
[root@test244 redmine]#
[root@test244 redmine]# docker-compose ps -a
NAME      IMAGE     COMMAND   SERVICE   CREATED   STATUS    PORTS
[root@test244 redmine]#

コンテナを強制終了

強制終了するのみでコンテナの削除は実施されない。

docker-compose kill

実行例

[root@test244 redmine]# docker-compose ps
NAME               IMAGE                  COMMAND                                                                                        SERVICE            CREATED         STATUS         PORTS
redmine-4.0.4      redmine:4.0.4-alpine   "/docker-entrypoint.sh rails server -b 0.0.0.0"                                                redmine            4 seconds ago   Up 2 seconds   0.0.0.0:8080->3000/tcp, :::8080->3000/tcp
redmine-db-4.0.4   mariadb:10.8.2         "docker-entrypoint.sh mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci"   redmine-db-4.0.4   4 seconds ago   Up 2 seconds   3306/tcp
[root@test244 redmine]#
[root@test244 redmine]# docker-compose kill
[+] Killing 2/2
 ? Container redmine-db-4.0.4  Killed                                          0.3s
 ? Container redmine-4.0.4     Killed                                          0.4s
[root@test244 redmine]#
[root@test244 redmine]# docker-compose ps
NAME      IMAGE     COMMAND   SERVICE   CREATED   STATUS    PORTS
[root@test244 redmine]#
[root@test244 redmine]# docker-compose ps -a
NAME               IMAGE                  COMMAND                                                                                        SERVICE            CREATED          STATUS                       PORTS
redmine-4.0.4      redmine:4.0.4-alpine   "/docker-entrypoint.sh rails server -b 0.0.0.0"                                                redmine            16 seconds ago   Exited (137) 4 seconds ago
redmine-db-4.0.4   mariadb:10.8.2         "docker-entrypoint.sh mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci"   redmine-db-4.0.4   16 seconds ago   Exited (137) 4 seconds ago
[root@test244 redmine]#

コンテナの再起動

docker-compose restart

実行例

[root@test244 redmine]# docker-compose ps
NAME               IMAGE                  COMMAND                                                                                        SERVICE            CREATED              STATUS          PORTS
redmine-4.0.4      redmine:4.0.4-alpine   "/docker-entrypoint.sh rails server -b 0.0.0.0"                                                redmine            About a minute ago   Up 32 seconds   0.0.0.0:8080->3000/tcp, :::8080->3000/tcp
redmine-db-4.0.4   mariadb:10.8.2         "docker-entrypoint.sh mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci"   redmine-db-4.0.4   About a minute ago   Up 32 seconds   3306/tcp
[root@test244 redmine]#
[root@test244 redmine]# docker-compose restart
[+] Restarting 2/2
 ? Container redmine-db-4.0.4  Started                                         1.1s
 ? Container redmine-4.0.4     Started                                         1.1s
[root@test244 redmine]#
[root@test244 redmine]#
[root@test244 redmine]# docker-compose ps
NAME               IMAGE                  COMMAND                                                                                        SERVICE            CREATED              STATUS         PORTS
redmine-4.0.4      redmine:4.0.4-alpine   "/docker-entrypoint.sh rails server -b 0.0.0.0"                                                redmine            About a minute ago   Up 3 seconds   0.0.0.0:8080->3000/tcp, :::8080->3000/tcp
redmine-db-4.0.4   mariadb:10.8.2         "docker-entrypoint.sh mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci"   redmine-db-4.0.4   About a minute ago   Up 3 seconds   3306/tcp
[root@test244 redmine]#

停止中のコンテナを削除

docker-compose rm

コンテナを選択して削除する場合にはコマンドの最後に名前をつけて実行

docker-compose rm <コンテナ名>

実行例

[root@test244 redmine]# docker-compose ps -a
NAME               IMAGE                  COMMAND                                                                                        SERVICE            CREATED         STATUS                      PORTS
redmine-4.0.4      redmine:4.0.4-alpine   "/docker-entrypoint.sh rails server -b 0.0.0.0"                                                redmine            2 minutes ago   Exited (1) 12 seconds ago
redmine-db-4.0.4   mariadb:10.8.2         "docker-entrypoint.sh mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci"   redmine-db-4.0.4   2 minutes ago   Exited (0) 12 seconds ago
[root@test244 redmine]#
[root@test244 redmine]# docker-compose rm
? Going to remove redmine-4.0.4, redmine-db-4.0.4 Yes
[+] Removing 2/0
 ? Container redmine-db-4.0.4  Removed                                         0.0s
 ? Container redmine-4.0.4     Removed                                         0.1s
[root@test244 redmine]#
[root@test244 redmine]# docker-compose ps -a
NAME      IMAGE     COMMAND   SERVICE   CREATED   STATUS    PORTS
[root@test244 redmine]#

コンテナの一覧とステータスを表示

docker-compose、docker コマンドでそれぞれ ps オプションをつけて実行するが、表示内容に差異があるので確認したい内容によって使い分ける。

コンテナ名、サービス名を確認したい場合

docker-compose ps

以下のように表示される。

[root@test244 redmine]# docker-compose ps -a
NAME               IMAGE                  COMMAND                                                                                        SERVICE            CREATED         STATUS         PORTS
redmine-4.0.4      redmine:4.0.4-alpine   "/docker-entrypoint.sh rails server -b 0.0.0.0"                                                redmine            8 minutes ago   Up 8 minutes   0.0.0.0:8080->3000/tcp, :::8080->3000/tcp
redmine-db-4.0.4   mariadb:10.8.2         "docker-entrypoint.sh mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci"   redmine-db-4.0.4   8 minutes ago   Up 8 minutes   3306/tcp
[root@test244 redmine]#

コンテナ ID、コンテナ名を確認したい場合

docker ps -a
[root@test244 redmine]# docker ps -a
CONTAINER ID   IMAGE                  COMMAND                   CREATED          STATUS          PORTS                                       NAMES
be9b709829a6   mariadb:10.8.2         "docker-entrypoint.s…"   10 minutes ago   Up 10 minutes   3306/tcp                                    redmine-db-4.0.4
1e621f8f6f16   redmine:4.0.4-alpine   "/docker-entrypoint.…"   10 minutes ago   Up 10 minutes   0.0.0.0:8080->3000/tcp, :::8080->3000/tcp   redmine-4.0.4
[root@test244 redmine]#

ログをみる

docker-compose logs

foreground で表示し続ける場合は以下。

docker-compose logs -f

表示の終了は Ctrl + c で。

実行例

[root@test244 redmine]# docker-compose logs -f
redmine-db-4.0.4  | 2023-10-10 08:06:14+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.8.2+maria~focal started.
redmine-db-4.0.4  | 2023-10-10 08:06:14+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
redmine-db-4.0.4  | 2023-10-10 08:06:14+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.8.2+maria~focal started.
redmine-db-4.0.4  | 2023-10-10 08:06:14+00:00 [Note] [Entrypoint]: MariaDB upgrade not required
redmine-db-4.0.4  | 2023-10-10  8:06:14 0 [Note] mysqld (server 10.8.2-MariaDB-1:10.8.2+maria~focal) starting as process 1 ...
redmine-db-4.0.4  | 2023-10-10  8:06:14 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
redmine-db-4.0.4  | 2023-10-10  8:06:14 0 [Note] InnoDB: Number of transaction pools: 1
redmine-db-4.0.4  | 2023-10-10  8:06:14 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
redmine-db-4.0.4  | 2023-10-10  8:06:14 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
redmine-db-4.0.4  | 2023-10-10  8:06:14 0 [Note] InnoDB: Using Linux native AIO
redmine-db-4.0.4  | 2023-10-10  8:06:14 0 [Note] InnoDB: Initializing buffer pool, total size = 128.000MiB, chunk size = 2.000MiB
redmine-db-4.0.4  | 2023-10-10  8:06:14 0 [Note] InnoDB: Completed initialization of buffer pool
redmine-db-4.0.4  | 2023-10-10  8:06:14 0 [Note] InnoDB: Buffered log writes (block size=4096 bytes)
redmine-db-4.0.4  | 2023-10-10  8:06:15 0 [Note] InnoDB: 128 rollback segments are active.
redmine-db-4.0.4  | 2023-10-10  8:06:15 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ...
redmine-db-4.0.4  | 2023-10-10  8:06:15 0 [Note] InnoDB: File './ibtmp1' size is now 12.000MiB.
redmine-db-4.0.4  | 2023-10-10  8:06:15 0 [Note] InnoDB: log sequence number 1330483; transaction id 3066
redmine-db-4.0.4  | 2023-10-10  8:06:15 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
redmine-db-4.0.4  | 2023-10-10  8:06:15 0 [Note] Plugin 'FEEDBACK' is disabled.
redmine-db-4.0.4  | 2023-10-10  8:06:15 0 [Warning] You need to use --log-bin to make --expire-logs-days or --binlog-expire-logs-seconds work.
redmine-db-4.0.4  | 2023-10-10  8:06:15 0 [Note] Server socket created on IP: '0.0.0.0'.
redmine-db-4.0.4  | 2023-10-10  8:06:15 0 [Note] Server socket created on IP: '::'.
redmine-db-4.0.4  | 2023-10-10  8:06:15 0 [Note] mysqld: ready for connections.
redmine-db-4.0.4  | Version: '10.8.2-MariaDB-1:10.8.2+maria~focal'  socket: '/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
redmine-db-4.0.4  | 2023-10-10  8:06:15 0 [Note] InnoDB: Buffer pool(s) load completed at 231003  8:06:15
redmine-4.0.4     | The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x64-mingw32, x86-mswin32. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x64-mingw32 x86-mswin32`.
redmine-4.0.4     | The Gemfile's dependencies are satisfied
redmine-4.0.4     | => Booting WEBrick
redmine-4.0.4     | => Rails 5.2.3 application starting in production on http://0.0.0.0:3000
redmine-4.0.4     | => Run `rails server -h` for more startup options
redmine-4.0.4     | W, [2023-10-10T08:06:25.683238 #1]  WARN -- : Creating scope :system. Overwriting existing method Enumeration.system.
redmine-4.0.4     | [2023-10-10 08:06:26] INFO  WEBrick 1.4.2
redmine-4.0.4     | [2023-10-10 08:06:26] INFO  ruby 2.6.5 (2019-10-01) [x86_64-linux-musl]
redmine-4.0.4     | [2023-10-10 08:06:26] INFO  WEBrick::HTTPServer#start: pid=1 port=3000
^Ccanceled
[root@test244 redmine]#

サービス内でコマンドを実行

docker-compose exec <サービス名> <コマンド>

実行例

[root@test244 redmine]# docker-compose exec redmine bash
bash-5.0#
bash-5.0# free -h
              total        used        free      shared  buff/cache   available
Mem:          740Mi       428Mi        51Mi       1.0Mi       259Mi       192Mi
Swap:         1.0Gi        85Mi       938Mi
bash-5.0#
bash-5.0# exit
exit
[root@test244 redmine]#

コンテナのプロセス情報を表示

docker-compose top

実行例

[root@test244 redmine]# docker-compose top
redmine-4.0.4
UID        PID    PPID   C    STIME   TTY   TIME       CMD
systemd+   2719   2698   0    04:06   ?     00:00:04   /usr/local/bin/ruby bin/rails server -b 0.0.0.0

redmine-db-4.0.4
UID        PID    PPID   C    STIME   TTY   TIME       CMD
systemd+   2684   2648   0    04:06   ?     00:00:00   mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci

[root@test244 redmine]#

バージョンを表示

docker-compose version

実行例

[root@test244 redmine]# docker-compose version
Docker Compose version v2.22.0
[root@test244 redmine]#

Amazon Linux を Hyper-V で動かしてみる(オンプレ実行)

目的

仕事で Amazon Linux をさわりそう。
オンプレ版があるとの情報を得たので、自習のために自宅環境に設定してみる。

一般的な Linux とのインストール方法の違い

  • 一般的な Linux のインストール
  • Amazon Linux のインストール(というより設定)
    • Amazon から vhd をダウンロード
    • あわせて OS 用の情報ファイル meta-data、user-data を作成し iso を作成
    • 仮想環境で前項で取得した vhd を読み込み設定
    • iso を使用して起動を実施
    • iso に設定された設定で Amazon OS が起動する(一般的な OS インストールは存在しない)

準備した環境

  • 仮想環境:
  • iso 作成環境:
    • Miracle Linux 8.6
      • 前項 一般的な Linux とのインストール方法の違い で記載した iso の作成に使用
      • OS は Hyper-V 上の仮想マシンで動いている

事前準備

Amazon Linux vhd のダウンロード

Amazon Linuxvhd (Hyper-V 用) は以下からダウンロード。

ダウンロードしたら Hyper-V 実行環境に移動して展開しておく。
展開したファイルの保存場所は任意。

meta-data、user-data を取り込んだ iso の作成

以下の手順で作成

Miracle Linux 8.6 にログイン
・iso 作成ツールである genisoimage をインストール

yum install -y genisoimage

・vi コマンドで meta-data ファイルを作成(内容は下記)

local-hostname: test245
# eth0 is the default network interface enabled in the image. You can configure static network settings with an entry like the following.
network-interfaces: |
  auto eth0
  iface eth0 inet static
  address 192.168.3.245
  network 192.168.3.0
  netmask 255.255.255.0
  broadcast 192.168.3.255
  gateway 192.168.3.254

・ここではホスト名を test245、IP アドレスを 192.168.3.245 の固定設定で作成
・vi コマンドで user-data を作成 (内容は下記)

#cloud-config
#vim:syntax=yaml
users:
# A user by the name `ec2-user` is created in the image by default.
  - default
chpasswd:
  list: |
    ec2-user:password
# In the above line, do not add any spaces after 'ec2-user:'.

※ 上記 password と記載されている箇所にパスワードで使用する文字列を設定する

・iso を seed.iso という名前で作成

genisoimage -output seed.iso -volid cidata -joliet -rock user-data meta-data

・seed.iso をscp 等を用いて仮想マシンを実行する環境に移動する

注意事項:meta-data のパラメータの記載は空行を入れてはいけないみたい

以下のような meta-data を作成して seed.iso を作成したところ、Amazon Linux 起動時にネットワーク設定が反映されなかった。

local-hostname: test245

# local-hostnameに仮想マシンのホスト名を記載する。
# eth0 is the default network interface enabled in the image. You can configure static network settings with an entry like the following.
network-interfaces: |
  auto eth0

# eth0の設定をする。
# eth0をstaticで設定する。
  iface eth0 inet static

# eth0のIPアドレスを設定する。
  address 192.168.3.245

#仮想マシンが所属するネットワークアドレスを設定する。
  network 192.168.3.0

#仮想マシンが所属するサブネットを設定する。
  netmask 255.255.255.0

#仮想マシンが所属するネットワークのブロードキャストを設定する。

  broadcast 192.168.3.255

#仮想マシンが所属するネットワークのデフォルトゲートウェイを設定する。
  gateway 192.168.3.254

network-interfaces の設定にコメントをつけた際に空行をがんがんいれていたのがダメだったのかも。
コメントと空行をなくしたところうまくいったので、そうだと思っておく。
(上記うまく使えなかった情報はうまくいかなかった記録として残しておきます。)

Hyper-VAmazon Linux 使用設定

  • Hyper-V で新規 → 仮想マシンを選択
    • 次へ を選択
    • 名前を入れて次へ
    • 第1世代を選択して次へ
    • 起動メモリを設定して次へ
    • 今回の環境は空きメモリがそんなになかったので 2GB 固定にしました。
    • 使用するネットワークを設定して次へ
    • 既存の仮想ハードディスクを使用する を選択して Amazon からダウンロードしてきた vhd を選択する。
    • 内容を確認して 完了 を押す。

この時点ではまだ仮想マシンを起動してはいけない。
以下の設定を続けて実施。

  • Hyper-V で作成した仮想マシンを選択して設定を選択
  • プロセッサを選択して仮想プロセッサの数を変更する
    • 今回の環境では 2 にしてみた
  • DVD ドライブで メディア - イメージファイル を選択して、先般作成した seed.iso を選択する
  • OK を押して閉じる

これで仮想マシンの起動環境は完了。

仮想マシン起動

Hyper-V仮想マシンを起動する。

ログイン確認

Hyper-V接続 を使用して Amazon Linux にログインする。
(この時点ではパスワードを用いた SSH 接続が有効になっていないので、コンソールログインする。)

SSH の有効化

Amazon Linux にログイン後以下の設定変更で SSH でのパスワード認証を有効化する。

  • /etc/ssh/sshd_config を vi で開く
    • sudo vi /etc/ssh/sshd_config
  • 以下のパラメータを修正して保存
    • 修正前: PasswordAuthentication no
    • 修正後: PasswordAuthentication yes
  • sshd の再起動
    • sudo systemctl restart sshd

上記設定変更後は外部から ssh でログインすることができる。

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
[ec2-user@test245 ~]$
[ec2-user@test245 ~]$
[ec2-user@test245 ~]$
[ec2-user@test245 ~]$ free -h
              total        used        free      shared  buff/cache   available
Mem:           1.9G        113M        1.7G        424K        105M        1.6G
Swap:            0B          0B          0B
[ec2-user@test245 ~]$
[ec2-user@test245 ~]$
[ec2-user@test245 ~]$ df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        948M     0  948M   0% /dev
tmpfs           965M     0  965M   0% /dev/shm
tmpfs           965M  420K  964M   1% /run
tmpfs           965M     0  965M   0% /sys/fs/cgroup
/dev/sda1        25G  1.2G   24G   5% /
tmpfs           193M     0  193M   0% /run/user/1000
[ec2-user@test245 ~]$

ログインしてメモリとディスクの情報を表示してみたところ。
OKそう。

温湿度情報をZabbixで監視

目的

Raspberry Pi に装着した温湿度センサーで情報を取得できるようになったので Zabbix で監視してみる。

方法

過去の記事で書いたが、Raspberry Pi では現在 Zabbix Proxy と Zabbix Agent が動作している。
想定としては以下の流れで温湿度データを監視するようにしたい。

  • Raspberry Pi で温湿度情報を取得
  • 取得した情報を Zabbix Sender で Raspberry Pi 自身の Zabbix Proxy に送信
  • 温湿度情報が Zabbix サーバーに送信され監視される

温湿度情報を監視するために Zabbix にそれぞれの監視アイテムを作成する必要がある。
監視アイテムはホストに作成する必要があるが、今回は Raspberry Pi のエージェント監視を行っているホストに温湿度用の監視アイテムを作成してみる。

設定

Raspberry Pi

ZabbixSender 0.2.7 のインストール

温度センサーの情報は Pythonスクリプトで取得していることから、Zabbix にデータを送信する部分も Python で実施したい。
そこでぐぐって見つけたのが以下の ZabbixSender 0.2.7 である。

https://pypi.org/project/ZabbixSender/

pip を使ってインストールして利用できる状態にしてみる。

コマンド

pip install ZabbixSender

ログ

amegon@raspberrypi:~ $ pip install ZabbixSender
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting ZabbixSender
  Downloading https://www.piwheels.org/simple/zabbixsender/ZabbixSender-0.2.7-py3-none-any.whl (5.2 kB)
Installing collected packages: ZabbixSender
Successfully installed ZabbixSender-0.2.7
amegon@raspberrypi:~ $

インストールの確認

amegon@raspberrypi:~ $ pip list |grep ZabbixSender
ZabbixSender      0.2.7
amegon@raspberrypi:~ $

無事にインストールできた。

Python スクリプトの修正

次に、監視データを Zabbix Sender で送信する部分をスクリプトに実装する。
前回作成したコードに追加する。以下のような感じ。

コード

import Adafruit_DHT as DHT
import time
from ZabbixSender import ZabbixSender, ZabbixPacket

# センサーの定義
SENSOR_TYPE = DHT.DHT22
# GPIO 番号の定義
DHT_GPIO = 4

# 温湿度の取得
exec_time = int(time.time())
hum,temp = DHT.read_retry(SENSOR_TYPE, DHT_GPIO)

# データは小数点第2位を四捨五入して第1位まで表示。
print('Temp={0:0.1f}*C  Humidity={1:0.1f}%'.format(temp, hum))
temp = '{0:0.1f}'.format(temp)
hum = '{0:0.1f}'.format(hum)
print(temp)
print(hum)

# Zabbix Sender で送信
# 送信先 Zabbix Server or Zabix Proxy の IP アドレス
ZBX_SVR = '127.0.0.1'
# 送信先 Zabbix Server or Zabix Proxy の ポート番号(デフォルト 10051)
ZBX_SVR_PORT = 10051
# 監視データのアイテムを持つ Zabbix 上のホスト名
ZBX_HOST_NAME = 'RasPi_01'
# 監視データ用アイテムのキー文字列:温度
ZBX_ITEM_KEY_TEMP = 'raspberrypi.temperature'
# 監視データ用アイテムのキー文字列:湿度
ZBX_ITEM_KEY_HUM = 'raspberrypi.hummidity'

# ZabbixSender オブジェクトと packet オブジェクトを作成
server = ZabbixSender(ZBX_SVR, ZBX_SVR_PORT)
packet = ZabbixPacket()

# packet オブジェクトに送信するデータの組みあわせをセット
packet.add(ZBX_HOST_NAME, ZBX_ITEM_KEY_TEMP, temp, exec_time)
packet.add(ZBX_HOST_NAME, ZBX_ITEM_KEY_HUM, hum, exec_time)

# データを送信
server.send(packet)

# 送信したデータを表示
print(server.status)

実行したらエラー。

amegon@raspberrypi:~/work/scripts/sensor/samples $ python3 test5.py
Temp=28.8*C  Humidity=60.9%
28.8
60.9
Traceback (most recent call last):
  File "/home/amegon/work/scripts/sensor/samples/test5.py", line 42, in <module>
    server.send(packet)
  File "/home/amegon/.local/lib/python3.9/site-packages/ZabbixSender/ZabbixSender.py", line 36, in send
    status = re_status.search(status).groups()[0]
AttributeError: 'NoneType' object has no attribute 'groups'
amegon@raspberrypi:~/work/scripts/sensor/samples $

zabbix_proxy.log にも以下のログが書かれていることを発見。

Message from 127.0.0.1 is missing header. Message ignored.

ググってみると Zabbix サーバーと Zabbix エージェントのバージョンが不一致の場合に missing header のログが記録されるらしい。
ということは python ライブラリの方で Header に設定情報が足りていないのかな?と思い申すコスググる

そうしましたら以下の記事を発見。

https://www.happylifecreators.com/blog/20220323/

す、すごい。。。
コード ZabbixSender.py の保存場所を find で探して以下のように修正。
自分の環境では上記URLの修正のままだと動作しなかったので、struct の import 部分と pack の仕様部部分を書き換えています。

import json
import re
import socket
import time
from struct import *

class ZabbixSender:
    def __init__(self, server='127.0.0.1', port='10051', config=None):
        if config is not None:
            conf_file = open(config, 'r')
            re_server = re.compile('\\nServer=(\S*)\\n\\n')
            temp_server = re_server.search(conf_file.read())
            conf_file.close()
            self.server = temp_server.groups()[0]
        else:
            self.server = server
        self.port = port
        self.status = ''

    def __str__(self):
        return json.dumps({'server': self.server,
                           'port': self.port},
                          indent=4)

    def send(self, packet):
        packet = str(packet).encode('utf-8')
        s = socket.socket()
        try:
            s.connect((self.server, int(self.port)))
        except Exception as e:  # TODO: Horrible! Rewrite immediately.
            print(e)

        # Add Header (2023-09-07)
        header = pack(b'<4sBQ', b'ZBXD', 1, len(packet))
        packet = header + packet

        s.send(packet)
        time.sleep(0.5)
        status = s.recv(1024).decode('utf-8')
        re_status = re.compile('(\{.*\})')
        status = re_status.search(status).groups()[0]
        self.status = json.loads(status)
        s.close()

ログ

amegon@raspberrypi:~/work/scripts/sensor/samples $ python3 test5.py
Temp=24.2*C  Humidity=58.1%
24.2
58.1
{'response': 'success', 'info': 'processed: 2; failed: 0; total: 2; seconds spent: 0.000316'}
amegon@raspberrypi:~/work/scripts/sensor/samples $

動きました。

Zabbix 側

以下のようなアイテムを作成。
キーは先述のスクリプトに設定した文字列をあわせる。

温度

湿度

動作確認

データの受信も確認できた。

運用設定

作成したスクリプトの名前を変更して、cron で定期実行するようにして Zabbix での監視を行う。

cron の設定内容

# every 1 minute
* * * * * python3 /home/amegon/work/scripts/sensor/sendSensorData.py

Zabbix でも1分ごとにデータが受信できていることが確認できた。

Raspberry Pi に温度センサーの装着

目的

Raspberry Pi で温度、湿度のデータを取得したい。
データが取得できたら、そのデータを Zabbix に送信して監視しようと思っています。

温度センサーの購入

Amazon で DHT22 ってやつを買いました。

どちらかというと、センサーを先に買ってしまって、それが DHT22 だった、という流れです。。。
以下、調べながら記録していきます。

Raspberry Pi にセンサー DHT22 の装着

DHT22上の表示 Pin番号
GND 9番(6番はすでにファンで使っていた)
VCC 2番
DAT 7番(GPIO=4)

センサー情報の取得

センサー情報取得用ライブラリの設定

先人の知恵に感謝。
以下のライブラリを使用させていただく。

https://github.com/freedom27/MyPyDHT

作業用のフォルダを作成して以下のコマンドを順に実行。

sudo git clone --recursive https://github.com/freedom27/MyPyDHT
cd MyPyDHT
sudo python3 setup.py install

ログ

amegon@raspberrypi:~/work/library/sensor $ sudo git clone --recursive https://github.com/freedom27/MyPyDHT
Cloning into 'MyPyDHT'...
remote: Enumerating objects: 27, done.
remote: Total 27 (delta 0), reused 0 (delta 0), pack-reused 27
Receiving objects: 100% (27/27), 5.44 KiB | 1.81 MiB/s, done.
Resolving deltas: 100% (8/8), done.
Submodule 'source/MyDHT_RPi_Driver' (https://github.com/freedom27/MyDHT_RPi_Driver) registered for path 'source/MyDHT_RPi_Driver'
Cloning into '/home/amegon/work/library/sensor/MyPyDHT/source/MyDHT_RPi_Driver'...
remote: Enumerating objects: 48, done.
remote: Total 48 (delta 0), reused 0 (delta 0), pack-reused 48
Receiving objects: 100% (48/48), 9.03 KiB | 4.51 MiB/s, done.
Resolving deltas: 100% (19/19), done.
Submodule path 'source/MyDHT_RPi_Driver': checked out '650da4b507a43ae87cebc2d03cb2a03161012a55'
Submodule 'MyGPIO' (https://github.com/freedom27/MyGPIO) registered for path 'source/MyDHT_RPi_Driver/MyGPIO'
Cloning into '/home/amegon/work/library/sensor/MyPyDHT/source/MyDHT_RPi_Driver/MyGPIO'...
remote: Enumerating objects: 33, done.
remote: Total 33 (delta 0), reused 0 (delta 0), pack-reused 33
Receiving objects: 100% (33/33), 6.28 KiB | 3.14 MiB/s, done.
Resolving deltas: 100% (13/13), done.
Submodule path 'source/MyDHT_RPi_Driver/MyGPIO': checked out '3d6e6fdd7063298c22b4f16b7ffb04f1a6d032ab'
amegon@raspberrypi:~/work/library/sensor $
amegon@raspberrypi:~/work/library/sensor $
amegon@raspberrypi:~/work/library/sensor $
amegon@raspberrypi:~/work/library/sensor $ cd MyPyDHT
amegon@raspberrypi:~/work/library/sensor/MyPyDHT $
amegon@raspberrypi:~/work/library/sensor/MyPyDHT $ sudo python3 setup.py install
running install
running build
running build_py
creating build
creating build/lib.linux-aarch64-3.9
creating build/lib.linux-aarch64-3.9/MyPyDHT
copying MyPyDHT/__init__.py -> build/lib.linux-aarch64-3.9/MyPyDHT
running build_ext
building 'MyPyDHT.dht_driver' extension
creating build/temp.linux-aarch64-3.9
creating build/temp.linux-aarch64-3.9/source
creating build/temp.linux-aarch64-3.9/source/MyDHT_RPi_Driver
creating build/temp.linux-aarch64-3.9/source/MyDHT_RPi_Driver/MyGPIO
arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.9 -c source/MyDHT_RPi_Driver/MyGPIO/my_gpio.c -o build/temp.linux-aarch64-3.9/source/MyDHT_RPi_Driver/MyGPIO/my_gpio.o -std=gnu99
source/MyDHT_RPi_Driver/MyGPIO/my_gpio.c: In function ‘gpio_deinit’:
source/MyDHT_RPi_Driver/MyGPIO/my_gpio.c:78:12: warning: passing argument 1 of  ‘munmap’ discards ‘volatile’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   78 |     munmap(gpio_mapped_addr, GPIO_LENGTH);
      |            ^~~~~~~~~~~~~~~~
In file included from source/MyDHT_RPi_Driver/MyGPIO/my_gpio.c:5:
/usr/include/arm-linux-gnueabihf/sys/mman.h:76:26: note: expected ‘void *’ but argument is of type ‘volatile uint32_t *’ {aka ‘volatile unsigned int *’}
   76 | extern int munmap (void *__addr, size_t __len) __THROW;
      |                    ~~~~~~^~~~~~
arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.9 -c source/MyDHT_RPi_Driver/MyGPIO/my_time_utils.c -o build/temp.linux-aarch64-3.9/source/MyDHT_RPi_Driver/MyGPIO/my_time_utils.o -std=gnu99
arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.9 -c source/MyDHT_RPi_Driver/MyGPIO/my_utils.c -o build/temp.linux-aarch64-3.9/source/MyDHT_RPi_Driver/MyGPIO/my_utils.o -std=gnu99
arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.9 -c source/MyDHT_RPi_Driver/dht_driver.c -o build/temp.linux-aarch64-3.9/source/MyDHT_RPi_Driver/dht_driver.o -std=gnu99
source/MyDHT_RPi_Driver/dht_driver.c: In function ‘wait_for_value’:
source/MyDHT_RPi_Driver/dht_driver.c:12:31: warning: comparison of integer expressions of different signedness: ‘uint32_t’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
   12 |     while(gpio_read(gpio_pin) != value) {
      |                               ^~
arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.9 -c source/py_driver_wrapper.c -o build/temp.linux-aarch64-3.9/source/py_driver_wrapper.o -std=gnu99
arm-linux-gnueabihf-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -Wl,-z,relro -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-aarch64-3.9/source/MyDHT_RPi_Driver/MyGPIO/my_gpio.o build/temp.linux-aarch64-3.9/source/MyDHT_RPi_Driver/MyGPIO/my_time_utils.o build/temp.linux-aarch64-3.9/source/MyDHT_RPi_Driver/MyGPIO/my_utils.o build/temp.linux-aarch64-3.9/source/MyDHT_RPi_Driver/dht_driver.o build/temp.linux-aarch64-3.9/source/py_driver_wrapper.o -o build/lib.linux-aarch64-3.9/MyPyDHT/dht_driver.cpython-39-arm-linux-gnueabihf.so
running install_lib
creating /usr/local/lib/python3.9/dist-packages/MyPyDHT
copying build/lib.linux-aarch64-3.9/MyPyDHT/__init__.py -> /usr/local/lib/python3.9/dist-packages/MyPyDHT
copying build/lib.linux-aarch64-3.9/MyPyDHT/dht_driver.cpython-39-arm-linux-gnueabihf.so -> /usr/local/lib/python3.9/dist-packages/MyPyDHT
byte-compiling /usr/local/lib/python3.9/dist-packages/MyPyDHT/__init__.py to __init__.cpython-39.pyc
running install_egg_info
Writing /usr/local/lib/python3.9/dist-packages/MyPyDHT-0.1.egg-info
amegon@raspberrypi:~/work/library/sensor/MyPyDHT $

pythonスクリプトで情報取得

適当な場所に以下のコードが書かれたスクリプトを作成する。
ここでは test.py として作成。

#!/usr/bin/env python3
 
# センサーアクセス用のライブラリを import
import MyPyDHT
 
# 測定値の取得(4は接続したGPIO のポート番号:GPIO4 なら 4)
humidity, temperature = MyPyDHT.sensor_read(MyPyDHT.Sensor.DHT22, 4)
 
# 結果の表示
print("Temp = " + str(temperature) + " \nHumidity = " + str(humidity))

実行結果

amegon@raspberrypi:~/work/scripts/sensor $ python3 test.py
Traceback (most recent call last):
  File "/home/amegon/work/scripts/sensor/test.py", line 6, in <module>
    humidity, temperature = MyPyDHT.sensor_read(MyPyDHT.Sensor.DHT22, 4)
  File "/usr/local/lib/python3.9/dist-packages/MyPyDHT/__init__.py", line 52, in sensor_read
    raise DHTException(error_mess)
MyPyDHT.DHTException: An error occurred during the handshake with the sensor!
amegon@raspberrypi:~/work/scripts/sensor $

エラーになった。
はて。

センサーのデータがとれない(エラー対応)

調べてみたがコードもシンプルだし、ライブラリの中を見てみても特に使い方に問題はなさそう。
handshake でエラーとなっているメッセージなので、そもそも最初のアクセスができていないと思い、以下の見直しを実施。

  • 配線間違ってない?
  • コードに記入している GPIO の番号間違ってない?

どちらも間違っていない様子。

他のサイトを参考にしてピンの差し替えを実施。

DHT22上の表示 Pin番号
GND 39番(6番はすでにファンで使っていた)
VCC 17番 (3.3v)
DAT 37番(GPIO=26)

だが、結果は変わらず、handshake でエラー発生。

違うセンサーデータ取得用ライブラリを使用してみる

ピンの設定をもとに戻す。

DHT22上の表示 Pin番号
GND 9番(6番はすでにファンで使っていた)
VCC 2番
DAT 7番(GPIO=4)

違うライブラリをインストール。
こちらも先人の知恵に感謝です。

https://github.com/adafruit/Adafruit_Python_DHT

sudo git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
sudo python setup.py install

サンプルコード
先人のリポジトリ内にある example を参考に作成。

import Adafruit_DHT as DHT

SENSOR_TYPE = DHT.DHT22
DHT_GPIO = 4

h,t = DHT.read_retry(SENSOR_TYPE, DHT_GPIO)

print('Temp={0:0.1f}*C  Humidity={1:0.1f}%'.format(t, h))

実行結果

amegon@raspberrypi:~/work/scripts/sensor $ python3 getTempHum.py
Temp=30.9*C  Humidity=52.9%
amegon@raspberrypi:~/work/scripts/sensor $

値が取れた。
結局のところ、最初に利用させてもらおうと思ったライブラリが Raspberry Pi4B をサポートしていないのか、ということだったみたい。
Readme をみても Raspberry Pi 4 の情報はないのでそうかもと思うことにします。

値は手元にある 100均の温湿度計と比較してみた。
センサーは2つあって、片方は温度、湿度ともにだいたい同じ。
もう片方は温度はだいたい同じ、湿度は -7% くらい。
センサーでむらがあるのかな?
温度、湿度近いセンサーを使用してしばらく様子みてみたいと思います。

次なにやるか

これでセンサーで値が取れるようにあったので、次は Zabbix にデータを送信して監視できるようにトライしてみたいと思います。

Zabbix Proxy とした Raspberry Pi 4B に SNMP 関連の設定を実施

目的

前回 Zabbix Proxy として起動しはじめた Raspberry Pi 4B だが、SNMP の設定をするのと忘れていたことに気づく。
監視環境では SNMP 対応のネットワーク機器の監視も行っており、SNMP トラップの受信を監視したい。
そこで、ここでまとめて SNMP関連の設定を実施する。

snmptrapd のインストール

インストールの流れ

SNMP トラップの受信機能となる snmptrapd をインストールする。

  • snmptrapd のインストール
    • sudo apt install snmptrapd
  • 動作確認
    • systemctl status snmptrapd
      • 停止していることを確認
      • 起動する:
        • sudo systemctl start snmptrapd
        • sudo systemctl enable snmptrapd
    • systemctl status snmpd
      • 起動していることを確認
      • 自動起動が有効であることを確認
      • 停止する: 今すぐには使わない。。
        • sudo systemctl stop snmpd
        • sudo systemctl disable snmpd

ログ

amegon@raspberrypi:~ $ sudo apt install snmptrapd
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libfuse2 libreadline5 raspinfo
これを削除するには 'sudo apt autoremove' を利用してください。
以下の追加パッケージがインストールされます:
  libnetsnmptrapd40 snmpd
以下のパッケージが新たにインストールされます:
  libnetsnmptrapd40 snmpd snmptrapd
アップグレード: 0 個、新規インストール: 3 個、削除: 0 個、保留: 0 個。
101 kB のアーカイブを取得する必要があります。
この操作後に追加で 282 kB のディスク容量が消費されます。
続行しますか? [Y/n] y
取得:1 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf snmpd armhf 5.9+dfsg-4+deb11u1 [57.3 kB]
取得:2 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf libnetsnmptrapd40 armhf 5.9+dfsg-4+deb11u1 [20.0 kB]
取得:3 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf snmptrapd armhf 5.9+dfsg-4+deb11u1 [24.1 kB]
101 kB を 3秒 で取得しました (39.0 kB/s)
パッケージを事前設定しています ...
以前に未選択のパッケージ snmpd を選択しています。
(データベースを読み込んでいます ... 現在 183721 個のファイルとディレクトリがインストールされています。)
.../snmpd_5.9+dfsg-4+deb11u1_armhf.deb を展開する準備をしています ...
snmpd (5.9+dfsg-4+deb11u1) を展開しています...
以前に未選択のパッケージ libnetsnmptrapd40:armhf を選択しています。
.../libnetsnmptrapd40_5.9+dfsg-4+deb11u1_armhf.deb を展開する準備をしています ...
libnetsnmptrapd40:armhf (5.9+dfsg-4+deb11u1) を展開しています...
以前に未選択のパッケージ snmptrapd を選択しています。
.../snmptrapd_5.9+dfsg-4+deb11u1_armhf.deb を展開する準備をしています ...
snmptrapd (5.9+dfsg-4+deb11u1) を展開しています...
snmpd (5.9+dfsg-4+deb11u1) を設定しています ...
adduser: 警告: ホームディレクトリ `/var/lib/snmp' は、現在作成中のユーザの所属になっていません。
Created symlink /etc/systemd/system/multi-user.target.wants/snmpd.service → /lib/systemd/system/snmpd.service.
libnetsnmptrapd40:armhf (5.9+dfsg-4+deb11u1) を設定しています ...
snmptrapd (5.9+dfsg-4+deb11u1) を設定しています ...
man-db (2.9.4-2) のトリガを処理しています ...
libc-bin (2.31-13+rpt2+rpi1+deb11u5) のトリガを処理しています ...
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ systemctl status snmptrapd
● snmptrapd.service - Simple Network Management Protocol (SNMP) Trap Daemon.
     Loaded: loaded (/lib/systemd/system/snmptrapd.service; disabled; vendor pr>
     Active: inactive (dead)
...skipping...
● snmptrapd.service - Simple Network Management Protocol (SNMP) Trap Daemon.
     Loaded: loaded (/lib/systemd/system/snmptrapd.service; disabled; vendor pr>
     Active: inactive (dead)
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ sudo systemctl start snmptrapd
amegon@raspberrypi:~ $ sudo systemctl enable snmptrapd
Synchronizing state of snmptrapd.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable snmptrapd
Created symlink /etc/systemd/system/multi-user.target.wants/snmptrapd.service → /lib/systemd/system/snmptrapd.service.
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ systemctl status snmptrapd
● snmptrapd.service - Simple Network Management Protocol (SNMP) Trap Daemon.
     Loaded: loaded (/lib/systemd/system/snmptrapd.service; enabled; vendor pre>
     Active: active (running) since Tue 2023-09-05 13:54:42 JST; 19s ago
   Main PID: 26458 (snmptrapd)
      Tasks: 1 (limit: 4915)
        CPU: 31ms
     CGroup: /system.slice/snmptrapd.service
             mq26458 /usr/sbin/snmptrapd -LOw -f -p /run/snmptrapd.pid

 9月 05 13:54:42 raspberrypi systemd[1]: Started Simple Network Management Prot>
 9月 05 13:54:42 raspberrypi snmptrapd[26458]: Warning: no access control infor>
 9月 05 13:54:42 raspberrypi snmptrapd[26458]:   (Config search path: /etc/snmp>
 9月 05 13:54:42 raspberrypi snmptrapd[26458]: This receiver will *NOT* accept >
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ systemctl status snmpd
● snmpd.service - Simple Network Management Protocol (SNMP) Daemon.
     Loaded: loaded (/lib/systemd/system/snmpd.service; enabled; vendor preset:>
     Active: active (running) since Tue 2023-09-05 13:50:38 JST; 1min 1s ago
   Main PID: 25994 (snmpd)
      Tasks: 1 (limit: 4915)
        CPU: 190ms
     CGroup: /system.slice/snmpd.service
             mq25994 /usr/sbin/snmpd -LOw -u Debian-snmp -g Debian-snmp -I -smu>

 9月 05 13:50:38 raspberrypi systemd[1]: Starting Simple Network Management Pro>
 9月 05 13:50:38 raspberrypi systemd[1]: Started Simple Network Management Prot>
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ systemctl stop snmpd
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
'snmpd.service'を停止するには認証が必要です。
Authenticating as: ,,, (amegon)
Password:
==== AUTHENTICATION COMPLETE ===
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ sudo systemctl disable snmpd
Synchronizing state of snmpd.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable snmpd
Removed /etc/systemd/system/multi-user.target.wants/snmpd.service.
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ systemctl status snmpd
● snmpd.service - Simple Network Management Protocol (SNMP) Daemon.
     Loaded: loaded (/lib/systemd/system/snmpd.service; disabled; vendor preset>
     Active: inactive (dead)

 9月 05 13:50:38 raspberrypi systemd[1]: Starting Simple Network Management Pro>
 9月 05 13:50:38 raspberrypi systemd[1]: Started Simple Network Management Prot>
 9月 05 13:52:48 raspberrypi systemd[1]: Stopping Simple Network Management Pro>
 9月 05 13:52:48 raspberrypi systemd[1]: snmpd.service: Succeeded.
 9月 05 13:52:48 raspberrypi systemd[1]: Stopped Simple Network Management Prot>
amegon@raspberrypi:~ $

SNMPTT のインストール

インストールの流れ

snmptrapd が受信した SNMP トラップを人間が見やすいように翻訳する機能の SNMPTT をインストールする。

  • SNMPTT のインストール
    • sudo apt install snmptt
  • 動作確認
    • systemctl status snmptt
      • 起動していることを確認
      • 自動起動設定が有効であることを確認

ログ

amegon@raspberrypi:~ $ sudo apt install snmptt
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libfuse2 libreadline5 raspinfo
これを削除するには 'sudo apt autoremove' を利用してください。
以下の追加パッケージがインストールされます:
  libsnmp-perl
以下のパッケージが新たにインストールされます:
  libsnmp-perl snmptt
アップグレード: 0 個、新規インストール: 2 個、削除: 0 個、保留: 0 個。
1,821 kB のアーカイブを取得する必要があります。
この操作後に追加で 2,717 kB のディスク容量が消費されます。
続行しますか? [Y/n] y
取得:1 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf libsnmp-perl armhf 5.9+dfsg-4+deb11u1 [1,708 kB]
取得:2 http://ftp.udx.icscoe.jp/Linux/raspbian/raspbian bullseye/main armhf snmptt all 1.4.2-1 [114 kB]
1,821 kB を 2秒 で取得しました (998 kB/s)
以前に未選択のパッケージ libsnmp-perl を選択しています。
(データベースを読み込んでいます ... 現在 183765 個のファイルとディレクトリがインストールされています。)
.../libsnmp-perl_5.9+dfsg-4+deb11u1_armhf.deb を展開する準備をしています ...
libsnmp-perl (5.9+dfsg-4+deb11u1) を展開しています...
以前に未選択のパッケージ snmptt を選択しています。
.../snmptt_1.4.2-1_all.deb を展開する準備をしています ...
snmptt (1.4.2-1) を展開しています...
libsnmp-perl (5.9+dfsg-4+deb11u1) を設定しています ...
snmptt (1.4.2-1) を設定しています ...
システムユーザ `snmptt' (UID 120) を追加しています...
新しいグループ `snmptt' (GID 129) を追加しています...
新しいユーザ `snmptt' (UID 120) をグループ `snmptt' に追加しています...
ホームディレクトリ `/var/spool/snmptt' は作成しません。
Created symlink /etc/systemd/system/multi-user.target.wants/snmptt.service → /lib/systemd/system/snmptt.service.
man-db (2.9.4-2) のトリガを処理しています ...
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ systemctl status snmptt
● snmptt.service - SNMP trap translator
     Loaded: loaded (/lib/systemd/system/snmptt.service; enabled; vendor preset>
     Active: active (running) since Tue 2023-09-05 13:56:04 JST; 28s ago
    Process: 26668 ExecStart=/usr/sbin/snmptt $DAEMON_ARGS (code=exited, status>
   Main PID: 26671 (snmptt)
      Tasks: 2 (limit: 4915)
        CPU: 287ms
     CGroup: /system.slice/snmptt.service
             tq26670 /usr/bin/perl /usr/sbin/snmptt --daemon
             mq26671 /usr/bin/perl /usr/sbin/snmptt --daemon

 9月 05 13:56:04 raspberrypi snmptt[26668]: Smartmatch is experimental at /usr/>
 9月 05 13:56:04 raspberrypi snmptt[26668]: Redundant argument in sprintf at /u>
 9月 05 13:56:04 raspberrypi snmptt-sys[26668]: SNMPTT v1.4.2 started
 9月 05 13:56:04 raspberrypi snmptt-sys[26668]: Loading /etc/snmp/snmptt.conf
 9月 05 13:56:04 raspberrypi snmptt[26668]: Redundant argument in sprintf at /u>
 9月 05 13:56:04 raspberrypi snmptt[26668]: Redundant argument in sprintf at /u>
 9月 05 13:56:04 raspberrypi snmptt-sys[26668]: Finished loading 64 lines from >
 9月 05 13:56:04 raspberrypi snmptt-sys[26671]: Changing to UID: snmptt (120), >
 9月 05 13:56:04 raspberrypi systemd[1]: snmptt.service: Supervising process 26>
 9月 05 13:56:04 raspberrypi systemd[1]: Started SNMP trap translator.
amegon@raspberrypi:~ $

snmp のインストール

インストールの流れ

snmpwalk や snmptranslate といった SNMP 関連のツールをインストールする。

  • snmp のインストール
    • sudo apt install snmp
  • snmp-mibs-downloader をインストール(MIBをインストール。別の管理で利用するなら不要かも)
    • sudo apt install snmp-mibs-downloader
    • MIB は /var/lib/mibs/ietf/ に保存されている模様
  • MIB ファイルの更新実施
    • sudo download-mibs
  • snmp.conf の設定を変更
    • sudo vi /etc/snmp/snmp.conf
    • mibs :mibs ALL
  • 動作確認
    • snmpwalk コマンドを実行
      • ヘルプが表示される
    • snmptrap コマンドを実行
      • ヘルプが表示される
    • snmptranslate -On RFC1213-MIB:sysName
      • 以下の結果が表示されることを確認
        • .1.3.6.1.2.1.1.5

ログ

amegon@raspberrypi:~ $ sudo apt install snmp
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libfuse2 libreadline5 raspinfo
これを削除するには 'sudo apt autoremove' を利用してください。
以下のパッケージが新たにインストールされます:
  snmp
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
166 kB のアーカイブを取得する必要があります。
この操作後に追加で 560 kB のディスク容量が消費されます。
取得:1 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf snmp armhf 5.9+dfsg-4+deb11u1 [166 kB]
166 kB を 1秒 で取得しました (130 kB/s)
以前に未選択のパッケージ snmp を選択しています。
(データベースを読み込んでいます ... 現在 183856 個のファイルとディレクトリがインストールされています。)
.../snmp_5.9+dfsg-4+deb11u1_armhf.deb を展開する準備をしています ...
snmp (5.9+dfsg-4+deb11u1) を展開しています...
snmp (5.9+dfsg-4+deb11u1) を設定しています ...
man-db (2.9.4-2) のトリガを処理しています ...
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ sudo apt install snmp-mibs-downloader
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libfuse2 libreadline5 raspinfo
これを削除するには 'sudo apt autoremove' を利用してください。
以下の追加パッケージがインストールされます:
  smistrip
以下のパッケージが新たにインストールされます:
  smistrip snmp-mibs-downloader
アップグレード: 0 個、新規インストール: 2 個、削除: 0 個、保留: 0 個。
5,192 kB のアーカイブを取得する必要があります。
この操作後に追加で 5,434 kB のディスク容量が消費されます。
続行しますか? [Y/n] y
取得:1 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf smistrip all 0.4.8+dfsg2-16 [29.4 kB]
取得:2 http://ftp.udx.icscoe.jp/Linux/raspbian/raspbian bullseye/non-free armhf snmp-mibs-downloader all 1.5 [5,163 kB]
5,192 kB を 2秒 で取得しました (3,272 kB/s)
以前に未選択のパッケージ smistrip を選択しています。
(データベースを読み込んでいます ... 現在 183916 個のファイルとディレクトリがインストールされています。)
.../smistrip_0.4.8+dfsg2-16_all.deb を展開する準備をしています ...
smistrip (0.4.8+dfsg2-16) を展開しています...
以前に未選択のパッケージ snmp-mibs-downloader を選択しています。
.../snmp-mibs-downloader_1.5_all.deb を展開する準備をしています ...
snmp-mibs-downloader (1.5) を展開しています...
smistrip (0.4.8+dfsg2-16) を設定しています ...
snmp-mibs-downloader (1.5) を設定しています ...

Downloading documents and extracting MIB files.
This will take some minutes.

In case this process fails, it can always be repeated later by executing
/usr/bin/download-mibs again.

RFC1155-SMI: 119 lines.
RFC1213-MIB: 2613 lines.
NOTE: SMUX: ignored.
SMUX-MIB: 158 lines.
CLNS-MIB: 1294 lines.
RFC1381-MIB: 1007 lines.
RFC1382-MIB: 2627 lines.
RFC1414-MIB: 131 lines.
SNMPv2-PARTY-MIB: 1410 lines.
SNMPv2-M2M-MIB: 807 lines.
MIOX25-MIB: 708 lines.
PPP-LCP-MIB: 764 lines.
PPP-SEC-MIB: 289 lines.
PPP-IP-NCP-MIB: 203 lines.
PPP-BRIDGE-NCP-MIB: 429 lines.
FDDI-SMT73-MIB: 2126 lines.
TOKEN-RING-RMON-MIB: 2302 lines.
SOURCE-ROUTING-MIB: 450 lines.
DECNET-PHIV-MIB: 3030 lines.
DSA-MIB: 642 lines.
DPI20-MIB: 47 lines.
IBM-6611-APPN-MIB: 5112 lines.
DNS-SERVER-MIB: 1078 lines.
DNS-RESOLVER-MIB: 1196 lines.
UPS-MIB: 1899 lines.
CHARACTER-MIB: 646 lines.
RS-232-MIB: 788 lines.
PARALLEL-MIB: 286 lines.
SNA-NAU-MIB: 2765 lines.
SIP-MIB: 1099 lines.
Modem-MIB: 1340 lines.
RDBMS-MIB: 1377 lines.
RIPv2-MIB: 532 lines.
APPLETALK-MIB: 3398 lines.
SNA-SDLC-MIB: 2761 lines.
TOKENRING-MIB: 836 lines.
TOKENRING-STATION-SR-MIB: 175 lines.
TCPIPX-MIB: 331 lines.
SNMPv2-USEC-MIB: 238 lines.
MIP-MIB: 2127 lines.
DOT12-IF-MIB: 772 lines.
DLSW-MIB: 3560 lines.
APPC-MIB: 5104 lines.
SNMP-REPEATER-MIB: 3265 lines.
FRAME-RELAY-DTE-MIB: 992 lines.
ISDN-MIB: 1260 lines.
DIAL-CONTROL-MIB: 1270 lines.
RSVP-MIB: 2660 lines.
INTEGRATED-SERVICES-MIB: 750 lines.
INTEGRATED-SERVICES-GUARANTEED-MIB: 218 lines.
APPN-DLUR-MIB: 632 lines.
HPR-MIB: 1270 lines.
DOT12-RPTR-MIB: 1978 lines.
SYSAPPL-MIB: 1539 lines.
IPOA-MIB: 1654 lines.
IPATM-IPMC-MIB: 3244 lines.
IPV6-TCP-MIB: 211 lines.
IPV6-UDP-MIB: 141 lines.
APPN-MIB: 5611 lines.
APPN-TRAP-MIB: 477 lines.
EBN-MIB: 702 lines.
IPV6-TC: 67 lines.
IPV6-MIB: 1443 lines.
IPV6-ICMP-MIB: 529 lines.
DS0-MIB: 305 lines.
DS0BUNDLE-MIB: 311 lines.
ATM-ACCOUNTING-INFORMATION-MIB: 402 lines.
ACCOUNTING-CONTROL-MIB: 768 lines.
ATM-TC-MIB: 713 lines.
ATM-MIB: 2995 lines.
TN3270E-MIB: 1953 lines.
TN3270E-RT-MIB: 896 lines.
APPLICATION-MIB: 2995 lines.
SNMPv2-SMI: 344 lines.
NOTE: FIZBIN-MIB: ignored.
SNMPv2-TC: 772 lines.
SNMPv2-CONF: 322 lines.
HPR-IP-MIB: 487 lines.
WWW-MIB: 1272 lines.
DIRECTORY-SERVER-MIB: 772 lines.
SMON-MIB: 1254 lines.
ADSL-TC-MIB: 113 lines.
ADSL-LINE-MIB: 4328 lines.
ETHER-CHIPSET-MIB: 532 lines.
NHRP-MIB: 2596 lines.
Job-Monitoring-MIB: 1652 lines.
FLOW-METER-MIB: 1901 lines.
AGENTX-MIB: 527 lines.
SLAPM-MIB: 2842 lines.
SNMP-USM-DH-OBJECTS-MIB: 532 lines.
VRRP-MIB: 789 lines.
NETWORK-SERVICES-MIB: 626 lines.
MTA-MIB: 1226 lines.
HOST-RESOURCES-MIB: 1540 lines.
HOST-RESOURCES-TYPES: 389 lines.
RMON-MIB: 3980 lines.
FIBRE-CHANNEL-FE-MIB: 1781 lines.
HCNUM-TC: 118 lines.
IF-MIB: 1814 lines.
IF-INVERTED-STACK-MIB: 149 lines.
PTOPO-MIB: 804 lines.
IPMROUTE-STD-MIB: 869 lines.
IGMP-STD-MIB: 516 lines.
PIM-MIB: 889 lines.
COPS-CLIENT-MIB: 844 lines.
FRNETSERV-MIB: 2479 lines.
FR-ATM-PVC-SERVICE-IWF-MIB: 1066 lines.
RTP-MIB: 981 lines.
DISMAN-EVENT-MIB: 1882 lines.
DISMAN-EXPRESSION-MIB: 1182 lines.
NOTIFICATION-LOG-MIB: 753 lines.
IPV6-MLD-MIB: 417 lines.
FR-MFR-MIB: 888 lines.
PINT-MIB: 573 lines.
DOCS-BPI-MIB: 1569 lines.
INTERFACETOPN-MIB: 1023 lines.
DISMAN-SCRIPT-MIB: 1764 lines.
SFLOW-MIB: 389 lines.
CIRCUIT-IF-MIB: 369 lines.
FRSLD-MIB: 1768 lines.
DISMAN-SCHEDULE-MIB: 699 lines.
HC-RMON-MIB: 3149 lines.
DSMON-MIB: 4449 lines.
DIFFSERV-DSCP-TC: 64 lines.
DIFFSERV-MIB: 3514 lines.
GSMP-MIB: 1582 lines.
L2TP-MIB: 2664 lines.
SNMP-FRAMEWORK-MIB: 526 lines.
SNMP-MPD-MIB: 145 lines.
NOTE: : ignored.
SNMP-TARGET-MIB: 660 lines.
SNMP-NOTIFICATION-MIB: 589 lines.
SNMP-PROXY-MIB: 294 lines.
NOTE: : ignored.
SNMP-USER-BASED-SM-MIB: 912 lines.
SNMP-VIEW-BASED-ACM-MIB: 830 lines.
SNMPv2-PDU: 133 lines.
SNMPv2-TM: 176 lines.
SNMPv2-MIB: 854 lines.
TRANSPORT-ADDRESS-MIB: 421 lines.
ENTITY-SENSOR-MIB: 440 lines.
HC-ALARM-MIB: 707 lines.
ADSL-LINE-EXT-MIB: 1169 lines.
APS-MIB: 1659 lines.
MALLOC-MIB: 1364 lines.
SNMP-COMMUNITY-MIB: 505 lines.
OPT-IF-MIB: 6616 lines.
SONET-MIB: 2360 lines.
PerfHist-TC-MIB: 178 lines.
IPV6-FLOW-LABEL-MIB: 58 lines.
ATM2-MIB: 3220 lines.
POWER-ETHERNET-MIB: 621 lines.
EtherLike-MIB: 1862 lines.
HC-PerfHist-TC-MIB: 222 lines.
VDSL-LINE-MIB: 2844 lines.
APM-MIB: 2127 lines.
DIFFSERV-CONFIG-MIB: 243 lines.
NOTE: IANA-PRINTER-MIB: ignored.
Printer-MIB: 4389 lines.
NOTE: IANA-FINISHER-MIB: ignored.
Finisher-MIB: 869 lines.
MPLS-TC-STD-MIB: 635 lines.
MPLS-TE-STD-MIB: 2483 lines.
MPLS-LSR-STD-MIB: 2106 lines.
MPLS-FTN-STD-MIB: 1030 lines.
MPLS-LDP-STD-MIB: 2408 lines.
MPLS-LDP-ATM-STD-MIB: 757 lines.
MPLS-LDP-FRAME-RELAY-STD-MIB: 641 lines.
MPLS-LDP-GENERIC-STD-MIB: 321 lines.
ROHC-MIB: 1133 lines.
ROHC-UNCOMPRESSED-MIB: 197 lines.
ROHC-RTP-MIB: 636 lines.
SNMP-USM-AES-MIB: 62 lines.
TRIP-TC-MIB: 132 lines.
TRIP-MIB: 2007 lines.
SCTP-MIB: 1342 lines.
ALARM-MIB: 1127 lines.
NOTE: IANA-ITU-ALARM-TC-MIB: ignored.
ITU-ALARM-TC-MIB: 86 lines.
ITU-ALARM-MIB: 486 lines.
ARC-MIB: 396 lines.
DS3-MIB: 1786 lines.
TE-MIB: 1679 lines.
INET-ADDRESS-MIB: 402 lines.
NAT-MIB: 2391 lines.
POLICY-BASED-MANAGEMENT-MIB: 2060 lines.
TCP-MIB: 785 lines.
DOCS-IETF-SUBMGT-MIB: 672 lines.
FC-MGMT-MIB: 2205 lines.
VDSL-LINE-EXT-SCM-MIB: 420 lines.
VDSL-LINE-EXT-MCM-MIB: 662 lines.
TUNNEL-MIB: 738 lines.
UDP-MIB: 549 lines.
DOCS-IETF-BPI2-MIB: 3451 lines.
ENTITY-MIB: 1411 lines.
SSPM-MIB: 1029 lines.
TPM-MIB: 1916 lines.
BRIDGE-MIB: 1472 lines.
TE-LINK-STD-MIB: 1745 lines.
VPN-TC-STD-MIB: 72 lines.
ENTITY-STATE-TC-MIB: 169 lines.
ENTITY-STATE-MIB: 332 lines.
BGP4-MIB: 1232 lines.
IP-FORWARD-MIB: 1277 lines.
IP-MIB: 4993 lines.
MOBILEIPV6-MIB: 3984 lines.
RSTP-MIB: 306 lines.
HDSL2-SHDSL-LINE-MIB: 2503 lines.
DOCS-IETF-QOS-MIB: 3060 lines.
P-BRIDGE-MIB: 1157 lines.
Q-BRIDGE-MIB: 2367 lines.
MPLS-LC-ATM-STD-MIB: 336 lines.
MPLS-LC-FR-STD-MIB: 263 lines.
IFCP-MGMT-MIB: 1015 lines.
MPLS-L3VPN-STD-MIB: 1588 lines.
FCIP-MGMT-MIB: 1037 lines.
T11-FC-NAME-SERVER-MIB: 1136 lines.
T11-TC-MIB: 67 lines.
T11-FC-FABRIC-ADDR-MGR-MIB: 1241 lines.
ISIS-MIB: 4317 lines.
SCSI-MIB: 2758 lines.
AGGREGATE-MIB: 477 lines.
TIME-AGGREGATE-MIB: 375 lines.
RMON2-MIB: 5711 lines.
ISCSI-MIB: 3097 lines.
IPS-AUTH-MIB: 1156 lines.
DOCS-IF-MIB: 5291 lines.
DOCS-IETF-CABLE-DEVICE-NOTIFICATION-MIB: 1453 lines.
DISMAN-PING-MIB: 1561 lines.
DISMAN-TRACEROUTE-MIB: 1850 lines.
DISMAN-NSLOOKUP-MIB: 509 lines.
MSDP-MIB: 1182 lines.
T11-FC-ROUTE-MIB: 448 lines.
T11-FC-FSPF-MIB: 1170 lines.
LMP-MIB: 3185 lines.
DOCS-CABLE-DEVICE-MIB: 3141 lines.
RADIUS-AUTH-CLIENT-MIB: 710 lines.
RADIUS-AUTH-SERVER-MIB: 774 lines.
RADIUS-ACC-CLIENT-MIB: 638 lines.
RADIUS-ACC-SERVER-MIB: 727 lines.
RADIUS-DYNAUTH-CLIENT-MIB: 767 lines.
RADIUS-DYNAUTH-SERVER-MIB: 699 lines.
PKTC-IETF-MTA-MIB: 2081 lines.
ADSL2-LINE-TC-MIB: 729 lines.
ADSL2-LINE-MIB: 5476 lines.
RAQMON-MIB: 1417 lines.
RAQMON-RDS-MIB: 672 lines.
T11-FC-VIRTUAL-FABRIC-MIB: 523 lines.
OSPF-MIB: 4164 lines.
OSPF-TRAP-MIB: 584 lines.
SIP-TC-MIB: 177 lines.
SIP-COMMON-MIB: 1913 lines.
SIP-UA-MIB: 200 lines.
SIP-SERVER-MIB: 869 lines.
SNMP-IEEE802-TM-MIB: 40 lines.
GMPLS-TC-STD-MIB: 124 lines.
GMPLS-TE-STD-MIB: 1749 lines.
NOTE: IANA-GMPLS-TC-MIB: ignored.
GMPLS-LSR-STD-MIB: 503 lines.
GMPLS-LABEL-STD-MIB: 689 lines.
DS1-MIB: 3015 lines.
IPSEC-SPD-MIB: 2682 lines.
MAU-MIB: 1740 lines.
NOTE: IANA-MAU-MIB: ignored.
DOT3-EPON-MIB: 2532 lines.
DOT3-OAM-MIB: 2115 lines.
TCP-ESTATS-MIB: 2941 lines.
T11-FC-FABRIC-CONFIG-SERVER-MIB: 1717 lines.
T11-FC-FABRIC-LOCK-MIB: 490 lines.
T11-FC-ZONE-SERVER-MIB: 2638 lines.
ISNS-MIB: 3243 lines.
T11-FC-RSCN-MIB: 751 lines.
URI-TC-MIB: 133 lines.
PIM-STD-MIB: 3746 lines.
IF-CAP-STACK-MIB: 284 lines.
EFM-CU-MIB: 2995 lines.
UDPLITE-MIB: 513 lines.
PKTC-IETF-SIG-MIB: 3021 lines.
LANGTAG-TC-MIB: 56 lines.
IPMCAST-MIB: 2391 lines.
MIDCOM-MIB: 2260 lines.
PIM-BSR-MIB: 699 lines.
T11-FC-SP-TC-MIB: 637 lines.
T11-FC-SP-AUTHENTICATION-MIB: 920 lines.
T11-FC-SP-ZONING-MIB: 550 lines.
T11-FC-SP-POLICY-MIB: 4274 lines.
T11-FC-SP-SA-MIB: 2483 lines.
SYSLOG-TC-MIB: 202 lines.
PKTC-IETF-EVENT-MIB: 1163 lines.
NEMO-MIB: 1739 lines.
MGMD-STD-MIB: 1524 lines.
RSERPOOL-MIB: 1439 lines.
PW-TC-STD-MIB: 288 lines.
SNMP-TSM-MIB: 234 lines.
SNMP-SSH-TM-MIB: 329 lines.
NOTE: IANA-PWE3-MIB: ignored.
PW-STD-MIB: 2438 lines.
PW-MPLS-STD-MIB: 914 lines.
PW-ENET-STD-MIB: 491 lines.
PW-TDM-MIB: 1336 lines.
PW-ATM-MIB: 1205 lines.
OSPFV3-MIB: 3951 lines.
VDSL2-LINE-TC-MIB: 1479 lines.
VDSL2-LINE-MIB: 7189 lines.
SYSLOG-MSG-MIB: 598 lines.
DVB-RCS-MIB: 3329 lines.
FORCES-MIB: 391 lines.
IPFIX-MIB: 1677 lines.
NOTE: IPFIX-SELECTOR-MIB: ignored.
CAPWAP-BASE-MIB: 2618 lines.
CAPWAP-DOT11-MIB: 369 lines.
patching file ADSL-LINE-MIB
patching file DLSW-MIB
patching file DSA-MIB
patching file FDDI-SMT73-MIB
patching file HPR-MIB
patching file MIP-MIB
patching file Modem-MIB
patching file PPP-LCP-MIB
patching file RDBMS-MIB
patching file RFC1414-MIB
patching file SNA-NAU-MIB
patching file TCPIPX-MIB
patching file UPS-MIB
patching file SMUX-MIB
patching file IPATM-IPMC-MIB
IANA-PWE3-MIB: 137 lines.
NOTE: PW-STD-MIB: ignored.
NOTE: IPFIX-MIB: ignored.
IPFIX-SELECTOR-MIB: 173 lines.
IANAifType-MIB: 685 lines.
IANA-LANGUAGE-MIB: 126 lines.
IANA-ADDRESS-FAMILY-NUMBERS-MIB: 170 lines.
IANA-RTPROTO-MIB: 102 lines.
IANATn3270eTC-MIB: 303 lines.
IANA-MALLOC-MIB: 69 lines.
IANA-CHARSET-MIB: 361 lines.
IANA-PRINTER-MIB: 2111 lines.
IANA-FINISHER-MIB: 286 lines.
IANA-ITU-ALARM-TC-MIB: 335 lines.
IANA-GMPLS-TC-MIB: 359 lines.
IANA-IPPM-METRICS-REGISTRY-MIB: 818 lines.
IANA-MAU-MIB: 984 lines.
man-db (2.9.4-2) のトリガを処理しています ...
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ sudo download-mibs

Downloading documents and extracting MIB files.
This will take some minutes.

In case this process fails, it can always be repeated later by executing
/usr/bin/download-mibs again.

RFC1155-SMI: 119 lines.
RFC1213-MIB: 2613 lines.
NOTE: SMUX: ignored.
SMUX-MIB: 158 lines.
CLNS-MIB: 1294 lines.
RFC1381-MIB: 1007 lines.
RFC1382-MIB: 2627 lines.
RFC1414-MIB: 131 lines.
SNMPv2-PARTY-MIB: 1410 lines.
SNMPv2-M2M-MIB: 807 lines.
MIOX25-MIB: 708 lines.
PPP-LCP-MIB: 764 lines.
PPP-SEC-MIB: 289 lines.
PPP-IP-NCP-MIB: 203 lines.
PPP-BRIDGE-NCP-MIB: 429 lines.
FDDI-SMT73-MIB: 2126 lines.
TOKEN-RING-RMON-MIB: 2302 lines.
SOURCE-ROUTING-MIB: 450 lines.
DECNET-PHIV-MIB: 3030 lines.
DSA-MIB: 642 lines.
DPI20-MIB: 47 lines.
IBM-6611-APPN-MIB: 5112 lines.
DNS-SERVER-MIB: 1078 lines.
DNS-RESOLVER-MIB: 1196 lines.
UPS-MIB: 1899 lines.
CHARACTER-MIB: 646 lines.
RS-232-MIB: 788 lines.
PARALLEL-MIB: 286 lines.
SNA-NAU-MIB: 2765 lines.
SIP-MIB: 1099 lines.
Modem-MIB: 1340 lines.
RDBMS-MIB: 1377 lines.
RIPv2-MIB: 532 lines.
APPLETALK-MIB: 3398 lines.
SNA-SDLC-MIB: 2761 lines.
TOKENRING-MIB: 836 lines.
TOKENRING-STATION-SR-MIB: 175 lines.
TCPIPX-MIB: 331 lines.
SNMPv2-USEC-MIB: 238 lines.
MIP-MIB: 2127 lines.
DOT12-IF-MIB: 772 lines.
DLSW-MIB: 3560 lines.
APPC-MIB: 5104 lines.
SNMP-REPEATER-MIB: 3265 lines.
FRAME-RELAY-DTE-MIB: 992 lines.
ISDN-MIB: 1260 lines.
DIAL-CONTROL-MIB: 1270 lines.
RSVP-MIB: 2660 lines.
INTEGRATED-SERVICES-MIB: 750 lines.
INTEGRATED-SERVICES-GUARANTEED-MIB: 218 lines.
APPN-DLUR-MIB: 632 lines.
HPR-MIB: 1270 lines.
DOT12-RPTR-MIB: 1978 lines.
SYSAPPL-MIB: 1539 lines.
IPOA-MIB: 1654 lines.
IPATM-IPMC-MIB: 3244 lines.
IPV6-TCP-MIB: 211 lines.
IPV6-UDP-MIB: 141 lines.
APPN-MIB: 5611 lines.
APPN-TRAP-MIB: 477 lines.
EBN-MIB: 702 lines.
IPV6-TC: 67 lines.
IPV6-MIB: 1443 lines.
IPV6-ICMP-MIB: 529 lines.
DS0-MIB: 305 lines.
DS0BUNDLE-MIB: 311 lines.
ATM-ACCOUNTING-INFORMATION-MIB: 402 lines.
ACCOUNTING-CONTROL-MIB: 768 lines.
ATM-TC-MIB: 713 lines.
ATM-MIB: 2995 lines.
TN3270E-MIB: 1953 lines.
TN3270E-RT-MIB: 896 lines.
APPLICATION-MIB: 2995 lines.
SNMPv2-SMI: 344 lines.
NOTE: FIZBIN-MIB: ignored.
SNMPv2-TC: 772 lines.
SNMPv2-CONF: 322 lines.
HPR-IP-MIB: 487 lines.
WWW-MIB: 1272 lines.
DIRECTORY-SERVER-MIB: 772 lines.
SMON-MIB: 1254 lines.
ADSL-TC-MIB: 113 lines.
ADSL-LINE-MIB: 4328 lines.
ETHER-CHIPSET-MIB: 532 lines.
NHRP-MIB: 2596 lines.
Job-Monitoring-MIB: 1652 lines.
FLOW-METER-MIB: 1901 lines.
AGENTX-MIB: 527 lines.
SLAPM-MIB: 2842 lines.
SNMP-USM-DH-OBJECTS-MIB: 532 lines.
VRRP-MIB: 789 lines.
NETWORK-SERVICES-MIB: 626 lines.
MTA-MIB: 1226 lines.
HOST-RESOURCES-MIB: 1540 lines.
HOST-RESOURCES-TYPES: 389 lines.
RMON-MIB: 3980 lines.
FIBRE-CHANNEL-FE-MIB: 1781 lines.
HCNUM-TC: 118 lines.
IF-MIB: 1814 lines.
IF-INVERTED-STACK-MIB: 149 lines.
PTOPO-MIB: 804 lines.
IPMROUTE-STD-MIB: 869 lines.
IGMP-STD-MIB: 516 lines.
PIM-MIB: 889 lines.
COPS-CLIENT-MIB: 844 lines.
FRNETSERV-MIB: 2479 lines.
FR-ATM-PVC-SERVICE-IWF-MIB: 1066 lines.
RTP-MIB: 981 lines.
DISMAN-EVENT-MIB: 1882 lines.
DISMAN-EXPRESSION-MIB: 1182 lines.
NOTIFICATION-LOG-MIB: 753 lines.
IPV6-MLD-MIB: 417 lines.
FR-MFR-MIB: 888 lines.
PINT-MIB: 573 lines.
DOCS-BPI-MIB: 1569 lines.
INTERFACETOPN-MIB: 1023 lines.
DISMAN-SCRIPT-MIB: 1764 lines.
SFLOW-MIB: 389 lines.
CIRCUIT-IF-MIB: 369 lines.
FRSLD-MIB: 1768 lines.
DISMAN-SCHEDULE-MIB: 699 lines.
HC-RMON-MIB: 3149 lines.
DSMON-MIB: 4449 lines.
DIFFSERV-DSCP-TC: 64 lines.
DIFFSERV-MIB: 3514 lines.
GSMP-MIB: 1582 lines.
L2TP-MIB: 2664 lines.
SNMP-FRAMEWORK-MIB: 526 lines.
SNMP-MPD-MIB: 145 lines.
NOTE: : ignored.
SNMP-TARGET-MIB: 660 lines.
SNMP-NOTIFICATION-MIB: 589 lines.
SNMP-PROXY-MIB: 294 lines.
NOTE: : ignored.
SNMP-USER-BASED-SM-MIB: 912 lines.
SNMP-VIEW-BASED-ACM-MIB: 830 lines.
SNMPv2-PDU: 133 lines.
SNMPv2-TM: 176 lines.
SNMPv2-MIB: 854 lines.
TRANSPORT-ADDRESS-MIB: 421 lines.
ENTITY-SENSOR-MIB: 440 lines.
HC-ALARM-MIB: 707 lines.
ADSL-LINE-EXT-MIB: 1169 lines.
APS-MIB: 1659 lines.
MALLOC-MIB: 1364 lines.
SNMP-COMMUNITY-MIB: 505 lines.
OPT-IF-MIB: 6616 lines.
SONET-MIB: 2360 lines.
PerfHist-TC-MIB: 178 lines.
IPV6-FLOW-LABEL-MIB: 58 lines.
ATM2-MIB: 3220 lines.
POWER-ETHERNET-MIB: 621 lines.
EtherLike-MIB: 1862 lines.
HC-PerfHist-TC-MIB: 222 lines.
VDSL-LINE-MIB: 2844 lines.
APM-MIB: 2127 lines.
DIFFSERV-CONFIG-MIB: 243 lines.
NOTE: IANA-PRINTER-MIB: ignored.
Printer-MIB: 4389 lines.
NOTE: IANA-FINISHER-MIB: ignored.
Finisher-MIB: 869 lines.
MPLS-TC-STD-MIB: 635 lines.
MPLS-TE-STD-MIB: 2483 lines.
MPLS-LSR-STD-MIB: 2106 lines.
MPLS-FTN-STD-MIB: 1030 lines.
MPLS-LDP-STD-MIB: 2408 lines.
MPLS-LDP-ATM-STD-MIB: 757 lines.
MPLS-LDP-FRAME-RELAY-STD-MIB: 641 lines.
MPLS-LDP-GENERIC-STD-MIB: 321 lines.
ROHC-MIB: 1133 lines.
ROHC-UNCOMPRESSED-MIB: 197 lines.
ROHC-RTP-MIB: 636 lines.
SNMP-USM-AES-MIB: 62 lines.
TRIP-TC-MIB: 132 lines.
TRIP-MIB: 2007 lines.
SCTP-MIB: 1342 lines.
ALARM-MIB: 1127 lines.
NOTE: IANA-ITU-ALARM-TC-MIB: ignored.
ITU-ALARM-TC-MIB: 86 lines.
ITU-ALARM-MIB: 486 lines.
ARC-MIB: 396 lines.
DS3-MIB: 1786 lines.
TE-MIB: 1679 lines.
INET-ADDRESS-MIB: 402 lines.
NAT-MIB: 2391 lines.
POLICY-BASED-MANAGEMENT-MIB: 2060 lines.
TCP-MIB: 785 lines.
DOCS-IETF-SUBMGT-MIB: 672 lines.
FC-MGMT-MIB: 2205 lines.
VDSL-LINE-EXT-SCM-MIB: 420 lines.
VDSL-LINE-EXT-MCM-MIB: 662 lines.
TUNNEL-MIB: 738 lines.
UDP-MIB: 549 lines.
DOCS-IETF-BPI2-MIB: 3451 lines.
ENTITY-MIB: 1411 lines.
SSPM-MIB: 1029 lines.
TPM-MIB: 1916 lines.
BRIDGE-MIB: 1472 lines.
TE-LINK-STD-MIB: 1745 lines.
VPN-TC-STD-MIB: 72 lines.
ENTITY-STATE-TC-MIB: 169 lines.
ENTITY-STATE-MIB: 332 lines.
BGP4-MIB: 1232 lines.
IP-FORWARD-MIB: 1277 lines.
IP-MIB: 4993 lines.
MOBILEIPV6-MIB: 3984 lines.
RSTP-MIB: 306 lines.
HDSL2-SHDSL-LINE-MIB: 2503 lines.
DOCS-IETF-QOS-MIB: 3060 lines.
P-BRIDGE-MIB: 1157 lines.
Q-BRIDGE-MIB: 2367 lines.
MPLS-LC-ATM-STD-MIB: 336 lines.
MPLS-LC-FR-STD-MIB: 263 lines.
IFCP-MGMT-MIB: 1015 lines.
MPLS-L3VPN-STD-MIB: 1588 lines.
FCIP-MGMT-MIB: 1037 lines.
T11-FC-NAME-SERVER-MIB: 1136 lines.
T11-TC-MIB: 67 lines.
T11-FC-FABRIC-ADDR-MGR-MIB: 1241 lines.
ISIS-MIB: 4317 lines.
SCSI-MIB: 2758 lines.
AGGREGATE-MIB: 477 lines.
TIME-AGGREGATE-MIB: 375 lines.
RMON2-MIB: 5711 lines.
ISCSI-MIB: 3097 lines.
IPS-AUTH-MIB: 1156 lines.
DOCS-IF-MIB: 5291 lines.
DOCS-IETF-CABLE-DEVICE-NOTIFICATION-MIB: 1453 lines.
DISMAN-PING-MIB: 1561 lines.
DISMAN-TRACEROUTE-MIB: 1850 lines.
DISMAN-NSLOOKUP-MIB: 509 lines.
MSDP-MIB: 1182 lines.
T11-FC-ROUTE-MIB: 448 lines.
T11-FC-FSPF-MIB: 1170 lines.
LMP-MIB: 3185 lines.
DOCS-CABLE-DEVICE-MIB: 3141 lines.
RADIUS-AUTH-CLIENT-MIB: 710 lines.
RADIUS-AUTH-SERVER-MIB: 774 lines.
RADIUS-ACC-CLIENT-MIB: 638 lines.
RADIUS-ACC-SERVER-MIB: 727 lines.
RADIUS-DYNAUTH-CLIENT-MIB: 767 lines.
RADIUS-DYNAUTH-SERVER-MIB: 699 lines.
PKTC-IETF-MTA-MIB: 2081 lines.
ADSL2-LINE-TC-MIB: 729 lines.
ADSL2-LINE-MIB: 5476 lines.
RAQMON-MIB: 1417 lines.
RAQMON-RDS-MIB: 672 lines.
T11-FC-VIRTUAL-FABRIC-MIB: 523 lines.
OSPF-MIB: 4164 lines.
OSPF-TRAP-MIB: 584 lines.
SIP-TC-MIB: 177 lines.
SIP-COMMON-MIB: 1913 lines.
SIP-UA-MIB: 200 lines.
SIP-SERVER-MIB: 869 lines.
SNMP-IEEE802-TM-MIB: 40 lines.
GMPLS-TC-STD-MIB: 124 lines.
GMPLS-TE-STD-MIB: 1749 lines.
NOTE: IANA-GMPLS-TC-MIB: ignored.
GMPLS-LSR-STD-MIB: 503 lines.
GMPLS-LABEL-STD-MIB: 689 lines.
DS1-MIB: 3015 lines.
IPSEC-SPD-MIB: 2682 lines.
MAU-MIB: 1740 lines.
NOTE: IANA-MAU-MIB: ignored.
DOT3-EPON-MIB: 2532 lines.
DOT3-OAM-MIB: 2115 lines.
TCP-ESTATS-MIB: 2941 lines.
T11-FC-FABRIC-CONFIG-SERVER-MIB: 1717 lines.
T11-FC-FABRIC-LOCK-MIB: 490 lines.
T11-FC-ZONE-SERVER-MIB: 2638 lines.
ISNS-MIB: 3243 lines.
T11-FC-RSCN-MIB: 751 lines.
URI-TC-MIB: 133 lines.
PIM-STD-MIB: 3746 lines.
IF-CAP-STACK-MIB: 284 lines.
EFM-CU-MIB: 2995 lines.
UDPLITE-MIB: 513 lines.
PKTC-IETF-SIG-MIB: 3021 lines.
LANGTAG-TC-MIB: 56 lines.
IPMCAST-MIB: 2391 lines.
MIDCOM-MIB: 2260 lines.
PIM-BSR-MIB: 699 lines.
T11-FC-SP-TC-MIB: 637 lines.
T11-FC-SP-AUTHENTICATION-MIB: 920 lines.
T11-FC-SP-ZONING-MIB: 550 lines.
T11-FC-SP-POLICY-MIB: 4274 lines.
T11-FC-SP-SA-MIB: 2483 lines.
SYSLOG-TC-MIB: 202 lines.
PKTC-IETF-EVENT-MIB: 1163 lines.
NEMO-MIB: 1739 lines.
MGMD-STD-MIB: 1524 lines.
RSERPOOL-MIB: 1439 lines.
PW-TC-STD-MIB: 288 lines.
SNMP-TSM-MIB: 234 lines.
SNMP-SSH-TM-MIB: 329 lines.
NOTE: IANA-PWE3-MIB: ignored.
PW-STD-MIB: 2438 lines.
PW-MPLS-STD-MIB: 914 lines.
PW-ENET-STD-MIB: 491 lines.
PW-TDM-MIB: 1336 lines.
PW-ATM-MIB: 1205 lines.
OSPFV3-MIB: 3951 lines.
VDSL2-LINE-TC-MIB: 1479 lines.
VDSL2-LINE-MIB: 7189 lines.
SYSLOG-MSG-MIB: 598 lines.
DVB-RCS-MIB: 3329 lines.
FORCES-MIB: 391 lines.
IPFIX-MIB: 1677 lines.
NOTE: IPFIX-SELECTOR-MIB: ignored.
CAPWAP-BASE-MIB: 2618 lines.
CAPWAP-DOT11-MIB: 369 lines.
patching file ADSL-LINE-MIB
patching file DLSW-MIB
patching file DSA-MIB
patching file FDDI-SMT73-MIB
patching file HPR-MIB
patching file MIP-MIB
patching file Modem-MIB
patching file PPP-LCP-MIB
patching file RDBMS-MIB
patching file RFC1414-MIB
patching file SNA-NAU-MIB
patching file TCPIPX-MIB
patching file UPS-MIB
patching file SMUX-MIB
patching file IPATM-IPMC-MIB
IANA-PWE3-MIB: 137 lines.
NOTE: PW-STD-MIB: ignored.
NOTE: IPFIX-MIB: ignored.
IPFIX-SELECTOR-MIB: 173 lines.
IANAifType-MIB: 685 lines.
IANA-LANGUAGE-MIB: 126 lines.
IANA-ADDRESS-FAMILY-NUMBERS-MIB: 170 lines.
IANA-RTPROTO-MIB: 102 lines.
IANATn3270eTC-MIB: 303 lines.
IANA-MALLOC-MIB: 69 lines.
IANA-CHARSET-MIB: 361 lines.
IANA-PRINTER-MIB: 2111 lines.
IANA-FINISHER-MIB: 286 lines.
IANA-ITU-ALARM-TC-MIB: 335 lines.
IANA-GMPLS-TC-MIB: 359 lines.
IANA-IPPM-METRICS-REGISTRY-MIB: 818 lines.
IANA-MAU-MIB: 984 lines.
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ snmpwalk
No hostname specified.
USAGE: snmpwalk [OPTIONS] AGENT [OID]

  Version:  5.9
  Web:      http://www.net-snmp.org/
  Email:    net-snmp-coders@lists.sourceforge.net

OPTIONS:
  -h, --help            display this help message
  -H                    display configuration file directives understood
  -v 1|2c|3             specifies SNMP version to use
  -V, --version         display package version number
SNMP Version 1 or 2c specific
  -c COMMUNITY          set the community string
SNMP Version 3 specific
  -a PROTOCOL           set authentication protocol (MD5|SHA|SHA-224|SHA-256|SHA-384|SHA-512)
  -A PASSPHRASE         set authentication protocol pass phrase
  -e ENGINE-ID          set security engine ID (e.g. 800000020109840301)
  -E ENGINE-ID          set context engine ID (e.g. 800000020109840301)
  -l LEVEL              set security level (noAuthNoPriv|authNoPriv|authPriv)
  -n CONTEXT            set context name (e.g. bridge1)
  -u USER-NAME          set security name (e.g. bert)
  -x PROTOCOL           set privacy protocol (DES|AES)
  -X PASSPHRASE         set privacy protocol pass phrase
  -Z BOOTS,TIME         set destination engine boots/time
General communication options
  -r RETRIES            set the number of retries
  -t TIMEOUT            set the request timeout (in seconds)
Debugging
  -d                    dump input/output packets in hexadecimal
  -D[TOKEN[,...]]       turn on debugging output for the specified TOKENs
                           (ALL gives extremely verbose debugging output)
General options
  -m MIB[:...]          load given list of MIBs (ALL loads everything)
  -M DIR[:...]          look in given list of directories for MIBs
    (default: /home/amegon/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf)
  -P MIBOPTS            Toggle various defaults controlling MIB parsing:
                          u:  allow the use of underlines in MIB symbols
                          c:  disallow the use of "--" to terminate comments
                          d:  save the DESCRIPTIONs of the MIB objects
                          e:  disable errors when MIB symbols conflict
                          w:  enable warnings when MIB symbols conflict
                          W:  enable detailed warnings when MIB symbols conflict
                          R:  replace MIB symbols from latest module
  -O OUTOPTS            Toggle various defaults controlling output display:
                          0:  print leading 0 for single-digit hex characters
                          a:  print all strings in ascii format
                          b:  do not break OID indexes down
                          e:  print enums numerically
                          E:  escape quotes in string indices
                          f:  print full OIDs on output
                          n:  print OIDs numerically
                          p PRECISION:  display floating point values with specified PRECISION (printf format string)
                          q:  quick print for easier parsing
                          Q:  quick print with equal-signs
                          s:  print only last symbolic element of OID
                          S:  print MIB module-id plus last element
                          t:  print timeticks unparsed as numeric integers
                          T:  print human-readable text along with hex strings
                          u:  print OIDs using UCD-style prefix suppression
                          U:  don't print units
                          v:  print values only (not OID = value)
                          x:  print all strings in hex format
                          X:  extended index format
  -I INOPTS             Toggle various defaults controlling input parsing:
                          b:  do best/regex matching to find a MIB node
                          h:  don't apply DISPLAY-HINTs
                          r:  do not check values for range/type legality
                          R:  do random access to OID labels
                          u:  top-level OIDs must have '.' prefix (UCD-style)
                          s SUFFIX:  Append all textual OIDs with SUFFIX before parsing
                          S PREFIX:  Prepend all textual OIDs with PREFIX before parsing
  -L LOGOPTS            Toggle various defaults controlling logging:
                          e:           log to standard error
                          o:           log to standard output
                          n:           don't log at all
                          f file:      log to the specified file
                          s facility:  log to syslog (via the specified facility)

                          (variants)
                          [EON] pri:   log to standard error, output or /dev/null for level 'pri' and above
                          [EON] p1-p2: log to standard error, output or /dev/null for levels 'p1' to 'p2'
                          [FS] pri token:    log to file/syslog for level 'pri' and above
                          [FS] p1-p2 token:  log to file/syslog for levels 'p1' to 'p2'
  -C APPOPTS            Set various application specific behaviours:
                          p:  print the number of variables found
                          i:  include given OID in the search range
                          I:  don't include the given OID, even if no results are returned
                          c:  do not check returned OIDs are increasing
                          t:  Display wall-clock time to complete the walk
                          T:  Display wall-clock time to complete each request
                          E {OID}:  End the walk at the specified OID
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ snmptrap
No hostname specified.
USAGE: snmptrap [OPTIONS] AGENT TRAP-PARAMETERS

  Version:  5.9
  Web:      http://www.net-snmp.org/
  Email:    net-snmp-coders@lists.sourceforge.net

OPTIONS:
  -h, --help            display this help message
  -H                    display configuration file directives understood
  -v 1|2c|3             specifies SNMP version to use
  -V, --version         display package version number
SNMP Version 1 or 2c specific
  -c COMMUNITY          set the community string
SNMP Version 3 specific
  -a PROTOCOL           set authentication protocol (MD5|SHA|SHA-224|SHA-256|SHA-384|SHA-512)
  -A PASSPHRASE         set authentication protocol pass phrase
  -e ENGINE-ID          set security engine ID (e.g. 800000020109840301)
  -E ENGINE-ID          set context engine ID (e.g. 800000020109840301)
  -l LEVEL              set security level (noAuthNoPriv|authNoPriv|authPriv)
  -n CONTEXT            set context name (e.g. bridge1)
  -u USER-NAME          set security name (e.g. bert)
  -x PROTOCOL           set privacy protocol (DES|AES)
  -X PASSPHRASE         set privacy protocol pass phrase
  -Z BOOTS,TIME         set destination engine boots/time
General communication options
  -r RETRIES            set the number of retries
  -t TIMEOUT            set the request timeout (in seconds)
Debugging
  -d                    dump input/output packets in hexadecimal
  -D[TOKEN[,...]]       turn on debugging output for the specified TOKENs
                           (ALL gives extremely verbose debugging output)
General options
  -m MIB[:...]          load given list of MIBs (ALL loads everything)
  -M DIR[:...]          look in given list of directories for MIBs
    (default: /home/amegon/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf)
  -P MIBOPTS            Toggle various defaults controlling MIB parsing:
                          u:  allow the use of underlines in MIB symbols
                          c:  disallow the use of "--" to terminate comments
                          d:  save the DESCRIPTIONs of the MIB objects
                          e:  disable errors when MIB symbols conflict
                          w:  enable warnings when MIB symbols conflict
                          W:  enable detailed warnings when MIB symbols conflict
                          R:  replace MIB symbols from latest module
  -O OUTOPTS            Toggle various defaults controlling output display:
                          0:  print leading 0 for single-digit hex characters
                          a:  print all strings in ascii format
                          b:  do not break OID indexes down
                          e:  print enums numerically
                          E:  escape quotes in string indices
                          f:  print full OIDs on output
                          n:  print OIDs numerically
                          p PRECISION:  display floating point values with specified PRECISION (printf format string)
                          q:  quick print for easier parsing
                          Q:  quick print with equal-signs
                          s:  print only last symbolic element of OID
                          S:  print MIB module-id plus last element
                          t:  print timeticks unparsed as numeric integers
                          T:  print human-readable text along with hex strings
                          u:  print OIDs using UCD-style prefix suppression
                          U:  don't print units
                          v:  print values only (not OID = value)
                          x:  print all strings in hex format
                          X:  extended index format
  -I INOPTS             Toggle various defaults controlling input parsing:
                          b:  do best/regex matching to find a MIB node
                          h:  don't apply DISPLAY-HINTs
                          r:  do not check values for range/type legality
                          R:  do random access to OID labels
                          u:  top-level OIDs must have '.' prefix (UCD-style)
                          s SUFFIX:  Append all textual OIDs with SUFFIX before parsing
                          S PREFIX:  Prepend all textual OIDs with PREFIX before parsing
  -L LOGOPTS            Toggle various defaults controlling logging:
                          e:           log to standard error
                          o:           log to standard output
                          n:           don't log at all
                          f file:      log to the specified file
                          s facility:  log to syslog (via the specified facility)

                          (variants)
                          [EON] pri:   log to standard error, output or /dev/null for level 'pri' and above
                          [EON] p1-p2: log to standard error, output or /dev/null for levels 'p1' to 'p2'
                          [FS] pri token:    log to file/syslog for level 'pri' and above
                          [FS] p1-p2 token:  log to file/syslog for levels 'p1' to 'p2'
  -C APPOPTS            Set various application specific behaviour:
                          i:  send an INFORM instead of a TRAP

  -v 1 TRAP-PARAMETERS:
         enterprise-oid agent trap-type specific-type uptime [OID TYPE VALUE]...
  or
  -v 2 TRAP-PARAMETERS:
         uptime trapoid [OID TYPE VALUE] ...
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ snmptranslate -On RFC1213-MIB:sysName
.1.3.6.1.2.1.1.5
amegon@raspberrypi:~ $

snmptrapd 設定変更

/etc/snmp/snmptrapd.conf の設定変更

  • sudo vi /etc/snmp/snmptrapd.conf
  • 以下の記載をファイル文末に追加
traphandle default /usr/sbin/snmptthandler
disableAuthorization yes

変更前

amegon@raspberrypi:~ $ cat /etc/snmp/snmptrapd.conf

#
# EXAMPLE-trap.conf:
#   An example configuration file for configuring the Net-SNMP snmptrapd agent.
#
###############################################################################
#
# This file is intended to only be an example.
# When the snmptrapd agent starts up, this is where it will look for it.
#
# All lines beginning with a '#' are comments and are intended for you
# to read.  All other lines are configuration commands for the agent.

#
# PLEASE: read the snmptrapd.conf(5) manual page as well!
#
#authCommunity log,execute,net private 
#authCommunity log,execute,net public
#
## send mail when get any events
#traphandle default /usr/bin/traptoemail -s smtp.example.org foobar@example.org
#
## send mail when get linkDown
#traphandle .1.3.6.1.6.3.1.1.5.3 /usr/bin/traptoemail -s smtp.example.org foobar@example.org

変更後

amegon@raspberrypi:~ $ cat /etc/snmp/snmptrapd.conf

#
# EXAMPLE-trap.conf:
#   An example configuration file for configuring the Net-SNMP snmptrapd agent.
#
###############################################################################
#
# This file is intended to only be an example.
# When the snmptrapd agent starts up, this is where it will look for it.
#
# All lines beginning with a '#' are comments and are intended for you
# to read.  All other lines are configuration commands for the agent.

#
# PLEASE: read the snmptrapd.conf(5) manual page as well!
#
#authCommunity log,execute,net private 
#authCommunity log,execute,net public
#
## send mail when get any events
#traphandle default /usr/bin/traptoemail -s smtp.example.org foobar@example.org
#
## send mail when get linkDown
#traphandle .1.3.6.1.6.3.1.1.5.3 /usr/bin/traptoemail -s smtp.example.org foobar@example.org

traphandle default /usr/sbin/snmptthandler
disableAuthorization yes
amegon@raspberrypi:~ $

/etc/default/snmptrapd の編集

SNMPトラップの受信メッセージを SNMPTT で変換するために、snmptrapd ではトラップの OID 情報を文字に変換せず数値のままとする設定を入れる。

  • sudo vi /etc/default/snmptrapd

以下の設定に変更する。

TRAPDOPTS='-On -p /run/snmptrapd.pid'

変更前

amegon@raspberrypi:~ $ cat /etc/default/snmptrapd
# This file controls the behaviour of /etc/init.d/snmptrapd
# but not of the corresponding systemd service file.
# If needed, create an override file in
# /etc/systemd/system/snmptrapd.service.d/local.conf
# see man 5 systemd.unit and man 5 systemd.service

# snmptrapd options (use syslog).
TRAPDOPTS='-LSwd -p /run/snmptrapd.pid'
amegon@raspberrypi:~ $

変更後

amegon@raspberrypi:~ $ cat /etc/default/snmptrapd
# This file controls the behaviour of /etc/init.d/snmptrapd
# but not of the corresponding systemd service file.
# If needed, create an override file in
# /etc/systemd/system/snmptrapd.service.d/local.conf
# see man 5 systemd.unit and man 5 systemd.service

# snmptrapd options (use syslog).
#TRAPDOPTS='-LSwd -p /run/snmptrapd.pid'
TRAPDOPTS='-On -p /run/snmptrapd.pid'
amegon@raspberrypi:~ $

snmptrapd を再起動

これで設定変更した内容が反映された状態で実行される。

sudo systemctl restart snmptrapd

SNMPTT 設定変更

/etc/snmp/snmptt.ini の修正

sudo vi /etc/snmp/snmptt.ini

以下パラメータを修正

mode = standalone
net_snmp_perl_enable = 0
net_snmp_perl_best_guess = 0
↓
mode = daemon
net_snmp_perl_enable = 1
net_snmp_perl_best_guess = 2

以下のパラメータは設定が想定通りになっていることを確認。

log_file = /var/log/snmptt/snmptt.log

snmptt 用トラップ翻訳用 conf ファイルの設定

sudo vi /etc/snmp/snmptt.conf

以下を文末に追加。

#
#
#
EVENT general .* "LOGONLY" Normal
FORMAT ZBXTRAP $aA received unexpected trap

snmptt の再起動

sudo systemctl restart snmptt

SNMP トラップの受信確認

自分自身から SNMP トラップを送信して受信してみる

snmptrap コマンドを使用して自分自身にトラップを送信してみる。

snmptrap -v 2c -c test 127.0.0.1 '' .1.1.1 .1.1.1 s "This is a test."

/var/log/messages/var/log/snmptt/snmptt.log に以下のログ記録されていれば正常にトラップ受信ができている。

ログ

amegon@raspberrypi:~ $ tail -f /var/log/messages
Sep  5 14:27:33 raspberrypi snmptt-sys[880]: Changing to UID: snmptt (120), GID: snmptt (129)
Sep  5 14:29:32 raspberrypi kernel: [80910.986558] IPv6: MLD: clamping QRV from 1 to 2!
Sep  5 14:31:37 raspberrypi kernel: [81035.992868] IPv6: MLD: clamping QRV from 1 to 2!
Sep  5 14:32:23 raspberrypi snmptt-sys[880]: SNMPTT v1.4.2 shutdown
Sep  5 14:32:23 raspberrypi snmptt-sys[880]: Total traps received=0,Total traps translated=0,Total traps ignored=0,Total unknown traps=0
Sep  5 14:32:24 raspberrypi snmptt-sys[1092]: SNMPTT v1.4.2 started
Sep  5 14:32:24 raspberrypi snmptt-sys[1092]: Loading /etc/snmp/snmptt.conf
Sep  5 14:32:24 raspberrypi snmptt-sys[1092]: Finished loading 69 lines from /etc/snmp/snmptt.conf
Sep  5 14:32:24 raspberrypi snmptt-sys[1096]: Changing to UID: snmptt (120), GID: snmptt (129)
Sep  5 14:33:42 raspberrypi kernel: [81160.999241] IPv6: MLD: clamping QRV from 1 to 2!
Sep  5 14:34:49 raspberrypi snmptt[1096]: .1.1.1 Normal "LOGONLY" localhost - ZBXTRAP 127.0.0.1 received unexpected trap
^C
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ tail -100 /var/log/snmptt/snmptt.log
Tue Sep  5 14:34:45 2023 .1.1.1 Normal "LOGONLY" localhost - ZBXTRAP 127.0.0.1 received unexpected trap
amegon@raspberrypi:~ $

他の機器から SNMP トラップを受信してみる

周りに適当な SNMP 機器がいたらトラップを送ってみる。

ログ

amegon@raspberrypi:~ $ tail -f /var/log/messages | grep snmptt
Sep  5 14:54:19 raspberrypi snmptt[1096]: .1.3.6.1.4.1.207.8.48.1.0.107 Normal "LOGONLY" UNKNOWN - ZBXTRAP 192.168.1.254 received unexpected trap
^C
amegon@raspberrypi:~ $

受信できた。
アライドテレシス社製品のログイントラップを受信しました。

Zabbix Proxy の設定変更

Zabbix Proxy で受信した SNMP トラップを処理するために設定を行う。

zabbix_proxy.conf の設定変更

  • zabbix_proxy.conf をエディタで開く
    • sudo vi /etc/zabbix/zabbix_proxy.conf
  • 定義されているパラメータを以下の内容に修正
    • SNMPTrapperFile=/var/log/snmptt/snmptt.log
    • StartSNMPTrapper=1
  • zabbix-proxy プロセスの再起動
    • sudo systemctl restart zabbix-proxy

Raspberry Pi 4B に Zabbix 関連の設定をしてプロキシとして動作させる

目的

今自宅環境で Zabbix Proxy を動かしていますが、仮想環境上に構築した仮想マシンとして動いています。
この仮想環境上には Zabbix サーバーも一緒に動いていて、仮想基盤本体の再起動時など一緒に再起動しちゃうので、監視データが欠落してしまうこともありもったいない部分でした。
今回入手した Raspberry Pi 4B を Zabbix サーバーとは物理的に異なる環境で動作させる Zabbix プロキシとしたいと思います。

Zabbix Proxy のインストール

Zabbix Proxy インストール前の状態

amegon@raspberrypi:~ $ df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
/dev/root         56G   11G   42G   21% /
devtmpfs         3.6G     0  3.6G    0% /dev
tmpfs            3.9G     0  3.9G    0% /dev/shm
tmpfs            1.6G  1.2M  1.6G    1% /run
tmpfs            5.0M  4.0K  5.0M    1% /run/lock
/dev/mmcblk0p6   253M   51M  202M   20% /boot
tmpfs            782M   32K  782M    1% /run/user/1000
amegon@raspberrypi:~ $
amegon@raspberrypi:~ $ free -h
               total        used        free      shared  buff/cache   available
Mem:           7.6Gi       210Mi       6.9Gi        53Mi       529Mi       7.2Gi
Swap:           99Mi          0B        99Mi
amegon@raspberrypi:~ $

インストール実行

su になってリポジトリ追加

sudo su
# wget https://repo.zabbix.com/zabbix/5.0/raspbian/pool/main/z/zabbix-release/zabbix-release_5.0-2%2Bdebian11_all.deb
# dpkg -i zabbix-release_5.0-2+debian11_all.deb
# apt update

インストール

# apt install zabbix-proxy-mysql mariadb-server zabbix-agent

↑ 最初は zabbix-proxy-mysql だけ入れてた。ログでは1回目に zabbix-proxy-mysql だけ、2回目で 3つのモジュールをインストールしている。

# systemctl status mysql
↑ インストール後に起動していた。自動起動も有効っぽい。

DB 作成

mysql -uroot
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user 'zabbix'@'localhost' identified by 'zabbix';
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
mysql> quit;

# zcat /usr/share/doc/zabbix-proxy-mysql/schema.sql.gz | mysql -uzabbix -p zabbix

Zabbix Proxy の設定ファイル修正

# vi /etc/zabbix/zabbix_proxy.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=<password>
Server=<ZabbixサーバーのIP>

Zabbix Proxy の起動と自動起動設定有効化

# systemctl start zabbix-proxy
# systemctl enable zabbix-proxy

ログで起動状況を確認

root@raspberrypi:/home/amegon# tail -100 /var/log/zabbix/zabbix_proxy.log
  5650:20230904:205444.684 Starting Zabbix Proxy (active) [RasPi_01]. Zabbix 5.0.37 (revision 3f4cd9bec9b).
  5650:20230904:205444.684 **** Enabled features ****
  5650:20230904:205444.685 SNMP monitoring:       YES
  5650:20230904:205444.685 IPMI monitoring:       YES
  5650:20230904:205444.685 Web monitoring:        YES
  5650:20230904:205444.685 VMware monitoring:     YES
  5650:20230904:205444.685 ODBC:                  YES
  5650:20230904:205444.685 SSH support:           YES
  5650:20230904:205444.685 IPv6 support:          YES
  5650:20230904:205444.685 TLS support:           YES
  5650:20230904:205444.685 **************************
  5650:20230904:205444.685 using configuration file: /etc/zabbix/zabbix_proxy.conf
  5650:20230904:205444.699 current database version (mandatory/optional): 05000000/05000007
  5650:20230904:205444.699 required mandatory version: 05000000
  5650:20230904:205444.723 proxy #0 started [main process]
  5655:20230904:205444.725 proxy #1 started [configuration syncer #1]
  5655:20230904:205444.765 cannot obtain configuration data from server at "192.168.3.100": empty string received
  5657:20230904:205444.826 proxy #2 started [trapper #1]
  5658:20230904:205444.827 proxy #3 started [trapper #2]
  5659:20230904:205444.828 proxy #4 started [trapper #3]
  5662:20230904:205444.830 proxy #5 started [trapper #4]
  5663:20230904:205444.831 proxy #6 started [trapper #5]
  5664:20230904:205444.833 proxy #7 started [preprocessing manager #1]
  5668:20230904:205444.836 proxy #8 started [preprocessing worker #1]
  5669:20230904:205444.836 proxy #9 started [preprocessing worker #2]
  5670:20230904:205444.838 proxy #10 started [preprocessing worker #3]
  5671:20230904:205444.839 proxy #11 started [heartbeat sender #1]
  5672:20230904:205444.840 proxy #12 started [data sender #1]
  5673:20230904:205444.842 proxy #13 started [housekeeper #1]
  5675:20230904:205444.843 proxy #14 started [http poller #1]
  5677:20230904:205444.845 proxy #15 started [discoverer #1]
  5671:20230904:205444.845 cannot send heartbeat message to server at "192.168.3.100": proxy "RasPi_01" not found
  5678:20230904:205444.846 proxy #16 started [history syncer #1]
  5682:20230904:205444.850 proxy #18 started [history syncer #3]
  5684:20230904:205444.852 proxy #19 started [history syncer #4]
  5685:20230904:205444.854 proxy #20 started [self-monitoring #1]
  5687:20230904:205444.855 proxy #21 started [task manager #1]
  5688:20230904:205444.858 proxy #22 started [poller #1]
  5690:20230904:205444.859 proxy #23 started [poller #2]
  5679:20230904:205444.861 proxy #17 started [history syncer #2]
  5691:20230904:205444.862 proxy #24 started [poller #3]
  5672:20230904:205444.862 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5695:20230904:205444.865 proxy #25 started [poller #4]
  5697:20230904:205444.866 proxy #26 started [poller #5]
  5699:20230904:205444.868 proxy #27 started [unreachable poller #1]
  5701:20230904:205444.870 proxy #28 started [icmp pinger #1]
  5672:20230904:205445.866 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205446.870 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205447.874 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205448.877 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205449.881 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5658:20230904:205450.233 cannot send list of active checks to "127.0.0.1": host [Zabbix server] not found
  5672:20230904:205450.886 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205451.890 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205452.894 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205453.898 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205454.903 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205455.908 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205456.913 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found

起動は完了。 しかし、Proxy RasPi_01 が見つからない。 Zabbix サーバー側のプロキシに同名のプロキシが登録されていないから。

Zabbix サーバー側にプロキシを追加

Zabbix サーバーの管理画面からログインして、管理 → プロキシで今回のプロキシ名を名前として追加。

Zabbix Proxy 側で以下のコマンドを実行

root@raspberrypi:/home/amegon# zabbix_proxy -R config_cache_reload
zabbix_proxy [5767]: command sent successfully
root@raspberrypi:/home/amegon#

ログを確認。

root@raspberrypi:/home/amegon# tail -f /var/log/zabbix/zabbix_proxy.log
  5672:20230904:205727.631 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205728.635 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205729.639 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205730.644 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205731.648 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205732.653 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
  5672:20230904:205733.657 cannot send proxy data to server at "192.168.3.100": proxy "RasPi_01" not found
zabbix_proxy [5763]: Is this process already running? Could not lock PID file [/var/run/zabbix/zabbix_proxy.pid]: [11] Resource temporarily unavailable
  5655:20230904:205807.966 forced reloading of the configuration cache
  5655:20230904:205807.987 received configuration data from server at "192.168.3.100", datalen 3662

サーバーとの設定同期が実行され、Proxy が見つからないログは停止した。

Zabbix サーバーでプロキシのデータがとれた

最新データ受信時刻 (経過時間) が直近になっていることで、データの受信が行われていることが確認できた。

Zabbix エージェントのインストール

モジュールのインストール

プロキシのインストール時に実施済なのでここでは何もしない。

Zabbix エージェントの設定

実行コマンド

vi /etc/zabbix/zabbix_agentd.conf

編集箇所

HostName=RasPi_01

Zabbix エージェントの再起動

systemctl restart zabbix-agent

エージェントを監視するホストを Zabbix サーバーに作成

ホストに適用しているテンプレートは下記の画像を参照。

設定同期

zabbix_proxy -R config_cache_reload

ログを確認

  4542:20230904:210709.324 Zabbix Agent stopped. Zabbix 5.0.37 (revision 3f4cd9bec9b).
  5838:20230904:210709.382 Starting Zabbix Agent [RasPi_01]. Zabbix 5.0.37 (revision 3f4cd9bec9b).
  5838:20230904:210709.382 **** Enabled features ****
  5838:20230904:210709.382 IPv6 support:          YES
  5838:20230904:210709.382 TLS support:           YES
  5838:20230904:210709.382 **************************
  5838:20230904:210709.382 using configuration file: /etc/zabbix/zabbix_agentd.conf
  5838:20230904:210709.383 agent #0 started [main process]
  5839:20230904:210709.385 agent #1 started [collector]
  5840:20230904:210709.386 agent #2 started [listener #1]
  5841:20230904:210709.387 agent #3 started [listener #2]
  5842:20230904:210709.388 agent #4 started [listener #3]
  5843:20230904:210709.389 agent #5 started [active checks #1]
  5843:20230904:210709.399 no active checks on server [127.0.0.1:10051]: host [RasPi_01] not found
  5843:20230904:210909.428 no active checks on server [127.0.0.1:10051]: host [RasPi_01] not found
  5843:20230904:211109.459 no active checks on server [127.0.0.1:10051]: host [RasPi_01] not found

host [RasPi_01] not found のログはとまった。 また、Zabbix サーバーで監視データがとれるようになった。

Zabbix エージェントの監視データ確認

とれていた。

インストール後の状態

そんなに負荷がかかっているようにも見えない。
じゅうぶん使えそうだと期待してしまいそう。

root@raspberrypi:/home/amegon# df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
/dev/root         56G   12G   42G   22% /
devtmpfs         3.6G     0  3.6G    0% /dev
tmpfs            3.9G     0  3.9G    0% /dev/shm
tmpfs            1.6G  1.2M  1.6G    1% /run
tmpfs            5.0M  4.0K  5.0M    1% /run/lock
/dev/mmcblk0p6   253M   51M  202M   20% /boot
tmpfs            782M   32K  782M    1% /run/user/1000
root@raspberrypi:/home/amegon#
root@raspberrypi:/home/amegon# free -h
               total        used        free      shared  buff/cache   available
Mem:           7.6Gi       318Mi       6.5Gi        53Mi       806Mi       7.1Gi
Swap:           99Mi          0B        99Mi
root@raspberrypi:/home/amegon#

Zabbix エージェントで mysql の監視

MySQL 関連の監視データがとれていない

template_db_mysql.conf の作成

Raspbbery Pi に以下のファイルを保存。

  • 保存ファイル: /etc/zabbix/zabbix_agentd.d/template_db_mysql.conf
  • ファイルの所有者: root
  • ファイルのパーミッション: 644
  • ファイルの内容:
UserParameter=mysql.ping[*], mysqladmin --defaults-extra-file=/var/lib/zabbix/.my.cnf 
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | mysql --defaults-extra-file=/var/lib/zabbix/.my.cnf -N | awk '{print $$2}' 
UserParameter=mysql.get_status_variables[*], mysql --defaults-extra-file=/var/lib/zabbix/.my.cnf -sNX -e "show global status" 
UserParameter=mysql.version[*], mysqladmin --defaults-extra-file=/var/lib/zabbix/.my.cnf -s version 
UserParameter=mysql.db.discovery[*], mysql --defaults-extra-file=/var/lib/zabbix/.my.cnf -sN -e "show databases" 
UserParameter=mysql.dbsize[*], mysql --defaults-extra-file=/var/lib/zabbix/.my.cnf -sN -e "SELECT SUM(DATA_LENGTH + INDEX_LENGTH) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'" 
UserParameter=mysql.replication.discovery[*], mysql --defaults-extra-file=/var/lib/zabbix/.my.cnf -sNX -e "show slave status" 
UserParameter=mysql.slave_status[*], mysql --defaults-extra-file=/var/lib/zabbix/.my.cnf -sNX -e "show slave status"

my.cnf の作成

Raspbbery Pi に以下のファイルを保存。

  • 保存ファイル: /var/lib/zabbix/my.cnf
  • ファイルの所有者: root
  • ファイルのパーミッション: 644
  • ファイルの内容:
[client]
user='zabbix'
password='zabbix'

Zabbix エージェントの再起動

systemctl restart zabbix-agent

Zabbix で監視アイテムの確認

とれました。