m_shige1979のときどきITブログ

プログラムの勉強をしながら学習したことや経験したことをぼそぼそと書いていきます

Github(変なおっさんの顔でるので気をつけてね)

https://github.com/mshige1979

chef soloをインストールして確認

chef

インフラツールでセットアップの自動化が可能かもしれない…

環境

vagrant
  • CentOS64
初期設定
# iptables off
sudo chkconfig iptables off
sudo service iptables stop

# epel,remi
sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

# developer
sudo yum -y update
sudo yum -y groupinstall "Development Tools"

cd /etc/yum.repos.d/
sudo wget http://wing-repo.net/wing/6/EL6.wing.repo
sudo wget http://wing-repo.net/wing/extras/6/EL6.wing-extras.repo
sudo yum clean all
sudo yum -y install yum-priorities

# git
sudo yum -y remove git
sudo yum -y install git --enablerepo=wing

# ntp
sudo yum -y install ntp
sudo service ntpd start
sudo chkconfig ntpd on

# vim
sudo yum -y install vim
chef soloのインストール
curl -L https://www.opscode.com/chef/install.sh | sudo bash
確認
$ chef-solo -v
Chef: 11.12.8
$
knifeコマンドでクックブックを作成
$ sudo knife cookbook create sample1 -o /var/chef/cookbooks
WARNING: No knife configuration file found
** Creating cookbook sample1
** Creating README for cookbook: sample1
** Creating CHANGELOG for cookbook: sample1
** Creating metadata for cookbook: sample1
$
作成後のディレクトリ
$ tree /var/chef/cookbooks
/var/chef/cookbooks
└── sample1
    ├── CHANGELOG.md
    ├── README.md
    ├── attributes
    ├── definitions
    ├── files
    │   └── default
    ├── libraries
    ├── metadata.rb
    ├── providers
    ├── recipes
    │   └── default.rb
    ├── resources
    └── templates
        └── default

11 directories, 4 files
$
編集する
#
# Cookbook Name:: sample1
# Recipe:: default
#
# Copyright 2014, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
log "Hello, World!"

※sudo vim /var/chef/cookbooks/sample1/recipes/default.rb

Chef Soloを実行
[vagrant@localhost ~]$ sudo chef-solo -o sample1
[2014-07-07T13:47:00+00:00] WARN: *****************************************
[2014-07-07T13:47:00+00:00] WARN: Did not find config file: /etc/chef/solo.rb, using command line options.
[2014-07-07T13:47:00+00:00] WARN: *****************************************
[2014-07-07T13:47:00+00:00] WARN:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SSL validation of HTTPS requests is disabled. HTTPS connections are still
encrypted, but chef is not able to detect forged replies or man in the middle
attacks.

To fix this issue add an entry like this to your configuration file:

```
  # Verify all HTTPS connections (recommended)
  ssl_verify_mode :verify_peer

  # OR, Verify only connections to chef-server
  verify_api_cert true
```

To check your SSL configuration, or troubleshoot errors, you can use the
`knife ssl check` command like so:

```
  knife ssl check -c /etc/chef/solo.rb
```

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Starting Chef Client, version 11.12.8
[2014-07-07T13:47:07+00:00] WARN: Run List override has been provided.
[2014-07-07T13:47:07+00:00] WARN: Original Run List: []
[2014-07-07T13:47:07+00:00] WARN: Overridden Run List: [recipe[sample1]]
Compiling Cookbooks...
Converging 1 resources
Recipe: sample1::default
  * log[Hello, World!] action write


Running handlers:
Running handlers complete

Chef Client finished, 1/1 resources updated in 7.345644891 seconds
[vagrant@localhost ~]$

なんか出ているけどこれでいいのかな?

今回はここまで。
インフラのテストや設定ファイルの追加、ディストリビューションに合わせたインストールもできるかいろいろ検証する必要がありそう。vagrantの「Vagrantfile」にもいろいろ組み込めるみたいだし。毎回インストール方法を忘れてググるのはまずいのでこれで多少は簡略化できるといいかも

参考

Chef実践入門 ~コードによるインフラ構成の自動化 (WEB+DB PRESS plus)

Chef実践入門 ~コードによるインフラ構成の自動化 (WEB+DB PRESS plus)

所感

今回はchef soloの導入のみ。
気になることとしては本番環境などもでも簡単に対応できるかということ。
ネットワークのプロキシやファイアウォールなどで失敗することも考えられるので順分に調べておく。

毎回、インストールを実行してやったほうが安全だけどサーバ構成などはExcelやPDFなどで管理せずにコードで管理しておいたほうが
同じようなことをしたい場合に便利かもしれないので