4bff4e7275a83071a18f03c6b29ea5f98e3aee95
[openafs-wiki.git] / admin / InstallingOpenAFSonCentOS7.mdwn
1 This is a step-by-step guide to installing OpenAFS and setting up an AFS cell
2 on CentOS 7, and presumably RedHat Enterprise Linux 7, and anything from that
3 same family.  It is current as of OpenAFS version 1.8.3 on CentOS 7.
4
5 This document is based on [[InstallingOpenAFSonRHEL]] and includes information from 
6 the [Unix Quick Start Guide](http://docs.openafs.org/QuickStartUnix/).
7
8 [[!toc levels=1]]
9
10 ## Naming conventions
11
12 When setting up an AFS cell on the internet, the convention is to user your
13 internet domain name for your Kerberos realm and AFS cell name.  The Kerberos
14 realm name should be uppercase and the AFS cell name should be lowercase.
15
16 Note, it is possible to create a AFS cell with a different name than the
17 Kerberos realm (or even use a single Kerberos realm in multiple cells).  See
18 the documentation for the OpenAFS `krb.conf` server configuration file for
19 details on mapping realms to cell names.
20
21 ## Server setup
22
23 A minimal OS install is sufficient.
24
25 For a simple installation, you may use a single server to host the Kerberos
26 KDC, OpenAFS database server, and OpenAFS fileserver.  For a production
27 environment, it is recommended that the Kerberos KDC be deployed on a
28 dedicated, secure server, the OpenAFS database servers be deployed on three
29 separate machines, and multiple file servers deployed as needed.
30
31 ### Disk Partitions
32
33 An important thing to keep in mind is that you'll need at least one partition
34 on the file server to store volumes for AFS.  This will be mounted at
35 `/vicepa`. If you have multiple partitions they can be mounted at `/vicepb`,
36 `/vicepc`, etc.  The file server uses file-based storage (not block based).
37 `ext3`, `ext4`, and `xfs` are commonly used filesystems on the vicep
38 partitions.
39
40 Clients should have a dedicated partition for the file cache. The cache
41 partition is traditionally mounted at `/usr/vice/cache`.
42
43 ### Networking
44
45 DNS should be working correctly for forward and reverse name lookups before you
46 begin the Kerberos and OpenAFS installation.  `bind` can be installed if you
47 need a local DNS server.  Use `system-config-bind` to add a zone and entries.
48
49 Servers need at least one IPv4 interface that is accessible by the AFS clients.
50 IPv6 interfaces are not yet supported.
51
52 ### Time keeping
53
54 Kerberos, and therefore OpenAFS, requires good clock synchronization between
55 clients and servers. As CentOS 7 enables `chronyd` for time synchronization
56 out of the box, it is unlikely you will need to make a change.
57
58 ### Firewall
59
60 The default firewall settings on RHEL will block the network ports used by
61 Kerberos and OpenAFS.  You will need to adjust the firewall rules on the
62 servers to allow traffic on these ports. 
63
64 On the Kerberos server, open udp ports 88 and 646:
65
66     # firewall-cmd --zone=public --add-port=88/udp
67     # firewall-cmd --zone=public --add-port=646/udp
68     # firewall-cmd --runtime-to-permanent
69
70 On the OpenAFS database servers, open the udp ports 7002, 7003, and 7007:
71
72     # firewall-cmd --zone=public --add-port=7002/udp
73     # firewall-cmd --zone=public --add-port=7003/udp
74     # firewall-cmd --zone=public --add-port=7007/udp
75     # firewall-cmd --runtime-to-permanent
76
77 On the OpenAFS file servers, open the udp ports 7000, 7005, and 7007:
78
79     # firewall-cmd --zone=public --add-port=7000/udp
80     # firewall-cmd --zone=public --add-port=7005/udp
81     # firewall-cmd --zone=public --add-port=7007/udp
82     # firewall-cmd --runtime-to-permanent
83
84 OpenAFS clients use udp port 7001. Open udp port 7001 on any system that will
85 have the OpenAFS client installed.
86
87     # firewall-cmd --zone=public --add-port=7001/udp
88     # firewall-cmd --runtime-to-permanent
89
90 ## Installing Kerberos
91
92 Install the Kerberos server and client packages with the command:
93
94     # yum install -y krb5-server krb5-workstation krb5-libs
95
96 Replace every instance of `EXAMPLE.COM` with your realm name in the following
97 configuration files:
98
99   * `/etc/krb5.conf`
100   * `/var/kerberos/krb5kdc/kdc.conf`
101   * `/var/kerberos/krb5kdc/kadm5.acl`
102
103 Replace every instance of the example hostname `kerberos.example.com` with
104 the actual hostname of your Kerberos server in the file `/etc/krb5.conf`.
105
106 Create the Kerberos database using the `krb5_util` command. You will be
107 prompted for a master principal password. Choose a password, keep it secret,
108 and keep it safe.
109
110     # /usr/sbin/kdb5_util create -s
111
112 Start the Kerberos servers.
113
114     # systemctl start krb5kdc
115     # systemctl start kadmin
116     # systemctl enable krb5kdc
117     # systemctl enable kadmin
118
119 ## Installing OpenAFS servers
120
121 ### Installing servers
122
123 OpenAFS source RPM packages are available on the OpenAFS website. You will need to build the
124 RPMs using the `rpmbuild` command.  There are third party sources for pre-built packages, in particular
125 the CentOS Storage SIG, but note that at least with the Storage SIG's packages, configuration files are
126 located in `/etc/openafs` and servers `/usr/libexec/openafs` instead of the traditional paths.
127
128     # curl -O http://openafs.org/dl/openafs/<version>/openafs-<version>-1.src.rpm
129     # yum install ncurses-devel flex bison automake autoconf libtool perl-devel perl-ExtUtils-Embed krb5-del
130     # rpmbuild --rebuild -bb \
131         openafs-<version>-1.src.rpm
132
133 where `<version>` is the OpenAFS version you wish to install, e.g. "1.8.3".
134
135 Use `yum` to install the OpenAFS server packages from your your rpmbuild RPMS directory:
136     # yum install -y openafs-<version>-1.el7.x86_64.rpm openafs-server-<version>-1.el7.x86_64.rpm openafs-docs-<version>-1.el7.x86_64.rpm openafs-krb5-<version>-1.el7.x86_64.rpm
137
138 Create the Kerberos AFS service key and export it to a keytab file:
139
140     # cellname=<cellname>
141     # kadmin.local -q "addprinc -randkey -e aes256-cts-hmac-sha1-96:normal,aes128-cts-hmac-sha1-96:normal afs/${cellname}"
142     # kadmin.local -q "ktadd -k /usr/afs/etc/rxkad.keytab -e aes256-cts-hmac-sha1-96:normal,aes128-cts-hmac-sha1-96:normal afs/${cellname}"
143
144 where `<cellname>` is the name of your cell.  Make note of the key version number (kvno) as it is needed for the next step where it shows `<kvno>`.
145
146     # asetkey add rxkad_krb5 <kvno> 18 /usr/afs/etc/rxkad.keytab afs/${cellname}
147     # asetkey add rxkad_krb5 <kvno> 17 /usr/afs/etc/rxkad.keytab afs/${cellname}
148
149
150 If your Kerberos REALM name is different from your cell name add your upper case
151 REALM name in /usr/afs/etc/krb.conf, else you will not know why your cell does not work!
152
153 Start the OpenAFS servers:
154
155     # systemctl start openafs-server
156     # systemctl enable openafs-server
157
158 Check the server log `/usr/afs/logs/BosLog` to verify the OpenAFS `bosserver`
159 process started.  Set the cell name with the command:
160
161     # bos setcellname localhost ${cellname} -localauth
162
163 ### Starting the database services
164
165 The `ptserver` process stores the AFS users and group names in your cell. The
166 `vlserver` process stores the file server locations of the AFS volumes in your
167 cell.  Start the OpenAFS database processes with the commands:
168
169     # bos create localhost ptserver simple -cmd /usr/afs/bin/ptserver -localauth
170     # bos create localhost vlserver simple -cmd /usr/afs/bin/vlserver -localauth
171
172 Check the log files `BosLog`, `PTLog`, `VLLog` in the `/usr/afs/logs`
173 directory to verify the `ptserver` and `vlserver` started.
174
175 ### Starting the file server
176
177 Start the file server. This is a rather long command line.
178
179     # bos create localhost \
180        dafs dafs -cmd \
181        "/usr/afs/bin/dafileserver -L" \
182        "/usr/afs/bin/davolserver -p 64 -log" \
183        "/usr/afs/bin/salvageserver" \
184        "/usr/afs/bin/dasalvager -parallel all32" \
185        -localauth
186
187 Check the servers logs `BosLog`, `FileLog`, `VolserLog`, and `SalsrvLog`, in
188 `/usr/afs/logs' to verify the file server started.  At this point the OpenAFS
189 server processes should be running.
190
191 ### Creating the admin account
192
193 Create a user account for Kerberos and AFS administration.
194
195     # myname=<username>
196     # kadmin.local -q "addprinc ${myname}/admin"
197     Enter password: <password>
198     Re-enter password: <password>
199     # pts createuser ${myname}.admin -localauth
200     # pts adduser ${myname}.admin system:administrators -localauth
201     # bos adduser localhost ${myname}.admin -localauth
202
203 where `<myname>` is your user name and `<password>` is your chosen password.
204
205 The admin principal can be any name you want.  The recommended practice is to
206 create two principals for admins: one for your normal user, and an additional
207 admin account. For example, I may have `steve` and `steve/admin`. Note that for
208 Kerberos 5, the name is `steve/admin@REALM`, whereas in AFS, the name is
209 `steve.admin`. Use `steve.admin` for all AFS commands.  Since this is to be an
210 administrator we will also register it as such with the `bos` server. We can give
211 it administrator rights by adding it to the group `system:administrators`. This
212 is an AFS default group. The `pts membership` command will list all the groups
213 that your user is a member of. Verify that it lists `system:administrators`.
214
215 ### Create the root volumes
216
217 At this point we need our `/vicepa` partition.  You should have done this when
218 installing the operating system. If you have not, do it now, then restart the
219 fileserver with `systemctl restart openafs-server`.  (If this is only a test
220 system you may create a pseudo partition without needing to create an actual
221 separate filesystem. To do this, create an empty directory called `/vicepa` and
222 then create an empty file called `/vicepa/AlwaysAttach`, then restart the file
223 server with `systemctl restart openafs-server`.)
224
225 Create the root volumes with the commands:
226
227     # vos create localhost a root.afs -localauth
228     # vos create localhost a root.cell -localauth
229
230 Check the volume location database to verify the two volumes are listed.
231
232     # vos listvldb
233
234 Finally, now that the server configuration is done, put the `bosserver` into
235 the more secure restricted mode, which disables several bos commands which are
236 strictly not needed for normal operation.
237
238     # bos setrestricted localhost -mode 1 -localauth
239
240 This completes the server side setup. At this point will need to install the
241 OpenAFS cache manager (client), setup the top level directories, and then start
242 adding files to your new cell.  The cache manager may be installed on a
243 separate machine (for example, your laptop.)  Also, you will no longer be using
244 the `root` user to run OpenAFS commands, but instead from this point forward
245 you should use your Kerberos credentials.
246
247 ## Installing OpenAFS Client
248
249 ### Kernel Module
250
251 If installing the cache manager on an OpenAFS server, first remove the symlinks
252 created by `bosserver`. These will be in the way if the client is installed.
253
254     # test -h /usr/vice/etc/ThisCell && rm /usr/vice/etc/ThisCell
255     # test -h /usr/vice/etc/CellServDB && rm /usr/vice/etc/CellServDB
256
257 The OpenAFS kernel module must match your kernel version.  Unless you are maintaining
258 a local `yum` repository that tracks every single kernel release and updates its kmod builds,
259 you will want to use the DKMS mechanism for installing the the kernel module.  If
260 you are installing on a freshly patched machine, be sure to reboot before installing
261 the OpenAFS kernel module.  Assuming you are using the same set of packages built earlier:
262
263     # yum install -y dkms gcc kernel-devel kernel-headers
264     # yum install -y openafs-<version>-1.el7.x86_64.rpm openafs-client-<version>-1.el7.x86_64.rpm openafs-krb5-<version>-1.el7.x86_64.rpm dkms-openafs-<version>-1.el7.x86_64.rpm
265
266 ### Client side configuration
267
268 `/usr/afs/etc` is the location for the server files. We also need to configure
269 the client. The client files are located in `/usr/vice/etc`. RPM based OpenAFS
270 packages are set up in such a way that there are two `CellServDB` client
271 files in `/usr/vice/etc`: `CellServDB.dist` and `CellServDB.local`. We will
272 copy ours to the local list.
273
274     # cp /usr/afs/etc/CellServDB /usr/vice/etc/CellServDB.local
275     # cp /usr/afs/etc/ThisCell /usr/vice/etc/ThisCell
276
277 The RPM based `openafs-client` init script will combine the `CellServDB.dist`
278 and `CellServDB.local` files into the `CellServDB` file, which the cache
279 manager reads on startup.
280
281 ### Start the cache manager
282
283 Start the cache manager with the command:
284
285     # systemctl start openafs-client
286     # systemctl enable openafs-client
287
288 Run the `mount` command to verify the AFS filesystem is mounted at `/afs`.
289
290 Try logging in to AFS. `kinit` logs you into Kerberos (this is the normal
291 Kerberos utility). `aklog` gets you an AFS token.  The `tokens` command lists
292 the tokens you have. You should see `afs@<cellname>`. If you run into problems, you
293 can use `klist` to list your Kerberos tickets, or `aklog` with the `-d` flag.
294
295     $ kinit <username>/admin
296     <password>
297     $ aklog
298     $ tokens
299
300 ## Setting up the cell root directory
301
302 Now we will set up the root directories.  The root directory for the AFS
303 namespace is in the volume called `root.afs`. The root directory of your cell
304 should be in a volume called `root.cell`. You will need to set the ACLs for
305 these directories.  AFS access rights are rather different from those in UNIX.
306 I suggest reading the IBM documentation for this; it still applies.
307
308 The cache manager is started in `-dynroot` mode on RPM-based installations.
309 This allows the cache manager to mount the AFS filesystem without the need to
310 contact the OpenAFS servers. The side-effect of `-dynroot` is the `root.afs`
311 volume cannot be accessed directly.  Fortunately, we can use "magic" `.:mount`
312 directory to access the `root.afs` volume.
313
314 Set up the top level directories.
315
316     $ cellname=$(cat /usr/vice/etc/ThisCell)
317     
318     $ cd /afs/.:mount/${cellname}:root.afs/
319     $ fs mkmount ${cellname} root.cell -cell ${cellname}
320     $ fs mkmount .${cellname} root.cell -cell ${cellname} -rw
321     $ fs setacl . system:anyuser read
322     
323     $ cd /afs/.:mount/${cellname}:root.cell/
324     $ fs setacl . system:anyuser read
325
326 Replicate the root volumes so that you have read only copies.  Later, if more
327 file servers are added to the cell, additional read-only copies should be made.
328
329     $ server=<hostname of the fileserver>
330     $ vos addsite ${server} a root.afs
331     $ vos release root.afs
332     $ vos addsite ${server} a root.cell
333     $ vos release root.cell
334
335 ## Adding users and volumes
336
337 Now that OpenAFS is installed, the site specific AFS volumes and directory
338 structure can be set up. Users should be made, along with their home
339 volumes. ACLs for the volume directories should be established.
340
341 This section provides an example setup. The names of the volumes and
342 directories can be specific to your needs.
343
344 You must first authenticate as a Kerberos/AFS admin to run the commands
345 shown in this section.
346
347     $ kadmin <username>/admin
348     $ aklog
349
350 ### Creating user accounts
351
352 We can create a user by registering it to Kerberos and the `ptserver` database.
353 If you use integrated login, make sure that the users' UNIX uids and pts ids
354 match.
355
356     $ kadmin -q "addprinc <username>"
357     <enter password for username>
358     $ pts createuser <username> -id <numeric uid>
359
360 If you use integrated login, make sure that you add an entry to /etc/passwd or
361 whatever means you use of distributing user information.
362
363 ### Setting up volumes for users
364
365 First, we can make a top level volume to contain the mount points to volumes
366 for individuals. The IBM documentation suggests making a directory
367 `/afs/<cellname>/user` with volume name user for all of your AFS users. Some
368 sites have adopted the directory `home` instead of `user`.  If you use `home`,
369 your users may feel more comfortable, as this is the convention in Linux and
370 most UNIXes.
371
372 The following commands create the `home` volume and make a read-only replica:
373
374     $ vos create <fileserver> a home
375     $ cd /afs/.<cellname>
376     $ fs mkmount home home
377     $ vos addsite <fileserver> a home
378     $ vos release root.cell
379     $ vos release home
380
381 Now you can create directories for any of your users. We will not replicate
382 these volumes. By not replicating them, we force the cache manager to access a
383 read/write volume. This means that even if we access the cell through the
384 read-only volume we can still access our read/write user directories (this is
385 what you want). Maxquota 0 means that there is no size restriction to the
386 volume. You can give it a restriction if you like (the default is 5mb). Do
387 these commands for every directory you like.
388
389     $ vos create <fileserver> a home.<uid> -maxquota 0
390     $ cd /afs/.<cellname>/home
391     $ fs mkmount <user> home.<uid>
392     $ vos release home
393
394 The home volume is released to make the new directories are visible from the
395 read only mount point.
396
397 ### Setting ACLs
398
399 Now that we have volumes, we should set some restrictions on those volumes.
400 If you trust the users not to make directories *world writable*, you
401 can give the user of the directory full rights.
402
403     $ cd /afs/.<cellname>/home
404     $ fs setacl -dir <user> -acl <user> all
405
406 To give the users read and write access, but not rights to change ACLs,
407
408     $ cd /afs/.<cellname>/home
409     $ fs setacl -dir <user> -acl <user> write
410