LoginSignup
8
10

More than 5 years have passed since last update.

AWSでJenkinsを立ち上げる

Last updated at Posted at 2015-05-21

1. AWS EC2でインスタンスを立ち上げる

1-1. AWS -> EC2 -> インスタンス -> インスタンス作成

スクリーンショット 2015-05-19 11.59.45.png

1-2. AMIの選択

Amazon Linux AMIを選択
スクリーンショット 2015-05-19 12.03.33.png

1-3. インスタンスタイプの選択

t2.microだと色々辛いのでt2.smallかt2.mediumが良いかも。
今回は説明のため無料枠のt2.microを選択。
スクリーンショット 2015-05-20 11.12.18.png

1-4. インスタンスの設定

そのまま

1-5. ストレージの追加

デフォルトの8GBだとすぐストレージがいっぱいになってしまうので16GBとかに増やす。
スクリーンショット 2015-05-20 11.15.48.png

1-6. インスタンスのタグ付け

そのまま

1-7. セキュリティグループの設定

SSHとHTTPのポートを開け、jenkinsのデフォルトのポート番号8080を開ける
タイプ:カスタムTCPルール
プロトコル:TCP
ポート範囲:8080
送信元:任意の場所
スクリーンショット 2015-05-20 11.25.10.png

1-8. インスタンスを作成

作成後、ステータスチェックが完了するのを待つ!

2. 作成したインスタンスにjenkinsをインストールする

作成したインスタンスにsshでログイン

2-1. 基本的なコマンドのインストール

sudo yum update -y
sudo yum install -y git
sudo yum install -y emacs (※宗教的理由です)

2-2. nginxのインストール・設定・起動

nginxのインストール

sudo yum install -y nginx

設定
/etc/nginx/nginx.confに以下をコピペ

user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    keepalive_timeout  65;

    include /etc/nginx/conf.d/*.conf;

    index   index.html index.htm;

    server {
        listen       80;
        server_name  test-jenkins.co.jp;

        location / {
            proxy_pass http://localhost:8080;
        }

        # redirect server error pages to the static page /40x.html                        
        #                                                                                 
        error_page  404              /404.html;
        location = /40x.html {
        }

        # redirect server error pages to the static page /50x.html                        
        #                                                                                 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        }

    }
}

nginxの起動

sudo service nginx start

2-3. jenkinsのインストール・設定・起動

jenkinsのダウンロード・インストール

sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
sudo yum install -y jenkins

設定
/etc/sysconfig/jenkinsに以下をコピペ

## Path:        Development/Jenkins
## Description: Configuration for the Jenkins continuous build server
## Type:        string
## Default:     "/var/lib/jenkins"
## ServiceRestart: jenkins
#
# Directory where Jenkins store its configuration and working
# files (checkouts, build reports, artifacts, ...).
#
JENKINS_HOME="/var/lib/jenkins"

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Java executable to run Jenkins
# When left empty, we'll try to find the suitable Java.
#
JENKINS_JAVA_CMD=""

## Type:        string
## Default:     "jenkins"
## ServiceRestart: jenkins
#
# Unix user account that runs the Jenkins daemon
# Be careful when you change this, as you need to update
# permissions of $JENKINS_HOME and /var/log/jenkins.
#
JENKINS_USER="jenkins"

## Type:        string
## Default:     "-Djava.awt.headless=true"
## ServiceRestart: jenkins
#
# Options to pass to java when running Jenkins.
#
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -XX:MaxPermSize=512m -Xms512m -Xmx1024m"

## Type:        integer(0:65535)
## Default:     8080
## ServiceRestart: jenkins
#
# Port Jenkins is listening on.
# Set to -1 to disable
#
JENKINS_PORT="8080"

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# IP address Jenkins listens on for HTTP requests.
# Default is all interfaces (0.0.0.0).
#
JENKINS_LISTEN_ADDRESS=""

## Type:        integer(0:65535)
## Default:     ""
## ServiceRestart: jenkins
#
# HTTPS port Jenkins is listening on.
# Default is disabled.
#
JENKINS_HTTPS_PORT=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Path to the keystore in JKS format (as created by the JDK 'keytool').
# Default is disabled.
#
JENKINS_HTTPS_KEYSTORE=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Password to access the keystore defined in JENKINS_HTTPS_KEYSTORE.
# Default is disabled.
#
JENKINS_HTTPS_KEYSTORE_PASSWORD=""

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# IP address Jenkins listens on for HTTPS requests.
# Default is disabled.
#
JENKINS_HTTPS_LISTEN_ADDRESS=""

## Type:        integer(0:65535)
## Default:     8009
## ServiceRestart: jenkins
#
# Ajp13 Port Jenkins is listening on.
# Set to -1 to disable
#
JENKINS_AJP_PORT="8009"

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# IP address Jenkins listens on for Ajp13 requests.
# Default is all interfaces (0.0.0.0).
#
JENKINS_AJP_LISTEN_ADDRESS=""

## Type:        integer(1:9)
## Default:     5
## ServiceRestart: jenkins
#
# Debug level for logs -- the higher the value, the more verbose.
# 5 is INFO.
#
JENKINS_DEBUG_LEVEL="5"

## Type:        yesno
## Default:     no
## ServiceRestart: jenkins
#
# Whether to enable access logging or not.
#
JENKINS_ENABLE_ACCESS_LOG="no"

## Type:        integer
## Default:     100
## ServiceRestart: jenkins
#
# Maximum number of HTTP worker threads.
#
JENKINS_HANDLER_MAX="100"

## Type:        integer
## Default:     20
## ServiceRestart: jenkins
#
# Maximum number of idle HTTP worker threads.
#
JENKINS_HANDLER_IDLE="20"

## Type:        string
## Default:     ""
## ServiceRestart: jenkins
#
# Pass arbitrary arguments to Jenkins.
# Full option list: java -jar jenkins.war --help
#
JENKINS_ARGS="--prefix=/ --httpPort=${JENKINS_PORT} --ajp13Port=${JENKINS_AJP_PORT}"

設定の適応・jenkins起動

sudo chkconfig jenkins on
sudo service jenkins start

2-4. jenkins起動の確認

立ち上げたインスタンスのパブリックDNSのURLかパブリックIPに:8080をつけてjenkinsのトップページが表示されるか確認。(jenkins起動直後だと表示されないことがあるので、表示されなかったらしばらく待ってみる)
ローカルで名前解決してtest-jenkins.co.jp:8080でもアクセスできるか確認。

8
10
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
8
10