Nginxをインストール

  • ChefにてNginxをインストール
    • Nginxのcookbook
$ tree nginx/
nginx/
├── CHANGELOG.md
├── README.md
├── metadata.rb
├── recipes
│   ├── default.rb
│   └── jenkins.rb
└── templates
    └── default
        └── jenkins.conf.erb
$ cat jenkins.rb
package "nginx" do
  action :install
  not_if 'which nginx'
end

service "nginx" do
 action [:enable, :start]
 supports :status => true, :restart => true, :reload => true
end

template "/etc/nginx/conf.d/jenkins.conf" do
  source "jenkins.conf.erb"
  owner "root"
  group "root"
  mode 0644
  variables({
    :hostname => `/bin/hostname`.chomp
  })
end
※ (手動インストールも一応記載)
#rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
# yum -y install nginx 
# service nginx start
  • Nginxのリバースプロキシの設定
    • リバプロ先:10.0.1.46
    • フロントエンドポート番号:80
    • バックエンドポート番号:8080
    • confファイルは下記の通りに設定
$cat /etc/nginx/conf.d/jenkins.conf
upstream backend-jenkins {
    server 10.0.1.46:8080 max_fails=3 fail_timeout=10s;
}

server {
    listen 80;
    server_name <host_name>;
    keepalive_timeout  300;
    client_max_body_size 50M;
    proxy_read_timeout 600;
    proxy_pass_header Server;
    proxy_redirect                          off;
    proxy_set_header Host                   $host;
    proxy_set_header X-Real-IP              $remote_addr;
    proxy_set_header X-Forwarded-Host       $host;
    proxy_set_header X-Forwarded-Server     $host;
    proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;
    #server_tokens  off;

    location / {
    proxy_pass http://backend-jenkins;
    break;
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
       root   /usr/share/nginx/html;
    }
}

Jenkins

  • ChefにてJenkinsをインストール
    • Jenkinsのcookbook
$ tree jenkins/
jenkins/
├── CHANGELOG.md
├── README.md
├── attributes
│   └── default.rb
├── metadata.rb
├── recipes
│   └── default.rb
└── templates
    └── default
        └── jenkins.erb
$ cat attributes/default.rb
default['jdk']['path'] = '/usr/bin/java'
default['prefix']['path'] = 'jenkins'
$ cat templates/default/jenkins.erb
JENKINS_HOME="/var/lib/jenkins"
JENKINS_JAVA_CMD=""
JENKINS_USER="jenkins"
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true"
JENKINS_PORT="8080"
JENKINS_LISTEN_ADDRESS=""
JENKINS_HTTPS_PORT=""
JENKINS_HTTPS_KEYSTORE=""
JENKINS_HTTPS_KEYSTORE_PASSWORD=""
JENKINS_HTTPS_LISTEN_ADDRESS=""
JENKINS_AJP_PORT="8009"
JENKINS_AJP_LISTEN_ADDRESS=""
JENKINS_DEBUG_LEVEL="5"
JENKINS_ENABLE_ACCESS_LOG="no"
JENKINS_HANDLER_MAX="100"
JENKINS_HANDLER_IDLE="20"
JENKINS_JAVA_CMD="<%= @jdk_path %>"
JENKINS_ARGS="--prefix=/<%= @prefix %>"
$ cat recipes/default.rb
include_recipe "wget"
include_recipe "nginx::jenkins"

execute "add-jenkins-repo" do
  command <<-EOH
    wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
    rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
  EOH
  action :run
  not_if {::File.exists?("/etc/yum.repos.d/jenkins.repo")}
end

package "jenkins" do
  action :install
end

template "/etc/sysconfig/jenkins" do
  source "jenkins.erb"
  user "root"
  group "root"
  mode 0600
  variables(
    :jdk_path => node['jdk']['path'],
    :prefix => node['prefix']['path']
  )
end


service "jenkins" do
  action [:enable, :start]
end
  • アクセス方法
    • http://<jenkins_domain or IPaddress>/jenkins
    • 下記の画面が表示されればOK
nat-instance