54
52

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vagrantとchefを使ってCentOS6.4にCI(Jenkins)サーバを構築

Last updated at Posted at 2014-04-09

前提環境

  • Mac(OS X Mountain Lion)
  • Ruby (2.1.1p76)
  • VirtualBox(4.3.6)

インストール

chefの導入

gemでchefを入れる。

$ gem install chef knife-solo

Vagrantの導入

上記公式サイトからインストール

仮想OS立ち上げまで

boxの登録とVagrantfileの作成

$ vagrant box add CentOS64 http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130427.box
$ mkdir JenkinsVag && cd JenkinsVag
$ vagrant init CentOS64

Vagrantfileのコメントアウトを外す

$ config.vm.network "private_network", ip: "192.168.33.10"

仮想マシンの立ち上げ

$ vagrant up

vagrantコマンド経由でsshログイン

$ vagrant ssh

※Vagrantコマンド効くディレクトリでないとアクセスできません。

仮想マシンのssh情報を.ssh/configに登録

$ vagrant ssh-config --host jenkins >> ~/.ssh/config
$ ssh jenkins

これで、どこのディレクトリでも仮想マシンにアクセスできます。

chefの準備

chefのリポジトリ作成

#JenkinsVagディレクトリ上でやりましたが、どこでも構わないです。
$ knife solo init chef-repo
$ tree chef-repo
chef-repo
├── cookbooks
├── data_bags
├── environments
├── nodes
├── roles
└── site-cookbooks

レシピの作成

$ cd chef-repo
$ knife cookbook create jenkins -o site-cookbooks
$ tree site-cookbooks
jenkins
├── CHANGELOG.md
├── README.md
├── attributes
├── definitions
├── files
│   └── default
├── libraries
├── metadata.rb
├── providers
├── recipes
│   └── default.rb
├── resources
└── templates
    └── default

レシピの中身を書いていく

chef-repo/jenkins/recipes/default.rb

package 'java-1.7.0-openjdk' do
  action :install
end

remote_file '/tmp/' + node['jenkins']['rpm'] do
  source node['jenkins']['rpm_url']
  owner "root"
  group "root"
  mode "0755"
  not_if "test -e " + '/tmp/' + node['jenkins']['rpm']
end

package "jenkins" do
  action :install
  source '/tmp/' + node['jenkins']['rpm']
  provider Chef::Provider::Package::Rpm
  not_if "rpm -q jenkins"
end

service "jenkins" do
  action [:enable, :start]
end

service 'iptables' do
    action [:disable, :stop]
end

Jenkinsの公式サイトから最新のURLを登録しておく

http://pkg.jenkins-ci.org/redhat/
上記公式サイトからURLをコピーしてくる。

chef-repo/jenkins/attributes/default.rb
default['jenkins']['rpm'] = "jenkins-1.558-1.1.noarch.rpm"
default['jenkins']['rpm_url'] = "http://pkg.jenkins-ci.org/redhat/jenkins-1.558-1.1.noarch.rpm"

レシピを仮想マシンに適用する

仮想マシンをchef対応にする

$ knife solo prepare jenkins

レシピ適用の実行

$ knife solo cook jenkins

確認してみる

Jenkinsおじさんと出会えたらOK

54
52
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
54
52

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?