2024年10月17日木曜日

KubernetesでPostgreSQLをアップグレードする方法

KubernetesでPostgreSQLをアップグレードする場合、以下の順序でバージョンアップを行います。

1. 現バージョンでバックアップを取得
kubectl exec --stdin ※ポッド名 --container ※コンテナ名 -- /usr/local/bin/pg_dumpall -U postgres > dumpall.sql

2. バージョンアップ後に使用するPV/PVCを作成

3. deploymentなどで使用するPostgreSQLのイメージを新しいものに変更し、PVCもあたらしいものを参照するようにymlを更新。kubectl applyで反映。

4. 新バージョンでデータをインポート
cat dumpall.sql | kubectl exec --stdin ※ポッド名 --container ※コンテナ名 -- /usr/local/bin/psql -U postgres

5. 動作確認後、古いバージョンのPV/PVCを削除

2024年10月16日水曜日

Kubernetesでポッド内のコンテナのマウント名とパスを一覧表示する

Kubernetesでポッド内のコンテナのマウント名とパスを一覧表示するには、以下のコマンドを実行します

1.ポッド一覧を取得
kubectl get pods

2.ポッドのコンテナ内のマウント名とパスを一覧表示
kubectl get pod ※1で取得したポッド名 -o jsonpath='{range .spec.containers[*]}{.name}{"\n"}{range .volumeMounts[*]}{"- "}{.name}{":"}{.mountPath}{"\n"}{end}{end}'

2024年10月15日火曜日

Kubernetesでポッド内のコンテナ名とイメージ名を一覧表示する

Kubernetesでポッド内のコンテナ名とイメージ名を一覧表示するには、以下のコマンドを実行します
1.ポッド一覧を取得
kubectl get pods

2.コンテナ名とイメージ名を一覧表示
kubectl get pod ※1で取得したポッド名 -o jsonpath='{range .spec.containers[*]}{.name}{":"}{.image}{"\n"}{end}'

2024年8月29日木曜日

Ubuntu24.04にLangFlowをインストールする

Ubuntu24.04でpipenvを使用してLangFlowをインストールするには、以下の手順を実行します。

1.pipenvのインストール
sudo apt-get -y install python3-pip python3-dev python3-testresources pipenv 

echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.profile

source ~/.profile

2. LangFlowをインストール
mkdir ~/langflow

cd ~/langflow

pipenv install langflow

3. LangFlowをサービスとして登録
※ユーザ名・パスは適宜変更してください。
cat << EOF | sudo tee /etc/systemd/system/langflow.service
[Unit]
Description=LangFlow
[Service]
Type=simple
ExecStart=/home/ubuntu/langflow/.venv/bin/langflow run --host 0.0.0.0
User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu/langflow
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF

sudo systemctl enable langflow

sudo systemctl start langflow

4. ブラウザでLangFlowにアクセスします。

http://ホスト名またはIPアドレス:7860

2024年7月7日日曜日

Ubuntu24.04にllama.cppをインストールしてLlama-3-ELYZA-JP-8B-q4_k_m.ggufモデルで対話を行う

Llama.cppをインストールして、Llama-3-ELYZA-JP-8B-q4_k_m.ggufモデルでい対話するには以下のコマンドを実行します。
wget https://github.com/ggerganov/llama.cpp/releases/download/b3328/llama-b3328-bin-ubuntu-x64.zip

unzip ./llama-b3328-bin-ubuntu-x64.zip

cd ./build/bin

wget https://huggingface.co/elyza/Llama-3-ELYZA-JP-8B-GGUF/resolve/main/Llama-3-ELYZA-JP-8B-q4_k_m.gguf?download=true -O Llama-3-ELYZA-JP-8B-q4_k_m.gguf

./llama-cli -m Llama-3-ELYZA-JP-8B-q4_k_m.gguf -p "あなたは優秀なアシスタントです" -cnv
この後は対話文を入力します。対話を終了するときはCtrl+Cを押します。

2024年1月24日水曜日

CPUだけで高速にAI画像を生成できるFastSD CPUをUbuntu22.04にインストールする

FastSD CPUでGPUを使用しなくても高速にAI画像を生成することができます。

インストール方法

Ubuntu22.04にFastSD CPUをインストールするには以下の手順を実行します。
sudo apt-get -y install python3.10-venv

wget https://github.com/rupeshs/fastsdcpu/archive/refs/tags/v1.0.0-beta.23.tar.gz

tar xvfz ./v1.0.0-beta.23.tar.gz

cd fastsdcpu-1.0.0-beta.23/

chmod +x install.sh

※server外からwebuiにアクセスしたい場合は以下のファイルを変更します。
vi src/frontend/webui/ui.py
以下の行を
webui.launch(share=share)
以下に変更
webui.launch(share=share, server_name='0.0.0.0')

./start-webui.sh

ブラウザから以下にアクセスします
http://{ubuntuのIP}:7860

サンプル画像

2024年1月8日月曜日

Ubuntu 22.04にOpenCVをインストールしてネットワークカメラの画像を保存する

Ubuntu 22.04にOpenCVをインストールしてネットワークカメラの画像を保存するには、以下の手順を実行します。

1.pipenvのインストール

sudo apt-get -y install python3-pip python3-distutils python3-dev python3-testresources

python3 -m pip install --user pipenv

echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.profile

echo 'export PATH=$PATH:$HOME/.local/bin' >> ~/.profile

source ~/.profile

2. opencvをインストールした環境を作成

mkdir dev_opencv
※ディレクトリは適宜変更してください
cd dev_opencv

pipenv --python 3

pipenv install opencv-python

pipenv shell

3. RTSPプロトコルで配信されたカメラ画像を保存するプログラムの作成と実行

test.py
import cv2

# RTSPのURLは適宜適宜変更してください
RTSP_URL = 'rtsp://xxx.xxx.xxx.xxx:8554/cam'
cap = cv2.VideoCapture(RTSP_URL, cv2.CAP_FFMPEG)
result, image = cap.read()
if result:
    cv2.imwrite("camera.png", image)

実行
python test.py