Elastic Compute Service (ECS) インスタンスに Subversion (SVN) をデプロイし、HTTP または svnserve アクセスを使用して、チェックアウト、更新、コミットを通じてコードを管理します。
前提条件
ECS インスタンスを作成します。 詳細については、「カスタム起動タブを使用したインスタンスの作成」をご参照ください。
インスタンスは、次の要件を満たす必要があります:
-
インスタンスには、固定パブリック IP アドレスまたは Elastic IP Address (EIP) が必要です。 詳細については、「パブリック帯域幅の有効化」をご参照ください。
-
オペレーティングシステム:Alibaba Cloud Linux 3、Alibaba Cloud Linux 2、または CentOS 7.x。
-
インスタンスタイプ:4 vCPU および 4 GiB 以上のメモリ。 正確な仕様は、プロジェクトのサイズとチームの規模によって異なります。
-
セキュリティグループのインバウンドルールで、ポート 22、80、443 でのトラフィックを許可します。 詳細については、「セキュリティグループルールの追加」をご参照ください。
説明svnserve モードを使用する場合は、ポート 3690 でのトラフィックも許可する必要があります。
このチュートリアルは、SVN のワンクリックデプロイをサポートしています。 ワンクリックで実行
SVN のデプロイ
SVN は、HTTP と svnserve の 2 つのアクセスモードをサポートしています。
|
特徴 |
HTTP モード |
svnserve モード |
|
プロトコル |
HTTP |
カスタム SVN プロトコル |
|
アクセス方法 |
Web ブラウザまたは SVN クライアント |
SVN クライアントのみ |
|
ポート |
80 |
3690 |
|
セキュリティ |
HTTPS 暗号化 |
デフォルトではプレーンテキスト、暗号化はオプション |
|
設定 |
Web サーバーの設定 |
SVN サーバーの設定 |
|
機能サポート |
権限管理やログ表示など、より多くの機能 |
より少ない機能 |
HTTP を使用した SVN のデプロイ
ステップ 1: SVN のインストール
-
Linux インスタンスに接続します。
詳細については、「ワークベンチを使用して Linux インスタンスに接続する」をご参照ください。
-
SVN をインストールします。
sudo yum install -y subversion -
SVN のバージョンを確認します。
svnserve --version以下のような出力が表示された場合、SVN がインストールされていることを示します。
[ecs-user@iZ2zeczc ~]$ svnserve --version svnserve, version 1.14.1 (r1886195) compiled Sep 29 2022
ステップ 2: Apache のインストール
-
httpd をインストールします。
sudo yum install httpd -y -
httpd のバージョンを確認します。
httpd -version以下のような出力が表示された場合、httpd がインストールされていることを示します。
[ecs-user@iZ2zeczd ~]$ httpd -version Server version: Apache/2.4.6 (AlibabaCloudLinux) Server built: May 26 2023 16:19:35
ステップ 3: mod_dav_svn のインストール
mod_dav_svn は、SVN リポジトリへの Web アクセスを提供する Apache モジュールです。
mod_dav_svn をインストールします。
sudo yum install mod_dav_svn -y
ステップ 4: SVN の設定
-
SVN リポジトリを作成します。
sudo mkdir /var/svn cd /var/svn sudo svnadmin create /var/svn/svnrepos -
SVN リポジトリのユーザーグループを apache に変更します。
sudo chown -R apache:apache /var/svn/svnrepos -
自動生成されたリポジトリファイルを表示します。
cd svnrepos ls次の表に、Subversion のディレクトリについて説明します。
内容
説明
db
すべてのバージョン管理データファイルを保存します。
hooks
フックスクリプトファイルを保存します。
locks
リポジトリにアクセスするクライアントを追跡します。
format
リポジトリ設定のバージョンを示す整数を含むテキストファイル。
conf
アクセスアカウントと権限を含む SVN リポジトリ設定ファイル。
-
コマンドを実行して、SVN リポジトリのユーザーとパスワードを追加します。
デフォルトでは、SVN はプレーンテキストパスワードを使用しますが、HTTP ではハッシュ化されたパスワードが必要です。 別の passwd ファイルを生成します。 この例では、ユーザー名が
userTest、パスワードがpassWDTestのユーザーが追加されます。 次のいずれかのコマンドを実行します:-
最初のユーザーを追加するには、
-cパラメーターを使用してファイルを作成します。sudo htpasswd -c /var/svn/svnrepos/conf/passwd userTest -
2 人目以降のユーザーを追加するには、
-cを省略します。sudo htpasswd /var/svn/svnrepos/conf/passwd userTest
プロンプトに従ってパスワードを設定します。
-
-
conf ディレクトリに移動します。
cd /var/svn/svnrepos/conf/ -
アカウントの読み取りおよび書き込み権限を設定します。
-
アクセス制御ファイルを開きます。
sudo vim authz -
iを押して編集モードに入ります。 -
ファイルの末尾に次のコードを追加します。
userTestはアカウント、rは読み取り権限、wは書き込み権限です。[/] userTest=rw[aliases] # joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average [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 [/] userTest=rw -
Escキーを押し、:wqと入力して Enter キーを押し、保存して終了します。
-
-
SVN サービスの設定を変更します。
-
SVN サービス設定ファイルを開きます。
sudo vim svnserve.conf -
iを押して編集モードに入ります。 -
次の行を見つけ、コメント記号 (#) と先頭のスペースを削除します。
説明各行はスペースで始まってはならず、等号 (=) の両側にスペースが必要です。
anon-access = read auth-access = write password-db = passwd authz-db = authz realm = /var/svn/svnrepos[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 = read 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 ### The groups-db option controls the location of the file with the ### group definitions and allows maintaining groups separately from the ### authorization rules. The groups-db file is of the same format as the ### authz-db file and should contain a single [groups] section with the ### group definitions. If the option is enabled, the authz-db file cannot ### contain a [groups] section. 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. ### This option is not being used by default. # groups-db = groups ### This option specifies the authentication realm of the repository. ### If two repositories have the same authentication realm, they should ### have the same password database, and vice versa. The default realm ### is repository's uuid. realm = /var/svn/svnrepos ### The force-username-case option causes svnserve to case-normalize ### usernames before comparing them against the authorization rules in the ### authz-db file configured above. Valid values are "upper" (to upper- -
Escキーを押し、:wqと入力して Enter キーを押し、保存して終了します。
-
-
SVN リポジトリを起動します。
このコマンドは、リポジトリの親ディレクトリをルートとして設定するため、クライアントは URL にリポジトリ名を追加することでリポジトリにアクセスできます (例:
svn://<EIP>/svnrepos)。sudo svnserve -d -r /var/svn/説明SVN サービスを停止するには、
killall svnserveコマンドを実行します。 -
SVN サービスが起動しているかどうかを確認します。
ps -ef |grep svn以下のような出力が表示された場合、SVN サービスが実行中であることを示します。
[ecs-user@iZ2zeczdpa5xxx conf]$ ps -ef |grep svn ecs-user 2767 1 0 16:50 ? 00:00:00 svnserve -d -r /var/svn/ ecs-user 2808 2568 1 0 16:50 pts/0 00:00:00 grep --color=auto svn
ステップ 5: Apache の設定
-
httpd 設定ファイルを作成して編集します。
sudo vim /etc/httpd/conf.d/subversion.conf -
iを押して編集モードに入ります。 -
subversion.confファイルに次の設定を入力します。<Location /svn> DAV svn SVNParentPath /var/svn AuthType Basic AuthName "Authorization SVN" AuthzSVNAccessFile /var/svn/svnrepos/conf/authz AuthUserFile /var/svn/svnrepos/conf/passwd Require valid-user </Location> -
Escキーを押し、:wqと入力して Enter キーを押し、保存して終了します。 -
Apache サービスを起動します。
sudo systemctl start httpd.service
svnserve を使用した SVN のデプロイ
ステップ 1: SVN のインストール
-
Linux インスタンスに接続します。
詳細については、「ワークベンチを使用して Linux インスタンスに接続する」をご参照ください。
-
SVN をインストールします。
sudo yum install -y subversion -
SVN のバージョンを確認します。
svnserve --version以下のような出力が表示された場合、SVN がインストールされていることを示します。
[ecs-user@iZ2zeczc ~]$ svnserve --version svnserve, version 1.14.1 (r1886195) compiled Sep 29 2022
ステップ 2: SVN の設定
-
SVN リポジトリを作成します。
sudo mkdir /var/svn cd /var/svn sudo svnadmin create /var/svn/svnrepos -
自動生成されたリポジトリファイルを表示します。
cd svnrepos ls次の表に、Subversion のディレクトリについて説明します。
内容
説明
db
すべてのバージョン管理データファイルを保存します。
hooks
フックスクリプトファイルを保存します。
locks
リポジトリにアクセスするクライアントを追跡します。
format
リポジトリ設定のバージョンを示す整数を含むテキストファイル。
conf
アクセスアカウントと権限を含む SVN リポジトリ設定ファイル。
-
SVN リポジトリのユーザー名とパスワードを設定します。
-
ユーザー設定ファイルを開きます。
cd conf/ sudo vim passwd -
iを押して編集モードに入ります。 -
[users]セクションに移動し、ユーザー名とパスワードを追加します。説明フォーマット:
username = password。 例:userTest = passWDTest(下記参照)。 等号 (=) の両側にスペースが必要です。### This file is an example password file for svnserve. ### Its format is similar to that of svnserve.conf. As shown in the ### example below it contains one section labelled [users]. ### The name and password for each user follow, one account per line. [users] # harry = harrysecret # sally = sallyssecret userTest = passWDTest -
Escキーを押し、:wqと入力して Enter キーを押し、保存して終了します。
-
-
アカウントの読み取りおよび書き込み権限を設定します。
-
アクセス制御ファイルを開きます。
sudo vim authz -
iを押して編集モードに入ります。 -
ファイルの末尾に次のコードを追加します。
userTestはアカウント、rは読み取り権限、wは書き込み権限です。[/] userTest=rw[aliases] # joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average [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 [/] userTest=rw -
Escキーを押し、:wqと入力して Enter キーを押し、保存して終了します。
-
-
SVN サービスの設定を変更します。
-
SVN サービス設定ファイルを開きます。
sudo vim svnserve.conf -
iを押して編集モードに入ります。 -
次の行を見つけ、コメント記号 (#) と先頭のスペースを削除します。
説明各行はスペースで始まってはならず、等号 (=) の両側にスペースが必要です。
anon-access = read auth-access = write password-db = passwd authz-db = authz realm = /var/svn/svnrepos[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 = read 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 ### The groups-db option controls the location of the file with the ### group definitions and allows maintaining groups separately from the ### authorization rules. The groups-db file is of the same format as the ### authz-db file and should contain a single [groups] section with the ### group definitions. If the option is enabled, the authz-db file cannot ### contain a [groups] section. 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. ### This option is not being used by default. # groups-db = groups ### This option specifies the authentication realm of the repository. ### If two repositories have the same authentication realm, they should ### have the same password database, and vice versa. The default realm ### is repository's uuid. realm = /var/svn/svnrepos ### The force-username-case option causes svnserve to case-normalize ### usernames before comparing them against the authorization rules in the ### authz-db file configured above. Valid values are "upper" (to upper- -
Escキーを押し、:wqと入力して Enter キーを押し、保存して終了します。
-
-
SVN リポジトリを起動します。
このコマンドは、リポジトリの親ディレクトリをルートとして設定するため、クライアントは URL にリポジトリ名を追加することでリポジトリにアクセスできます (例:
svn://<EIP>/svnrepos)。sudo svnserve -d -r /var/svn/説明SVN サービスを停止するには、
killall svnserveコマンドを実行します。 -
SVN サービスが起動しているかどうかを確認します。
ps -ef |grep svn以下のような出力が表示された場合、SVN サービスが実行中であることを示します。
[ecs-user@iZ2zeczdpa5xxx conf]$ ps -ef |grep svn ecs-user 2767 1 0 16:50 ? 00:00:00 svnserve -d -r /var/svn/ ecs-user 2808 2568 1 0 16:50 pts/0 00:00:00 grep --color=auto svn
SVN の使用
一般的な SVN コード管理のワークフローは次のとおりです:
-
チェックアウト:ソースコードをローカルコンピューターにチェックアウトします。
-
他のユーザーがソースコードを変更し、リポジトリにコミットします。
-
更新:最新のコードを取得します。
-
ソースコードを変更し、デバッグします。
-
コミット:変更したコードをリポジトリにコミットします。 これにより、他のプログラマーが変更内容を確認できるようになります。
ソースコードをローカルディレクトリにチェックアウトする (チェックアウト)
-
ローカルの Windows コンピューターに TortoiseSVN クライアントをダウンロードしてインストールします。
-
ローカルプロジェクトフォルダーの空白領域を右クリックします。
この例では、フォルダーは
C:\Testです。 -
ポップアップメニューで [SVN Checkout...] を選択します。
-
次の情報を入力し、[OK] をクリックします:
-
[URL of repository]:ソースコードが保存されている URL。
-
HTTP アクセスモード:URL は
http://<ECS インスタンスのパブリック IP アドレス>/svn/<SVN リポジトリ名>の形式です。 -
svnserve アクセスモード:URL は
svn://<インスタンスのパブリック IP アドレス>/<SVN リポジトリ名>の形式です。説明SVN サービスがリポジトリの親ディレクトリで起動された場合は、SVN チェックアウト URL にリポジトリ名を追加します。
-
-
[Checkout directory]:ソースコードのローカルディレクトリ。 この例では、
C:\Testです。
説明初回ログイン時に、[passwd] ファイルで設定したユーザー名とパスワードを入力します。
チェックアウトが完了すると、[Checkout Finished!] ダイアログボックスが表示され、[At revision: 0] と表示されます。これは、ソースコードが正常にチェックアウトされたことを示します。
-
更新の取得 (Update)
サーバー側リポジトリが更新された後、ローカルプロジェクトフォルダーの空白領域を右クリックし、[SVN Update] を選択して最新バージョンをダウンロードします。
SVN Update は、プロジェクトフォルダー内の既存のコンテンツを上書きします。 更新する前にプロジェクトをバックアップしてください。
変更のコミット (Commit)
ローカルの変更をサーバー側リポジトリにコミットします:
-
プロジェクトファイルの空白領域を右クリックし、[SVN Commit...] を選択します。
-
バージョン更新のコメントを入力し、コミットするコンテンツを選択して、[OK] をクリックします。
ローカルプロジェクトがリポジトリプロジェクトを上書きします。
説明-
2 人のユーザーが変更をコミットした場合、バージョンが古いため、後のコミットは失敗します。 プロジェクトをバックアップし、サーバーから最新バージョンをダウンロードし、ローカルフォルダーをご自身の変更で上書きしてから、[SVN Commit] をクリックしてください。
-
コミットされたプロジェクト内のファイルを削除すると、次のようなメッセージが表示されます。 [Commit] ダイアログボックスで、[Message] エリアにコミットメッセージを入力します。 [Changes made] エリアには、コミットするファイルとそのステータスが一覧表示されます (例:ステータスが [missing] の
test1.txtは、ファイルが作業コピーから削除されたことを示します)。 [OK] をクリックしてコミットします。
-
ファイルの復元
SVN で削除されたファイルを復元します:
-
ローカルプロジェクトフォルダーを開き、右クリックして [SVN Checkout]... を選択し、データをチェックアウトします。
-
ファイルの 1 つを削除します。
-
変更をコミットしたかどうかに基づいて、適切な操作を選択します:
-
まだコミットしていない場合は、空白領域を右クリックし、 を選択します。
-
すでにコミットしている場合、サーバー側リポジトリが同期され、そこでもファイルが削除されます。 次の手順で元に戻します:
-
空白領域を右クリックし、 を選択します。
-
削除のログエントリをクリックします。 削除されたデータが下に表示されます。
[Changed Paths] エリアには、削除されたファイルのパス (例:
/test2.txt) と操作タイプ [Deleted] が表示されます。 -
削除されたデータを右クリックし、[Save revision to...] をクリックします。
-
ファイル名を設定し、[Save] をクリックしてファイルを元の場所に復元します。 保存ダイアログボックスで、保存パス (例:
C:\Test) を選択し、ファイル名フィールドに [test2.txt] と入力して、[Save] をクリックします。
-
-
-
元のフォルダーを開き、[SVN Commit...] をクリックしてリポジトリと同期します。
よくある質問
TortoiseSVN を使用して SVN サーバーにアクセスすると、「ホストが応答しませんでした」というプロンプトが表示されるのはなぜですか?
考えられる原因:
-
SVN サーバーが起動していない。
-
必要なポートがセキュリティグループで開かれていない。
-
firewalld ファイアウォールが有効になっているが、必要なポートが許可されていない。
次のようにトラブルシューティングを行ってください:
-
SVN サービスの状態を確認します。
ps -ef |grep svn出力に svnserve プロセスが含まれている場合、SVN サービスは実行中です。 含まれていない場合は、
sudo svnserve -d -r /var/svn/を実行して起動します。 -
セキュリティグループルールが SVN サーバーの要件を満たしているかどうかを確認します。
-
HTTP モード:ポート 22、80、443。
-
svnserve モード:ポート 22、80、443、3690。
-
-
firewalld ファイアウォールを確認します。
-
firewalld の状態を確認します。
sudo firewall-cmd --state-
not runningが返された場合、ファイアウォールは無効になっており、SVN には影響しません。 -
runningが返された場合、ファイアウォールは有効です。 次のステップに進んでください。
-
-
必要な SVN ポート (ポート 3690 など) でのトラフィックを許可します。
sudo firewall-cmd --add-port=3690/tcp --permanent -
firewalldの設定をリロードします。sudo systemct
-