0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

セキュアサーバに、なりたいな「ハイ!rclone crypt」⑤Gitサーバを構築してみる

Last updated at Posted at 2025-12-24

📚 シリーズ目次

本シリーズは、作業の一部で Linux Mint 22.2 Cinnamon Edition を使用します。
Windows 11 での作業手順も併記しています。)

1. はじめに

SVNサーバが遅い。コミットは散々待たされた挙句に最後で失敗する。チェックアウトも遅いので、QEMUのCPUエミュレーションがボトルネックなのかと。ダメさ加減に肩を落としつつ、最後の希望をGitサーバに託します。

本記事では、非rootのスマホに仮想マシンを導入し、Android OS上でネイティブなLinuxサーバを稼働させることを目指します。

2. コア数の設定

2.1 CPUコア数を変えてみる

QEMU起動時のCPU設定は、現状2コアで運用してました。ここを増やしたら速度が改善されるのではないかと。280MBのSVNリポジトリをチェックアウトする所要時間で比較してみます。確認結果はこちら!(ドドン)

オプション 所要時間
-smp 2 5分16秒
-smp 4 4分21秒

…うん、微妙。何とも言い難い。

2.2 増やして運用する?

Snapdragon 4 Gen 2は「高性能コア×2」と「省電力コア×6」の構成なので、2コアからさらに増やしてもあまり効果は望めないのかもしれない。なのに、Debianの起動時間はむしろ長くなってしまうので、2コアのままで進めます。

3. Gitサーバのセットアップ

3.1 Gitのインストール

それでは、サーバ構築の作業に入ります。まずは、Debianに接続しましょう。

Linux PC
ssh termux-qemu

接続できたら、以下のコマンドで必要なパッケージをインストールします。GitでHTTPS接続を行うためのCGIモジュールは、Gitと一緒に導入されます。

Debian
sudo apt install git

3.2 Gitの公開設定

続いて、Apacheでの公開設定を編集します。まずは、Gitリポジトリ用のフォルダを準備しましょう。rclone-mounter.service に以下の項目を追加してサービスを再起動すると、暗号化フォルダ内のサブフォルダが /srv/git にマウントされます。

Debian
sudo nano /etc/systemd/system/rclone-mounter.service
Debian /etc/systemd/system/rclone-mounter.service
ExecStartPre=/usr/bin/mkdir -p /srv/git

ExecStart=/usr/bin/rclone mount termux-secure:git /srv/git \
  --uid 1000 --gid 33 --umask 002 --allow-other \
  --vfs-cache-mode writes --daemon

ExecStop=/usr/bin/fusermount -u /srv/git
Debian
sudo systemctl daemon-reload
sudo systemctl restart rclone-mounter

それでは、設定ファイルを作成します。以下をコピペして作成ください。ユーザ設定ファイルは、SVNサーバで使用しているものを共用します。

Debian
sudo nano /etc/apache2/sites-available/git.conf
Debian /etc/apache2/sites-available/git.conf
<VirtualHost *:443>
    ServerName termux.home.arpa

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/termux.crt
    SSLCertificateKeyFile /etc/ssl/private/termux.key

    SetEnv GIT_PROJECT_ROOT /srv/git
    SetEnv GIT_HTTP_EXPORT_ALL
    ScriptAlias /git/ /usr/lib/git-core/git-http-backend/

    <Directory /usr/lib/git-core>
        Options +ExecCGI
        Require all granted
    </Directory>

    <Location /git>
        AuthType Basic
        AuthName "Git Repository"
        AuthUserFile /etc/apache2/.htpasswd
        Require valid-user
    </Location>
</VirtualHost>

変更を保存したら、モジュールを有効化してApacheを再起動します。

Debian
sudo a2enmod cgi
sudo a2ensite git.conf
sudo systemctl restart apache2

4. Gitリポジトリの操作

4.1 リポジトリの作成

リポジトリ作成の前に、Gitの設定をしてしまいましょう。以下のコマンドで設定します。クライアントPCも同様に設定してください。

Debian
sudo git config --system init.defaultBranch main
sudo git config --system user.name "$(hostname)"
sudo git config --system user.email user@example.com
Linux PC
git config --global init.defaultBranch main
git config --global user.name "$(hostname)"
git config --global user.email user@example.com

それでは、リポジトリを作成してHTTPS経由でのアクセスを確認します。以下のコマンドで作成してください。リポジトリ名は my-first-git とすることにします。

Debian
mkdir -p /srv/git/my-first-git
cd /srv/git/my-first-git
git init --bare
sudo git config --system --add safe.directory "$(pwd)"

4.2 PCでのクローン

リポジトリが作成できたら、クライアントPCでクローンしてみましょう。Git作業用のフォルダ(~/GIT など)で右クリックして、「RabbitVCS Git」から「Clone」を選択します。「URL」欄に以下をコピペしてOKボタンをクリックすると、クローンされます。

Linux PC URL
https://termux.home.arpa:8443/git/my-first-git

Screenshot from 2025-12-24 10-39-25.png

初回接続時は、事前に以下のコマンドで認証情報を保存しておくと良いでしょう。

Linux PC
git config --global credential.helper store
git ls-remote https://termux.home.arpa:8443/git/my-first-git

HTTPはPOSTサイズが制限を受けるため、リポジトリの復旧などでGB単位のデータをプッシュすると失敗します。SSH接続などの回避策が必要です。

4.3 メディアフォルダのGit管理

ここでは、スマホのメディアフォルダをGit管理できるようにします。SDカードのルートディレクトリをワークスペースとし、複数のフォルダを一度に管理します。まずは、以下のコマンドでメディアフォルダ用のリポジトリを作成します。

Debian
mkdir -p /srv/git/sdcard
cd /srv/git/sdcard
git init --bare
sudo git config --system --add safe.directory "$(pwd)"

続いて、SDカードのルートディレクトリをGitのワークスペースにします。以下のコマンドでローカルリポジトリを作成し、先ほど作成したリポジトリと紐付けます。

Debian
cd /mnt/sdcard
git init
git remote add origin /srv/git/sdcard
sudo git config --system --add safe.directory "$(pwd)"

内部ストレージのメディアフォルダを対象にする場合は、sdcardshared と読み替えてください。

今回は DCIMMovies をまとめてコミットします。まずは、管理対象とするフォルダの設定です。以下のコマンドで .gitignore ファイルを作成して編集します。管理対象フォルダは、各自の必要に応じて設定ください。

Debian
nano .gitignore
Debian .gitignore
/*
!/.gitignore
!/DCIM/
!/Movies/
.tmfs/
.thumbnails/

編集が終わったら、以下のコマンドですべてを追加してコミット&プッシュします。

Debian
git add -A
git commit -m "Initial commit"
git push -u origin main

5. おわりに

例のSVNリポジトリと同内容のGitリポジトリは、3分13秒でクローンできました。加えて、コミットやプッシュでの失敗も発生しない。安定していて良いんだけど、この運用ってどうなんだろ。Debianの起動には2分ほど掛かる。暗号化フォルダを使わないならTermux完結でいろいろ速いし、暗号化フォルダだけだったらPCでマウントしてローカルリポジトリでOK。セットアップも手間なこともあって、差し引きでのメリットが見えないのでした。


◀️ 前の記事 次の記事 ▶️
セキュアサーバに、なりたいな「ハイ!rclone crypt」④SNVサーバを構築してみる セキュアサーバに、なりたいな「ハイ!rclone crypt」⑥サーバ構成を改変してみる
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?