Giter Club home page Giter Club logo

mysqld's Introduction

mysqld cookbook

Manage your mysqld servers with this cookbook. Unlike the official opscode mysql cookbook, it doesn't mess with the default mysql configuration. If you do not specify anything explicitly, the defaults of your distribution will be used. (At least if I do not mess up - Check the default attributes, if unsure (and file a pull request if you need to correct anything))

Features

  • Defaults to OS settings unless explicitly specified otherwise
  • Supports all my.cnf settings

Compatibility

This cookbook is currently tested on Ubuntu 16.04. It should work on other Ubuntu/ Debian systems as well, as long as a compatible database version is used (e.g. >= mysql-5.7.6 or >= mariadb-10.1).

For older database versions, it might be required to adapt some of the my.cnf attributes. Furthermore, the mysqld_password provider only works with the mentioned compatible databases. In case you need to use mysqld_password with older versions (e.g. < mysql-5.7.6), you need to version-lock this cookbook to 1.0.5. This can be achieved by putting the following in your Berksfile:

cookbook 'mysqld', '~> 1.0'

Note: The support for RHEL was dropped with version v2.2.0, pull-requests are welcome!

Contributions to support other systems are very welcome!

Requirements

You need to add the following line to your metadata.rb

depends 'mysqld'

Attributes

Configuration

Everything in your my.cnf can be maintained using attributes. Consider using the provides LWRPs (see below)

If you do not specify anything, the defaults of your os will be used.

This recipe supports every setting in the my.cnf. All your settings will be merged with the systems default, and then written to the my.cnf config file. The packages to install, the path to my.cnf as well as the name of the service are set automatically, and can be overwritten using the following attributes:

node['mysqld']['my.cnf_path']
node['mysqld']['service_name']
node['mysqld']['mysql_packages']          # When node['mysqld']['use_mariadb'] == false
node['mysqld']['mariadb_packages']
node['mysqld']['mariadb_galera_packages'] # When using mariadb_galera_install recipe

The configuration is stored in the node['mysqld']['my.cnf'] hash, and can be adapted like so

# node['mysqld']['my.conf'][<category>][<key>] = <value>
node['mysqld']['my.cnf']['mysqld']['bind-address'] = '0.0.0.0'

This will expand to the following in your config file (leaving all other settings untouched)

[mysqld]
bind-address = 0.0.0.0

To remove a default option, you can pass false or nil as the value

# Remove deprecated innodb option
default['mysqld']['my.cnf']['mysqld']['innodb_additional_mem_pool_size'] = false

As the configuration file is constructed from the config hash, every my.cnf configuration option is supported.

node['mysqld']['root_password'] = 'yourpass'

Recipes

default

  • Setup official MariaDB repository
  • Install MariaDB server
  • Configure MariaDB server according to the attributes. If no attributes are given, stick with the systems default

mariadb_repository

Sets up official MariaDB repository to install packages from. Configure it using the following attributes

node['mysqld']['repository']['version'] # Defaults to '10.1'
node['mysqld']['repository']['mirror']  # Defaults to HostEurope mirror

install

Install mariadb/ mysql packages (according to attributes, defaults to mariadb-server)

configure

Configure mysql according to attributes. Sets the databases root account (resp. debian-sys-maint on Debian/Ubuntu systems) to use the password in node['mysqld']['root_password'], if the attribute is set.

mariadb_galera_init

Run mariadb_repository and mariadb_galera_install recipes, then configure as the configure recipe would do, but start mariadb with --wsrep-new-cluster --wsrep_cluster_address=gcomm:// to initialize a new Galera cluster.

Use this if you want to setup a new Galera cluster, and run it on your first node once:

$ sudo chef-client --once -o 'recipe[mysqld::mariadb_galera_init]'

Once you connected the other nodes using the regular recipes, re-run chef-client as you did on the other servers.

Note: If you use a wrapper cookbook to configure your instances, attributes might not be available when running the recipe with -o recipe[]. Create a mariadb_galera_init recipe in your wrapper cookbook, calling this recipe if you have trouble.

Providers

mysqld

You can configure your database also using the mysqld provider:

include_recipe 'mysqld::mariadb_galera_install'

