07 - CHEF - Configuration Management

CHEF - Configuration Management

  • Chef is a configuration management tool written in Ruby and Erlang
  • Was written to manage Linux but later versions also support Microsoft Windows
  • It uses a pure-Ruby to write system configuration “recipes”
  • Integrates with cloud-based platforms such as Internap, Amazon EC2, Google Cloud
  • Platform, OpenStack, SoftLayer, Microsoft Azure and Rackspace
  • Support for includes AIX, RHEL/CentOS, FreeBSD, OS X, Solaris, Microsoft Windows and
  • Ubuntu platforms
  • Chef Server can be on RHEL/CentOS, Oracle Linux, and Ubuntu
  • Chef can run in client/server mode or standalone configuration named “chef-solo”
Chef Architecture
  • Chef Development Kit has tools to develop and test your infrastructure automation code
  • Infrastructure as code automation code is developed locally on workstation and then deployed in production
  • Chef Server is a central repository for Chef cookbooks and have information about every node being managed
  • Chef client runs on each node and securely communicates with the Chef server to get the latest configuration instructions
  • for that node
  • Chef cookbooks have code for desired state of infrastructure
  • Chef node is a physical machine or virtual machine in network being managed by the Chef server
  • Not for container
  • Only for VM'
  • Pull based tools
  • Current Ver 14
    • Hosted Chef
    • On-Premises Chef
    • Chef Solo



           Workstation     --------------------------------->   Production

Chef Development Kit         Knife                  Chef Server

  • Chef    - Ruby     - Agent-based  - pull mechanisms
  • Puppet  - Ruby    - Agent-based  - pull mechanisms
  • Ansible - Python - AngetLess     - push mechanisms

CHEF Terminology

  • Server  - Store all configuration ( recipe etc ), response providing policy to the chef-client
  • Node   - Any webserver , database , caching .. etc    --> Chef Client
  • Resource - Changed to order achieve desired state  ( Networking, Files, Directories, symlinks, Mount, Registry Keys, PowerShell script, service, package, template ... )
  • Recipe - Main configuration file 
  • Cookbook   - Contain all recipe attributes everything else
  • Run List - List of recipe needs to run on server  ( Monitoring, logging, installing ... )
  • Roles - Webserver -> attach Run List which have all the recipe to required to run -> Load balancer, Application server , database cache, monitoring
  • Search - Perform search of Nodes ( List of database, Nodes with Roles, Find Ip Address, Hostnames )

Hosted Chef:  http://www.chef.io

  • Chef Organization
    • Companies
    • Business units
    • Department

  • Download Starter Kit  ( .pam 256 character key file -> for authentication (API call) )
  • Centos image--> server--> bootstrap server (install chef-client)---> image---> subsequent server create from it

  • Chef Installation includes
    • Knife - Command-line tools for administration
    • Chef-Client - Client application
    • Ruby language
    • Ohai - system profiler .....  and more ...
/et/chef/client.rb Chef Server Enterprise Server Node object chef-client (client.rb) --> Virtual / Physical / Cloud bootstrap Administration's Workstation ( Developers ) Starter Kit zip chef dk chef-repo Cookbooks Knife

Tutorial of Chef
https://www.edureka.co/blog/chef-tutorial/

Chef Lab

