Ubuntu Server 22.04 LTSにOctoPrintを導入

2022年6月2日木曜日

Linux Rasberry Pi

t f B! P L
010_Ubuntu Server 22.04 LTSにOctoPrintを導入.md

概要

Ubuntu Server 22.04 LTSでOctoPrintを使うのが目的です。
OctoPrintにカメラ機能を連携させるため、MJPG-Streamerも動作させます。
デフォルトだと、OctoPrintは5000/tcp、MJPG-Streamerは8080/tcpで動きますが、ユーザビリティ向上のためにhaproxyをリバースプロキシ用途で使い、OctoPrintは「 http://IPアドレス 」、MJPG-Streamerは「 http://IPアドレス/webcam 」でもアクセス出来るようにします。

前提

以下構成を前提にしています。
ハードウェアやソフトウェアのバージョンが異なると手順が異なる可能性があります。

  • Raspberry Pi 4 Model Bのメモリ8GBモデル
  • Raspberry Pi HQ Camera
  • Raspberry Pi HQ Camera用6 mm 広角レンズ
  • Ubuntu 22.04 LTS
  • OctoPrint 1.8.1
  • haproxy 2.4.14-1
  • mjpg-streamer v1.0.0

以下の続きの記事です。

Rasberry Pi 4 Model BにUbuntu Server 22.04 LTSを導入

Ubuntu Server 22.04 LTSのシステムアップデートと時刻同期設定

Ubuntu Server 22.04 LTSでGoogle DomainsのダイナミックDNSを自動更新

Ubuntu Server 22.04 LTSにWireGuardを導入

環境構築

Raspberry Pi HQ Cameraの認識

vcgencmd get_cameraの結果が、supported=1 detected=1になればカメラは正常に認識しています。 それ以外はカメラが正常に認識していない状態です。

  1. HQ Cameraの場合は、デフォルト状態ではカメラが認識しません。
username@ubuntu:~$ vcgencmd get_camera supported=0 detected=0
  1. HQ Cameraが認識するように設定を変更します。
username@ubuntu:~$ sudo vi /boot/firmware/config.txt

[all]セクションの設定を変更と追記。

[all]セクションにあるcamera_auto_detectの設定を無効にし、カメラの自動認識機能をオフにする。 ~~~ camera_auto_detect=1 ↓ camera_auto_detect=0 ~~~ [all]セクションの末尾に以下を追記して、HQ Cameraが認識するように設定。 ~~~ # Raspberry Pi HQ Camera start_x=1 gpu_mem=256 ~~~
  1. カメラが認識している事を確認します。
    supportedとdetectedがどちらも1になっていれば、正常に認識しています。
username@ubuntu:~$ vcgencmd get_camera supported=1 detected=1

mjpg-streamerの導入

  1. mjpg-streamerの導入に必要になるcmakeとlibjpeg9-dev、gcc、g++をインストールします。
username@ubuntu:~$ sudo apt-get install cmake libjpeg9-dev gcc g++
  1. Ubuntuのインストール時に作成した一般ユーザのhomeディレクトリにインストールします。
username@ubuntu:~$ cd ~ username@ubuntu:~$ git clone https://github.com/jacksonliam/mjpg-streamer.git Cloning into 'mjpg-streamer'... remote: Enumerating objects: 2964, done. remote: Total 2964 (delta 0), reused 0 (delta 0), pack-reused 2964 Receiving objects: 100% (2964/2964), 3.48 MiB | 4.30 MiB/s, done. Resolving deltas: 100% (1885/1885), done. username@ubuntu:~$ ls mjpg-streamer username@ubuntu:~$ export LD_LIBRARY_PATH=. username@ubuntu:~$ cd mjpg-streamer/mjpg-streamer-experimental username@ubuntu:~/mjpg-streamer/mjpg-streamer-experimental$ make
  1. mjpg-streamerのテスト実行。終了するにはCtrl+Cです。

