LoginSignup
5
8

More than 3 years have passed since last update.

Subversion構築手順 (CentOS7)

Last updated at Posted at 2019-05-29

CentOS7でSubversion構築の手順です。
※2019/07/31 随所に誤りがあったので、検証しつつ細かい部分を修正しました。
Subversionをとりあえず動かせるようにするまでと、リビジョン管理としてWebSVNもインストールします。

SVNリポジトリの中でcode,document,operationという3つのフォルダを作成します。

追加ディスクのマウント

だいたいSVNのリポジトリとなるディレクトリは、追加ディスクをマウントして利用します。
本手順に置き換えると/svn_repo というディレクトリにマウントして構築するとよいと思います。

前提

CentOS7で構築。
TCP3690ポートを開放していること。
selinux無効化

SVN構築手順

※rootユーザでの作業です。

インストール

yum install subversion mod_dav_svn mod_ldap

確認
svnserve --version

リポジトリ作成

mkdir /svn_repo/test_repo/
ls -ld /svn_repo/test_repo/
sudo svnadmin create --fs-type fsfs /svn_repo/test_repo/repo
svn mkdir file:///svn_repo/test_repo/repo/code -m "create"
svn mkdir file:///svn_repo/test_repo/repo/document -m "create"
svn mkdir file:///svn_repo/test_repo/repo/operation -m "create"

権限付与
chmod -R g+w /svn_repo/test_repo

レポジトリ領域のオーナー変更
ls -l /svn_repo/test_repo/
chown -R apache:apache /svn_repo/test_repo/
ls -l /svn_repo/test_repo/

設定

設定ファイル作成
cd /svn_repo/test_repo/repo/conf
cp -p svnserve.conf{,_`date +'%y%m%d'`}
ls -l svnserve.conf_`date +'%y%m%d'`

vi svnserve.conf
※下記を記載

[general]
anon-access = none
auth-access = write
authz-db = authz
realm = test.co.jp

ACLファイル作成

リポジトリへのアクセス権限設定ファイルの作成
cd /svn_repo/test_repo/repo/conf/
cp -p authz{,__`date +'%y%m%d'`}
ls -l authz__`date +'%y%m%d'`

vi authz
※とりあえず下記、全員読み書き可の設定を記載しておきます。
[/]
* = rw

リポジトリの仮想ルートを修正

vi /etc/sysconfig/svnserve
※以下修正
[変更前]
OPTIONS="-r /var/svn"
[変更後]
OPTIONS="-r /svn_repo/test_repo/repo/"

svnserve起動

systemctl start svnserve
systemctl status svnserve
systemctl enable svnserve
systemctl is-enabled svnserve

Apache設定

vi /etc/httpd/conf.d/dav_svn.conf
※以下記載。/svn_repo/test_repo/repo/conf/authzというファイルでACLの設定をします(この記事では割愛)。
<Location /svn_repo>
DAV svn
SVNPath /svn_repo/test_repo/repo
AuthzSVNAccessFile /svn_repo/test_repo/repo/conf/authz
</Location>

SSL化

※とりあえず自己証明書を配置しておきます。
# mod_sslインストール
yum install mod_ssl
# 秘密鍵作成
openssl genrsa -aes128 2048 > server.key
# 秘密鍵パスフレーズ解除
openssl rsa -in server.key -out server.key
# CSR作成
openssl req -new -key server.key > server.csr
※以下入力(このあたりは自由です。)
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Tokyo
Locality Name (eg, city) [Default City]:Tokyo
Organization Name (eg, company) [Default Company Ltd]:XXX CO., Ltd.
Organizational Unit Name (eg, section) []:Development Dept.
Common Name (eg, your name or your server's hostname) []:SVNサーバのGIPなど
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

# 証明書作成
openssl x509 -req -days 3650 -signkey server.key < server.csr > server.crt

# 秘密鍵と証明書移動
mkdir /etc/httpd/ssl/
cp server.key server.crt /etc/httpd/ssl/

# パーミッション変更
chmod 400 /etc/httpd/ssl/server.*

# 設定変更
cp -p /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.bk

vi /etc/httpd/conf.d/ssl.conf
※以下の項目を修正
SSLCertificateFile /etc/httpd/ssl/server.crt
SSLCertificateKeyFile /etc/httpd/ssl/server.key

#HTTP→HTTPSリダイレクト設定
vi /etc/httpd/conf.d/rewrite.conf
※以下記載
<ifModule mod_rewrite.c>
RewriteEngine On
LogLevel crit rewrite:trace3
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%\{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</ifModule>

# apacheサービス再起動、自動起動設定
systemctl restart httpd
systemctl status httpd
systemctl enable httpd
systemctl is-enabled httpd

確認作業

テストファイルのインポート
echo "test">test.txt
svn import test.txt file:///svn_repo/test_repo/repo/code/test.txt -m "import"
svn list file:///svn_repo/test_repo/repo/code

表示確認

※HTTPSポートを開放しておくこと
WEBブラウザ表示確認 https://SVNサーバのGIP/svn_repo/
"svn_repo - Revision X: /"などリビジョン番号が表示されます。
キャプチャ.PNG

またTortoiseSVNをダウンロードし、
ファイルのアップロードなど正常に行えるか確認するとよいです。

TortoiseSVN Registory Managerを開き、https://SVNサーバのGIP/svn_repo/ でログインします。
以下のように作成した3つのフォルダが表示されるとOKです。
InkedInkedキャプチャ2_LI.jpg

Websvn設定手順

インストールイメージの取得
websvn-2.3.3.tar.gzを以下からダウンロードする。
http://websvn.tigris.org/

  

必要なパッケージのインストール(上で既にしてるけど)

yum --enablerepo=php-repo,base install php php-pear php-mbstring

インストールイメージ配置

mkdir /svn_repo/www/
websvn-2.3.3.tar.gzを/svn_repo/www/に転送する
cd /svn_repo/www/
tar zxvf websvn-2.3.3.tar.gz
ls -l /svn_repo/www/

権限変更
chown -R apache:apache /svn_repo/www/websvn-2.3.3/
chmod -R 755 /svn_repo/www/websvn-2.3.3/

Apache設定

vi /etc/httpd/conf.d/websvn.conf
※以下記載。
Alias /websvn /svn_repo/www/websvn-2.3.3
<Location /websvn>
Require all granted
</Location>

Websvn設定ファイル作成

cd /svn_repo/www/websvn-2.3.3/include/
cp -p distconfig.php config.php
ls -l config.php
vi config.php
※以下編集。
・82行目
[変更前]
// $config->addRepository('NameToDisplay', 'URL to repository (e.g. file:///c:/svn/proj)');
[変更後]
$config->addRepository('test_svn', 'file:///svn_repo/test_repo/repo');
・221行目
[変更前]
// $config->useAuthenticationFile('/path/to/accessfile'); // Global access file
[変更後]
$config->useAuthenticationFile('/svn_repo/test_repo/repo/conf/authz');

確認
diff distconfig.php config.php

# Apache再起動
systemctl restart httpd

ブラウザ表示確認 https://SVNサーバのGIP/websvn/
キャプチャ2.PNG
こちらでリビジョン管理等が確認できるようになります。

Tortoisesvnなどツールの使い方やACLについては別の記事で記載できたらと思います。
構築より運用の方法を決めて管理するほうが大変だったりするんですけどね…

5
8
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
5
8