Hello. This is Komiya from the platform.
Chef is popular these days.
That's why I'm going to write an article that lets me ride this wave and try it according to the product environment.
I would like to get to Serverspec quickly, but this time I will only introduce the article and the recipe will be next time.
It's at the level of trying it out, so I have a feeling that it will be a recipe worth refactoring.
Now, the environment we are trying to convert to Chef this time is to migrate to a VPC. (The configuration is web2, db2, stg1, nat1.) ELB utilization. I feel that solo is enough. )
Since it seems possible to use VPC with Vagrant-AWS, I will use Knife-solo while using Vagrant for configuration management.
It is possible to save the OS state and roll it back by linking vagrant and sahara.
It seems that knife-solo may try to erase the ruby under /sbin and replace it, so make sure you don't use ruby in your application.
Since I will put vagrant, I will put a version higher than ruby 1.8.7 with rbenv.
(In the case of CentOS 5 series.) For 6 series and other distributions, please check separately with ruby -v)
In fact, if you put the Chef-Client under /opt/chef through the PATH as shown below, you may not have to worry about the ruby version.
[shell]# curl -L https://www.opscode.com/chef/install.sh | bash # export PATH=$PATH:/opt/chef/embedded/bin/ # vi ~/.bashrc PATH [/shell] gem seems to be an old way to put chef in the gem.
- Introduced Oracle VirtualBox first
The reason for including it is to launch and manage instances in Vagrant-aws.
[shell]cat /etc/redhat-release CentOS release 5.8 (Final) yum install libXmu libXt mesa-libGL qt qt-x11 SDL
wget http://download.virtualbox.org/virtualbox/4.2.12/VirtualBox-4.2-4.2.12\_84980\_el5-1.x86\_64.rpm rpm -ivh VirtualBox-4.2-4.2.12_84980_el5-1.x86_64.rpm[/shell]
- Introduce a newer version than ruby-1.8.7 (if necessary)
[shell]yum -y install zlib-devel readline-devel openssl-devel yum install ruby ruby-devel rdoc irb rubygems yum install git --enablerepo=rpmforge[/shell]
Installing RBENV
[shell]git clone git://github.com/sstephenson/rbenv.git ~/.rbenv[/shell]
The following two lines are added to set the path of rbenv
[shell]vi ~/.bashrc export PATH="$HOME/.rbenv/bin:$PATH" eval "$(rbenv init -)" source ~/.bashrc[/shell] Please match the PATH here for each environment (if you don't want to enter it with rbenv, go through /opt/chef/embedded/bin, etc.)
Installing ruby-build
[shell]git clone git://github.com/sstephenson/ruby-build.git cd ruby-build sudo ./install.sh Installed ruby-build at /usr/local
rbenv install -l rbenv install 1.9.2-p290[/shell]
Specify the default version
[shell]rbenv global 1.9.2-p290 rbenv rehash[/shell]
Version Check
[shell]ruby -v[/shell]
Gem Location
~/.rbenv/versions/version-number/lib/ruby/gems/version-number/gems
- Install vagrant (1.1 or higher) and plugins
I can't get it in the gem, so I download the package
[shell]wget http://files.vagrantup.com/packages/7e400d00a3c5a0fdf2809c8b5001a035415a607b/vagrant\_1.2.2\_x86\_64.rpm rpm -ivh vagrant_1.2.2_x86_64.rpm rpm -ql vagrant| grep bin
vagrant -v yum install -y rubygem-nokogiri yum install -y gcc ruby-devel libxml2 libxml2-devel libxslt libxslt-devel vagrant plugin install vagrant-aws vagrant plugin install sahara vagrant plugin install vagrant-vbguest[/shell]
I don't need an OS image, but I need a box, so add a dummy box
[shell]vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box vagrant box list[/shell] and create a configuration file in vagrant init, but write it separately
・Introduction of knife-solo
[shell]gem install bundler gem install knife-solo --pre gem install knife-solo_data_bag gem list chef-solo --version Chef: 11.4.4[/shell]
If you add a new knife-solo, describe the following (setting the temporary directory used by knife-solo)
[shell]mkdir -p ~/.chef vi ~/.chef/knife.rb knife[:solo_path] = '/root/chef-solo' cookbook_path ['/root/chef-repo/site-cookbooks', '/root/chef-repo/site-cookbooks'] data_ bag_path '/root/chef-repo/data_bags' encrypted_data_bag_secret '/etc/chef/encrypted_data_bag_secret'
mv ./*rpm /usr/local/src/[/shell]
Setting Ruby Environment Variables
[shell]vi /root/.bashrc export PATH="$HOME/.rbenv/bin:$PATH:/root/.rbenv/versions/1.9.2-p290/bin" eval "$(rbenv init -)" export EDITOR=vi
bash[/shell]
If you use the opscodeCommunity cookbook, create a git repository and commit it
Sign up on the following page
https://community.opscode.com/users
Get the new private key from below and save it
http://community.opscode.com/users/your\_userid/user\_key/new
[shell]vi /root/.chef/pkey.pem Attach the private key vi /root/.chef/knife.rb cookbook_path ['/root/chef-repo/site-cookbooks','/root/chef-repo/cookbooks'] client_key '/root/.chef/ pkey.pem'[/shell]
The OpsCodeCommunity cookbook can be retrieved with the knife command, but it must be repository-managed and committed in git
[shell]cd /root/chef-repo git init Reinitialized existing Git repository in /root/chef-repo/.git/ git config --global user.email "hoge@isao.co.jp" git config --global user.name "hoge hoge" git add . git commit -m 'first commit'[/shell] Now you can get the cookbook with knife (I will continue to get the recipe separately)
Reference:
How to create multiple instances with Vagrant 1.1 + vagrant-aws Detailed explanation of how to install, configure, and use VirtualBox virtualbox.orgVagrant 1.1 to EC2 with vagrant 1.1 using vagrant up Amazon How to set up a CentOS instance on EC2 I use vagrant plugins
To be continued. Next, I plan to write about the Vagrantfile and its configuration, such as recipes and roles.
Hello. This is Komiya from the platform.
Chef is popular these days.
That's why I'm going to write an article that lets me ride this wave and try it according to the product environment.
I want to get to Serverspec quickly, but this time I will only write an article about introduction and recipes next time.
It's at the level of trying it out, so I have a feeling that it will be a recipe worth refactoring.
Now, the environment we are trying to convert to Chef this time is to migrate to a VPC. (The configuration is web2, db2, stg1, nat1.) ELB utilization. I feel that solo is enough. )
Since it seems possible to use VPC with Vagrant-AWS, I will use Knife-solo while using Vagrant for configuration management.
It is possible to save the OS state and roll it back by linking vagrant and sahara.
It seems that knife-solo may try to erase the ruby under /sbin and replace it, so make sure you don't use ruby in your application.
Since I will put vagrant, I will put a version higher than ruby 1.8.7 with rbenv. (CentOS5 series)
Deploying Oracle VirtualBox first
The reason for including it is to launch and manage instances in Vagrant-aws.
[shell]cat /etc/redhat-release CentOS release 5.8 (Final) yum install libXmu libXt mesa-libGL qt qt-x11 SDL
wget http://download.virtualbox.org/virtualbox/4.2.12/VirtualBox-4.2-4.2.12\_84980\_el5-1.x86\_64.rpm rpm -ivh VirtualBox-4.2-4.2.12_84980_el5-1.x86_64.rpm[/shell]
Introduced newer version than ruby-1.8.7
[shell]yum install ruby ruby-devel rdoc irb rubygems yum install git --enablerepo=rpmforge[/shell]
Installing RBENV
[shell]git clone git://github.com/sstephenson/rbenv.git ~/.rbenv[/shell]
The following two lines are added to set the path of rbenv
[shell]vi ~/.bashrc export PATH="$HOME/.rbenv/bin:$PATH" eval "$(rbenv init -)" source ~/.bashrc[/shell]
Installing ruby-build
[shell]git clone git://github.com/sstephenson/ruby-build.git cd ruby-build sudo ./install.sh Installed ruby-build at /usr/local
rbenv install -l rbenv install 1.9.2-p290[/shell]
Specify the default version
[shell]rbenv global 1.9.2-p290 rbenv rehash[/shell]
Version Check
[shell]ruby -v[/shell]
Gem Location
~/.rbenv/versions/version-number/lib/ruby/gems/version-number/gems
- Install vagrant (1.1 or higher) and plugins
I can't get it in the gem, so I download the package
[shell]wget http://files.vagrantup.com/packages/64e360814c3ad960d810456add977fd4c7d47ce6/vagrant\_x86\_64.rpm rpm -ivh vagrant_1.2.2_x86_64.rpm rpm -ql vagrant|grep bin
vagrant -v yum install -y rubygem-nokogiri yum install -y gcc ruby-devel libxml2 libxml2-devel libxslt libxslt-devel vagrant plugin install vagrant-aws vagrant plugin install sahara vagrant plugin install vagrant-vbguest[/shell]
I don't need an OS image, but I need a box, so add a dummy box
[shell]vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box vagrant box list[/shell] and create a configuration file in vagrant init, but write it separately
・Introduction of knife-solo
[shell]gem install bundler gem install knife-solo --pre gem install knife-solo_data_bag gem list chef-solo --version Chef: 11.4.4[/shell] If you put a new knife-solo, describe the following ( Setting the temporary directory used by knife-solo)
[shell]mkdir -p ~/.chef vi ~/.chef/knife.rb knife[:solo_path] = '/tmp/chef-solo' cookbook_path ['/root/chef-repo/site-cookbooks', '/root/chef-repo/site-cookbooks']
mv ./*rpm /usr/local/src/[/shell]
Setting Ruby Environment Variables
[shell]vi /root/.bashrc export PATH="$HOME/.rbenv/bin:$PATH:/root/.rbenv/versions/1.9.2-p290/bin" eval "$(rbenv init -)"
bash[/shell]
Reference:
How to create multiple instances with Vagrant 1.1 + vagrant-aws Detailed explanation of how to install, configure, and use VirtualBox virtualbox.orgvagrant up EC2 with Vagrant 1.1How to Launch a CentOS Instance on Amazon EC2 with Vagrant 1.1 I use vagrant plugins
Click here for the rest of the series of articles↓
About the environment before writing recipes in Chef-Solo (Vagrantfile, role, node, data_bags) Writing recipes for existing procedures in Chef 1 (Default Settings) Writing recipes for existing procedures in Chef 2 (User Creation)Write recipes for existing procedures in Chef 3 (WEB server) Write recipes for existing procedures in Chef 4 (DB server) Write recipes for existing procedures in Chef 5 (munin, zabbix) Test recipes written in Chef (serverspec)