2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Berkshelfを使ってvagrant環境に、MySQL5.5を入れる

Posted at

Berkshelf は、chef-DKで入れることを推奨

Berkshelf って何?

  • Cookbookの管理をする
  • Cookbookの依存関係を管理する

良くCookbookのgemとか言われる

作業用ディレクトリ作成

mkdir mysql_server

初手

vagrant init
vim Vagrantfile
Vagrant.configure(2) do |config|
  config.omnibus.chef_version = :latest
  config.vm.box = "chef/centos-7.0"
  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = './chef-repo/cookbooks' # ここに、Berkshelfで生成される Cookbook が置かれる
    chef.add_recipe 'setup_mysql'
  end
end

インストール用のレシピを作成

knife cookbook create setup_mysql -o cookbooks/
cd cookbooks/setup_mysql

ここの内容に従い、Berkshelfで落としてきたMySQLのcookbook を使って、MySQLをインストールするためのレシピを作成

metadata.rb
name             'setup_mysql'
maintainer       'YOUR_COMPANY_NAME'
maintainer_email 'YOUR_EMAIL'
license          'All rights reserved'
description      'Installs/Configures setup_mysql'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version          '0.1.0'
depends          'mysql'
recipes/default.rb
#
# Cookbook Name:: setup_mysql
# Recipe:: default
#
# Copyright 2015, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
mysql_service 'default' do
  version '5.5'
  initial_root_password ''
  action [:create, :start]
end

mysql_client 'default' do
  action :create
end

Berkshelf作業用ディレクトリを生成

mkdir chef-repo/
cd chef-repo
vim Berksfile

Berksfile に必要なCookbookを列挙

source "https://supermarket.chef.io"
cookbook 'mysql' # supermarket.chef.io から取得
cookbook 'setup_mysql', path: '../cookbooks/setup_mysql' # 自前のcookbook(MySQLインストール用)

Berkshelfの情報を元にcookbookを生成

berks vendor cookbooks

サーバ起動 & provision

vagrant up

動作確認

vagrant ssh
mysql -u root

参考

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?