Skip to content

Commit 77448e5

Browse files
committed
3.0 config: instance configuration
1 parent 496be5d commit 77448e5

File tree

5 files changed

+448
-529
lines changed

5 files changed

+448
-529
lines changed
122 KB
Loading
135 KB
Loading

doc/book/admin/instance_config.rst

Lines changed: 123 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,177 +1,175 @@
11
.. _admin-instance_config:
2+
.. _admin-instance-environment-overview:
3+
.. _admin-tt_config_file:
24

3-
Instance configuration
4-
======================
5+
Cluster configuration
6+
=====================
57

6-
For each Tarantool instance, you need two files:
8+
This section provides a high-level overview on how to prepare a Tarantool application for deploying
9+
and how the application's environment and layout might look like.
10+
This information is helpful for understanding how to administer Tarantool instances using :ref:`tt CLI <tt-cli>`.
711

8-
* [Optional] An :ref:`application file <app_server-launching_app>` with
9-
instance-specific logic. Put this file into the ``/usr/share/tarantool/``
10-
directory.
12+
The main steps of creating and preparing the application are:
1113

12-
For example, ``/usr/share/tarantool/my_app.lua`` (here we implement it as a
13-
:ref:`Lua module <app_server-modules>` that bootstraps the database and
14-
exports ``start()`` function for API calls):
14+
1. :ref:`Initializing a local environment <admin-instance_config-init-environment>`.
1515

16-
.. code-block:: lua
16+
2. :ref:`Creating and developing an application <admin-instance_config-develop-app>`.
1717

18-
local function start()
19-
box.schema.space.create("somedata")
20-
box.space.somedata:create_index("primary")
21-
<...>
22-
end
18+
3. :ref:`Packaging the application <admin-instance_config-package-app>`.
2319

24-
return {
25-
start = start;
26-
}
20+
In this section, a `sharded_cluster <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/sharding/instances.enabled/sharded_cluster>`_ application is used as an example.
21+
This cluster includes 5 instances: one router and 4 storages, which constitute two replica sets.
2722

28-
* An :ref:`instance file <admin-instance_file>` with
29-
instance-specific initialization logic and parameters. Put this file, or a
30-
symlink to it, into the **instance directory**
31-
(see ``instances_enabled`` parameter in :ref:`tt configuration file <tt-config_file>`).
23+
.. image:: admin_instances_dev.png
24+
:align: left
25+
:width: 700
26+
:alt: Cluster topology
3227

33-
For example, ``/etc/tarantool/instances.enabled/my_app.lua`` (here we load
34-
``my_app.lua`` module and make a call to ``start()`` function from that
35-
module):
3628

37-
.. code-block:: lua
3829

39-
#!/usr/bin/env tarantool
30+
.. _admin-instance_config-init-environment:
31+
.. _admin-start_stop_instance-running_locally:
4032

41-
box.cfg {
42-
listen = 3301;
43-
}
33+
Initializing a local environment
34+
--------------------------------
4435

45-
-- load my_app module and call start() function
46-
-- with some app options controlled by sysadmins
47-
local m = require('my_app').start({...})
36+
Before creating an application, you need to set up a local environment for ``tt``:
4837

49-
.. _admin-instance_file:
38+
1. Create a home directory for the environment.
5039

51-
Instance file
52-
-------------
40+
2. Run ``tt init`` in this directory:
5341

54-
After this short introduction, you may wonder what an instance file is, what it
55-
is for, and how ``tt`` uses it. After all, Tarantool is an application
56-
server, so why not start the application stored in ``/usr/share/tarantool``
57-
directly?
42+
.. code-block:: console
5843
59-
A typical Tarantool application is not a script, but a daemon running in
60-
background mode and processing requests, usually sent to it over a TCP/IP
61-
socket. This daemon needs to be started automatically when the operating system
62-
starts, and managed with the operating system standard tools for service
63-
management -- such as ``systemd`` or ``init.d``. To serve this very purpose, we
64-
created **instance files**.
44+
$ tt init
45+
• Environment config is written to 'tt.yaml'
6546
66-
You can have more than one instance file. For example, a single application in
67-
``/usr/share/tarantool`` can run in multiple instances, each of them having its
68-
own instance file. Or you can have multiple applications in
69-
``/usr/share/tarantool`` -- again, each of them having its own instance file.
47+
This command creates a default ``tt`` configuration file ``tt.yaml`` for a local
48+
environment and the directories for applications, control sockets, logs, and other
49+
artifacts:
7050

