hatenob

プログラムって分からないことだらけ

一人Web開発~第6夜 MariaDBの導入

アプリケーション実行環境の最後、データストアとあるRDBMSとしてMariaDBをインストールする。せっかくなので、まだ安定はしてないけれど、10.0を入れることにします。

MariaDBのインストール

MariadDBのレシピは今のところとても少ない。

# Install package

cookbook_file "/etc/yum.repos.d/mariadb.repo" do
  mode 00644
end

yum_package "MariaDB-server" do
  action :install
  options '--enablerepo=mariadb'
end

service "mysql" do
  action [:disable, :stop]
end

# Setup my.cnf

template "/etc/my.cnf.d/server.cnf" do
  source "server.cnf.erb"
  mode 00644
  variables({
    :max_con => node[:mariadb][:max_con]
  })
end

パッケージ管理を楽にするためにyumリポジトリを追加してyumでインストールするようにしています。
my.cnfはテンプレートで。とは言え、MariaDBの設定項目とかほとんどしらないのでほぼデフォルト。
下記のサイトなんかを見て調整していきたいなぁと思います。
Yakst - MySQLをインストールしたら、必ず確認すべき10の設定

MariaDBのテスト

テストも至って普通。

require 'spec_helper'

describe package('MariaDB-server') do
  it { should be_installed }
end

describe service('mysql') do
  it { should_not be_enabled }
  it { should     be_running }
end

describe port(3306) do
  it { should be_listening }
end

describe file('/etc/my.cnf.d/server.cnf') do
  it { should be_file }
  it { should contain "character_set_server = utf8" }
end

describe group('mysql') do
  it { should exist }
end

describe user('mysql') do
  it { should exist }
  it { should belong_to_group 'mysql' }
  it { should have_login_shell '/sbin/nologin' }
end

describe yumrepo('mariadb') do
  it { should exist }
  it { should be_enabled }
end

設定を追加したら項目を増やしていく感じかな。
yumリポジトリのテストも念のため。

次は

一通り実行環境ができたので、次はアプリケーションを作成してデプロイし、ちゃんと動くか確かめたいと思います。