×
Community Blog How to Install Chef Server Workstation on ECS

How to Install Chef Server Workstation on ECS

In this tutorial, we will be setting up a Chef Server Workstation on an Alibaba Cloud Elastic Compute Service (ECS) with Ubuntu 16.04 installed.

By Arslan Ud Din Shafiq, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud's incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Chef is a powerful platform for automation that helps you to automate how infrastructure is configured, deployed and managed across your network. It transforms infrastructure into code and allows you to manage and deploy resources across multiple nodes or servers. Before deploying code to any other environment, you create it and test it on your workstation. On your workstation, you can administer your infrastructure and write your cookbooks.

In this tutorial, I will show you how to install and set up a Chef Server Workstation on Alibaba Cloud Elastic Compute Service (ECS) with Ubuntu 16.04.

Prerequisites

  • You must have Alibaba Cloud Elastic Compute Service (ECS) activated and verified your valid payment method. If you are a new user, you can get $300 - $1200 worth in Alibaba Cloud credits for your new account. If you don't k about how to setup your ECS instance, you can refer to this tutorial or quick-start guide. Your ECS instance must have at least 8GB RAM and 4 Core processor.
  • A domain name registered from Alibaba Cloud. If you have already registered a domain from Alibaba Cloud or any other host, you can update its domain nameserver records.
  • Domain name must be pointed to your Alibaba Cloud ECS's IP address
  • Access to VNC console in your Alibaba Cloud or SSH client installed in your PC
  • Set up your server's hostname and create user with root privileges.

Setting Up Your Server

Before proceeding with installation of any kind of package, use the following command to update your Ubuntu system. To execute this command, remember to login from non-root user with sudo privileges.

# sudo apt update && sudo apt upgrade

Install Chef Server:

Chef server behaves as a hub of interaction between all nodes and workstations using Chef. When changes are made, these are uploaded to Chef server. After it, chef client accesses Chef server and helps in configuring each individual node. To install Chef server, follow the steps below.

You will need to download Chef server core. To download it, execute the following command.

# wget https://packages.chef.io/files/stable/chef-server/12.17.33/ubuntu/16.04/chef-server-core_12.17.33-1_amd64.deb  

You will need to de-package and install the .deb using the following command.

# sudo dpkg -i chef-server-core_12.17.33-1_amd64.deb

Remove the downloaded .deb file by executing the command below.

# sudo rm chef-server-core_12.17.33-1_amd64.deb

Execute the following command to start Chef server command line utility. It will start Chef server services.

# sudo chef-server-ctl reconfigure

You will see the following screen if your installation is successful.

1

Create a Chef User and Organization:

For linking nodes and workstations to your Chef server, you will need to create an admin user and organization with associated RSA private keys. To do so, follow the steps below.

Create a directory for storing the keys by executing the command below.

# mkdir .chef

To create user, you will use Chef command line utility. Execute the following command to create a user and remember to replace aareez with your desired username, 123@example.com with your desired email address and file name aareez.pem to your_username.pem, 654321Ab with your desired password, Arslan with your first name and Malik with your last name.

# sudo chef-server-ctl user-create aareez Arslan Shafiq 123@example.com '654321Ab' --filename ~/.chef/aareez.pem

Create an organization and add the user created in the step above in admins and billing admins security groups. To do so, execute the following command.

# sudo chef-server-ctl org-create org_name "org_full_name" --association_user aareez --filename ~/.chef/org_name.pem

Remember to replace org_name and org_full_name with your organization's name and aareez with your username.

Install Git:

Create a new Alibaba Cloud instance for Chef Workstation and update it.

# sudo apt update && sudo apt upgrade

Install Git with the command below.

# sudo apt-get install git

(Optional) Execute the commands below to configure Git by providing your name and valid email address so that commit messages may contain your correct information.

# git config --global user.name "Aareez"
# git config --global user.email "xyz@example.com"