71-
An instance file is typically created by a system administrator. An application
72-
file is often provided by a developer, in a Lua rock or an rpm/deb package.
51+
.. code-block:: console
7352
74-
An instance file is designed to not differ in any way from a Lua application.
75-
It must, however, configure the database, i.e. contain a call to
76-
:doc:`box.cfg{} </reference/reference_lua/box_cfg>` somewhere in it, because it’s the
77-
only way to turn a Tarantool script into a background process, and
78-
``tt`` is a tool to manage background processes. Other than that, an
79-
instance file may contain arbitrary Lua code, and, in theory, even include the
80-
entire application business logic in it. We, however, do not recommend this,
81-
since it clutters the instance file and leads to unnecessary copy-paste when
82-
you need to run multiple instances of an application.
53+
$ ls
54+
bin distfiles include instances.enabled modules templates tt.yaml
8355
84-
.. _admin-tt-preload:
56+
Find the detailed information about the ``tt`` configuration parameters and launch modes
57+
on the :ref:`tt configuration page <tt-config>`.
8558

86-
Preloading Lua scripts and modules
87-
----------------------------------
8859

89-
Tarantool supports loading and running chunks of Lua code before the loading instance file.
90-
To load or run Lua code immediately upon Tarantool startup, specify the ``TT_PRELOAD``
91-
environment variable. Its value can be either a path to a Lua script or a Lua module name:
9260

93-
* To run the Lua script ``script.lua`` from the ``preload/path/`` directory inside
94-
the working directory in Tarantool before ``main.lua``, set ``TT_PRELOAD`` as follows:
61+
.. _admin-instance_config-develop-app:
62+
.. _admin-start_stop_instance-multi-instance:
63+
.. _admin-start_stop_instance-multi-instance-layout:
9564

96-
.. code-block:: console
65+
Creating and developing an application
66+
--------------------------------------
9767

98-
$ TT_PRELOAD=/preload/path/script.lua tarantool main.lua
68+
You can create an application in two ways:
9969

100-
Tarantool runs the ``script.lua`` code, waits for it to complete, and
101-
then starts running ``main.lua``.
70+
- Manually by preparing prepare its layout in a directory inside ``instances_enabled``.
71+
The directory name is used as the application identifier.
10272

103-
* To load the ``preload.module`` into the Tarantool Lua interpreter
104-
executing ``main.lua``, set ``TT_PRELOAD`` as follows:
73+
- From a template by using the :ref:`tt create <tt-create>` command.
10574

106-
.. code-block:: console
75+
In this example, the application's layout is prepared manually.
10776

108-
$ TT_PRELOAD=preload.module tarantool main.lua
77+
.. code-block:: none
10978
110-
Tarantool loads the ``preload.module`` code into the interpreter and
111-
starts running ``main.lua`` as if its first statement was ``require('preload.module')``.
79+
myapp
80+
├── instances.enabled
81+
│ └── sharded_cluster
82+
│ ├── config.yaml
83+
│ ├── instances.yaml
84+
│ ├── router.lua
85+
│ ├── sharded_cluster-scm-1.rockspec
86+
│ └── storage.lua
87+
└── tt.yaml
11288
113-
.. warning::
11489
115-
``TT_PRELOAD`` values that end with ``.lua`` are considered scripts,
116-
so avoid module names with this ending.
90+
The ``sharded_cluster`` directory contains the following files:
11791

118-
To load several scripts or modules, pass them in a single quoted string, separated
119-
by semicolons:
92+
- ``config.yaml``: contains :ref:`configuration <configuration>` of the cluster.
93+
- ``instances.yml``: specifies instances to run in the current environment.
94+
- ``router.lua``: includes code specific for a router.
95+
- ``sharded_cluster-scm-1.rockspec``: specifies the required external dependencies (for example, ``vshard``).
96+
- ``storage.lua``: includes code specific for storages.
12097

121-
.. code-block:: console
98+
You can find the full example here:
99+
`sharded_cluster <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/sharding/instances.enabled/sharded_cluster>`_.
122100

123-
$ TT_PRELOAD="/preload/path/script.lua;preload.module" tarantool main.lua
124101

125-
In the preload script, the three dots (``...``) value contains the module name
126-
if you're preloading a module or the path to the script if you're running a script.
127102

128-
The :ref:`arg <index-init_label>` value from the main script is visible in
129-
the preload script or module.
103+
.. _admin-instance_config-package-app:
104+
.. _admin-instance-app-layout:
105+
.. _admin-instance_file:
130106

131-
For example, when preloading this script:
107+
Packaging the application
108+
-------------------------
132109

