Filip Pytloun | 5b3c12e | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 1 | |
Ales Komarek | 2813a68 | 2017-04-12 10:07:23 +0200 | [diff] [blame] | 2 | ============= |
| 3 | MySQL Formula |
| 4 | ============= |
Filip Pytloun | 5b3c12e | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 5 | |
Ales Komarek | 2813a68 | 2017-04-12 10:07:23 +0200 | [diff] [blame] | 6 | MySQL is the world's second most widely used open-source relational database |
| 7 | management system (RDBMS). |
Filip Pytloun | 5b3c12e | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 8 | |
Filip Pytloun | 5b3c12e | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 9 | |
Ales Komarek | 2813a68 | 2017-04-12 10:07:23 +0200 | [diff] [blame] | 10 | Sample Metadata |
| 11 | =============== |
| 12 | |
| 13 | |
| 14 | Standalone setups |
| 15 | ----------------- |
Filip Pytloun | 5b3c12e | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 16 | |
| 17 | Standalone MySQL server |
| 18 | |
| 19 | .. code-block:: yaml |
| 20 | |
| 21 | mysql: |
| 22 | server: |
| 23 | enabled: true |
| 24 | version: '5.5' |
| 25 | admin: |
| 26 | user: root |
| 27 | password: pass |
| 28 | bind: |
| 29 | address: '127.0.0.1' |
| 30 | port: 3306 |
| 31 | database: |
| 32 | name: |
| 33 | encoding: 'utf8' |
| 34 | users: |
| 35 | - name: 'username' |
| 36 | password: 'password' |
| 37 | host: 'localhost' |
| 38 | rights: 'all privileges' |
Dzmitry Stremkouski | 588a021 | 2018-10-04 10:15:22 +0200 | [diff] [blame] | 39 | target: '*.*' |
Filip Pytloun | 5b3c12e | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 40 | |
Ales Komarek | 2813a68 | 2017-04-12 10:07:23 +0200 | [diff] [blame] | 41 | |
Filip Pytloun | 5b3c12e | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 42 | MySQL replication master with SSL |
| 43 | |
| 44 | .. code-block:: yaml |
| 45 | |
| 46 | mysql: |
| 47 | server: |
| 48 | enabled: true |
| 49 | version: 5.5 |
| 50 | replication: |
| 51 | role: master |
| 52 | ssl: |
| 53 | enabled: true |
| 54 | authority: Org_CA |
| 55 | certificate: name_of_service |
| 56 | admin: |
| 57 | user: root |
| 58 | password: pass |
| 59 | bind: |
| 60 | address: '127.0.0.1' |
| 61 | port: 3306 |
| 62 | |
| 63 | MySQL replication slave with SSL |
| 64 | |
| 65 | .. code-block:: yaml |
| 66 | |
| 67 | mysql: |
| 68 | server: |
| 69 | enabled: true |
| 70 | version: '5.5' |
| 71 | replication: |
| 72 | role: slave |
| 73 | master: master.salt.id |
| 74 | ssl: |
| 75 | enabled: true |
| 76 | authority: Org_CA |
| 77 | certificate: name_of_service |
| 78 | client_certificate: name_of_client_cert |
| 79 | admin: |
| 80 | user: root |
| 81 | password: pass |
| 82 | bind: |
| 83 | address: '127.0.0.1' |
| 84 | port: 3306 |
| 85 | |
| 86 | Tuned up MySQL server |
| 87 | |
| 88 | .. code-block:: yaml |
| 89 | |
| 90 | mysql: |
| 91 | server: |
| 92 | enabled: true |
| 93 | version: '5.5' |
| 94 | admin: |
| 95 | user: root |
| 96 | password: pass |
| 97 | bind: |
| 98 | address: '127.0.0.1' |
| 99 | port: 3306 |
| 100 | key_buffer: 250M |
| 101 | max_allowed_packet: 32M |
| 102 | max_connections: 1000 |
| 103 | thread_stack: 512K |
| 104 | thread_cache_size: 64 |
| 105 | query_cache_limit: 16M |
| 106 | query_cache_size: 96M |
| 107 | force_encoding: utf8 |
Jakub Pavlik | da755f2 | 2016-09-02 12:06:53 +0200 | [diff] [blame] | 108 | sql_mode: "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" |
Filip Pytloun | 5b3c12e | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 109 | database: |
| 110 | name: |
| 111 | encoding: 'utf8' |
| 112 | users: |
| 113 | - name: 'username' |
| 114 | password: 'password' |
| 115 | host: 'localhost' |
| 116 | rights: 'all privileges' |
| 117 | |
Ales Komarek | 2813a68 | 2017-04-12 10:07:23 +0200 | [diff] [blame] | 118 | |
| 119 | MySQL Galera cluster |
Filip Pytloun | 5b3c12e | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 120 | -------------------- |
| 121 | |
Ales Komarek | 2813a68 | 2017-04-12 10:07:23 +0200 | [diff] [blame] | 122 | MySQL Galera cluster is configured for ring connection between 3 nodes. Each |
| 123 | node should have just one member. |
Filip Pytloun | 5b3c12e | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 124 | |
| 125 | Galera initial server (master) |
| 126 | |
| 127 | .. code-block:: yaml |
| 128 | |
| 129 | mysql: |
| 130 | cluster: |
| 131 | enabled: true |
| 132 | name: openstack |
| 133 | role:master |
| 134 | bind: |
| 135 | address: 192.168.0.1 |
| 136 | members: |
| 137 | - host: 192.168.0.1 |
| 138 | port: 4567 |
| 139 | user: |
| 140 | name: wsrep_sst |
| 141 | password: password |
| 142 | server: |
| 143 | enabled: true |
| 144 | version: 5.5 |
| 145 | admin: |
| 146 | user: root |
| 147 | password: pass |
| 148 | bind: |
| 149 | address: 192.168.0.1 |
| 150 | database: |
| 151 | name: |
| 152 | encoding: 'utf8' |
| 153 | users: |
| 154 | - name: 'username' |
| 155 | password: 'password' |
| 156 | host: 'localhost' |
| 157 | rights: 'all privileges' |
| 158 | |
Ales Komarek | 2813a68 | 2017-04-12 10:07:23 +0200 | [diff] [blame] | 159 | MySQL client |
| 160 | ------------ |
Ales Komarek | 04991c0 | 2016-10-05 10:02:59 +0200 | [diff] [blame] | 161 | |
Jiri Broulik | 3675447 | 2017-04-27 22:15:29 +0200 | [diff] [blame] | 162 | Database with initial data (Restore DB) |
| 163 | |
| 164 | .. code-block:: yaml |
| 165 | |
| 166 | mysql: |
| 167 | client: |
| 168 | server: |
| 169 | database: |
| 170 | admin: |
| 171 | host: localhost |
| 172 | port: 3306 |
| 173 | user: ${_param:mysql_admin_user} |
| 174 | password: ${_param:mysql_admin_password} |
| 175 | encoding: utf8 |
| 176 | database: |
| 177 | neutron_upgrade: |
| 178 | encoding: utf8 |
| 179 | users: |
| 180 | - name: neutron |
| 181 | password: ${_param:mysql_neutron_password} |
| 182 | host: '%' |
| 183 | rights: all |
| 184 | - name: neutron |
| 185 | password: ${_param:mysql_neutron_password} |
| 186 | host: ${_param:single_address} |
| 187 | rights: all |
| 188 | initial_data: |
| 189 | engine: backupninja |
| 190 | source: ${_param:backupninja_backup_host} |
| 191 | host: ${linux:network:fqdn} |
| 192 | database: neutron |
| 193 | |
| 194 | .. note:: This client role needs to be put directly on dbs node. |
| 195 | The provided setup restores db named neutron_upgrade with data from db called neutron. |
| 196 | |
| 197 | |
Ales Komarek | 04991c0 | 2016-10-05 10:02:59 +0200 | [diff] [blame] | 198 | Database management on remote MySQL server |
| 199 | |
| 200 | .. code-block:: yaml |
| 201 | |
| 202 | mysql: |
| 203 | client: |
| 204 | enabled: true |
| 205 | server: |
| 206 | server01: |
| 207 | admin: |
| 208 | host: database.host |
| 209 | port: 3306 |
| 210 | user: root |
| 211 | password: password |
| 212 | encoding: utf8 |
| 213 | database: |
| 214 | database01: |
| 215 | encoding: utf8 |
| 216 | users: |
| 217 | - name: username |
| 218 | password: 'password' |
| 219 | host: 'localhost' |
| 220 | rights: 'all privileges' |
| 221 | |
Jiri Broulik | 3675447 | 2017-04-27 22:15:29 +0200 | [diff] [blame] | 222 | |
Ales Komarek | 04991c0 | 2016-10-05 10:02:59 +0200 | [diff] [blame] | 223 | User management on remote MySQL server |
| 224 | |
| 225 | .. code-block:: yaml |
| 226 | |
| 227 | mysql: |
| 228 | client: |
| 229 | enabled: true |
| 230 | server: |
| 231 | server01: |
| 232 | admin: |
| 233 | host: database.host |
| 234 | port: 3306 |
| 235 | user: root |
| 236 | password: password |
| 237 | encoding: utf8 |
| 238 | users: |
| 239 | - name: user01 |
| 240 | host: "*" |
| 241 | password: 'sdgdsgdsgd' |
| 242 | - name: user02 |
| 243 | host: "localhost" |
| 244 | |
| 245 | |
Ales Komarek | 2813a68 | 2017-04-12 10:07:23 +0200 | [diff] [blame] | 246 | Sample Usage |
| 247 | ============ |
Filip Pytloun | 5b3c12e | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 248 | |
| 249 | MySQL Galera check sripts |
| 250 | |
| 251 | .. code-block:: bash |
| 252 | |
| 253 | mysql> SHOW STATUS LIKE 'wsrep%'; |
| 254 | |
| 255 | mysql> SHOW STATUS LIKE 'wsrep_cluster_size' ;" |
| 256 | |
| 257 | Galera monitoring command, performed from extra server |
| 258 | |
| 259 | .. code-block:: bash |
| 260 | |
| 261 | garbd -a gcomm://ipaddrofone:4567 -g my_wsrep_cluster -l /tmp/1.out -d |
| 262 | |
| 263 | 1. salt-call state.sls mysql |
| 264 | 2. Comment everything starting wsrep* (wsrep_provider, wsrep_cluster, wsrep_sst) |
| 265 | 3. service mysql start |
| 266 | 4. run on each node mysql_secure_install and filling root password. |
| 267 | |
| 268 | .. code-block:: bash |
| 269 | |
| 270 | Enter current password for root (enter for none): |
| 271 | OK, successfully used password, moving on... |
| 272 | |
| 273 | Setting the root password ensures that nobody can log into the MySQL |
| 274 | root user without the proper authorisation. |
| 275 | |
| 276 | Set root password? [Y/n] y |
| 277 | New password: |
| 278 | Re-enter new password: |
| 279 | Password updated successfully! |
| 280 | Reloading privilege tables.. |
| 281 | ... Success! |
| 282 | |
| 283 | By default, a MySQL installation has an anonymous user, allowing anyone |
| 284 | to log into MySQL without having to have a user account created for |
| 285 | them. This is intended only for testing, and to make the installation |
| 286 | go a bit smoother. You should remove them before moving into a |
| 287 | production environment. |
| 288 | |
| 289 | Remove anonymous users? [Y/n] y |
| 290 | ... Success! |
| 291 | |
| 292 | Normally, root should only be allowed to connect from 'localhost'. This |
| 293 | ensures that someone cannot guess at the root password from the network. |
| 294 | |
| 295 | Disallow root login remotely? [Y/n] n |
| 296 | ... skipping. |
| 297 | |
| 298 | By default, MySQL comes with a database named 'test' that anyone can |
| 299 | access. This is also intended only for testing, and should be removed |
| 300 | before moving into a production environment. |
| 301 | |
| 302 | Remove test database and access to it? [Y/n] y |
| 303 | - Dropping test database... |
| 304 | ... Success! |
| 305 | - Removing privileges on test database... |
| 306 | ... Success! |
| 307 | |
| 308 | Reloading the privilege tables will ensure that all changes made so far |
| 309 | will take effect immediately. |
| 310 | |
| 311 | Reload privilege tables now? [Y/n] y |
| 312 | ... Success! |
| 313 | |
| 314 | Cleaning up... |
| 315 | |
| 316 | 5. service mysql stop |
| 317 | 6. uncomment all wsrep* lines except first server, where leave only in my.cnf wsrep_cluster_address='gcomm://'; |
| 318 | 7. start first node |
| 319 | 8. Start third node which is connected to first one |
| 320 | 9. Start second node which is connected to third one |
| 321 | 10. After starting cluster, it must be change cluster address at first starting node without restart database and change config my.cnf. |
| 322 | |
| 323 | .. code-block:: bash |
| 324 | |
| 325 | mysql> SET GLOBAL wsrep_cluster_address='gcomm://10.0.0.2'; |
| 326 | |
Ales Komarek | 2813a68 | 2017-04-12 10:07:23 +0200 | [diff] [blame] | 327 | More Information |
| 328 | ================ |
Filip Pytloun | 5b3c12e | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 329 | |
| 330 | * http://dev.mysql.com/doc/ |
| 331 | * http://www.slideshare.net/osscube/mysql-performance-tuning-top-10-tips |
| 332 | |
Filip Pytloun | 5b3c12e | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 333 | * http://sourceforge.net/projects/automysqlbackup/ |
| 334 | * https://labs.riseup.net/code/projects/backupninja/wiki |
| 335 | * http://wiki.zmanda.com/index.php/Mysql-zrm |
Filip Pytloun | fc6c334 | 2017-02-02 13:02:03 +0100 | [diff] [blame] | 336 | |
Ales Komarek | 2813a68 | 2017-04-12 10:07:23 +0200 | [diff] [blame] | 337 | |
Filip Pytloun | fc6c334 | 2017-02-02 13:02:03 +0100 | [diff] [blame] | 338 | Documentation and Bugs |
| 339 | ====================== |
| 340 | |
| 341 | To learn how to install and update salt-formulas, consult the documentation |
| 342 | available online at: |
| 343 | |
| 344 | http://salt-formulas.readthedocs.io/ |
| 345 | |
| 346 | In the unfortunate event that bugs are discovered, they should be reported to |
| 347 | the appropriate issue tracker. Use Github issue tracker for specific salt |
| 348 | formula: |
| 349 | |
| 350 | https://github.com/salt-formulas/salt-formula-mysql/issues |
| 351 | |
| 352 | For feature requests, bug reports or blueprints affecting entire ecosystem, |
| 353 | use Launchpad salt-formulas project: |
| 354 | |
| 355 | https://launchpad.net/salt-formulas |
| 356 | |
| 357 | You can also join salt-formulas-users team and subscribe to mailing list: |
| 358 | |
| 359 | https://launchpad.net/~salt-formulas-users |
| 360 | |
| 361 | Developers wishing to work on the salt-formulas projects should always base |
| 362 | their work on master branch and submit pull request against specific formula. |
| 363 | |
| 364 | https://github.com/salt-formulas/salt-formula-mysql |
| 365 | |
| 366 | Any questions or feedback is always welcome so feel free to join our IRC |
| 367 | channel: |
| 368 | |
| 369 | #salt-formulas @ irc.freenode.net |