mjpg-streamerの実行例

  • QVGA 320x240、フレームレート30fps、待ち受けポート8080/tcp
    • ./mjpg_streamer -i "./input_uvc.so -n -d /dev/video0 -r QVGA -f 30" -o "./output_http.so -w ./www -p 8080"
  • VGA 640x480、フレームレート30fps、待ち受けポート8080/tcp
    • ./mjpg_streamer -i "./input_uvc.so -n -d /dev/video0 -r VGA -f 30" -o "./output_http.so -w ./www -p 8080"
  • VGA 640x480、フレームレート30fps、待ち受けポート8080/tcp、ユーザ名fooでパスワードbarの認証
    • ./mjpg_streamer -i "./input_uvc.so -n -d /dev/video0 -r QVGA -f 30" -o "./output_http.so -w ./www -p 8080 -c foo:bar"

mjpg_streamerのUsageは以下で表示できます。

username@ubuntu:~/mjpg-streamer/mjpg-streamer-experimental$ ./mjpg_streamer --help ----------------------------------------------------------------------- Usage: ./mjpg_streamer -i | --input "<input-plugin.so> [parameters]" -o | --output "<output-plugin.so> [parameters]" [-h | --help ]........: display this help [-v | --version ].....: display version information [-b | --background]...: fork to the background, daemon mode ----------------------------------------------------------------------- Example #1: To open an UVC webcam "/dev/video1" and stream it via HTTP: ./mjpg_streamer -i "input_uvc.so -d /dev/video1" -o "output_http.so" ----------------------------------------------------------------------- Example #2: To open an UVC webcam and stream via HTTP port 8090: ./mjpg_streamer -i "input_uvc.so" -o "output_http.so -p 8090" ----------------------------------------------------------------------- Example #3: To get help for a certain input plugin: ./mjpg_streamer -i "input_uvc.so --help" ----------------------------------------------------------------------- In case the modules (=plugins) can not be found: * Set the default search path for the modules with: export LD_LIBRARY_PATH=/path/to/plugins, * or put the plugins into the "/lib/" or "/usr/lib" folder, * or instead of just providing the plugin file name, use a complete path and filename: ./mjpg_streamer -i "/path/to/modules/input_uvc.so" -----------------------------------------------------------------------

input_uvc.soのUsageは以下で表示できます。

username@ubuntu:~/mjpg-streamer/mjpg-streamer-experimental$ ./mjpg_streamer -i 'input_uvc.so --help' MJPG Streamer Version: git rev: 310b29f4a94c46652b20c4b7b6e5cf24e532af39 --------------------------------------------------------------- Help for input plugin..: UVC webcam grabber --------------------------------------------------------------- The following parameters can be passed to this plugin: [-d | --device ].......: video device to open (your camera) [-r | --resolution ]...: the resolution of the video device, can be one of the following strings: QQVGA QCIF CGA QVGA CIF PAL VGA SVGA XGA HD SXGA UXGA FHD or a custom value like the following example: 640x480 [-f | --fps ]..........: frames per second (camera may coerce to different value) [-q | --quality ] .....: set quality of JPEG encoding [-m | --minimum_size ].: drop frames smaller then this limit, useful if the webcam produces small-sized garbage frames may happen under low light conditions [-e | --every_frame ]..: drop all frames except numbered [-n | --no_dynctrl ]...: do not initalize dynctrls of Linux-UVC driver [-l | --led ]..........: switch the LED "on", "off", let it "blink" or leave it up to the driver using the value "auto" [-t | --tvnorm ] ......: set TV-Norm pal, ntsc or secam [-u | --uyvy ] ........: Use UYVY format, default: MJPEG (uses more cpu power) [-y | --yuv ] ........: Use YUV format, default: MJPEG (uses more cpu power) [-fourcc ] ............: Use FOURCC codec 'argopt', currently supported codecs are: RGB24, RGBP [-timestamp ]..........: Populate frame timestamp with system time [-softfps] ............: Drop frames to try and achieve this fps set your camera to its maximum fps to avoid stuttering [-timeout] ............: Timeout for device querying (seconds) [-dv_timings] .........: Enable DV timings queriyng and events processing --------------------------------------------------------------- Optional parameters (may not be supported by all cameras): [-br ].................: Set image brightness (auto or integer) [-co ].................: Set image contrast (integer) [-sh ].................: Set image sharpness (integer) [-sa ].................: Set image saturation (integer) [-cb ].................: Set color balance (auto or integer) [-wb ].................: Set white balance (auto or integer) [-ex ].................: Set exposure (auto, shutter-priority, aperature-priority, or integer) [-bk ].................: Set backlight compensation (integer) [-rot ]................: Set image rotation (0-359) [-hf ].................: Set horizontal flip (true/false) [-vf ].................: Set vertical flip (true/false) [-pl ].................: Set power line filter (disabled, 50hz, 60hz, auto) [-gain ]...............: Set gain (auto or integer) [-cagc ]...............: Set chroma gain control (auto or integer) --------------------------------------------------------------- input_init() return value signals to exit

