Chef is an
automated server configuration management tool that can automate the configuration of managed objects, such as system management and software installation. Chef consists of three major components: Chef Server, Chef Workstation, and Chef Node.
Chef Server is the core server, maintains a set of configuration scripts (Cookbook), interacts with each managed node (Chef Node) and gives configuration instructions.
Chef Workstation provides an interface for us to interact with Chef Server: we create a defined Cookbook on Workstation and upload the Cookbook to Chef Server to ensure that managed machines can obtain the latest configuration instructions from Chef Server.
Chef Node is a managed node with chef-client installed and registered. It can be a physical machine or a virtual machine or other objects. Every time Chef Node runs chef-client, it will get the latest configuration instructions (Cookbook) from Chef Server and configure itself according to the instructions.
A Chef environment contains a Chef Server, at least one Chef Workstation, and one or more Chef Nodes.
Installation of Chef environment
The installation steps of the Chef environment are generally: first install the Chef Server, then configure the Chef Workstation, and finally install the Chef Client on the client machine as needed and register it as a Chef Node. Chef Server and Chef Workstation can be configured on the same machine or can be configured separately. The Chef environment consists of Chef Server, Chef Workstation, and multiple Chef Nodes.
There are detailed instructions on Chef's installation steps on Chef's official website. The official website provides automatic download and installation of software using the network under the premise of an external
network environment. This article will provide a Chef environment installation process under an external network environment based on practice.
Media preparation
Since the server has no external network environment, the required software packages are downloaded to the local and prepared in advance.
Download the installation packages of Chef Server and Chef Client and the Chef Repository package from the official website of Chef (http://www.opscode.com/chef/install).
Chef Server installation package
Open http://www.opscode.com/chef/install, click the "Chef Server" page, select the appropriate operating system, version, etc., select the latest Chef Server version to download.
Chef Client installation package
Open http://www.opscode.com/chef/install, click the "Chef Client" page, select the appropriate operating system, version, etc., select the latest Chef Client version to download.
Download Chef Repository (chef-repo-master.zip) from https://github.com/opscode/chef-repo
Since the operating system of our server is 64-bit Redhat 6.4, we chose Enterprise Linux version 6 when downloading. The downloaded Chef Server and Chef Client installation packages are in RPM format. The following installation uses our environment as an example: The Chef Server installation package is chef-server-11.0.11-1.el6.x86_64.rpm, and the Chef Client installation package is chef-11.10.4-1.el6.x86_64.rpm.
Install Chef Server
Upload the Chef Server installation package to the Chef Server server. Log in to the Chef Server server and follow the steps below to configure Chef Server:
Install the Chef Server installation package:
$ rpm -ihv chef-server-11.0.11-1.el6.x86_64.rpm
Configure Chef Server 11.x: (Make sure the firewall is turned off)
$ sudo chef-server-ctl reconfigure
This command will create all the necessary components of Chef Server 11.x, including Erchef, RabbitMQ, PostgreSQL, etc.
Verify that the hostname of the server is a legal full name with a domain name.
You can add the hostname to the /etc/hosts file by running the following command:
$ echo -e "Chef_Server_IP `hostname` `hostname -s`" | sudo tee -a /etc/hosts
Verify that Chef Server 11.x is installed successfully.
There are two ways to verify: One is to run the "$ sudo chef-server-ctl test" command on the Chef Server. This command will run the chef-pedant test components and report that all components are working properly and installed correctly. The second is to open the Chef Server page directly in the browser: https://Chef_Server_IP. If the login interface appears, the Chef Server has been started correctly.
Install Chef Workstation
Upload the Chef Client installation package and Chef Repository to the Chef Workstation server. Log in to the Chef Workstation server and follow the steps below to configure Chef Workstation:
Install the Chef Client installation package:
# rpm -ihv chef-11.10.4-1.el6.x86_64.rpm
Verify that chef-client has been successfully installed:
# chef-client -v
Chef: 11.10.4
Identify a directory that is the Chef Repository, such as creating the /home/chef directory (this will be used as an example later). Unzip and copy the Chef Repository package (chef-repo-master.zip) to the /home/chef directory and rename it chef-repo.
Create a .chef directory under /home/chef.
Copy the admin.pem and chef-validator.pem files (located in /etc/chef-server) on the Chef Server to the Chef Repository's .chef directory.
Run the "knife configure --initial" command to configure Chef Workstation, the example is as follows:
Listing 1. Configure Chef Workstation
[root@chefwst .chef]# knife configure --initial
Where should I put the config file? (/root/.chef/knife.rb) /home/chef/chef-repo/.chef/knife.rb
Please enter the chef server URL: [https://localhost:443] https://Chef_Server_IP:443
Please enter a name for the new user: [root]
Please enter the existing admin name: [admin]
Please enter the location of the existing admin's private key: [/etc/chef-server/admin.pem]
/home/chef/chef-repo/.chef/admin.pem
Please enter the validation clientname: [chef-validator]
Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem]
/home/chef/chef-repo/.chef/chef-validator.pem
Please enter the path to a chef repository (or leave blank): /home/chef/chef-repo
Creating initial API user...
Please enter a password for the new user:
Created user[root]
Configuration file written to /home/chef/chef-repo/.chef/knife.rb
[root@chefwst .chef]# ls
admin.pem chef-validator.pem knife.rb root.pem
Verify that Chef Workstation is successfully configured:
A sign of a successful Workstation installation is that you can use the "Knife" command to communicate with the server. Run "knife client list" and "knife user list" to verify, as shown in Listing 2.
Listing 2. Verify Chef Workstation
[root@chefwst ~]# cd /home/chef/chef-repo
[root@chefwst chef-repo]# knife client list
chef-validator
chef-webui
[root@chefwst chef-repo]# knife user list
admin
root
Install Chef Client
Upload the Chef Client installation package to the target machine, log in to this machine, and configure the Chef Client according to the following steps:
Install the Chef Client installation package:
# rpm -ihv chef-11.10.4-1.el6.x86_64.rpm
Verify that chef-client has been successfully installed:
# chef-client -v
Chef: 11.10.4
Ensure that the Chef Client machine clock is synchronized with the Server clock (less than 15 minutes apart)
Register this machine with Chef Client installed as a Chef Node.
Run the bootstrap command on Chef Workstation:
# knife bootstrap Chef_Client_IP -x username -P password
The bootstrap command will check whether the client-side chef-client software is installed. If it is not installed, it will directly download the installation package from the
network to install and register; if it is already installed, it will directly register the client as a Chef Node. You can then execute the node list command on the workstation to see if there is an additional node:
# knife node list