4 Preamble: referenced user accounts
5 ----------------------------------
7 In subsequent sections, we will refer to a number of different accounts, as
10 * Linux user accounts:
11 ** The *user* Linux account is the account that you use to log onto the
12 Linux system as a regular user.
13 ** The *root* Linux account is an account that has system administrator
14 privileges. On Debian you can switch to this account from
15 your *user* account by issuing the `su -` command and entering the
16 password for the *root* account when prompted. On Ubuntu you can switch
17 to this account from your *user* account using the `sudo su -` command
18 and entering the password for your *user* account when prompted.
19 ** The *opensrf* Linux account is an account that you will create as part
20 of installing OpenSRF. You can switch to this account from the *root*
21 account by issuing the `su - opensrf` command.
23 Download and unpack the code
24 ----------------------------
26 Issue the following commands as the *user* Linux account.
28 1. Acquire a stable release tarball from https://evergreen-ils.org/opensrf-downloads/
31 ------------------------------------------------------------------------------
32 wget https://evergreen-ils.org/downloads/opensrf-OSRFVERSION.tar.gz
33 ------------------------------------------------------------------------------
36 Developers can find the full source code at the OpenSRF Git repository:
37 http://git.evergreen-ils.org/?p=OpenSRF.git
39 2. Unpack the tarball, and move into that directory:
42 ------------------------------------------------------------------------------
43 tar -xvf opensrf-OSRFVERSION.tar.gz
44 cd opensrf-OSRFVERSION/
45 ------------------------------------------------------------------------------
47 Installing prerequisites
48 ------------------------
50 OpenSRF has a number of prerequisite packages that must be installed
51 before you can successfully configure, compile, and install OpenSRF.
52 On Debian and Ubuntu, the easiest way to install these prerequisites
53 is to use the Makefile.install prerequisite installer.
55 Issue the following commands as the *root* Linux account to install
56 prerequisites using the Makefile.install prerequisite installer, substituting
57 your operating system identifier for <osname> below:
60 ---------------------------------------------------------------------------
62 make -f src/extras/Makefile.install <osname>
63 ---------------------------------------------------------------------------
65 Well-tested values for <osname> include:
67 * `debian-stretch` for Debian 9
68 * `debian-jessie` for Debian 8
69 * `ubuntu-trusty` for Ubuntu 14.04
70 * `ubuntu-xenial` for Ubuntu 16.04
71 * `ubuntu-bionic` for Ubuntu 18.04
73 Patches and suggestions for improvement from users of these distributions,
74 or others, are welcome!
76 When the prerequisite installer reaches the Perl module stage, you may
77 be prompted for configuration of Comprehensive Perl Archive Network (CPAN)
78 on your server. You can generally accept the defaults by pressing <return>
79 for all of the prompts, except for the country configuration.
81 Preamble: Developer instructions
82 --------------------------------
85 Skip this section if you are using an official release tarball downloaded
86 from https://evergreen-ils.org/opensrf-downloads/
88 Developers working directly with the source code from the Git repository,
89 rather than an official release tarball, must install some extra packages
90 and perform one step before they can proceed with the `./configure` step.
92 As the *root* Linux account, install the following packages:
98 As the *user* Linux account, issue the following command in the OpenSRF
99 source directory to generate the configure script and Makefiles:
102 ------------------------------------------------------------------------------
104 ------------------------------------------------------------------------------
106 Configuration and compilation instructions
107 ------------------------------------------
109 Use the `configure` command to configure OpenSRF, and the `make` command to
110 build OpenSRF. The default installation prefix (PREFIX) for OpenSRF is
113 If you are building OpenSRF for Evergreen, issue the following commands as
114 the *user* Linux account to configure and build OpenSRF:
117 ---------------------------------------------------------------------------
118 ./configure --prefix=/openils --sysconfdir=/openils/conf
120 ---------------------------------------------------------------------------
122 By default, OpenSRF includes C, Perl, and JavaScript support.
123 You can add the `--enable-python` option to the configure command
124 to build Python support and `--enable-java` for Java support.
126 If you are planning on proxying WebSockets traffic (see below), you
127 can add `--with-websockets-port=443` to specify that WebSockets traffic
128 will be going through port 443. Without that option, the default port
131 Installation instructions
132 -------------------------
134 1. Once you have configured and compiled OpenSRF, issue the following
135 command as the *root* Linux account to install OpenSRF:
138 ---------------------------------------------------------------------------
140 ---------------------------------------------------------------------------
142 Create and set up the opensrf Unix user environment
143 ---------------------------------------------------
145 This user is used to start and stop all OpenSRF processes, and must own all
146 files contained in the PREFIX directory hierarchy. Issue the following
147 commands as the *root* Linux account to create the `opensrf` user and set up
148 its environment, substituting <PREFIX> with the value you passed to `--prefix`
149 in your configure command:
151 .Creating the `opensrf` user
153 ---------------------------------------------------------------------------
154 useradd -m -s /bin/bash opensrf
155 echo "export PATH=\$PATH:/<PREFIX>/bin" >> /home/opensrf/.bashrc
157 chown -R opensrf:opensrf /<PREFIX>
158 ---------------------------------------------------------------------------
160 Define your public and private OpenSRF domains
161 ----------------------------------------------
163 For security purposes, OpenSRF uses Jabber domains to separate services
164 into public and private realms. Throughout these instructions, we will use
165 the example domains `public.localhost` and `private.localhost`.
167 On a single-server system, the easiest way to define public and private
168 domains is to define separate hostnames by adding entries to the `/etc/hosts`
169 file. Here are entries that you could add to a stock `/etc/hosts` file for our
172 .Example added entries for `/etc/hosts`
174 ---------------------------------------------------------------------------
175 127.0.1.2 public.localhost public
176 127.0.1.3 private.localhost private
177 ---------------------------------------------------------------------------
179 Adjust the system dynamic library path
180 --------------------------------------
182 Add `<PREFIX>/lib/` to the system's dynamic library path, and then run
183 `ldconfig` as the *root* Linux account.
185 On Debian and Ubuntu systems, run the following commands as the *root*
188 .Adjusting the system dynamic library path
190 ---------------------------------------------------------------------------
191 echo <PREFIX>/lib > /etc/ld.so.conf.d/opensrf.conf
193 ---------------------------------------------------------------------------
195 On most other systems, you can add these entries to `/etc/ld.so.conf`, or
196 create a file within the `/etc/ld.so.conf.d/` directory, and then run
197 `ldconfig` as the *root* Linux account.
199 Configure the ejabberd server
200 -----------------------------
202 OpenSRF requires an XMPP (Jabber) server. For performance reasons, ejabberd is
203 the Jabber server of choice for the OpenSRF project. In most cases, you only
204 have to make a few changes to the default configuration file to make ejabberd
207 1. Stop ejabberd before making any changes to its configuration by issuing the
208 following command as the *root* Linux account:
210 .(Ubuntu Trusty) Stopping ejabberd
212 ---------------------------------------------------------------------------
213 /etc/init.d/ejabberd stop
214 ---------------------------------------------------------------------------
216 .(Debian / Ubuntu Xenial / Ubuntu Bionic) Stopping ejabberd
218 ---------------------------------------------------------------------------
219 systemctl stop ejabberd.service
220 ---------------------------------------------------------------------------
222 2. Edit the ejabberd config file.
224 (Ubuntu Trusty) Ejabberd 2.x.x::
225 Open `/etc/ejabberd/ejabberd.cfg` and make the following
227 a. Define your public and private domains in the `hosts` directive. For
231 ---------------------------------------------------------------------------
232 {hosts, ["localhost", "private.localhost", "public.localhost"]}.
233 ---------------------------------------------------------------------------
235 b. Change all `maxrate` values to 500000
236 c. Increase the `max_user_sessions` value to 10000
237 d. Comment out the `mod_offline` directive
239 (Debian Jessie) Ejabberd 13.x and 14.x::
240 Open `/etc/ejabberd/ejabberd.yml` and make the following
242 a. Define your public and private domains in the `hosts` directive. For
246 ---------------------------------------------------------------------------
249 - "private.localhost"
251 ---------------------------------------------------------------------------
253 b. Change `shaper:` `normal` and `fast` values to 500000
254 c. Increase the `max_user_sessions:` `all:` value to 10000
255 d. Comment out the `mod_offline` directive
257 -----------------------
259 ##access_max_user_messages: max_user_offline_messages
260 -----------------------
262 (Debian Stretch / Ubuntu Xenial) Ejabberd 16.x::
263 Open `/etc/ejabberd/ejabberd.yml` and make the following
265 a. Define your public and private domains in the `hosts` directive. For
269 ---------------------------------------------------------------------------
272 - "private.localhost"
274 ---------------------------------------------------------------------------
276 b. Change `auth_password_format` to plain
277 c. Change `shaper:` `normal` and `fast` values to 500000
278 d. Increase the `max_user_sessions:` `all:` value to 10000
279 e. Comment out the `mod_offline` directive
281 -----------------------
283 ##access_max_user_messages: max_user_offline_messages
284 -----------------------
286 (Ubuntu Bionic) Ejabberd 18.x::
287 Open `/etc/ejabberd/ejabberd.yml` and make the following
289 a. Define your public and private domains in the `hosts` directive. For
293 ---------------------------------------------------------------------------
296 - "private.localhost"
298 ---------------------------------------------------------------------------
300 b. Change `starttls_required` to false
301 c. Change `auth_password_format` to plain
302 d. Change `shaper:` `normal` and `fast` values to 500000
303 e. Increase the `max_user_sessions:` `all:` value to 10000
304 f. Comment out the `mod_offline` directive
306 -----------------------
308 ##access_max_user_messages: max_user_offline_messages
309 -----------------------
311 g. Uncomment the `mod_legacy_auth` directive
312 3. Restart the ejabberd server to make the changes take effect:
314 .(Ubuntu Trusty) Starting ejabberd
316 ---------------------------------------------------------------------------
317 /etc/init.d/ejabberd start
318 ---------------------------------------------------------------------------
320 .(Debian / Ubuntu Xenial / Ubuntu Bionic) Starting ejabberd
322 ---------------------------------------------------------------------------
323 systemctl start ejabberd.service
324 ---------------------------------------------------------------------------
326 Create the OpenSRF Jabber users
327 -------------------------------
329 On each domain, you need two Jabber users to manage the OpenSRF communications:
331 * a `router` user, to whom all requests to connect to an OpenSRF service
332 will be routed; this Jabber user must be named `router`
333 * an `opensrf` user, which clients use to connect to OpenSRF services; this
334 user can be named anything you like
336 Create the Jabber users by issuing the following commands as the *root* Linux
337 account. Substitute `<password>` for your chosen passwords for each user
340 .Creating the OpenSRF Jabber users
342 ---------------------------------------------------------------------------
343 ejabberdctl register router private.localhost <password>
344 ejabberdctl register opensrf private.localhost <password>
345 ejabberdctl register router public.localhost <password>
346 ejabberdctl register opensrf public.localhost <password>
347 ---------------------------------------------------------------------------
349 Update the OpenSRF configuration files
350 --------------------------------------
352 About the OpenSRF configuration files
353 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
354 There are several configuration files that you must update to make OpenSRF
355 work. SYSCONFDIR is `/opensrf/etc` by default, or the value that you passed to
356 `--sysconfdir` during the configuration phase.
358 * `SYSCONFDIR/opensrf.xml` - this file lists the services that this
359 OpenSRF installation supports; if you create a new OpenSRF service,
360 you need to add it to this file.
361 ** The `<hosts>` element at the bottom of the file lists the services
362 that should be started for each hostname. You can force the system
363 to use `localhost`, so in most cases you will leave this section
366 * `SYSCONFDIR/opensrf_core.xml` - this file lists the Jabber connection
367 information that will be used for the system, as well as determining
368 logging verbosity and defining which services will be exposed on the
371 * `~/.srfsh.xml` - this file gives a Linux account the ability to use
372 the `srfsh` interpreter to communicate with OpenSRF services.
374 Updating the OpenSRF configuration files
375 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
376 1. As the *opensrf* Linux account, copy the example configuration files
377 to create your locally customizable OpenSRF configuration files:
379 .Copying the example OpenSRF configuration files
381 ---------------------------------------------------------------------------
383 cp opensrf_core.xml.example opensrf_core.xml
384 cp opensrf.xml.example opensrf.xml
385 ---------------------------------------------------------------------------
387 2. Edit the `SYSCONFDIR/opensrf_core.xml` file to update the four username
388 / password pairs to match the Jabber user accounts you just created:
390 a. `<config><opensrf>` = use the private Jabber `opensrf` user
391 b. `<config><gateway>` = use the public Jabber `opensrf` user
392 c. `<config><routers><router>` = use the public Jabber `router` user
393 d. `<config><routers><router>` = use the private Jabber `router` user
394 3. Create a `.srfsh.xml` file in the home directory of each user
395 that you want to use `srfsh` to communicate with OpenSRF services. For
396 example, to enable the *opensrf* Linux account to use `srfsh`:
397 a. `cp SYSCONFDIR/srfsh.xml.example ~/.srfsh.xml`
398 b. Open `~/.srfsh.xml` in your text editor of choice and update the
399 password to match the password you set for the Jabber `opensrf` user
400 at the `private.localhost` domain.
402 Starting and stopping OpenSRF services
403 --------------------------------------
405 To start all OpenSRF services with a hostname of `localhost`, issue the
406 following command as the *opensrf* Linux account:
409 ---------------------------------------------------------------------------
410 osrf_control --localhost --start-all
411 ---------------------------------------------------------------------------
413 To stop all OpenSRF services with a hostname of `localhost`, issue the
414 following command as the *opensrf* Linux account:
417 ---------------------------------------------------------------------------
418 osrf_control --localhost --stop-all
419 ---------------------------------------------------------------------------
421 Testing the default OpenSRF services
422 ------------------------------------
424 By default, OpenSRF ships with an `opensrf.math` service that performs basic
425 calculations involving two integers. Once you have started the OpenSRF
426 services, test the services as follows:
428 1. Start the `srfsh` interactive OpenSRF shell by issuing the following
429 command as the *opensrf* Linux account:
431 .Starting the `srfsh` interactive OpenSRF shell
433 ---------------------------------------------------------------------------
435 ---------------------------------------------------------------------------
437 2. Issue the following request to test the `opensrf.math` service:
440 ---------------------------------------------------------------------------
441 srfsh# request opensrf.math add 2,2
442 ---------------------------------------------------------------------------
444 You should receive the value `4`.
446 Websockets installation instructions: Option #1 Apache
447 -------------------------------------------------------
448 Websockets are new to OpenSRF 2.4+ and are required for operating the new web-based
449 staff client for Evergreen. Complete the following steps as the *root* Linux
452 1. Install git if not already present:
455 ---------------------------------------------------------------------------
456 apt-get install git-core
457 ---------------------------------------------------------------------------
459 2. Install the apache-websocket module:
462 ---------------------------------------------------------------------------
463 # Use a temporary directory
465 git clone https://github.com/disconnect/apache-websocket
467 apxs2 -i -a -c mod_websocket.c
468 ---------------------------------------------------------------------------
470 3. Create the websocket Apache instance (more information about this in
471 `/usr/share/doc/apache2/README.multiple-instances`)
474 ---------------------------------------------------------------------------
475 sh /usr/share/doc/apache2/examples/setup-instance websockets
476 ---------------------------------------------------------------------------
478 4. Remove from the main apache instance
481 ---------------------------------------------------------------------------
483 ---------------------------------------------------------------------------
485 5. Change to the directory into which you unpacked OpenSRF, then copy into
486 place the config files
489 ---------------------------------------------------------------------------
490 cd /path/to/opensrf-OSRFVERSION
491 cp examples/apache_24/websockets/apache2.conf /etc/apache2-websockets/
492 ---------------------------------------------------------------------------
494 6. OPTIONAL: add these configuration variables to `/etc/apache2-websockets/envvars`
495 and adjust as needed.
498 ---------------------------------------------------------------------------
499 export OSRF_WEBSOCKET_IDLE_TIMEOUT=120
500 export OSRF_WEBSOCKET_IDLE_CHECK_INTERVAL=5
501 export OSRF_WEBSOCKET_CONFIG_FILE=/openils/conf/opensrf_core.xml
502 export OSRF_WEBSOCKET_CONFIG_CTXT=gateway
503 export OSRF_WEBSOCKET_MAX_REQUEST_WAIT_TIME=600
504 ---------------------------------------------------------------------------
506 * `IDLE_TIMEOUT` specifies how long we will allow a client to stay connected
507 while idle. A longer timeout means less network traffic (from fewer
508 websocket CONNECT calls), but it also means more Apache processes are
509 tied up doing nothing.
510 * `IDLE_CHECK_INTERVAL` specifies how often we wake to check the idle status
511 of the connected client.
512 * `MAX_REQUEST_WAIT_TIME` is the maximum amount of time the gateway will
513 wait before declaring a client as idle when there is a long-running
514 outstanding request, yet no other activity is occurring. This is
515 primarily a fail-safe to allow idle timeouts when one or more requests
516 died on the server, and thus no response was ever delivered to the gateway.
517 * `CONFIG_FILE / CTXT` are the standard opensrf core config options.
519 7. Before you can start websockets, you must install a valid SSL certificate
520 in `/etc/apache2/ssl/`. It is possible, but not recommended, to generate a
521 self-signed SSL certificate. For example, if you need to test with a self-signed
522 certicate on Chrome or Chromimum browsers, one workaround is to start the browser
523 with `--ignore-certificate-errors`.
525 8. After OpenSRF is up and running (or after any re-install),
526 fire up the secondary Apache instance. Errors will appear in
527 `/var/log/apache2-websockets/error.log`. Start apache2-websockets with:
530 ---------------------------------------------------------------------------
531 /etc/init.d/apache2-websockets start
532 ---------------------------------------------------------------------------
534 Websockets installation instructions: Option #2 Websocketd
535 ----------------------------------------------------------
537 1. Install websocketd (latest stable release from http://websocketd.com/)
541 ---------------------------------------------------------------------------
543 wget 'https://github.com/joewalnes/websocketd/releases/download/v0.3.0/websocketd-0.3.0-linux_amd64.zip'
544 unzip websocketd-0.3.0-linux_amd64.zip
545 sudo cp websocketd /usr/local/bin/
546 ---------------------------------------------------------------------------
550 Choose option a or b, below.
552 a. Run websocketd as 'opensrf'
555 ===========================================================================
556 This choice requires one of the proxy configurations mentioned below.
557 ===========================================================================
561 ---------------------------------------------------------------------------
562 /usr/local/bin/websocketd --port 7682 /openils/bin/osrf-websocket-stdio &
564 # Other useful command line parameters include:
565 # --loglevel debug|trace|access|info|error|fatal
568 # --origin=host[:port][,host[:port]...]
570 # See https://github.com/joewalnes/websocketd/blob/master/help.go
571 ---------------------------------------------------------------------------
573 b. Run websocketd without a proxy
577 ---------------------------------------------------------------------------
578 sudo -b /usr/local/bin/websocketd --port 7682 --ssl --sslcert=/etc/apache2/ssl/server.crt \
579 --sslkey=/etc/apache2/ssl/server.key /openils/bin/osrf-websocket-stdio
580 ---------------------------------------------------------------------------
582 Optional: Using NGINX as a proxy
583 --------------------------------
584 NGINX can be used to proxy HTTP, HTTPS, and WebSockets traffic. Among other
585 reasons, this can be useful for Evergreen setups that want to have both
586 HTTPS and secure WebSockets traffic both go through port 443 while using
587 two Apache instances (one for the WebSockets gateway and one for the more
588 memory-intensive TPAC pages).
590 The following instructions are a guide for setting this up on Debian
591 and Ubuntu systems, but expect general familiarity with various system
592 administration and network tasks. The steps should be run as the *root*
593 Linux account, and assume that you already followed the instructions
594 for installing WebSockets support.
596 1. Configure the main Apache instance to listen on port 7080 for HTTP and
597 port 7443 for HTTPS and ensure that it is not listening on ports 80
598 and 443, then restart Apache.
600 2. Install NGINX if not already present:
603 ---------------------------------------------------------------------------
604 apt-get install nginx
605 ---------------------------------------------------------------------------
607 3. Copy the example NGINX configuration file into place and remove default.
610 ---------------------------------------------------------------------------
611 cd /path/to/opensrf-OSRFVERSION
612 cp examples/nginx/osrf-ws-http-proxy /etc/nginx/sites-available/
613 ln -s /etc/nginx/sites-available/osrf-ws-http-proxy /etc/nginx/sites-enabled/osrf-ws-http-proxy
614 rm /etc/nginx/sites-enabled/default
615 ---------------------------------------------------------------------------
617 4. Edit `/etc/nginx/sites-available/osrf-ws-http-proxy` to set the location
618 of the SSL certificate and private key.
619 5. Generate a dhparam file in the directory specified in the nginx config.
622 ---------------------------------------------------------------------------
623 # Default config stores dhparam.pem in the Apache2 ssl directory.
624 openssl dhparam -out /etc/apache2/ssl/dhparam.pem 2048
625 ---------------------------------------------------------------------------
630 ---------------------------------------------------------------------------
631 /etc/init.d/nginx start
632 ---------------------------------------------------------------------------
634 7. If you didn't run `configure` with the `--with-websockets-port=443` option,
635 edit `<PREFIX>/javascript/opensrf_ws.js` and `<PREFIX>/javascript/opensrf_ws_shared.js`
639 ---------------------------------------------------------------------------
640 var WEBSOCKET_PORT_SSL = 7682;
641 ---------------------------------------------------------------------------
646 ---------------------------------------------------------------------------
647 var WEBSOCKET_PORT_SSL = 443;
648 ---------------------------------------------------------------------------
650 Optional: Using HAProxy as a proxy
651 ----------------------------------
652 HAProxy can also be used to proxy HTTP, HTTPS, and WebSockets traffic
653 as an alternative to NGINX.
655 The following instructions are a guide for setting this up on Debian
656 and Ubuntu systems, but expect general familiarity with various system
657 administration and network tasks. The steps should be run as the *root*
658 Linux account, and assume that you already followed the instructions
659 for installing WebSockets support.
661 1. Install HAProxy if not already present:
664 ---------------------------------------------------------------------------
665 apt-get install haproxy
666 ---------------------------------------------------------------------------
668 2. Configure the main Apache instance to listen on port 7080 for HTTP and
669 port 7443 for HTTPS and ensure that it is not listening on ports 80
670 and 443, then restart Apache.
671 3. Append the example HAProxy to `haproxy.cfg`.
674 ---------------------------------------------------------------------------
675 cd /path/to/opensrf-OSRFVERSION
676 cat examples/haproxy/osrf-ws-http-proxy >> /etc/haproxy/haproxy.cfg
677 ---------------------------------------------------------------------------
679 4. Edit `/etc/haproxy/haproxy.cfg` to set the location
680 of the PEM file containing the SSL certificate and private key.
684 ---------------------------------------------------------------------------
685 /etc/init.d/haproxy start
686 ---------------------------------------------------------------------------
688 6. Edit `<PREFIX>/javascript/opensrf_ws.js` and `<PREFIX>/javascript/opensrf_ws_shared.js`
692 ---------------------------------------------------------------------------
693 var WEBSOCKET_PORT_SSL = 7682;
694 ---------------------------------------------------------------------------
699 ---------------------------------------------------------------------------
700 var WEBSOCKET_PORT_SSL = 443;
701 ---------------------------------------------------------------------------
703 Troubleshooting note for Python users
704 -------------------------------------
706 If you are running a Python client and trying to connect to OpenSRF running on
707 localhost rather than a hostname that can be resolved via DNS, you will
708 probably receive exceptions about `dns.resolver.NXDOMAIN`. If this happens,
709 you need to install the `dnsmasq` package, configure it to serve up a DNS
710 entry for localhost, and point your local DNS resolver to `dnsmasq`. For example,
711 on Ubuntu you can issue the following commands as the *root* Linux account:
713 .Installing and starting `dnsmasq`
715 ---------------------------------------------------------------------------
716 aptitude install dnsmasq
717 /etc/init.d/dnsmasq restart
718 ---------------------------------------------------------------------------
720 Then edit `/etc/resolv.conf` and ensure that `nameserver 127.0.0.1` is the
721 first entry in the file.
726 Need help installing or using OpenSRF? Join the mailing lists at
727 http://evergreen-ils.org/communicate/mailing-lists/ or contact us
728 on the Freenode IRC network on the #evergreen channel.