そろそろUbuntu 24にしたい&サーバー代を節約したい。ということで、ふと思い立って鯖移転& 初期OSをUbuntu 24にしました。 ## やったやつ・やる予定 1. サーバー移転&データ復旧 2. Elasticsearchの設定 3. Mastodon Botの設定 4. R2のバックアップ(予定) 8時から始め、15:30までに3を終わりました。R2へのバックアップ設定はまだ時間がかかりそうです。 ## 苦戦したところ ### sshdの設定 Ubuntu23・24でsshdの設定が変わっていました。具体的に言うと、「ssh.service」というものが追加され、初期設定ではそれが動くようでした。詳しくは下記の項目にて。 - [UbuntuにおけるSSHポートの設定と変更 - Ubuntu24.04対応 - Qiita](https://qiita.com/11ppm/items/a17e585e05cc3903f5c9) `sshd_config`だけいじっても、`sshd`の再起動の際にエラーが出てしまう。従来の`/etc/ssh/sshd_config`のほかにも、`/lib/systemd/system/ssh.socket`のポートも変更する必要があります。 ``` # sudo nano /etc/ssh/sshd_config # sudo systemctl restart ssh # sudo systemctl status ssh.socket # nano /lib/systemd/system/ssh.socket # sudo systemctl daemon-reload # sudo systemctl restart ssh.socket ``` ### Mastodonインストール~データ復旧 - [[Mastodon・Misskeyのデータベースをリストアする]] - [ソースからのインストール - Mastodon documentation](https://docs.joinmastodon.org/admin/install/) - [新しいマシンへの移行 - Mastodon ドキュメント](https://docs.joinmastodon.org/admin/migrating/) 前回は一度インストールしてから各種設定ファイル・DBをリストアしていましたが、今回は手動でマイグレーション・プリコンパイルを行いました。余談ですが、Mastodon公式ドキュメントにサーバー移転方法か書いてあってびっくりしました。まああんまりやらんかったけど……。 大まかな流れとしてはこんな感じ。証明書とRedisのインポートはしていません。 1. Mastodonに必要なものをインストール 2. Ngnix経由で証明書を入手 3. 設定&DBリストア 4. その他起動までの諸設定 5. マイグレーション・プリコンパイル ### Elasticsearch設定 - [Configuring full-text search - Mastodon documentation](https://docs.joinmastodon.org/admin/elasticsearch/) - [CT の Mastodon を VM の Ubuntu Server 24.04 LTS に移行する \| 自鯖](https://jisaba.life/%E8%A8%AD%E5%AE%9A/mastodon/2024-09-08-ct-%E3%81%AE-mastodon-%E3%82%92-vm-%E3%81%AE-ubuntu-server-2404-lts-%E3%81%AB%E7%A7%BB%E8%A1%8C%E3%81%99%E3%82%8B) ドキュメントが古く、同じようにやっても「Elasticsearchのリポジトリが見つからない」と出てしまった。上記のブログをもとにリポジトリ登録を変更したらなんとかなった。(ブログ元だとVer8を参照するので注意) - [Install Elasticsearch with Debian Package \| Elasticsearch Guide \[8.17\] \| Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html) ``` # wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg # echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list ``` あとはSudachiと辞書を入れてMastodonのコマンドを打てばおk。 ### Pythonの仮想環境構築 - [【備忘録】Ubuntu 24.04 で Python3.12 の Pip を利用する - Qiita](https://qiita.com/keith_campbell/items/e7dc4afc44527b802f6e) 24からPython pipを行う際、仮想環境が必要になった。そのため、BOT用のユーザーを作成して仮想環境を構築、bashで仮想環境を起動→プログラムを起動するようにしました。 #### 仮想環境構築まで ``` # sudo apt install python3-venv # sudo su - bot $ python3 -m venv ~/venv_py $ source ~/venv_py/bin/activate $ pip install mastodon.py ``` #### shファイル ```bash #!/bin/bash echo "Bot start." # 仮想環境起動 source /home/bot/venv_py/bin/activate # バックアップファイル作成 python3 /usr/local/bin/mastodon-bot/planet_transit.py ``` この後shファイルのパーミッションを755にしてcronで起動するようにすればOK。 ## 関連リンク - [[Mastodon・Misskeyのデータベースをリストアする]] ## 参考サイト - [UbuntuにおけるSSHポートの設定と変更 - Ubuntu24.04対応 - Qiita](https://qiita.com/11ppm/items/a17e585e05cc3903f5c9) - [ソースからのインストール - Mastodon documentation](https://docs.joinmastodon.org/admin/install/) - [新しいマシンへの移行 - Mastodon ドキュメント](https://docs.joinmastodon.org/admin/migrating/) - [Configuring full-text search - Mastodon documentation](https://docs.joinmastodon.org/admin/elasticsearch/) - [CT の Mastodon を VM の Ubuntu Server 24.04 LTS に移行する \| 自鯖](https://jisaba.life/%E8%A8%AD%E5%AE%9A/mastodon/2024-09-08-ct-%E3%81%AE-mastodon-%E3%82%92-vm-%E3%81%AE-ubuntu-server-2404-lts-%E3%81%AB%E7%A7%BB%E8%A1%8C%E3%81%99%E3%82%8B) - [【備忘録】Ubuntu 24.04 で Python3.12 の Pip を利用する - Qiita](https://qiita.com/keith_campbell/items/e7dc4afc44527b802f6e)