LoginSignup
6
7

More than 5 years have passed since last update.

Jenkins Master/Slave Cluster Memo

Last updated at Posted at 2014-10-18

個人的なメモ

永続化させたいデータ

  • master/var/lib/jenkins のみ
  • ※他は要らない

Gitによるバージョン管理

  • 管理対象はmasterの /var/lib/jenkins
  • 定期的に変更点を反映(backup)
    • ※config.xmlを修正して、git-commit/git-pushするのではない
    • ※backup方式だと運用が上手く回ってる(経験談)
    • 定期的にbackupジョブをmasterノードで実行
    • 手順は下記スクリプトを定義したシェルジョブ

定期コミット

#!/bin/bash
#
# requires:
#  bash, git
#
set -e
set -x

LANG=C
LC_ALL=C

cd; pwd

git status
git add --all
git commit -m "periodic commit: $(date +%Y%m%d.%H%M)" || :
git log -p -n 1

git push origin master
git push origin --tags

.gitignore

#
# The following ignores...
# Miscellaneous Jenkins litter
*.log
*.log.*
*.tmp
*.old
*.bak
*.jar
*.json

# Generated Jenkins state
/.owner
/secret.key
/queue.xml
/fingerprints/
/shelvedProjects/
/updates/

# Tools that Jenkins manages
/tools/

# Extracted plugins
plugins/

# monitoring plugin files
monitoring/

# Job state
builds/
workspace/
lastStable
lastSuccessful
nextBuildNumber
modules/

#
users/*
.bash_history
.s3cfg
/secret.key.not-so-secret
.lesshst
*.zip
.pulse-cookie
.pulse/*
.fontconfig
.ssh/authorized_keys
*.rpm
jobs/*/outOfOrderBuilds/*

masterノード内buildログ掃除

直近約2ヶ月分のログが保存されていれば良い

  • 下記スクリプトをmasterノード内で日次実行
  • 言うまでも無くジョブとして登録し、masterノードで実行させる
#!/bin/bash
#
# requires:
#  bash
#
set -e
set -o pipefail

LANG=C
LC_ALL=C

threshold=+$((30 * 2))

function disk_usage() {
  df -h
  df -k
}

disk_usage

for target_dir in /var/lib/jenkins/jobs/*/builds; do
  [[ -d "${target_dir}" ]] || continue
  echo ... ${target_dir}

  while read line; do
    [[ -f "${line}" ]] || continue
    rm ${line}
  done < <(find ${target_dir} -type f -mtime ${threshold})
done

disk_usage

masterノードで実行させるべきジョブ

polling系

  • polling系ジョブをslaveで動かしていると、ノード入れ替えた場合、前回分の差分が消滅するので、予期せぬビルドが実行される
  • masterではpollingする程度に留めておき、ビルド手順は定義しない
  • 実際のビルド手順は、ビルドジョブを別途作成し、slaveに任せる

master <-> slave 間通信はSSH

  • 理由の1つは、rbenvを動かすため
  • 「SSH経由でUnixマシンのスレーブエージェントを起動」ではなく、「マスターでコマンドを実行してスレーブ起動」を選択
    • ssh <slave> java -var /var/lib/jenkins/slave.jar

slave用2ndディスクは/var/lib/jenkins/workspace

  • ディスク使用サイズが多い場合は/var/lib/jenkins/workspaceを2ndディスクとして増設する
6
7
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
6
7