우분투(ubuntu) - svn 설치
"리눅스 서버(우분투) 설치하기"에 이은 글입니다. 형상 관리 시스템중의 하나인 서브버전(Subversion)을 설치하고 형상 관리 리포지토리를 생성한 다음에 다른 컴퓨터에서 네트워크로 체크아웃 받고 커밋하는 과정까지를 다룹까 합니다. 우분투 서버에 서브버전 및 트랙 설치는 Ubuntu 16.04 32비트 버전에서 수행 했습니다.
모든 설치 작업 이전에는 일단 sudo apt-get update 명령으로 업데이트를 수행한 다음에 작업을 진행합니다.
sudo apt-get update
받기:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]
기존:2 http://us.archive.ubuntu.com/ubuntu xenial InRelease
받기:3 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
받기:4 http://us.archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
받기:5 http://us.archive.ubuntu.com/ubuntu xenial/main Translation-ko [80.2 kB]
받기:6 http://us.archive.ubuntu.com/ubuntu xenial/restricted Translation-ko [716 B]
받기:7 http://us.archive.ubuntu.com/ubuntu xenial/universe Translation-ko [158 kB]
내려받기 564 k바이트, 소요시간 4초 (136 k바이트/초)
패키지 목록을 읽는 중입니다... 완료
■ 서브버전 설치
우분투 서버에서의 서브버전 설치는 sudo apt-get install subversion 명령으로 수행합니다. 아래는 그 설치 과정입니다.
sudo apt-get install subversion
[sudo] password for ssu:
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다
상태 정보를 읽는 중입니다... 완료
The following additional packages will be installed:
libapr1 libaprutil1 libserf-1-1 libsvn1
제안하는 패키지:
db5.3-util libapache2-mod-svn subversion-tools
다음 새 패키지를 설치할 것입니다:
libapr1 libaprutil1 libserf-1-1 libsvn1 subversion
0개 업그레이드, 5개 새로 설치, 0개 제거 및 36개 업그레이드 안 함.
2,237 k바이트 아카이브를 받아야 합니다.
이 작업 후 9,910 k바이트의 디스크 공간을 더 사용하게 됩니다.
계속 하시겠습니까? [Y/n] y
받기:1 http://archive.ubuntu.com/ubuntu bionic/main amd64 libapr1 amd64 1.6.3-2 [90.9 kB]
받기:2 http://archive.ubuntu.com/ubuntu bionic/main amd64 libaprutil1 amd64 1.6.1-2 [84.4 kB]
받기:3 http://archive.ubuntu.com/ubuntu bionic/universe amd64 libserf-1-1 amd64 1.3.9-6 [44.4 kB]
받기:4 http://archive.ubuntu.com/ubuntu bionic/universe amd64 libsvn1 amd64 1.9.7-4ubuntu1 [1,183 kB]
받기:5 http://archive.ubuntu.com/ubuntu bionic/universe amd64 subversion amd64 1.9.7-4ubuntu1 [834 kB]
내려받기 2,237 k바이트, 소요시간 4초 (531 k바이트/초)
Selecting previously unselected package libapr1:amd64.
(데이터베이스 읽는중 ...현재 67517개의 파일과 디렉터리가 설치되어 있습니다.)
Preparing to unpack .../libapr1_1.6.3-2_amd64.deb ...
Unpacking libapr1:amd64 (1.6.3-2) ...
Selecting previously unselected package libaprutil1:amd64.
Preparing to unpack .../libaprutil1_1.6.1-2_amd64.deb ...
Unpacking libaprutil1:amd64 (1.6.1-2) ...
Selecting previously unselected package libserf-1-1:amd64.
Preparing to unpack .../libserf-1-1_1.3.9-6_amd64.deb ...
Unpacking libserf-1-1:amd64 (1.3.9-6) ...
Selecting previously unselected package libsvn1:amd64.
Preparing to unpack .../libsvn1_1.9.7-4ubuntu1_amd64.deb ...
Unpacking libsvn1:amd64 (1.9.7-4ubuntu1) ...
Selecting previously unselected package subversion.
Preparing to unpack .../subversion_1.9.7-4ubuntu1_amd64.deb ...
Unpacking subversion (1.9.7-4ubuntu1) ...
libapr1:amd64 (1.6.3-2) 설정하는 중입니다 ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
libaprutil1:amd64 (1.6.1-2) 설정하는 중입니다 ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
libserf-1-1:amd64 (1.3.9-6) 설정하는 중입니다 ...
libsvn1:amd64 (1.9.7-4ubuntu1) 설정하는 중입니다 ...
subversion (1.9.7-4ubuntu1) 설정하는 중입니다 ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
정상적으로 서브버전이 설치되면 리눅스/유닉스에서 서브버전 형상 관리 서비스를 사용할 때 사용하는 명령인 svn을 svn help 명령으로 정상적으로 동작하는지 확인합니다.
$ svn help
usage: svn <subcommand> [options] [args]
Subversion command-line client.
Type 'svn help <subcommand>' for help on a specific subcommand.
Type 'svn --version' to see the program version and RA modules
or 'svn --version --quiet' to see just the version number.
......
■ 아파치 웹서버 설치
서브버전은 자체 서버가 있어서 서버를 가동시키면 "svn://도메인주소/리포지토리이름"과 같은 형식의 URL을 통해서 저장소에 접근하여 체크아웃하거나 커밋 할 수도 있지만 많은 프로젝트등은 통상 웹서버를 통해서 서브버전 저장소에 접근할 수 있는 통로를 제공합니다. "http://도메인주소/svn/리포지토리이름"과 같은 형식의 URL을 사용할 수 있습니다. 본 포스팅에서는 웹서버를 통한 서비스 제공 방법을 다룰까 합니다.
웹서버 설치는 sudo apt-get install apache2 명령으로 진행합니다.
웹서버 설치가 끝나면 앞서 ssh 서버를 설치했을 때와 마찬가지로 설치가 끝나면 웹서버를 자동으로 가동시킵니다. 현재 서비스 대기중인 포트를 검색하는 명령인 "netstat -a | grep LISTEN"를 수행하면 위의 그림과 같이 ssh 서버와 웹서버(http)가 가동중임을 확인할 수 있습니다.
이 상태에서 웹브라우저에 주소를 입력하면 위의 그림과 같은 기본 페이지를 확인할 수 있습니다.
■ 서브버전 관련 아파치 모듈 설치
아파치 웹서버는 확장 모듈을 통해서 다양한 기능을 사용할 수 있는데 서브버전 확장 모듈을 설치하면 웹서비스를 통해서 서브버전 저장소에 접근할 수 있습니다.
sudo apt-get install libapache2-mod-svn libapache2-svn libsvn-dev 명령으로 서브버전 관련 아파치 모듈들을 설치 할 수 있습니다.
연관 모듈 설치가 끝나면 아래의 명령들을 차례대로 수행시킵니다.
sudo a2enmod dav
sudo a2enmod dav_svn
sudo service apache2 restart
위의 명령들은 설치한 서브버전 연관 모듈을 아파치 웹서버에 적용하고 웹서비스를 재가동시키는 과정입니다. 연관 모듈을 설치하면서 바로 적용되기 때문에 위의 명령들은 생략해도 되지만 확인을 위해서 각 과정을 진행합니다.
■ 아파치 웹서버 설정
웹서버 설정에 서브버전 연관 설정을 추가합니다. sudo vi /etc/apache2/mods-enabled/dav_svn.conf 명령으로 편집합니다.(vi 에디터 사용법은 "VI(Vim)에서 자주사용하는 기능 정리"를 참조합니다)
# dav_svn.conf - Example Subversion/Apache configuration
#
# For details and further options see the Apache user manual and
# the Subversion book.
#
# NOTE: for a setup with multiple vhosts, you will want to do this
# configuration in /etc/apache2/sites-available/*, not here.
# <Location URL> ... </Location>
# URL controls how the repository appears to the outside world.
# In this example clients access the repository as http://hostname/svn/
# Note, a literal /svn should NOT exist in your document root.
<Location /svn>
# Uncomment this to enable the repository
DAV svn
# Set this to the path to your repository
#SVNPath /var/lib/svn
# Alternatively, use SVNParentPath if you have multiple repositories under
# under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
# You need either SVNPath and SVNParentPath, but not both.
SVNParentPath /var/lib/svn
# Access control is done at 3 levels: (1) Apache authentication, via
# any of several methods. A "Basic Auth" section is commented out
# below. (2) Apache <Limit> and <LimitExcept>, also commented out
# below. (3) mod_authz_svn is a svn-specific authorization module
# which offers fine-grained read/write access control for paths
# within a repository. (The first two layers are coarse-grained; you
# can only enable/disable access to an entire repository.) Note that
# mod_authz_svn is noticeably slower than the other two layers, so if
# you don't need the fine-grained control, don't configure it.
# Basic Authentication is repository-wide. It is not secure unless
# you are using https. See the 'htpasswd' command to create and
# manage the password file - and the documentation for the
# 'auth_basic' and 'authn_file' modules, which you will need for this
# (enable them with 'a2enmod').
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
# To enable authorization via mod_authz_svn (enable that module separately):
#<IfModule mod_authz_svn.c>
#AuthzSVNAccessFile /etc/apache2/dav_svn.authz
#</IfModule>
# The following three lines allow anonymous read, but make
# committers authenticate themselves. It requires the 'authz_user'
# module (enable it with 'a2enmod').
#<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
#</LimitExcept>
</Location>
dav_svn.conf 파일을 열면 모든 라인 앞에 #를 붙여서 주석처리하고 있는데 필요한 부분 라인에 대해서 #를 제거하고 설정을 변경합니다. 설정 파일에 대부분의 설명이 있으므로 참조하고 주요 설정은 아래와 같습니다.
- SVNParentPath : 서브버전 저장소의 루트 디렉토리로 지정한 디렉토리는 다음 단계에서 생성해야 하고 이 폴더 아래에 각 프로젝트별 저장소를 생성합니다.
- AuthUserFile : 사용자 아이디와 비밀번호를 가지고 있는 파일로 추후에 설치할 Trac 프로젝트에서도 인증 파일로 사용하므로 잘 메모해 두어야 합니다. 이 인증 파일에 대해서 htpasswd 도구로 사용자를 추가하거나 비밀번호를 등록합니다.
- LimitExcept 와 Require valid-user : 오픈 소스 프로젝트 처럼 저장소에 대한 접근을 아이디가 없는 사람에게도 공개하는 경우에는 LimitExcept 구문에 대한 주석을 풀어야 겠지만 필자의 경우에는 내부 팀에서 아이디가 있는 사용자만 읽기 및 쓰기가 가능하도록 할 예정이므로 LimitExcept 구문은 적용하지 않았습니다.
설정이 끝났으면 sudo service apache2 restart 명령으로 웹서버를 재가동 시켜 설정 내용을 적용 시킵니다.
■ 서브버전 사용자 생성 및 관리
sudo htpasswd -cm /etc/apache2/dav_svn.passwd admin
New password:
Re-type new password:
Adding password for user admin
앞서 아파치 설정으로 등록한 서브버전 인증 파일 경로를 대상으로 위의 그림과 같이 sudo htpasswd -cm /etc/apache2/dav_svn.passwd admin 명령으로 인증 파일을 생성합니다. 관리자 아이디는 admin이 아닌 사용자 나름의 아이디로 등록해도 됩니다.
일단 인증 파일을 생성한 다음에는 "sudo htpasswd -m /etc/apache2/dav_svn.passwd user1" 와 같은 방식으로 사용자를 추가하거나 비밀번호를 변경 할 수 있습니다. 특정 사용자를 삭제 하려면 -D 옵션을 사용하면 됩니다.
■ 서브버전 저장소 생성
sudo mkdir -p /var/lib/svn/
sudo chown -R www-data:www-data /var/lib/svn
sudo chmod -R 775 /var/lib/svn
앞서 아파치 설정으로 등록했던 서브버전 저장소를 생성하고 웹 프로세스의 사용자 아이디인 "www-data"로 소유자를 변경하고 폴더 접근 권한을 변경 합니다.
cd /var/lib/svn/
sudo svnadmin create testprj
sudo chown -R www-data:www-data testprj
sudo chmod -R 775 testprj
sudo svn mkdir --username admin --password admin -m "New repository" file:////var/lib/svn/testprj/trunk file:////var/lib/svn/testprj/tags file:////var/lib/svn/testprj/branches
프로젝트 단위로 저장소를 추가할 때는 저장소의 루트 폴더인 /var/lib/svn/로 이동하여 위와 같은 명령으로 프로젝트별 저장소를 생성하고 작업을 준비합니다. 새롭게 생성한 프로젝트 폴더에 대한 소유자 및 접근 권한 변경 다음의 작업은 통상 서브버전 형상 관리 저장소의 기본 디렉토리인 trunk, tags, branches를 앞서 생성한 관리자 및 관리자 비밀번호 인증으로 생성하는 과정입니다. 새로운 프로젝트를 추가할 때 마다 위의 작업을 해주면 됩니다.
■ 저장소 접근 테스트
테스트는 윈도우 시스템을 사용하는 다른 컴퓨터에서 진행하는 예제입니다. 예제에서는 토터스SVN(TortoiseSVN)을 사용합니다. 다운로드 및 설치는 https://tortoisesvn.net/downloads.html 를 참조합니다.
정상적으로 설치했으면 탐색기의 팝업 메뉴에 다음 그림과 같이 SVN Checkout과 TortoiseSVN 메뉴를 확인할 수 있습니다.

윈도우 탐색기에서 프로젝트 사본을 저장할 곳으로 이동하여 컨텍스트 메뉴>SVN Checkout을 선택 합니다.

URL에는 앞서 설치한 우분투 서버의 IP주소(hosts에 IP주소를 등록해 놓으면 이름으로 사용해서 더 편리할 수 있습니다)와 /svn/프로젝트이름을 기술하고 그 다음에 기본 디렉토리 중에 trunk에서 작업을 시작합니다. 체크 아웃 디렉토리는 프로젝트 이름을 보고 자동 설정해 주기는 하지만 어떤 이름으로 해도 상관 없습니다.

체크아웃을 진행하면 위의 그림과 같이 인증 정보를 요구하는데 앞서 등록한 사용자 아이디와 비밀번호를 입력합니다. "Save authentication"을 체크해 두면 다음번 부터는 이 서버에 대해서 인증창에 다시 나오지 않도록 자동 인증 합니다.

출처: https://yaraba.tistory.com/1239 [야라바]