output_http.soのUsageは以下で表示できます。

username@ubuntu:~/mjpg-streamer/mjpg-streamer-experimental$ ./mjpg_streamer -o "./output_http.so --help" MJPG Streamer Version: git rev: 310b29f4a94c46652b20c4b7b6e5cf24e532af39 --------------------------------------------------------------- Help for output plugin..: HTTP output plugin --------------------------------------------------------------- The following parameters can be passed to this plugin: [-w | --www ]...........: folder that contains webpages in flat hierarchy (no subfolders) [-p | --port ]..........: TCP port for this HTTP server [-l ] --listen ]........: Listen on Hostname / IP [-c | --credentials ]...: ask for "username:password" on connect [-n | --nocommands ]....: disable execution of commands --------------------------------------------------------------- output_init() return value signals to exit username@ubuntu:~/mjpg-streamer/mjpg-streamer-experimental$
  1. mjpg-streamerをsystemdサービスにするための設定ファイルをヒアドキュメントで作成する。
username@ubuntu:~$ sudo -i [sudo] password for username: root@ubuntu:~# cat <<EOF > /etc/systemd/system/mjpg-streamer.service [Unit] Description=MJPG-Streamer After=network-online.target Wants=network-online.target [Service] Type=simple User=username ExecStart=/home/username/mjpg-streamer/mjpg-streamer-experimental/mjpg_streamer -i "/home/username/mjpg-streamer/mjpg-streamer-experimental/input_uvc.so -n -d /dev/video0 -r VGA -f 30" -o "/home/username/mjpg-streamer/mjpg-streamer-experimental/output_http.so -w /home/username/mjpg-streamer/mjpg-streamer-experimental/www -p 8080" Restart=always [Install] WantedBy=multi-user.target EOF
  1. 作成したmjpg-streamerのsystemdサービスを起動し、自動起動を有効にする。
