Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

前提環境

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

インストール

chefの導入

gemでchefを入れる。

$ gem install chef knife-solo

Vagrantの導入

http://www.vagrantup.com/

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

仮想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

確認してみる

http://192.168.33.10:8080/

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした