以前から自分でサーバーを作りたいと思っていたのですが、Raspberry Pi が手元にあるので自分で作りたいと思っています。
1.構成
ハードウェア: ラズベリーパイ B4
ハードディスク: 4T 機械式ハードディスク
システム: ubuntu-22.04.2-preinstalled-server-arm64+raspi (Raspberry Pi 公式サイトからダウンロード)
2. 事前準備
Raspberry Pi の公式 Web サイトに従ってシステムを書き込み、実行します。
3. ハードディスクをマウントする
3.1 マウント用メカニカルハードディスクのフォーマット
実際の運用において、ボリュームラベルが中国語であることが判明した場合、ubuntu コンソールを使用してボリュームラベルを変更するとエラーが報告されるため、ボリュームラベルを英語に変更することをお勧めします。
3.2 ハードディスクのマウント
ハードディスクを Raspberry Pi に接続してからマウントします.この手順では、まずハードディスクを接続してからマシンを起動する必要があります.そうしないと,操作中に入出力エラーが報告されます.
3.2.1 ディレクトリを作成します。
Linux のハードディスク マウントは、Linux システムが自動的に認識できず、指定されたディレクトリにしかマウントできないため、システム ディレクトリにマウントする必要がありますが、インターネットでは、通常は mnt ディレクトリに作成されると言われています。初心者として、私もこのディレクトリの下に作成されました。
sudo mkdir /mnt/DbDisk
3.2.2 ハードディスクの識別
fdisk -l コマンドでハードディスクを識別します。
ubuntu@ubuntu:~$ sudo fdisk -l
Disk /dev/loop0: 59.09 MiB, 61956096 bytes, 121008 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop1: 59.12 MiB, 61988864 bytes, 121072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop2: 109.61 MiB, 114929664 bytes, 224472 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop3: 43.19 MiB, 45289472 bytes, 88456 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop4: 43.18 MiB, 45277184 bytes, 88432 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sdb: 119.24 GiB, 128035676160 bytes, 250069680 sectors
Disk model: e SSD ST600 MSAT
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
Disklabel type: dos
Disk identifier: 0x12c9124a
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 526335 524288 256M c W95 FAT32 (LBA)
/dev/sdb2 526336 250069679 249543344 119G 83 Linux
Disk /dev/sda: 3.64 TiB, 4000787030016 bytes, 7814037168 sectors
Disk model: 006-3CW104
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 9463367F-46F9-46DB-AC72-5633AEA58D7E
Device Start End Sectors Size Type
/dev/sda1 4096 7814037134 7814033039 3.6T Microsoft basic data
マウントするハードディスクは /dev/sda1 で、マウントするハードディスクのサイズに基づいて特定します。
3.2.3 ハードディスクをマウントします。
sudo mount /dev/sda1 /mnt/DbDisk
sudo df を使用して、ハードディスクのマウント ステータスを表示できます。現在、sda1 ハードディスクを DbDisk ディレクトリにマウントしています。
ubuntu@ubuntu:~$ sudo df
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 388000 3176 384824 1% /run
/dev/sdb2 122731688 4809364 111667360 5% /
tmpfs 1939984 0 1939984 0% /dev/shm
tmpfs 5120 0 5120 0% /run/lock
/dev/sdb1 258095 151621 106475 59% /boot/firmware
/dev/sda1 3907016516 221416 3906795100 1% /mnt/DbDisk
tmpfs 387996 4 387992 1% /run/user/1000
3.2.4 自動マウントの設定
ダイレクトマウントは再起動の度に一度マウントする必要がありますが、一般的には設定ファイルを変更することで実現できる自動マウントを設定した方が良いでしょう。
ubuntu@ubuntu:~$ sudo vim /etc/fstab
次に、新しくマウントするディスクを構成ファイルに追加します。
LABEL=writable / ext4 discard,errors=remount-ro 0 1
LABEL=system-boot /boot/firmware vfat defaults 0 1
/dev/sda1 /mnt/DbDisk ntfs auto,user,rw 0 1
マウントの先頭にある識別番号は、LABEL ボリューム ラベル、UUID ハードディスク番号、または私のようなシステムによって認識されるデバイス パスを直接書き込むことができます。実際に使ってみると、LABELもUUIDも認識できない状況があったので、デバイスパスを直接マウントして使いやすいように変更しました。
設定後、Raspberry Pi を再起動して正常に動作するか確認してください。
4.svnserver をインストールする
4.1 svn サーバーのインストール
sudo apt-get install subversion
4.2 svn ウェアハウス フォルダの作成
ubuntu@ubuntu:~$ sudo mkdir /mnt/DbDisk/svn
ハード ディスク ディレクトリに svn ウェアハウス フォルダーを作成し、svn ウェアハウス フォルダーとして使用します。
ubuntu@ubuntu:/mnt/DbDisk/svn$ sudo mkdir test
ubuntu@ubuntu:/mnt/DbDisk/svn$ ls
test
ウェアハウス ディレクトリのバージョン ライブラリ テスト
4.3 リポジトリの作成
sudo svnadmin create /mnt/DbDisk/svn/test
ubuntu@ubuntu:/mnt/DbDisk/svn/test$ ls
README.txt conf db format hooks locks
ubuntu@ubuntu:/mnt/DbDisk/svn/test$ ls -a
. .. README.txt conf db format hooks locks
ubuntu@ubuntu:/mnt/DbDisk/svn/test$
作成が完了すると、ディレクトリにファイルがあります。
4.4 構成
conf フォルダーの下のファイルを変更して、アクセス許可を構成します。
設定ファイル svnserve.conf、authz、passwd を変更する場合、すべての行ヘッダーを空にすることはできず、最後に空白を追加することはできないことに注意してください。実際の変更中に追加することはできません。そうしないと、「承認に失敗しました」というエラーが報告されます。
4.4.1 svnserve.conf ファイル
[general]
### The anon-access and auth-access options control access to the
### repository for unauthenticated (a.k.a. anonymous) users and
### authenticated users, respectively.
### Valid values are "write", "read", and "none".
### Setting the value to "none" prohibits both reading and writing;
### "read" allows read-only access, and "write" allows complete
### read/write access to the repository.
### The sample settings below are the defaults and specify that anonymous
### users have read-only access to the repository, while authenticated
### users have read and write access to the repository.
anon-access = none # 设置匿名用户不可读
auth-access = write # 权限用户可写
### The password-db option controls the location of the password
### database file. Unless you specify a path starting with a /,
### the file's location is relative to the directory containing
### this configuration file.
### If SASL is enabled (see below), this file will NOT be used.
### Uncomment the line below to use the default password file.
password-db = passwd # 使用用密码文件
### The authz-db option controls the location of the authorization
### rules for path-based access control. Unless you specify a path
### starting with a /, the file's location is relative to the
### directory containing this file. The specified path may be a
### repository relative URL (^/) or an absolute file:// URL to a text
### file in a Subversion repository. If you don't specify an authz-db,
### no path-based access control is done.
### Uncomment the line below to use the default authorization file.
authz-db = authz # 使用权限文件
4.4.2 authz ファイル
[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
# [/foo/bar]
# harry = rw
# &joe = r
# * =
# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r
# 在末尾添加信息
admin = admin # 管理员用户admin分组属于admin组
[/] # 从仓库开始设置权限
@admin = rw # 管理员组的权限是读写
4.4.3 passwd ファイル
[users]
# harry = harryssecret
# sally = sallyssecret
admin = 123456 # 在末尾添加用户和密码,明文输入
4.5 サーバーの起動
ubuntu@ubuntu:/mnt/DbDisk/svn/test/conf$ sudo svnserve -d -r /mnt/DbDisk/svn
- -d: フラグはデーモン モードで開始します
- -r: svnリポジトリのルートディレクトリを設定するので、フルパスでアクセスしない
- その他:まだ調べていません。
4.6 接続ステータスの表示
ubuntu@ubuntu:~$ ps -aux | grep svnserve
root 1588 0.0 0.0 18904 2552 ? Ss 07:46 0:00 svnserve -d -r /mnt/DbDisk/svn
ubuntu 1598 0.0 0.0 6420 1864 pts/0 S+ 07:51 0:00 grep --color=auto svnserve
u
サービスが表示された場合は、サーバーが正常に起動したことを意味します。
4.7 サーバーを停止する
killall svnserve
5 svnへのアクセス
5.1 ビューポート
ubuntu@ubuntu:~$ sudo netstat -anp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 822/systemd-resolve
tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 1588/svnserve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 987/sshd: /usr/sbin
tcp 0 0 192.168.1.17:22 192.168.1.19:60135 ESTABLISHED 1312/sshd: ubuntu [
tcp6 0 0 :::3389 :::* LISTEN 936/xrdp
tcp6 0 0 ::1:3350 :::* LISTEN 896/xrdp-sesman
tcp6 0 0 :::22 :::* LISTEN 987/sshd: /usr/sbin
udp 0 0 127.0.0.53:53 0.0.0.0:* 822/systemd-resolve
udp 0 0 192.168.1.17:68 0.0.0.0:* 820/systemd-network
udp6 0 0 fe80::dea6:32ff:fe4:546 :::* 820/systemd-network
raw6 0 0 :::58 :::* 7 820/systemd-network
sudo netstat -anp を使用して svn サービスのポート番号を表示します。ここで、svn サーバーのデフォルト ポートが 3690 であることがわかります。
5.2 svn サーバー ポートを開く
ubuntu@ubuntu:~$ sudo ufw allow 3690 # 开放端口
Rule added
Rule added (v6)
ubuntu@ubuntu:~$ sudo ufw status #检查端口状态
Status: active
To Action From
-- ------ ----
3690 ALLOW Anywhere
3690 (v6) ALLOW Anywhere (v6)
ポート開放後は外部からのアクセスが可能です。
5.3 svn ライブラリへのアクセス
ウィンドウ環境で svn クライアントを使用してアクセスします。
フォルダを作成してみてください:
5.4 楽しむ
インターネットの情報を見ていると、わかったような気がしますが、実際には、問題を見つけるにはまだ練習が必要です. 自分で設定して初めて、何かを得ることができます.