root@ubuntu:~# systemctl daemon-reload root@ubuntu:~# systemctl status mjpg-streamer ○ mjpg-streamer.service - MJPG-Streamer Loaded: loaded (/etc/systemd/system/mjpg-streamer.service; disabled; vendor preset: enabled) Active: inactive (dead) May 29 19:18:50 ubuntu mjpg_streamer[736]: MJPG-streamer [736]: HTTP TCP port........: 8080 May 29 19:18:50 ubuntu mjpg_streamer[736]: MJPG-streamer [736]: HTTP Listen Address..: (null) May 29 19:18:50 ubuntu mjpg_streamer[736]: MJPG-streamer [736]: username:password....: disabled May 29 19:18:50 ubuntu mjpg_streamer[736]: MJPG-streamer [736]: commands.............: enabled May 29 19:18:50 ubuntu mjpg_streamer[736]: MJPG-streamer [736]: starting input plugin /home/username/mjpg-streamer/mjpg-streamer-experimental/input_uvc.so May 29 19:18:50 ubuntu mjpg_streamer[736]: MJPG-streamer [736]: starting output plugin: /home/username/mjpg-streamer/mjpg-streamer-experimental/output_http.so (ID: 00) May 30 19:40:18 ubuntu systemd[1]: Stopping MJPG-Streamer... May 30 19:40:18 ubuntu systemd[1]: mjpg-streamer.service: Deactivated successfully. May 30 19:40:18 ubuntu systemd[1]: Stopped MJPG-Streamer. May 30 19:40:18 ubuntu systemd[1]: mjpg-streamer.service: Consumed 8min 30.266s CPU time. root@ubuntu:~# systemctl start mjpg-streamer root@ubuntu:~# systemctl status mjpg-streamer ● mjpg-streamer.service - MJPG-Streamer Loaded: loaded (/etc/systemd/system/mjpg-streamer.service; disabled; vendor preset: enabled) Active: active (running) since Mon 2022-05-30 19:42:29 JST; 6s ago Main PID: 4589 (mjpg_streamer) Tasks: 3 (limit: 9027) Memory: 436.0K CPU: 50ms CGroup: /system.slice/mjpg-streamer.service mq4589 /home/username/mjpg-streamer/mjpg-streamer-experimental/mjpg_streamer -i "/home/username/mjpg-streamer/mjpg-streamer-experimental/input_uvc.so -n -d /dev/video0 -r VGA -f > May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: Frames Per Second.: 30 May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: Format............: JPEG May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: TV-Norm...........: DEFAULT May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: www-folder-path......: /home/username/mjpg-streamer/mjpg-streamer-experimental/www/ May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: HTTP TCP port........: 8080 May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: HTTP Listen Address..: (null) May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: username:password....: disabled May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: commands.............: enabled May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: starting input plugin /home/username/mjpg-streamer/mjpg-streamer-experimental/input_uvc.so May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: starting output plugin: /home/username/mjpg-streamer/mjpg-streamer-experimental/output_http.so (ID: 00) root@ubuntu:~# systemctl enable mjpg-streamer Created symlink /etc/systemd/system/multi-user.target.wants/mjpg-streamer.service → /etc/systemd/system/mjpg-streamer.service. root@ubuntu:~# systemctl status mjpg-streamer ● mjpg-streamer.service - MJPG-Streamer Loaded: loaded (/etc/systemd/system/mjpg-streamer.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2022-05-30 19:42:29 JST; 37s ago Main PID: 4589 (mjpg_streamer) Tasks: 3 (limit: 9027) Memory: 436.0K CPU: 228ms CGroup: /system.slice/mjpg-streamer.service mq4589 /home/username/mjpg-streamer/mjpg-streamer-experimental/mjpg_streamer -i "/home/username/mjpg-streamer/mjpg-streamer-experimental/input_uvc.so -n -d /dev/video0 -r VGA -f > May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: Frames Per Second.: 30 May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: Format............: JPEG May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: TV-Norm...........: DEFAULT May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: www-folder-path......: /home/username/mjpg-streamer/mjpg-streamer-experimental/www/ May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: HTTP TCP port........: 8080 May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: HTTP Listen Address..: (null) May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: username:password....: disabled May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: commands.............: enabled May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: starting input plugin /home/username/mjpg-streamer/mjpg-streamer-experimental/input_uvc.so May 30 19:42:29 ubuntu mjpg_streamer[4589]: MJPG-streamer [4589]: starting output plugin: /home/username/mjpg-streamer/mjpg-streamer-experimental/output_http.so (ID: 00) root@ubuntu:~#
  1. mjpg-streamerに http://IPアドレス:8080 でアクセスし、Streamページを押してカメラの画像がリアルタイムに配信出来ている事を確認します。