# Name attribute will be ignored. Choose something that makes sense for you
mysqld 'galera' do
  my_cnf { 'bind-address' => '0.0.0.0' }
end

password

You can set passwords (incl. root and debian-sys-maint accounts) using this provider. By default, the provider uses the created root/debian-sys-maint accounts depending on the system you are on.

mysqld_password 'root' do
  password 'get_from_data_bag_maybe?'

  # If required, you can specify your own auth-scheme here
  # auth '-u specialuser -pmypass'
end

Contributing

Contributions are very welcome!

  1. Fork the repository on Github
  2. Create a named feature branch (like add_component_x)
  3. Write you change
  4. Write tests for your change (if applicable)
  5. Run the tests, ensuring they all pass
  6. Submit a Pull Request using Github

License and Authors

Authors: Chris Aumann [email protected]

License: GPLv3

mysqld's People

Contributors

chr4 avatar smelchior avatar whitekid avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mysqld's Issues

Percona support

If it's interesting, i can make a pull request with support for percona, like mariadb.

Required argument password is missing

I'm trying to use this cookbook with Vagrant, but I can't get it to allow the MySQL user root to have no password. I added cookbook "mysqld" to my Cheffile, and the following to my Vagrantfile:

config.vm.provision "chef_solo" do |chef|
    chef.add_recipe "mysqld"
end

But when I do vagrant up, the Chef configuration fails. Here is the relevant output:

==> default: ================================================================================
==> default: Recipe Compile Error in /tmp/vagrant-chef/82891d35d286774d89cfbe3b7a9ea9d4/cookbooks/mysqld/recipes/default.rb
==> default: ================================================================================
==> default: 
==> default: 
==> default: Chef::Exceptions::ValidationFailed
==> default: ----------------------------------
==> default: Required argument password is missing!
==> default: 
==> default: 
==> default: Cookbook Trace:
==> default: ---------------
==> default:   /tmp/vagrant-chef/82891d35d286774d89cfbe3b7a9ea9d4/cookbooks/mysqld/recipes/configure.rb:26:in `block in from_file'
==> default: 
==> default:   /tmp/vagrant-chef/82891d35d286774d89cfbe3b7a9ea9d4/cookbooks/mysqld/recipes/configure.rb:25:in `from_file'
==> default: 
==> default:   /tmp/vagrant-chef/82891d35d286774d89cfbe3b7a9ea9d4/cookbooks/mysqld/recipes/default.rb:22:in `from_file'
==> default: 
==> default: Relevant File Content:
==> default: ----------------------
==> default: /tmp/vagrant-chef/82891d35d286774d89cfbe3b7a9ea9d4/cookbooks/mysqld/recipes/configure.rb:
==> default: 
==> default:  19:  #
==> default:  20:  
==> default:  21:  # Configure mysql/mariadb according to attributes
==> default:  22:  mysqld 'default'
==> default:  23:  
==> default:  24:  # Set password according to attribute, if set
==> default:  25:  mysqld_password 'root' do
==> default:  26>>   password node['mysqld']['root_password']
==> default:  27:    only_if { node['mysqld']['root_password'] }
==> default:  28:  end
==> default:  29:  
==> default:  30:  # Set debian-sys-maint password on Debian family
==> default:  31:  mysqld_password 'debian-sys-maint' do
==> default:  32:    password node['mysqld']['root_password']
==> default:  33:    only_if { node['mysqld']['root_password'] && node['platform_family'] == 'debian' }
==> default:  34:  end
==> default:  35:  
==> default: 
==> default: [2015-03-26T21:29:12+00:00] ERROR: Running exception handlers
==> default: [2015-03-26T21:29:12+00:00] ERROR: Exception handlers complete
==> default: [2015-03-26T21:29:12+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
==> default: [2015-03-26T21:29:12+00:00] ERROR: Required argument password is missing!

The documentation mentions that the root password will be set if given, so I don't see why the argument is required.

Any thoughts?

Using chef 13 the cookbook doesn't converge due to modification of inmutable properties

Description

In Chef Client 13 some types of resource properties became immutable, including Hash.

========================================================
Error executing action create on resource 'mysqld[default]'

       RuntimeError
       ------------
       can't modify frozen Hash

       Cookbook Trace:
       ---------------
       /tmp/kitchen/cache/cookbooks/mysqld/providers/default.rb:23:in `block in class_from_file'

       Resource Declaration:
       ---------------------
       # In /tmp/kitchen/cache/cookbooks/mysqld/recipes/configure.rb

        22: mysqld 'default'
        23:

       Compiled Resource:
       ------------------
       # Declared in /tmp/kitchen/cache/cookbooks/mysqld/recipes/configure.rb:22:in `from_file'

       mysqld("default") do
         action [:create]
         default_guard_interpreter :default
         declared_type :mysqld
         cookbook_name "mysqld"
         recipe_name "configure"
       end

       System Info:
       ------------
       chef_version=13.2.20
       platform=ubuntu
       platform_version=16.04
       ruby=ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
       program_name=chef-client worker: ppid=1615;start=13:23:26;
       executable=/opt/chef/bin/chef-client