133-
.. code-block:: lua
110+
To package the ready application, use the :ref:`tt pack <tt-pack>` command.
111+
This command can be used to create an installable DEB/RPM package or to generate ``.tgz`` archive.
134112

135-
-- preload.lua --
136-
print("Preloading:")
137-
print("... arg is:", ...)
138-
print("Passed args:", arg[1], arg[2])
113+
The structure below reflects the content of the packed ``.tgz`` archive for the `sharded_cluster <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/sharding/instances.enabled/sharded_cluster>`_ application:
139114

140-
You get the following output:
115+
.. code-block:: none
141116
142-
.. code-block:: console
117+
/home/testuser/myapp
118+
├── bin
119+
│ ├── tarantool
120+
│ └── tt
121+
├── instances.enabled
122+
│ └── sharded_cluster -> ../sharded_cluster
123+
├── sharded_cluster
124+
│ ├── .rocks
125+
│ │ └── share
126+
│ │ └── ...
127+
│ ├── config.yaml
128+
│ ├── instances.yaml
129+
│ ├── router.lua
130+
│ ├── sharded_cluster-scm-1.rockspec
131+
│ └── storage.lua
132+
└── tt.yaml
143133
144-
$ TT_PRELOAD=preload.lua tarantool main.lua arg1 arg2
145-
Preloading:
146-
... arg is: preload.lua
147-
Passed args: arg1 arg2
148-
'strip_core' is set but unsupported
149-
... main/103/main.lua I> Tarantool 2.11.0-0-g247a9a4 Darwin-x86_64-Release
150-
... main/103/main.lua I> log level 5
151-
... main/103/main.lua I> wal/engine cleanup is paused
152-
< ... >
134+
The application's layout looks similar to the one defined when :ref:`developing the application <admin-instance_config-develop-app>` with some differences:
153135

154-
If an error happens during the execution of the preload script or module, Tarantool
155-
reports the problem and exits.
136+
- ``bin``: stores the ``tarantool`` and ``tt`` binaries.
156137

157-
.. _admin-tt_config_file:
138+
- ``instances.enabled``: contains a symlink to the packed ``sharded_cluster`` application.
158139

159-
tt configuration file
160-
---------------------
140+
- ``sharded_cluster``: a packed application. In addition to files created during the application development, includes the ``.rocks`` directory containing application dependencies (for example, ``vshard``).
161141

162-
While instance files contain instance configuration, the :ref:`tt <tt-cli>` configuration file
163-
contains the configuration that ``tt`` uses to set up the application environment.
164-
This includes the path to instance files, various working directories, and other
165-
parameters that connect the application to the system.
142+
- ``tt.yaml``: a tt configuration file.
166143

167-
To create a default ``tt`` configuration, run ``tt init``. This creates a ``tt.yaml``
168-
configuration file. Its location depends on the :ref:`tt launch mode <tt-config_modes>`
169-
(system or local).
170144

171-
Some ``tt`` configuration parameters are similar to those used by
172-
:doc:`box.cfg{} </reference/reference_lua/box_cfg>`, for example, ``memxt_dir``
173-
or ``wal_dir``. Other parameters define the ``tt`` environment, for example,
174-
paths to installation files used by ``tt`` or to connected :ref:`external modules <tt-external_modules>`.
175145

176-
Find the detailed information about the ``tt`` configuration parameters and launch modes
177-
on the :ref:`tt configuration page <tt-config>`.
146+
.. _admin-instances_to_run:
147+
148+
Instances to run
149+
~~~~~~~~~~~~~~~~
150+
151+
One more difference for a deployed application is the content of the ``instances.yaml`` file, which specifies instances to run in the current environment.
152+
153+
- On the developer's machine, this file might include all the instances defined in the cluster configuration.
154+
155+
.. image:: admin_instances_dev.png
156+
:align: left
157+
:width: 700
158+
:alt: Cluster topology
159+
160+
``instances.yaml``:
161+
162+
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster/instances.yaml
163+
:language: yaml
164+
:dedent:
165+
166+
- In the production environment, this file includes instances to run on the specific machine.
167+
168+
.. image:: admin_instances_prod.png
169+
:align: left
170+
:width: 700
171+
:alt: Cluster topology
172+
173+
For example, on ``Server-002``, this file includes ``storage-a-001`` and ``storage-b-001``.
174+
175+
The :ref:`Starting and stopping instances <admin-start_stop_instance>` describes how to start and stop Tarantool instances.

0 commit comments

Comments
 (0)