OctoPrintの導入

  1. OctoPrintをインストールします。
    OctoPrint 1.8.0以降はPython2では動作しないため、Python3が必要です。
    一般ユーザのhomeディレクトリにインストールする場合の手順です。
username@ubuntu:~$ python3 --version Python 3.10.4 username@ubuntu:~$ sudo apt install python3-pip python3-dev python3-venv libyaml-dev build-essential username@ubuntu:~$ mkdir OctoPrint && cd OctoPrint username@ubuntu:~/OctoPrint$ python3 -m venv venv username@ubuntu:~/OctoPrint$ source venv/bin/activate (venv) username@ubuntu:~/OctoPrint$ pip install pip --upgrade Requirement already satisfied: pip in ./venv/lib/python3.10/site-packages (22.0.2) Collecting pip Downloading pip-22.1.1-py3-none-any.whl (2.1 MB) qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq 2.1/2.1 MB 6.6 MB/s eta 0:00:00 Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 22.0.2 Uninstalling pip-22.0.2: Successfully uninstalled pip-22.0.2 Successfully installed pip-22.1.1 (venv) username@ubuntu:~/OctoPrint$ pip install octoprint
  1. USB接続された3Dプリンターにフルアクセスするため、dialoutグループとttyグループに所属している必要があります。
    Ubuntu Server 22.04 LTSの場合、デフォルトでdialoutグループには所属していたのでttyグループにのみ追加します。
(venv) username@ubuntu:~/OctoPrint$ sudo cat /etc/group|egrep "dialout|tty" tty:x:5: dialout:x:20:username (venv) username@ubuntu:~/OctoPrint$ sudo usermod -a -G tty username (venv) username@ubuntu:~/OctoPrint$ sudo cat /etc/group|egrep "dialout|tty" tty:x:5:username dialout:x:20:username
  1. OctoPrintの手動起動をします。
    systemdサービス化する前のテスト実行です。
(venv) username@ubuntu:~/OctoPrint$ ~/OctoPrint/venv/bin/octoprint serve
  1. OctoPrintをsystemdサービスにするための設定ファイルをヒアドキュメントで作成する。
(venv) username@ubuntu:~/OctoPrint$ deactivate username@ubuntu:~/OctoPrint$ username@ubuntu:~/OctoPrint$ sudo -i [sudo] password for username: root@ubuntu:~# cat <<EOF > /etc/systemd/system/octoprint.service [Unit] Description=The snappy web interface for your 3D printer After=network-online.target Wants=network-online.target [Service] Environment="LC_ALL=C.UTF-8" Environment="LANG=C.UTF-8" Type=exec User=username ExecStart=/home/username/OctoPrint/venv/bin/octoprint [Install] WantedBy=multi-user.target EOF
  1. 作成したOctoPrintのsystemdサービスを起動し、自動起動を有効にする。
