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