On the topic of centralized configuration management systems, many articles have been written on Habré and, in particular, there are several good articles about Chef. However, the number of releases of Chef is growing, and I decided to refresh its description for Habr's readers a little. The article is intended both for beginners and for those who have already become acquainted with the system, but for some reason postponed the study and still want to continue. And it is worth continuing! Because, Chef is useful for administering multiple VPS, and for managing a large fleet of servers. Especially if you often have to configure servers from scratch, connect additional nodes to the cluster, etc.rpm -Uvh https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-server-11.0.10-1.el6.x86_64.rpm Next, you need to perform the initial configuration of the server: chef-server-ctl reconfigure This command will set all the necessary components to operate the Chef server (Erchef, RabbitMQ, nginx, PostgreSQL)
curl -L https://www.opscode.com/chef/install.sh | sudo bash Either download the deb or rpm package and install it manually. apt-get install git You also need to have Ruby versions => 1.9.1. For Ubuntu 12.04 put like this: apt-get install ruby1.9.1 Clone your Chef repository markup into your home directory: git clone git://github.com/opscode/chef-repo.git To be able to manage nodes by roles, etc., with the help of knife from your desk, you need two keys:~/chef-repo/.chef/ knife configure -i here, you will need to specify the path to private keys, as well as the path to the directory with kukbukami. The knife configuration file will also be located in the ~ / chef-repo / .chef / directory and will look something like this: cat /home/it/chef-repo/.chef/knife.rb log_level :info log_location STDOUT node_name 'it' client_key '/root/Chef/chef-repo/.chef/it.pem' validation_client_name 'chef-validator' validation_key '/home/it/chef-repo/.chef/chef-validator.pem' chef_server_url 'https://chef.example.ru:443' syntax_check_cache_path '/home/it/chef-repo/.chef/syntax_check_cache' cookbook_path [ '/home/it/chef-repo/cookbooks', '/home/it/chef-repo/example' ] # knife[:editor] = 'vim' # knife Check the performance of the knife: knife client list All commands must be executed from the directory or subdirectory of your local Chef repository. knife bootstrap test.example.ru In the general case, connecting to the host via ssh as root takes place, but if root access is restricted, then you need to specify a user with admin (sudo) rights: knife bootstrap test.example.ru --sudo -x admin -P Password Check that the server is in the list of nodes: knife node list test.example.ru cd ~/chef-repo/cookbooks and we will incline here the first cookbook, for example, for chef-client: git clone https://github.com/opscode-cookbooks/chef-client.git If we look at metadata.rb, we will see a list of dependencies for this cookbook: suggests 'bluepill' suggests 'daemontools' suggests 'runit' depends 'cron', '>= 1.2.0' depends 'logrotate', '>= 1.2.0' they too will have to be cloned themselves, and then to the server. knife cookbook upload bluepill daemontools runit cron logrotate chef-client Now we can add the chef-client recipe for our test node and change the client's request to the server: knife node edit test.example.ru The node configuration is presented in json-format. Let's write the node circulation period to the server and add the chef-client recipe to the run list: { "name": "test.example.ru", "chef_environment": "_default", "normal": { "chef_client": { "interval": "300" }, "tags": [ ] }, "run_list": [ "recipe[chef-client]" ] } knife cookbook create test Add a directive to the “default” recipe to install a list of packages that we will distribute to all of our servers: vim ~/chef-repo/cookbooks/test/recipes/default.rb %w{ntp mc htop iotop iftop atop vim-common wget curl rkhunter git awstats postfix}.each do |packages| package packages do action :install end end It remains only to upload the kookbook to the server and register it in the run-list (list of executable recipes) of the node, but it is better to make a role and include this recipe there. But bad luck, we still need the epel repository, at least. You can put the config file in the cookbook and add the copy of the config file to yum.repos.d in the recipe, or use the yum cookbook from opscode: git clone https://github.com/opscode-cookbooks/yum.git Also, let's download the yum-epel Kukbook (for some reason, in the last release we decided to highlight recipes with main turnips into separate Kukbooks): git clone https://github.com/opscode-cookbooks/yum-epel.git Upload books to the server: knife cookbook upload yum yum-epel Now we can include the yum-epel recipe in our test recipe: vim ~/chef-repo/cookbooks/test/recipes/default.rb include_recipe “yum-epel” %w{ntp mc htop iotop iftop atop vim nano wget curl rkhunter git awstats postfix}.each do |packages| package packages do action :install end end We can also register package exclusions for epel-repo in the attributes of our cookbook: vim ~/chef-repo/cookbooks/test/attributes/default.rb default['yum']['epel']['exclude'] = “test*” Upload the kookbook to the server and apply the recipe on the node: knife cookbook upload test knife node edit test.example.ru { "name": "test.example.ru", "chef_environment": "_default", "normal": { "chef_client": { "interval": "300" }, "tags": [ ] }, "run_list": [ "recipe[chef-client]", “recipe[test]” ] } knife ssh name:test.example.ru "chef-client" -P r00tPassworD Source: https://habr.com/ru/post/208858/
All Articles