root@ubuntu:~# systemctl daemon-reload root@ubuntu:~# systemctl status octoprint ● octoprint.service - The snappy web interface for your 3D printer Loaded: loaded (/etc/systemd/system/octoprint.service; disabled; vendor preset: enabled) Active: active (running) since Tue 2022-05-31 23:24:08 JST; 38s ago Main PID: 1253 (octoprint) Tasks: 13 (limit: 9027) Memory: 73.7M CPU: 13.334s CGroup: /system.slice/octoprint.service mq1253 /home/username/OctoPrint/venv/bin/python3 /home/username/OctoPrint/venv/bin/octoprint May 31 23:24:16 ubuntu octoprint[1253]: 2022-05-31 23:24:16,906 - octoprint.util.pip - INFO - Using "/home/username/OctoPrint/venv/bin/python3 -m pip" as command to invoke pip May 31 23:24:16 ubuntu octoprint[1253]: 2022-05-31 23:24:16,911 - octoprint.util.pip - INFO - pip installs to /home/username/OctoPrint/venv/lib/python3.10/site-packages (writable -> yes), --user flag needed -> no, virtual env -> yes May 31 23:24:16 ubuntu octoprint[1253]: 2022-05-31 23:24:16,911 - octoprint.util.pip - INFO - ==> pip ok -> yes May 31 23:24:16 ubuntu octoprint[1253]: 2022-05-31 23:24:16,918 - octoprint.plugins.pluginmanager - INFO - Loaded notice data from disk, was still valid May 31 23:24:16 ubuntu octoprint[1253]: 2022-05-31 23:24:16,929 - octoprint.plugins.softwareupdate - INFO - Minimum free storage across all update relevant locations is 52.0GB. That is considered sufficient for updating. May 31 23:24:16 ubuntu octoprint[1253]: 2022-05-31 23:24:16,930 - octoprint.plugins.softwareupdate - INFO - Fetching check overlays from https://plugins.octoprint.org/update_check_overlay.json May 31 23:24:17 ubuntu octoprint[1253]: 2022-05-31 23:24:17,920 - octoprint.server.preemptive_cache - INFO - Preemptively caching / (ui _default) for {'base_url': 'http://192.168.1.50/', 'path': '/', 'query_string': 'l10n=en'} May 31 23:24:22 ubuntu octoprint[1253]: 2022-05-31 23:24:22,524 - octoprint.server.preemptive_cache - INFO - ... done in 4.60s May 31 23:24:22 ubuntu octoprint[1253]: 2022-05-31 23:24:22,525 - octoprint.server.preemptive_cache - INFO - Preemptively caching / (ui _default) for {'base_url': 'http://192.168.1.50:5000/', 'path': '/', 'query_string': 'l10n=en'} May 31 23:24:23 ubuntu octoprint[1253]: 2022-05-31 23:24:23,253 - octoprint.server.preemptive_cache - INFO - ... done in 0.73s root@ubuntu:~# systemctl enable octoprint Created symlink /etc/systemd/system/multi-user.target.wants/octoprint.service → /etc/systemd/system/octoprint.service. root@ubuntu:~# systemctl status octoprint ● octoprint.service - The snappy web interface for your 3D printer Loaded: loaded (/etc/systemd/system/octoprint.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2022-05-31 23:24:08 JST; 2min 28s ago Main PID: 1253 (octoprint) Tasks: 13 (limit: 9027) Memory: 73.8M CPU: 13.547s CGroup: /system.slice/octoprint.service mq1253 /home/username/OctoPrint/venv/bin/python3 /home/username/OctoPrint/venv/bin/octoprint May 31 23:24:16 ubuntu octoprint[1253]: 2022-05-31 23:24:16,906 - octoprint.util.pip - INFO - Using "/home/username/OctoPrint/venv/bin/python3 -m pip" as command to invoke pip May 31 23:24:16 ubuntu octoprint[1253]: 2022-05-31 23:24:16,911 - octoprint.util.pip - INFO - pip installs to /home/username/OctoPrint/venv/lib/python3.10/site-packages (writable -> yes), --user flag needed -> no, virtual env -> yes May 31 23:24:16 ubuntu octoprint[1253]: 2022-05-31 23:24:16,911 - octoprint.util.pip - INFO - ==> pip ok -> yes May 31 23:24:16 ubuntu octoprint[1253]: 2022-05-31 23:24:16,918 - octoprint.plugins.pluginmanager - INFO - Loaded notice data from disk, was still valid May 31 23:24:16 ubuntu octoprint[1253]: 2022-05-31 23:24:16,929 - octoprint.plugins.softwareupdate - INFO - Minimum free storage across all update relevant locations is 52.0GB. That is considered sufficient for updating. May 31 23:24:16 ubuntu octoprint[1253]: 2022-05-31 23:24:16,930 - octoprint.plugins.softwareupdate - INFO - Fetching check overlays from https://plugins.octoprint.org/update_check_overlay.json May 31 23:24:17 ubuntu octoprint[1253]: 2022-05-31 23:24:17,920 - octoprint.server.preemptive_cache - INFO - Preemptively caching / (ui _default) for {'base_url': 'http://192.168.1.50/', 'path': '/', 'query_string': 'l10n=en'} May 31 23:24:22 ubuntu octoprint[1253]: 2022-05-31 23:24:22,524 - octoprint.server.preemptive_cache - INFO - ... done in 4.60s May 31 23:24:22 ubuntu octoprint[1253]: 2022-05-31 23:24:22,525 - octoprint.server.preemptive_cache - INFO - Preemptively caching / (ui _default) for {'base_url': 'http://192.168.1.50:5000/', 'path': '/', 'query_string': 'l10n=en'} May 31 23:24:23 ubuntu octoprint[1253]: 2022-05-31 23:24:23,253 - octoprint.server.preemptive_cache - INFO - ... done in 0.73s

