1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
|
---|
3 | "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
|
---|
4 | <!ENTITY % general-entities SYSTEM "../../general.ent">
|
---|
5 | %general-entities;
|
---|
6 |
|
---|
7 | ]>
|
---|
8 |
|
---|
9 | <sect1 id="svnserver" xreflabel="Running a Subversion Server">
|
---|
10 | <?dbhtml filename="svnserver.html"?>
|
---|
11 | <title>Running a Subversion Server</title>
|
---|
12 |
|
---|
13 | <sect2>
|
---|
14 | <title>Running a Subversion Server</title>
|
---|
15 | <para>This section will describe how to set up, administer and secure
|
---|
16 | a <application>Subversion</application> server. Since
|
---|
17 | <application>Subversion</application> is intended to replace
|
---|
18 | <acronym>CVS</acronym>, it may surprise you how very different the setup
|
---|
19 | of a <application>Subversion</application> repository is compared to a
|
---|
20 | <acronym>CVS</acronym> repository.</para>
|
---|
21 |
|
---|
22 | <sect3><title><application>Subversion server</application> dependencies</title>
|
---|
23 | <sect4><title>Required</title>
|
---|
24 | <para><xref linkend="subversion"/> and <xref linkend="openssh"/></para></sect4>
|
---|
25 | </sect3>
|
---|
26 |
|
---|
27 | </sect2>
|
---|
28 |
|
---|
29 | <sect2>
|
---|
30 | <title>Setting up a <application>Subversion</application> server.</title>
|
---|
31 |
|
---|
32 | <para>A <application>Subversion</application> server will be set up using
|
---|
33 | OpenSSH as the remote access method.</para>
|
---|
34 |
|
---|
35 | <para>Configuration of the <application>Subversion</application> server
|
---|
36 | consists of the following steps:</para>
|
---|
37 |
|
---|
38 | <sect3><title>1. Setup users, groups, and permissions</title>
|
---|
39 | <para>You'll need to be user root for the initial portion of
|
---|
40 | configuration. Create the svn user and group with the following
|
---|
41 | commands:</para>
|
---|
42 |
|
---|
43 | <screen><userinput><command>groupadd svn &&
|
---|
44 | useradd -c "SVN Owner" -d /home/svn -m -g svn -s /bin/false svn</command></userinput></screen>
|
---|
45 |
|
---|
46 | <para>If you plan to have multiple repositories, you should have a
|
---|
47 | group dedicated to each repository for ease of administration. Create
|
---|
48 | the svntest group for our test repository and add the svn user to that
|
---|
49 | group with the following commands:</para>
|
---|
50 |
|
---|
51 | <screen><userinput><command>groupadd svntest &&
|
---|
52 | usermod -G svntest svn</command></userinput></screen>
|
---|
53 |
|
---|
54 | <para>Additionally you should set umask '002' while working with a
|
---|
55 | repository so that all new files will be writable by owner and group.
|
---|
56 | We'll make this mandatory by writing a wrapper script for
|
---|
57 | <command>svn</command> and <command>svnserve</command>:</para>
|
---|
58 |
|
---|
59 | <screen><userinput><command>mv /usr/bin/svn /usr/bin/svn.orig &&
|
---|
60 | mv /usr/bin/svnserve /usr/bin/svnserve.orig &&
|
---|
61 | cat >> /usr/bin/svn << "EOF" &&</command>
|
---|
62 | #!/bin/sh
|
---|
63 | umask 002
|
---|
64 | /usr/bin/svn.orig "$@"
|
---|
65 | <command>EOF
|
---|
66 | cat >> /usr/bin/svnserve << "EOF" &&</command>
|
---|
67 | #!/bin/sh
|
---|
68 | umask 002
|
---|
69 | /usr/bin/svnserve.orig "$@"
|
---|
70 | <command>EOF
|
---|
71 | chmod 0755 /usr/bin/svn{,serve}</command></userinput></screen>
|
---|
72 |
|
---|
73 | <note>If you use <application>apache</application> for working with
|
---|
74 | the repository over the web, even for anonymous access, you should wrap
|
---|
75 | <application>apache</application> in a similar script.</note>
|
---|
76 |
|
---|
77 | </sect3>
|
---|
78 |
|
---|
79 | <sect3><title>2. Create a <application>Subversion</application>
|
---|
80 | repository.</title>
|
---|
81 | <para>Create a new <application>Subversion</application> repository with
|
---|
82 | the following commands:</para>
|
---|
83 | <screen><userinput><command>install -d -m0755 /srv &&
|
---|
84 | install -d -m0755 -o svn -g svn /srv/svn/repositories &&
|
---|
85 | svnadmin create /srv/svn/repositories/svntest</command></userinput></screen>
|
---|
86 |
|
---|
87 | <para>Now that the repository is created, we need to populate it with
|
---|
88 | something useful. You'll need to have a predefined directory layout
|
---|
89 | setup exactly as you want your repository to look. For example, here
|
---|
90 | is a sample BLFS layout setup with a root of <filename>svntest/</filename>.
|
---|
91 | You'll need to setup a directory tree similar to the following:</para>
|
---|
92 |
|
---|
93 | <screen> svntest/ # The name of the repository
|
---|
94 | trunk/ # Contains the existing source tree
|
---|
95 | BOOK/
|
---|
96 | bootscripts/
|
---|
97 | edguide/
|
---|
98 | patches/
|
---|
99 | scripts/
|
---|
100 | branches/ # Needed for additional branches
|
---|
101 | tags/ # Needed for tagging release points</screen>
|
---|
102 |
|
---|
103 | <para>Once you've created your directory layout as above, you are ready to
|
---|
104 | do the initial import:</para>
|
---|
105 |
|
---|
106 | <screen><userinput><command>svn import -m "Initial import." \
|
---|
107 | <replaceable>[/path/to/source/tree]</replaceable> \
|
---|
108 | file:///srv/svn/repositories/svntest</command></userinput></screen>
|
---|
109 |
|
---|
110 | <para>Now go ahead and change owner and group information on the
|
---|
111 | repository, add your normal user to the svn and svntest groups:</para>
|
---|
112 |
|
---|
113 | <screen><userinput><command>chown -R svn:svntest /srv/svn/repositories/svntest &&
|
---|
114 | chmod -R g+w /srv/svn/repositories/svntest &&
|
---|
115 | chmod g+s /srv/svn/repositories/svntest/db &&
|
---|
116 | usermod -G svn,svntest,<replaceable>[insert existing groups]</replaceable> <replaceable>[username]</replaceable></command></userinput></screen>
|
---|
117 |
|
---|
118 | <para>svntest is the group assigned to the svntest repository. As
|
---|
119 | mentioned earlier, this eases administration of multiple repositories.
|
---|
120 | Going forward, you'll need to add your regular user, and any additional
|
---|
121 | users that you wish to have write access to the repository, to the svn and
|
---|
122 | svntest groups.</para>
|
---|
123 |
|
---|
124 | <para>In addition, you'll notice that the new repository's
|
---|
125 | <filename>db</filename> directory is set-groupID. If the reasoning is
|
---|
126 | not immediately obvious, when using any external authentication method
|
---|
127 | (such as ssh), the sticky bit is set so that all new files will be owned
|
---|
128 | by the user, but group of svntest. Anyone in the svntest group can
|
---|
129 | create files, but still give the entire group write access to those
|
---|
130 | files. This avoids locking out other users from the repository.</para>
|
---|
131 |
|
---|
132 | <para>Now, go ahead and return to your normal user account, and take a look at
|
---|
133 | your new repository using svnlook:</para>
|
---|
134 |
|
---|
135 | <screen><userinput><command>svnlook tree /srv/svn/repositories/svntest/</command></userinput></screen>
|
---|
136 |
|
---|
137 | <note>You may need to logout and back in again to refresh your group
|
---|
138 | memberships. 'su <replaceable>[username]</replaceable>' should work
|
---|
139 | around this as well. </note>
|
---|
140 |
|
---|
141 | </sect3>
|
---|
142 |
|
---|
143 | <sect3><title>3. Configure the server</title>
|
---|
144 |
|
---|
145 | <para>These instructions will configure the server to use only ssh
|
---|
146 | for write permission, and provide anonymous read-only permission. There
|
---|
147 | are several other ways to provide access to the repository. These
|
---|
148 | additional configurations are best explained at
|
---|
149 | <ulink url="http://svnbook.red-bean.com/" />.</para>
|
---|
150 |
|
---|
151 | <para>Access configuration needs to be done for each repository. Create
|
---|
152 | the <filename>svnserve.conf</filename> file for the svntest repository
|
---|
153 | using the following commands:</para>
|
---|
154 |
|
---|
155 | <screen><userinput><command>cp /srv/svn/repositories/svntest/conf/svnserve.conf \
|
---|
156 | /srv/svn/repositories/svntest/conf/svnserve.conf.default &&
|
---|
157 | cat > /srv/svn/repositories/svntest/conf/svnserve.conf << "EOF"</command>
|
---|
158 | [general]
|
---|
159 | anon-access = read
|
---|
160 | auth-access = write
|
---|
161 | <command>EOF</command></userinput></screen>
|
---|
162 |
|
---|
163 | <para>There is not a lot to the configuration file at all. You'll notice
|
---|
164 | that only the general section is required. Take a look at the
|
---|
165 | <filename>svnserve.conf.default</filename> for information on using
|
---|
166 | <command>svnserve</command>'s built-in authentication method.</para>
|
---|
167 |
|
---|
168 | </sect3>
|
---|
169 |
|
---|
170 | <sect3><title>4. Starting the server</title>
|
---|
171 | <para>There are a couple of ways to start <command>svnserve</command>. The
|
---|
172 | most common way is to start it as an <application>inetd</application> or
|
---|
173 | <application>xinetd</application> process. Alternately, you can use a
|
---|
174 | bootscript to start the service at startup.</para>
|
---|
175 |
|
---|
176 | <para>If you use <application>inetd</application>, add a line to your
|
---|
177 | <filename>/etc/inetd.conf</filename> using the following commands:</para>
|
---|
178 |
|
---|
179 | <screen><userinput><command>cat >> /etc/inetd.conf << "EOF"</command>
|
---|
180 | svn stream tcp nowait svn /usr/bin/svnserve svnserve -i
|
---|
181 | <command>EOF</command></userinput></screen>
|
---|
182 |
|
---|
183 | <para>If you use <application>xinetd</application>, add the following
|
---|
184 | lines to <filename>/etc/xinetd.conf</filename> file:</para>
|
---|
185 |
|
---|
186 | <screen><userinput><command>cat >> /etc/xinetd.conf << "EOF"</command>
|
---|
187 | service svn
|
---|
188 | {
|
---|
189 | port = 3690
|
---|
190 | socket_type = stream
|
---|
191 | protocol = tcp
|
---|
192 | wait = no
|
---|
193 | user = svn
|
---|
194 | server = /usr/bin/svnserve
|
---|
195 | server_args = -i -r /srv/svn/repositories
|
---|
196 | }
|
---|
197 | <command>EOF</command></userinput></screen>
|
---|
198 |
|
---|
199 | <para>Finally, if you wish to simply start the sever in daemon mode at
|
---|
200 | startup, install the svn bootscript included in the
|
---|
201 | <xref linkend="intro-important-bootscripts"/> package.</para>
|
---|
202 |
|
---|
203 | <screen><userinput><command>make install-svn</command></userinput></screen>
|
---|
204 |
|
---|
205 | </sect3>
|
---|
206 |
|
---|
207 | </sect2>
|
---|
208 |
|
---|
209 | </sect1>
|
---|
210 |
|
---|