Table of Contents

Middleware

Chef

Web Sites

Installation

Donwload ChefDK(Chef Development Kit) https://downloads.chef.io/chef-dk/

What's Included?

CentOS/RHEL

# curl -L -O https://packages.chef.io/stable/el/7/chefdk-0.16.28-1.el7.x86_64.rpm
# rpm -ivh chefdk-0.16.28-1.el7.x86_64.rpm

Check chef

# chef verify
Running verification for component 'berkshelf'
Running verification for component 'test-kitchen'
Running verification for component 'tk-policyfile-provisioner'
(abbr)
........
---------------------------------------------
Verification of component 'rubocop' succeeded.
Verification of component 'kitchen-vagrant' succeeded.
Verification of component 'openssl' succeeded.
Verification of component 'delivery-cli' succeeded.
Verification of component 'opscode-pushy-client' succeeded.
Verification of component 'berkshelf' succeeded.
Verification of component 'tk-policyfile-provisioner' succeeded.
Verification of component 'fauxhai' succeeded.
Verification of component 'inspec' succeeded.
Verification of component 'test-kitchen' succeeded.
Verification of component 'chef-dk' failed.
Verification of component 'chefspec' succeeded.
Verification of component 'knife-spork' succeeded.
Verification of component 'git' succeeded.
Verification of component 'chef-sugar' succeeded.
Verification of component 'chef-client' succeeded.
Verification of component 'generated-cookbooks-pass-chefspec' succeeded.
Verification of component 'package installation' succeeded.
Verification of component 'chef-provisioning' succeeded.
# which chef
/usr/bin/chef
# ls -l /usr/bin/chef
lrwxrwxrwx 1 root root 20 Aug  1 23:57 /usr/bin/chef -> /opt/chefdk/bin/chef


stand-alone (chef-zero)

Constitutuion

System Explanation
chef-zero new version
chef-solo + knife-solo old
chef-solo :
knife-solo : “knife-sole” is used to manage many node. “knife-sole” is use “rsync” to deploy Cookbook and “ssh” to execute chef-sole at many node.

Installation

# chef gem install knife-zero

Configuration

# chef generate repo chef-repo    <- create chef repository

# tree -a -I .git chef-repo
chef-repo
|-- .chef-repo.txt
|-- .gitignore
|-- LICENSE
|-- README.md
|-- chefignore
|-- conf.rb
|-- cookbooks
|   |-- README.md
|   `-- example
|       |-- README.md
|       |-- attributes
|       |   `-- default.rb
|       |-- metadata.rb
|       `-- recipes
|           `-- default.rb
|-- data_bags
|   |-- README.md
|   `-- example
|       `-- example_item.json
|-- environments
|   |-- README.md
|   `-- example.json
`-- roles
    |-- README.md
    `-- example.json

8 directories, 17 files
# knife cookbook create -o cookbooks sample

# tree -a cookbooks/
cookbooks/
|-- README.md
|-- example
|   |-- README.md
|   |-- attributes
|   |   `-- default.rb
|   |-- metadata.rb
|   `-- recipes
|       `-- default.rb
`-- sample
    |-- CHANGELOG.md
    |-- README.md
    |-- attributes
    |-- definitions
    |-- files
    |   `-- default
    |-- libraries
    |-- metadata.rb
    |-- providers
    |-- recipes
    |   `-- default.rb
    |-- resources
    `-- templates
        `-- default

14 directories, 9 files
# vi  cookbooks/sample/recipes/default.rb

# cat cookbooks/sample/recipes/default.rb
package "httpd" do
  action :install
end

service "httpd" do
  action [:enable, :start]
end

file "/var/www/html/index.html" do
  content '<h1>Hello, Chef Server World!!</h1>'
end

execution

# knife zero bootstrap xx.xx.xx.xx --sudo -N local-node
# knife node list
# knife node run_list add local-node sample
# knife zero converge 'name:xx.xx.xx.xx' --sudo






stand-alone (chef-solo)

Installation

# chef gem install knife-solo

Configuration

# chef generate repo chef-repo    <- create chef repository

# tree -a chef-repo
chef-repo
|-- .chef
|   `-- knife.rb
|-- .gitignore
|-- Berksfile
|-- cookbooks
|   `-- .gitkeep
|-- data_bags
|   `-- .gitkeep
|-- environments
|   `-- .gitkeep
|-- nodes
|   `-- .gitkeep
|-- roles
|   `-- .gitkeep
`-- site-cookbooks
    `-- .gitkeep

7 directories, 9 files
# cd chef-repo
# knife cookbook create -o cookbooks httpd

# tree -a cookbooks
cookbooks
|-- .gitkeep
`-- httpd
    |-- CHANGELOG.md
    |-- README.md
    |-- attributes
    |-- definitions
    |-- files
    |   `-- default
    |-- libraries
    |-- metadata.rb
    |-- providers
    |-- recipes
    |   `-- default.rb
    |-- resources
    `-- templates
        `-- default

11 directories, 5 files
# vi cookbooks/httpd/recipes/default.rb

 package "apache2" do
   action :install
 end

 service "apache2" do
   supports :status => true, :restart => true, :reload => true
   action [:enable, :start]
 end

execution

# knife solo prepare xx.xx.xx.xx
# vi chef-repo/nodes/xx.json
{
    "run_list":[
      "recipe[httpd]"
    ]
  }

# knife solo cook xx.xx.xx.xx






Client/Server

Constitutuion

System Explanation
Chef Server
Node Chef Client
Workstation You use “knife” command for magagement recip.

Server

Install

# rpm -vih chef-server-*.x86_64.rpm

Configuration

# chef-server-ctl reconfigure

Workstation

Install

# yum install ruby ruby-devel rubygems make gcc
# gem install chef
# mkdir ~/.chef
# scp CHEFSERVER:/etc/chef-server/admin.pem ~/.chef/
# scp CHEFSERVER:/etc/chef-server/chef-validator.pem ~/.chef/

Upload Cookbook from Workstation to Chef Server

# knife cookbook upload -a

Node (client)

Configuration Node Setting

# yum install ruby ruby-devel rubygems make gcc
# gem install chef
# mkdir -p /etc/chef
# scp CHEFSERVRE:/etc/chef-server/chef-validator.pem /etc/chef/validation.pem
# vi /etc/chef/client.rb
 chef_server_url 'https://CHEFSERVER'
 node_name 'NODENAME'

Execute Node Command

# chef-client -o mysql::client




Memo

Vagrant memo

# vi Vagrantfile
 Vagrant.configure("2") do |config|
   config.vm.box = "ubuntu"
   config.vm.network :private_network, ip: "192.168.33.10"
   config.vm.provision :chef_solo do |chef|
      chef.cookbooks_path = "./cookbooks"
      chef.add_recipe "httpd"
      chef.add_recipe "mysql"
      chef.add_recipe "php"
      chef.add_recipe "group"
   end
 end

# vagrant reload