haproxyの導入

  1. haproxyをインストールします。
username@ubuntu:~$ sudo apt install haproxy
  1. /etc/haproxy/haproxy.cfgの末尾に設定を追加。
username@ubuntu:~$ sudo vi /etc/haproxy/haproxy.cfg

globalセクション、defaultsセクションは変更せず、frontend public以降を追記しています。

global log /dev/log local0 log /dev/log local1 notice chroot /var/lib/haproxy stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners stats timeout 30s user haproxy group haproxy daemon # Default SSL material locations ca-base /etc/ssl/certs crt-base /etc/ssl/private # See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384 ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256 ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets defaults log global mode http option httplog option dontlognull timeout connect 5000 timeout client 50000 timeout server 50000 errorfile 400 /etc/haproxy/errors/400.http errorfile 403 /etc/haproxy/errors/403.http errorfile 408 /etc/haproxy/errors/408.http errorfile 500 /etc/haproxy/errors/500.http errorfile 502 /etc/haproxy/errors/502.http errorfile 503 /etc/haproxy/errors/503.http errorfile 504 /etc/haproxy/errors/504.http frontend public bind :::80 v4v6 use_backend webcam if { path_beg /webcam/ } default_backend octoprint backend octoprint option forwardfor server octoprint1 127.0.0.1:5000 backend webcam http-request replace-path /webcam/(.*) /\1 server webcam1 127.0.0.1:8080
  1. 手動で起動する事を確認する。
    自動起動はインストールしたら最初から有効だったので、手動でhaproxyが起動するかを確認します。
    もし、自動起動が有効でなかったらsudo systemctl enable haproxyで設定します。
username@ubuntu:~$ sudo systemctl start haproxy username@ubuntu:~$ sudo systemctl status haproxy ● haproxy.service - HAProxy Load Balancer Loaded: loaded (/lib/systemd/system/haproxy.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2022-06-02 10:27:15 JST; 4h 17min ago Docs: man:haproxy(1) file:/usr/share/doc/haproxy/configuration.txt.gz Process: 761 ExecStartPre=/usr/sbin/haproxy -Ws -f $CONFIG -c -q $EXTRAOPTS (code=exited, status=0/SUCCESS) Main PID: 811 (haproxy) Tasks: 5 (limit: 9027) Memory: 73.2M CPU: 685ms CGroup: /system.slice/haproxy.service tq811 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /run/haproxy-master.sock mq825 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /run/haproxy-master.sock Jun 02 10:27:14 ubuntu systemd[1]: Starting HAProxy Load Balancer... Jun 02 10:27:15 ubuntu haproxy[811]: [NOTICE] (811) : New worker #1 (825) forked Jun 02 10:27:15 ubuntu systemd[1]: Started HAProxy Load Balancer.
  1. 「 http://IPアドレス 」でOctoPrintに、「 http://IPアドレス/webcam 」でMJPG-Streamerにアクセス出来る事を確認する。

QooQ