chef.io Logins -> Management Console Create Account Organization - Full Name : UnixCloudFusion - Short Name : Congnixia Starter Kit - Download Starter Kit WinScp Protocol - SCP Hostname 127.0.0.1 Port 2222 usernmae : vagrant Click -< Advance Authentication -> key .vagrant -> machine -> default -> virtualbox copy chef-starter Chef-dk https://downloads.chef.io/chef-dk/ Downnload Centos7 or download directly in VM https://packages.chef.io/files/stable/chefdk/4.13.3/el/7/chefdk-4.13.3-1.el7.x86_64.rpm Chef Dependencies https://downloads.chef.io/products/chefdk?os=el
CREATE 3 VMs => vm1 , vm2 and vm3 1. CHEF WORKSTATION vagrant up sudo su - hostnamectl set-hostname Chefworkstation.unixcloudfusion.in bash vi /etc/hosts 192.168.33.11 Chefworkstation.unixcloudfusion.in 192.168.33.12 ChefNode1.unixcloudfusion.in 192.168.33.13 ChefNode2.unixcloudfusion.in mkdir infra-automation cd infra-automation cp /home/varant/chef-starter.zip /root/infra-automation/ -- download chef dk https://packages.chef.io/files/stable/chefdk/4.13.3/el/7/chefdk-4.13.3-1.el7.x86_64.rpm rpm -ivh chefdk-4.13.3-1.el7.x86_64.rpm yum install -y unzip unzip chef-starter.zip cd chef-repo ls -ltra cd .chef config.rb ankit6300.pem ** Chef Server user cd .. cd cookbooks chef generate cookbook apache cd apache ls -ltr cd recipes ls -ltr default.rb ** find .. package resource in chef ** find .. service resource chef ** find .. cookbook_file resource chef vi default.rb # install apache package "httpd" do action :install end service "httpd" do action [ :enable, :start ] end cookbook_file "/var/www/html/index.html" do source "index.html" mode "0644" action :create end cd .. mkdir files cd files mkdir default cd default vi index.html <html> <body> <h1>Hello, World </h1> </body> </html> cd .. cd .. ------------------------------- Go to CHEF Server website Click Nodes ** No nodes available ------------------------------ ** Upload cookbook to Chef Master website knife cookbook upload apache -------------------------------- Go to CHEF Server website Click Nodes ** Now apache node available ------------------------------ ** Create bootstrap into Node1 ** Install Chef Clint into Node1 knife bootstrap 192.168.33.12 --sudo -U vagrant -N Chefnode1 -> Password ** create run list for Node1 knife node run_list add ChefNode1 "rceipe[apache]" -------------------------------- Go to CHEF Server website Click Nodes ** Now apache node available ** also show run list ------------------------------ ** List of Nodes in Chef Server knife node list knife node show chefnode1 ** Gather info about nodes ohai | less ** How to check Chef version knife --version Chef Infra Client: 15..14.0 **** ATTRIBUTES ***** mkdir attributes cd attributes vi default.rb default["apache"]["indexfile"]="index1.html" cd .. cd default cp index.html index1.html vi index1.html add new line <h1>This is our index1.html<.h1> cd ../../rceipes vi default.rb change in cookbook_file .... source node["apache"]["indexfile"] knife cookbook upload apache ** Delete chefnode in Chef Master knife node delete chefnode1 **** Chef Supermark -> supermarket.chef.io Download cookbook as per requirment / software like mysql ** go to cookbook for mysql cd ../.. vi Berksfile source "https:supermarket.chef.io" cookbook 'mysql', '~> 9.0.0' $ berks install ** download from supermark and install ls -ltr ~/berkshelf/cookbooks/ cp -r ~/.berkshef/cookbooks /cookbooks cd cookbooks ls -ltr knife cookbook upload apache 2. CHEF NODE1 vagrant up sudo su - hostnamectl set-hostname Chefnode1.unixcloudfusion.in bash vi /etc/hosts 192.168.33.11 Chefworkstation.unixcloudfusion.in 192.168.33.12 ChefNode1.unixcloudfusion.in 192.168.33.13 ChefNode2.unixcloudfusion.in ** Reset password for install bootstrap from Chef Workstation su -vagrant sudo passwd vagrant -------------------------------- Go to CHEF Server website Click Nodes ** showing chefnode1 ...................... --------------------------------- sudo su - ps -ef | grep -i httpd ** not running apache ** Contact Chef Server and update Node -> Package $ chef-client ** go to desktop browser -> 192.168.33.12 Hello World ** Run again Chef-client after creatd attributes in chef workstation $ chef-client ** go to desktop browser -> 192.168.33.12 Hello World This is our index1.html 3. CHEF NODE2 vagrant up sudo su - hostnamectl set-hostname Chefnode2.unixcloudfusion.in bash vi /etc/hosts 192.168.33.11 Chefworkstation.unixcloudfusion.in 192.168.33.12 ChefNode1.unixcloudfusion.in 192.168.33.13 ChefNode2.unixcloudfusion.in

Comments

Popular posts from this blog

05 - Docker - Containers

08 - PUPPET - Configuration Management

06 - Docker Swarm - Container Orchestration