はじめに
1台の使用していないPC(Ubuntu PC)でOllamaを実行してサーバーとして動かしてみました。別のWindows PCでWSL上のUbuntuにDifyをインストールして、他のPC(Ubuntu PC)のOllamaにアクセスします。家庭内のLANで接続しただけなので、この場合に「サーバー」という単語が適切かどうかはわかりません。使用したPC
1台目:Ubuntu 22.04 2台目:Ubuntu 24.04 on WSL2 (Windows 11)
Ubuntu側の設定
OllamaはDockerを使わずに以下のコマンドでインストールしました。Dockerを使うとIP Addressが変わってしまうと思います。
curl -fsSL https://ollama.com/install.sh | sh
Ollamaの設定変更
「/etc/systemd/system/ollama.service」内の[Service]に「Environment="OLLAMA_HOST=0.0.0.0"」を追記する必要があります。以下を実行してエディタを開き追記します。
sudo nano /etc/systemd/system/ollama.service
確認は以下のコマンドです。
sudo ss -anpt | grep ollama
このようになっていれば成功です。
ISTEN 0 4096 *:11434 *:* users:(("ollama",pid=1260,fd=3))
UbuntuのIP addressを調べる
ip addr show
UbuntuのIP addressはWindows側の設定で使用します。
今回は仮に「192.168.0.12」だったとしてこの先に進みます。
Windows側の設定
ここからはセキュリティーに関わる設定になりますので自己責任でお願いします。例えば今回の方法よりもセキュリティを弱めない他の方法があるかもしれません。
設定1
「設定」→「プライバシーとセキュリティ」→「Windowsセキュリティ」→「ファイアウォールとネットワーク保護」→「詳細設定」→「受信の規則」→「新しい規則」を選択して以下のように設定します。![](https://cdn-ak.f.st-hatena.com/images/fotolife/t/touch-sp/20240526/20240526125435.jpg)
![](https://cdn-ak.f.st-hatena.com/images/fotolife/t/touch-sp/20240526/20240526125444.jpg)
![](https://cdn-ak.f.st-hatena.com/images/fotolife/t/touch-sp/20240526/20240526125452.jpg)
![](https://cdn-ak.f.st-hatena.com/images/fotolife/t/touch-sp/20240526/20240526125459.jpg)
![](https://cdn-ak.f.st-hatena.com/images/fotolife/t/touch-sp/20240526/20240526125506.jpg)
設定2
管理者権限でPowerShellを開いて以下を実行します。netsh interface portproxy delete v4tov4 listenport=11434
以前に設定していなければこのコマンドはエラーを出します。無視して下さい。
次に以下を実行します。(IP addressは各自変更して下さい)
$ip = "192.168.0.12" netsh interface portproxy add v4tov4 listenport=11434 connectaddress=$ip
確認は以下のコマンドです。
netsh interface portproxy show all
このようになれば成功です。
ipv4 をリッスンする: ipv4 に接続する: Address Port Address Port --------------- ---------- --------------- ---------- * 11434 192.168.0.12 11434
最終確認
Windows側のPowerShellから以下を実行します。(IP addressは各自変更して下さい)curl http://192.168.0.12:11434
このようになれば成功です。
Ollama is running
参考にさせて頂いたサイト
qiita.com![このエントリーをはてなブックマークに追加](https://b.st-hatena.com/images/v4/public/entry-button/button-only@2x.png)