Set Up Chef Workstations:

A Chef workstation allows you to create and configure your recipes, cookbooks, attributes and other changes made to your Chef configurations. To install and configure Chef Development Kit, follow the steps below.

You will need to download the Chef Development Kit by executing the command below.

# wget https://packages.chef.io/files/stable/chefdk/3.3.23/ubuntu/16.04/chefdk_3.3.23-1_amd64.deb

To install Chef Development Kit, execute the following command.

# sudo dpkg -i chefdk_3.3.23-1_amd64.deb

Remove the download .deb file by executing command below.

# sudo rm chefdk_3.3.23-1_amd64.deb

Generate chef-repo by executing command below.

# chef generate app chef-repo

Navigate to chef-repo

# cd chef-repo

Create .chef directory for storing aareez.pem, organization-validator.pem and knife.rb. Execute the following command.

# mkdir .chef

Add RSA Private Keys

The RSA keys generated while setting up and installing Chef server will be placed on the workstation. To do so, execute the following command.

# scp aareez@softpedia.xyz:~/.chef/*.pem ~/chef-repo/.chef/

Remember to replace aareez with your username and softpedia.xyz with your domain name or ECS IP address.

To confirm if the files have been copied successfully, you may execute the following command.

# ls ~/chef-repo/.chef

Set Up Version Control:

You will need to add .chef directory to .gitignore file. To do so, execute the command below.

# echo ".chef" > .gitignore

You will need to add and commit all existing files. For this, execute the command below.

For adding: # git add .

For committing: # git commit -m "initial commit"

You may check the status by executing command below.

# git status

Generate knife.rb:

To generate knife.rb file, follow the steps below.

Navigate to /chef-repo/.chef by executing the following command.

# cd ~/chef-repo/.chef

Create a file named knife.rb, a file will be opened in nano text editor by executing the command below.

# sudo nano knife.rb

Copy and paste the following text in opened file. Remember to replace aareez with your Chef server user name, org_name with your organization's name and chef_server_url value with your own domain or IP address.

current_dir = File.dirname(__FILE__)
log_level                :info
log_location             STDOUT
node_name                'aareez'
client_key               "aareez.pem"
validation_client_name   'org_name-validator'
validation_key           "org_name-validator.pem"
chef_server_url          'https://softpedia.xyz/organizations/org_name'
cache_type               'BasicFile'
cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
cookbook_path            ["#{current_dir}/../cookbooks"] 

Navigate back to /chef-repo and fetch by using commands below.

# cd ..
# knife ssl fetch

You can confirm if knife.rb has been set up correctly by executing the command below.

# knife client list

With a configured workstation and server, you may now bootstrap your first node.

Bootstrap a Node:

In bootstrapping a node, Chef client is installed. It validates the node and allows to read from Chef server and allows to make configurations. To bootstrap a node, follow the steps below.

Navigate to /chef-repo/.chef by executing the following command.

# cd ~/chef-repo/.chef

As a user with sudo privileges, execute the following command. Remember to change aareez with your node username, 654321Ab with password of user, softpedia.xyz with IP address or domain of Chef server and imaareez with name that you want to give to your node.

# knife bootstrap softpedia.xyz -x aareez -P 654321Ab --sudo --node-name imaareez

You can confirm if the node has been bootstrapped by executing the command below.

# knife client list

Set Up Firewalls and Ports

If you have activated firewalls, you will have to define a rule in Alibaba Cloud security group for your cloud server to add exception for port 80/tcp and 443/tcp. You can enable these ports while creating ECS instance, but in case if you have forgotten to unblock these ports, you can follow the procedure in this guide: https://www.alibabacloud.com/help/doc-detail/25471.htm

Congratulations! You have successfully installed and configured Chef Server and Chef Server Workstation on your ECS instance.

0 0 0
Share on

Alibaba Clouder

2,605 posts | 747 followers

You may also like

Comments