Skip to content

Commit 6d966b6

Browse files
3.0 config: updated the 'Instance configuration' and 'Starting and stopping instances' topics (#3928)
1 parent cf703aa commit 6d966b6

File tree

12 files changed

+509
-533
lines changed

12 files changed

+509
-533
lines changed
116 KB
Loading
128 KB
Loading

doc/book/admin/instance_config.rst

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

3-
Instance configuration
4-
======================
5+
Application environment
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 deployment
9+
and how the application's environment and layout might look.
10+
This information is helpful for understanding how to administer Tarantool instances using :ref:`tt CLI <tt-cli>` in both development and production environments.
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 for deployment 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:`admin-instance_config-init-environment`.
1515

16-
.. code-block:: lua
16+
2. :ref:`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:`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:
41+
42+
.. code-block:: console
5343
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?
44+
~/myapp$ tt init
45+
• Environment config is written to 'tt.yaml'
5846
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**.
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:
6550

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.
51+
.. code-block:: console
7052
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.
53+
~/myapp$ ls
54+
bin distfiles include instances.enabled modules templates tt.yaml
7355
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.
56+
Find detailed information about the ``tt`` configuration parameters and launch modes
57+
on the :ref:`tt configuration page <tt-config>`.
8358

84-
.. _admin-tt-preload:
8559

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

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:
61+
.. _admin-instance_config-develop-app:
62+
.. _admin-start_stop_instance-multi-instance:
63+
.. _admin-start_stop_instance-multi-instance-layout:
9264

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:
65+
Creating and developing an application
66+
--------------------------------------
9567

96-
.. code-block:: console
68+
You can create an application in two ways:
9769

98-
$ TT_PRELOAD=/preload/path/script.lua tarantool main.lua
70+
- Manually by preparing its layout in a directory inside ``instances_enabled``.
71+
The directory name is used as the application identifier.
9972

100-
Tarantool runs the ``script.lua`` code, waits for it to complete, and
101-
then starts running ``main.lua``.
73+
- From a template by using the :ref:`tt create <tt-create>` command.
10274

103-
* To load the ``preload.module`` into the Tarantool Lua interpreter
104-
executing ``main.lua``, set ``TT_PRELOAD`` as follows:
75+
In this example, the application's layout is prepared manually and looks as follows.
10576

106-
.. code-block:: console
77+
.. code-block:: console
78+
79+
~/myapp$ tree
80+
.
81+
├── bin
82+
├── distfiles
83+
├── include
84+
├── instances.enabled
85+
│ └── sharded_cluster
86+
│ ├── config.yaml
87+
│ ├── instances.yaml
88+
│ ├── router.lua
89+
│ ├── sharded_cluster-scm-1.rockspec
90+
│ └── storage.lua
91+
├── modules
92+
├── templates
93+
└── tt.yaml
94+
95+
96+
The ``sharded_cluster`` directory contains the following files:
10797

108-
$ TT_PRELOAD=preload.module tarantool main.lua
98+
- ``config.yaml``: contains the :ref:`configuration <configuration>` of the cluster. This file might include the entire cluster topology or provide connection settings to a centralized configuration storage.
99+
- ``instances.yml``: specifies instances to run in the current environment. For example, on the developer’s machine, this file might include all the instances defined in the cluster configuration. In the production environment, this file includes :ref:`instances to run on the specific machine <admin-instances_to_run>`.
100+
- ``router.lua``: includes code specific for a :ref:`router <vshard-architecture-router>`.
101+
- ``sharded_cluster-scm-1.rockspec``: specifies the required external dependencies (for example, ``vshard``).
102+
- ``storage.lua``: includes code specific for :ref:`storages <vshard-architecture-storage>`.
109103

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')``.
104+
You can find the full example here:
105+
`sharded_cluster <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/sharding/instances.enabled/sharded_cluster>`_.
106+
107+
108+
109+
.. _admin-instance_config-package-app:
110+
.. _admin-instance-app-layout:
111+
.. _admin-instance_file:
112112

113-
.. warning::
113+
Packaging the application
114+
-------------------------
114115

115-
``TT_PRELOAD`` values that end with ``.lua`` are considered scripts,
116-
so avoid module names with this ending.
116+
To package the ready application, use the :ref:`tt pack <tt-pack>` command.
117+
This command can create an installable DEB/RPM package or generate ``.tgz`` archive.
117118

118-
To load several scripts or modules, pass them in a single quoted string, separated
119-
by semicolons:
119+
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:
120120

121121
.. code-block:: console
122122
123-
$ TT_PRELOAD="/preload/path/script.lua;preload.module" tarantool main.lua
123+
~/myapp$ tree -a
124+
.
125+
├── bin
126+
│ ├── tarantool
127+
│ └── tt
128+
├── include
129+
├── instances.enabled
130+
│ └── sharded_cluster -> ../sharded_cluster
131+
├── modules
132+
├── sharded_cluster
133+
│ ├── .rocks
134+
│ │ └── share
135+
│ │ └── ...
136+
│ ├── config.yaml
137+
│ ├── instances.yaml
138+
│ ├── router.lua
139+
│ ├── sharded_cluster-scm-1.rockspec
140+
│ └── storage.lua
141+
└── tt.yaml
124142
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.
127143
128-
The :ref:`arg <index-init_label>` value from the main script is visible in
129-
the preload script or module.
144+
The application's layout looks similar to the one defined when :ref:`developing the application <admin-instance_config-develop-app>` with some differences:
130145

131-
For example, when preloading this script:
146+
- ``bin``: contains the ``tarantool`` and ``tt`` binaries packed with the application bundle.
132147

133-
.. code-block:: lua
148+
- ``instances.enabled``: contains a symlink to the packed ``sharded_cluster`` application.
134149

135-
-- preload.lua --
136-
print("Preloading:")
137-
print("... arg is:", ...)
138-
print("Passed args:", arg[1], arg[2])
150+
- ``sharded_cluster``: a packed application. In addition to files created during the application development, includes the ``.rocks`` directory containing application dependencies (for example, ``vshard``).
139151

140-
You get the following output:
152+
- ``tt.yaml``: a ``tt`` configuration file.
141153

142-
.. code-block:: console
143154

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-
< ... >
153155

154-
If an error happens during the execution of the preload script or module, Tarantool
155-
reports the problem and exits.
156+
.. _admin-instances_to_run:
156157

157-
.. _admin-tt_config_file:
158+
Instances to run
159+
~~~~~~~~~~~~~~~~
158160

159-
tt configuration file
160-
---------------------
161+
One more difference for a deployed application is the content of the ``instances.yaml`` file that specifies instances to run in the current environment.
161162

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.
163+
- On the developer's machine, this file might include all the instances defined in the cluster configuration.
166164

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).
165+
.. image:: admin_instances_dev.png
166+
:align: left
167+
:width: 700
168+
:alt: Cluster topology
170169

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>`.
170+
``instances.yaml``:
175171

176-
Find the detailed information about the ``tt`` configuration parameters and launch modes
177-
on the :ref:`tt configuration page <tt-config>`.
172+
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster/instances.yaml
173+
:language: yaml
174+
:dedent:
175+
176+
- In the production environment, this file includes instances to run on the specific machine.
177+
178+
.. image:: admin_instances_prod.png
179+
:align: left
180+
:width: 700
181+
:alt: Cluster topology
182+
183+
``instances.yaml`` (Server-001):
184+
185+
.. code-block:: yaml
186+
187+
router-a-001:
188+
189+
``instances.yaml`` (Server-002):
190+
191+
.. code-block:: yaml
192+
193+
storage-a-001:
194+
storage-b-001:
195+
196+
``instances.yaml`` (Server-003):
197+
198+
.. code-block:: yaml
199+
200+
storage-a-002:
201+
storage-b-002:
202+
203+
204+
The :ref:`Starting and stopping instances <admin-start_stop_instance>` section describes how to start and stop Tarantool instances.

0 commit comments

Comments
 (0)