Test Kitchen issues found on password setting

While coding the percona support, i have added a .kitchen.yml to verify the installations:

On ubuntu 16.04 found this:

run_list:

  • recipe[mysqld::mariadb_repository]
  • recipe[mysqld::default]

And set the root_password attribute:

But password is set on authentication string not on password field, i have accesed this mariadb but the password was not set, solved it using:

mysql --defaults-file=/etc/mysql/debian.cnf mysql -e "UPDATE user SET Password = PASSWORD('abcdef01234567890') WHERE User = 'root'; FLUSH PRIVILEGES;"

I dont know if this happened because using the mariadb.org repository.

Setting 'service_name' fails to change the service name defined in providers/default.rb

When trying to use this cookbook and changing the node.default['mysqld']['service_name'] value, I get the following error

==> db: ================================================================================
==> db: Error executing action restart on resource 'service[mysql]'
==> db: ================================================================================
==> db:
==> db: Mixlib::ShellOut::ShellCommandFailed
==> db: ------------------------------------
==> db: Expected process to exit with [0], but received '5'
==> db: ---- Begin output of /bin/systemctl restart mysql ----
==> db: STDOUT:
==> db: STDERR: Failed to restart mysql.service: Unit not found.
==> db: ---- End output of /bin/systemctl restart mysql ----
==> db: Ran /bin/systemctl restart mysql returned 5
==> db:
==> db: Resource Declaration:
==> db: ---------------------
==> db: # In /tmp/vagrant-chef/824d535e25710db30ed17d906f18aa01/cookbooks/mysqld/providers/default.rb
==> db:
==> db: 48: service new_resource.service_name do
==> db: 49: # Use --wsrep-new-cluster if this is an initial galera startup
==> db: 50: if new_resource.galera_init
==> db: 51: start_command "service #{new_resource.service_name} start --wsrep-new-cluster --wsrep_cluster_address=gcomm://"
==> db: 52: end
==> db: 53:
==> db:
==> db: Compiled Resource:
==> db: ------------------
==> db: # Declared in /tmp/vagrant-chef/824d535e25710db30ed17d906f18aa01/cookbooks/mysqld/providers/default.rb:48:in `block in class_from_file'
==> db:
==> db: service("mysql") do
==> db: action [:enable, :start]
==> db: supports {:restart=>nil, :reload=>nil, :status=>nil}
==> db: retries 0
==> db: retry_delay 2
==> db: default_guard_interpreter :default
==> db: service_name "mysql"
==> db: pattern "mysql"
==> db: declared_type :service
==> db: cookbook_name :mysqld
==> db: not_if { #code block }
==> db: end

It looks as though the service name is still "mysql" instead of the value I pass through as node.default['mysqld']['service_name'] - in this instance, "mysqld"

Debian 8 fails to update password

When using the default mysql (At this time 5.5.52 on debian 8) password doesn't get updated and mysql root user remains without password.

Updating authentication_string has no effect on this version. Searching over the web found the following:

MySQL 5.7.5 and earlier version:
SET PASSWORD FOR 'user_name' = PASSWORD('new_password');

MySQL 5.7.6 and later version:
alter user 'user_name' identified by 'new_password';

Also, the execution of the query fails with a "no database selected". fixed on a copy of the cookbook locally, but also the authentication_string also was of no effect to change the password.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.