| 1 |
SQL configuration backends |
| 2 |
========================== |
| 3 |
|
| 4 |
There is 2 types of SQL configuration backends for LemonLDAP::NG: |
| 5 |
|
| 6 |
- **CDBI**: very simple storage (recommended) |
| 7 |
- **RDBI**: triple store storage (deprecated) |
| 8 |
|
| 9 |
|
| 10 |
.. tip:: |
| 11 |
|
| 12 |
You can use any database engine if it provides a Perl Driver. |
| 13 |
You will find here examples for MySQL and PostgreSQL, but other engines |
| 14 |
may also work. |
| 15 |
|
| 16 |
See :doc:`how to change configuration backend<changeconfbackend>`. |
| 17 |
|
| 18 |
MySQL |
| 19 |
----- |
| 20 |
|
| 21 |
Perl Driver |
| 22 |
~~~~~~~~~~~ |
| 23 |
|
| 24 |
You need DBD::MySQL Perl module: |
| 25 |
|
| 26 |
- Debian: |
| 27 |
|
| 28 |
:: |
| 29 |
|
| 30 |
apt install libdbd-mysql-perl |
| 31 |
|
| 32 |
- Red Hat: |
| 33 |
|
| 34 |
:: |
| 35 |
|
| 36 |
yum install perl-DBD-MySQL |
| 37 |
|
| 38 |
Database and table creation |
| 39 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 40 |
|
| 41 |
|
| 42 |
.. code-block:: sql |
| 43 |
|
| 44 |
CREATE DATABASE lemonldap-ng CHARACTER SET utf8; |
| 45 |
|
| 46 |
|
| 47 |
Then execute ``/usr/share/lemonldap-ng/ressources/config.my.sql`` to create the table. |
| 48 |
|
| 49 |
Grant access |
| 50 |
~~~~~~~~~~~~ |
| 51 |
|
| 52 |
You have to grant read/write access for the manager component. Other |
| 53 |
components needs just a read access. You can also use the same user for |
| 54 |
all. |
| 55 |
|
| 56 |
|
| 57 |
.. tip:: |
| 58 |
|
| 59 |
You can use different dbiUser strings: |
| 60 |
|
| 61 |
- one with read/write rights for servers hosting the manager |
| 62 |
- one with just read rights for other servers |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
For example (suppose that our servers are in 10.0.0.0/24 network): |
| 67 |
|
| 68 |
.. code-block:: sql |
| 69 |
|
| 70 |
GRANT SELECT,INSERT,UPDATE,DELETE,LOCK TABLES ON lemonldap-ng.lmConfig |
| 71 |
TO [email protected] IDENTIFIED BY 'mypassword'; |
| 72 |
GRANT SELECT ON lemonldap-ng.lmConfig |
| 73 |
TO lemonldapro@'10.0.0.%' IDENTIFIED BY 'myotherpassword'; |
| 74 |
|
| 75 |
Connection settings |
| 76 |
------------------- |
| 77 |
|
| 78 |
Change configuration settings in ``/etc/lemonldap-ng/lemonldap-ng.ini`` |
| 79 |
file (section configuration): |
| 80 |
|
| 81 |
.. code-block:: ini |
| 82 |
|
| 83 |
[configuration] |
| 84 |
type = CDBI |
| 85 |
dbiChain = DBI:mysql:database=lemonldap-ng;host=1.2.3.4 |
| 86 |
dbiUser = lemonldaprw |
| 87 |
dbiPassword = mypassword |
| 88 |
; optional |
| 89 |
dbiTable = mytablename |
| 90 |
|
| 91 |
.. tip:: |
| 92 |
|
| 93 |
We recommend adding the `mysql_connect_timeout`, `mysql_write_timeout`, and `mysql_read_timeout` options to the DBI string |
| 94 |
|
| 95 |
PostGreSQL |
| 96 |
---------- |
| 97 |
|
| 98 |
.. _perl-driver-1: |
| 99 |
|
| 100 |
Perl Driver |
| 101 |
~~~~~~~~~~~ |
| 102 |
|
| 103 |
You need DBD::Pg Perl module: |
| 104 |
|
| 105 |
- Debian: |
| 106 |
|
| 107 |
:: |
| 108 |
|
| 109 |
apt install libdbd-pg-perl |
| 110 |
|
| 111 |
- Red Hat: |
| 112 |
|
| 113 |
:: |
| 114 |
|
| 115 |
yum install perl-DBD-Pg |
| 116 |
|
| 117 |
.. _database-and-table-creation-1: |
| 118 |
|
| 119 |
Database and table creation |
| 120 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 121 |
|
| 122 |
Create database: |
| 123 |
|
| 124 |
.. code-block:: sql |
| 125 |
|
| 126 |
CREATE DATABASE lemonldap-ng; |
| 127 |
|
| 128 |
Then execute ``/usr/share/lemonldap-ng/ressources/config.pg.sql`` to create the table. |
| 129 |
|
| 130 |
Connection settings |
| 131 |
------------------- |
| 132 |
|
| 133 |
Change configuration settings in ``/etc/lemonldap-ng/lemonldap-ng.ini`` |
| 134 |
file (section configuration): |
| 135 |
|
| 136 |
.. code-block:: ini |
| 137 |
|
| 138 |
[configuration] |
| 139 |
type = CDBI |
| 140 |
dbiChain = DBI:Pg:database=lemonldap-ng;host=1.2.3.4 |
| 141 |
dbiUser = lemonldaprw |
| 142 |
dbiPassword = mypassword |
| 143 |
; optional |
| 144 |
dbiTable = mytablename |
| 145 |
|
| 146 |
.. tip:: |
| 147 |
|
| 148 |
We recommend adding the `tcp_user_timeout` and `keepalives_idle` options to the DBI string |
| 149 |
|
| 150 |
Patroni support |
| 151 |
~~~~~~~~~~~~~~~ |
| 152 |
|
| 153 |
If you use a PostgreSQL cluster based on Patroni, you can add the list of |
| 154 |
Patroni API urls to get a native high-availability without needing any |
| 155 |
load-balancer. In case of error, LLNG will try to get the Patroni leader |
| 156 |
and update its "dbiChain": |
| 157 |
|
| 158 |
.. code-block:: ini |
| 159 |
|
| 160 |
[configuration] |
| 161 |
type = Patroni |
| 162 |
dbiChain = DBI:Pg:database=lemonldap-ng;host=1.2.3.4 |
| 163 |
patroniUrl = http://1.2.3.2:8008/cluster, http://1.2.3.3:8008/cluster, http://1.2.3.4:8008/cluster |
| 164 |
dbiUser = lemonldaprw |
| 165 |
dbiPassword = mypassword |
| 166 |
; optional |
| 167 |
dbiTable = mytablename |
| 168 |
patroniTimeout = 3 |
| 169 |
patroniCacheTTL = 60 |
| 170 |
patroniCircuitBreakerDelay = 30 |
| 171 |
|
| 172 |
Optional Patroni parameters: |
| 173 |
|
| 174 |
- **patroniTimeout**: Timeout in seconds for Patroni API requests (default: 3) |
| 175 |
- **patroniCacheTTL**: Time-to-live in seconds for the cached leader information. If all Patroni APIs are temporarily unavailable, LLNG will use the last known leader if the cache is still valid (default: 60) |
| 176 |
- **patroniCircuitBreakerDelay**: Circuit breaker delay in seconds. When Patroni API requests fail, LLNG will wait this amount of time before retrying, using the cached leader in the meantime (default: 30) |
| 177 |
|
| 178 |
Alternative: DBD::Patroni *(use with caution)* |
| 179 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 180 |
|
| 181 |
As an alternative to LLNG's native Patroni support, you can use the |
| 182 |
`DBD::Patroni <https://metacpan.org/dist/DBD-Patroni>`_ Perl driver. This |
| 183 |
driver wraps DBD::Pg and handles Patroni leader discovery transparently at |
| 184 |
the DBI level. |
| 185 |
|
| 186 |
.. danger:: |
| 187 |
|
| 188 |
DBD::Patroni is a recent project that has not been extensively tested. |
| 189 |
Please report any bugs, contribute improvements, or let us know if it |
| 190 |
works well for you! |
| 191 |
|
| 192 |
**Additional features compared to native support:** |
| 193 |
|
| 194 |
- Automatic query routing: SELECT queries go to replicas, write queries to the leader |
| 195 |
- Load balancing modes: round_robin, random, or leader_only |
| 196 |
- Works with the standard CDBI backend (no LLNG-specific code needed) |
| 197 |
|
| 198 |
Installation: |
| 199 |
|
| 200 |
:: |
| 201 |
|
| 202 |
cpan DBD::Patroni |
| 203 |
|
| 204 |
Configuration: |
| 205 |
|
| 206 |
.. code-block:: ini |
| 207 |
|
| 208 |
[configuration] |
| 209 |
type = CDBI |
| 210 |
dbiChain = dbi:Patroni:dbname=lemonldap-ng;patroni_url=http://1.2.3.2:8008/cluster,http://1.2.3.3:8008/cluster,http://1.2.3.4:8008/cluster |
| 211 |
dbiUser = lemonldaprw |
| 212 |
dbiPassword = mypassword |
| 213 |
|
| 214 |
Available DSN options: |
| 215 |
|
| 216 |
- **patroni_url**: Comma-separated Patroni REST API endpoints (required) |
| 217 |
- **patroni_lb**: Load balancing mode - ``round_robin`` (default), ``random``, or ``leader_only`` |
| 218 |
- **patroni_timeout**: HTTP timeout for Patroni API calls in seconds (default: 3) |
| 219 |
|
| 220 |
For HTTPS with self-signed certificates, you can disable SSL verification: |
| 221 |
|
| 222 |
.. code-block:: ini |
| 223 |
|
| 224 |
dbiChain = dbi:Patroni:dbname=lemonldap-ng;patroni_url=https://...;patroni_ssl_verify=0 |
| 225 |
|
| 226 |
See `DBD::Patroni documentation <https://metacpan.org/dist/DBD-Patroni>`_ for |
| 227 |
more options including mTLS configuration. |
| 228 |
|
| 229 |
RDBI (deprecated) |
| 230 |
------------------ |
| 231 |
|
| 232 |
In order to use the deprecated RDBI storage, use the following table schemas: |
| 233 |
|
| 234 |
|
| 235 |
MySQL |
| 236 |
~~~~~ |
| 237 |
|
| 238 |
.. code-block:: sql |
| 239 |
|
| 240 |
CREATE TABLE lmConfig ( |
| 241 |
cfgNum int(11) NOT NULL, |
| 242 |
field varchar(255) NOT NULL DEFAULT '', |
| 243 |
value longtext, |
| 244 |
PRIMARY KEY (cfgNum,field) |
| 245 |
); |
| 246 |
|
| 247 |
PostgreSQL |
| 248 |
~~~~~~~~~~ |
| 249 |
|
| 250 |
.. code-block:: sql |
| 251 |
|
| 252 |
CREATE TABLE lmconfig ( |
| 253 |
cfgnum integer NOT NULL, |
| 254 |
field text NOT NULL, |
| 255 |
value text, |
| 256 |
PRIMARY KEY (cfgNum,field) |
| 257 |
); |