LoginSignup
29

More than 5 years have passed since last update.

Vagrant + CoreOS + Compose でRedmineを立ち上げる

Last updated at Posted at 2015-05-15

まえがき

 しばらくDockerから遠ざかっていたので,リハビリを兼ねてRedmineを立ち上げてみました.作業ログの公開を主目的としています.なお,今回はMacOS X上で作業を行いました.
※作業ログは,ひと通り作業した後で再度コマンドを実行しています.ご注意ください.

今回使用したソフトウェアのバージョン

  1. vagrant 1.6.1(ちょっと古いです.最新バージョンは1.7.2)
  2. CoreOS alpha(681.0.0)
  3. docker 1.6.2(今回はdockerコマンド自体は使用しません)
  4. docker-compose 1.2.0

Vagrantのインストール

 VirtualBoxがインストールされているものとして話を進めます.まだインストールしていない人はインストールしてください.

 まずはVagrantのインストールです.DOWNLOAD VAGRANTから各自のOSに合うインストーラをダウンロードして,インストールしてください.

suda@sahara:~$ vagrant --version
Vagrant 1.6.1

CoreOSのインストールと起動

 CoreOSのインストールと起動方法はRunning CoreOS on Vagrantにまとまっています.以下のようにしてダウンロードしてください.

suda@sahara:~$ git clone https://github.com/coreos/coreos-vagrant.git
Cloning into 'coreos-vagrant'...
remote: Counting objects: 389, done.
remote: Total 389 (delta 0), reused 0 (delta 0), pack-reused 389
Receiving objects: 100% (389/389), 93.43 KiB | 0 bytes/s, done.
Resolving deltas: 100% (166/166), done.
Checking connectivity... done.

suda@sahara:~$ cd coreos-vagrant
suda@sahara:~/coreos-vagrant$ ls
CONTRIBUTING.md     MAINTAINERS     Vagrantfile
DCO         NOTICE          config.rb.sample
LICENSE         README.md       user-data.sample
suda@sahara:~$

 そのまま起動してもよいのですが,VirtualBoxのポートフォワードで躓くとトラブルシュートが面倒なので,Bridge設定にしてCoreOSをMacと同一ネットワーク上に配置します.121行目を以下のように変更しました.(※当初,DHCPの設定が付いていませんでしたが,付けたほうが安全そうなので付け加えました)

Vagrantfileの121行目
変更前  config.vm.network :private_network, ip: ip
変更後  config.vm.network :public_network, bridge: 'en0: Ethernet', type: "dhcp"

 続いてCoreOSを起動します.

suda@sahara:~/coreos-vagrant$ vagrant up
Bringing machine 'core-01' up with 'virtualbox' provider...
==> core-01: Importing base box 'coreos-alpha'...
==> core-01: Matching MAC address for NAT networking...
==> core-01: Checking if box 'coreos-alpha' is up to date...
==> core-01: Setting the name of the VM: redmine_core-01_1431683222503_94338
==> core-01: Clearing any previously set network interfaces...
==> core-01: Preparing network interfaces based on configuration...
    core-01: Adapter 1: nat
    core-01: Adapter 2: bridged
==> core-01: Forwarding ports...
    core-01: 22 => 2222 (adapter 1)
==> core-01: Running 'pre-boot' VM customizations...
==> core-01: Booting VM...
==> core-01: Waiting for machine to boot. This may take a few minutes...
    core-01: SSH address: 127.0.0.1:2222
    core-01: SSH username: core
    core-01: SSH auth method: private key
    core-01: Warning: Connection timeout. Retrying...
==> core-01: Machine booted and ready!
==> core-01: Setting hostname...
==> core-01: Configuring and enabling network interfaces...
suda@sahara:~/coreos-vagrant$

CoreOS上にdocker-composeをインストールする

 正常にCoreOSが起動したら,vagrant sshコマンドでCoreOSにログインして作業します.まずはログインして,IPアドレスを確認しておきます.

suda@sahara:~/coreos-vagrant$ vagrant ssh
Last login: Fri May 15 09:50:39 2015 from 10.0.2.2
CoreOS alpha (681.0.0)
core@core-01 ~ $ ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::a00:27ff:fe0d:b324  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:0d:b3:24  txqueuelen 1000  (Ethernet)
        RX packets 361  bytes 39531 (38.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 254  bytes 34560 (33.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.16.11.162  netmask 255.255.255.0  broadcast 172.16.11.255
        inet6 fe80::a00:27ff:fe6b:104c  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:6b:10:4c  txqueuelen 1000  (Ethernet)
        RX packets 1317  bytes 130373 (127.3 KiB)
        RX errors 0  dropped 1  overruns 0  frame 0
        TX packets 43  bytes 3702 (3.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 184  bytes 15024 (14.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 184  bytes 15024 (14.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
core@core-01 ~ $

 Vagrantの仕様(?)のため,NATネットワークとBridgeネットワークが共存しているようです.ちょっと気持ち悪いですが,このまま使います.ちなみに,10.0.2.0/24がNATネットワークで,172.16.11.162/24がBridgeネットワークです.

 念のため,CoreOSにインストールされているdockerコマンドのバージョンも調べておきます.ただし,今回はdockerコマンド自体は使用しません.

core@core-01 ~ $ docker --version
Docker version 1.6.2, build 7c8fca2-dirty
core@core-01 ~ $

docker-composeのインストール

 続いて,docker-compose(旧名fig)をインストールします.とりあえず,docker-compose1.2.0のリリースノートを参考に作業を進めます.
 ドキュメントに従うと/usr/local/binにファイルを作ろうとするのですが,Read-only file systemと言われてしまうので,ホームディレクトリに作ることにします.

core@core-01 ~ $ curl -L https://github.com/docker/compose/releases/download/1.2.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   405    0   405    0     0    481      0 --:--:-- --:--:-- --:--:--   487
100 5140k  100 5140k    0     0  1076k      0  0:00:04  0:00:04 --:--:-- 1457k
core@core-01 ~ $ chmod +x docker-compose
core@core-01 ~ $ ./docker-compose --version
docker-compose 1.2.0
core@core-01 ~ $

Redmineのインストール

 ここまで来たら,もう一息です.CentOS上にRedmineサーバ(sameersbn/redmine)をDockerコンテナとして立ち上げるを参考にして,docker-composeを使って一気にRedmineをインストールします.
 参考URLではユーザ名に「10001」を使用していましたが,省力化のためユーザ名はCoreOSの標準ユーザである「core」を使用します.また,CoreOS自体をBridgeネットワーク上で動かしているため,80番ポートをそのまま使います.複数のサービスを動かしたい場合はnginxなどでreverse-proxyを構成してください.
 docker-compose.ymlを以下に示します.

docker-compose.yml
postgresql:
  image: sameersbn/postgresql:9.4
  volumes:
    - /home/core/postgresql/data:/var/lib/postgresql
  environment:
    - DB_USER=redmine
    - DB_PASS=admin123
    - DB_NAME=redmin
memcached:
  image: sameersbn/memcached:latest
redmine:
  image: sameersbn/redmine:2.6.3
  links:
    - postgresql:postgresql
    - memcached:memcached
  volumes:
    - /var/run/docker.sock:/run/docker.sock
    - /usr/bin/docker:/bin/docker
    - /home/core/redmine/data:/home/redmine/data
  environment:
    - DB_USER=redmine
    - DB_PASS=admin123
    - DB_NAME=redmine
    - SMTP_HOST=smtp_server_fqdn
    - SMTP_PORT=25
  ports:
    - "80:80"

 それでは起動します.docker-compose upとするとフロントエンドで,docker-compose up -dとするとバックエンドで動作します.ここではバックエンドで起動してみましょう.なお,環境によりますが,初回起動時には数分から十数分ほど時間がかかります.

core@core-01 ~ $ ls
docker-compose  docker-compose.yml
core@core-01 ~ $ ./docker-compose up -d
Creating core_postgresql_1...
Pulling image sameersbn/postgresql:9.4...
Pulling repository sameersbn/postgresql
271ad7e099d3: Download complete
511136ea3c5a: Download complete
53f858aaaf03: Download complete
837339b91538: Download complete
615c102e2290: Download complete
b39b81afc8ca: Download complete
a9d82619e13b: Download complete
6ee48d1a59b6: Download complete
6b83459b4b16: Download complete
4f1075294a52: Download complete
3bd68d1e969e: Download complete
1010cbf0da70: Download complete
832ad990b27e: Download complete
1a6f1a9b1e31: Download complete
6133c0131c6a: Download complete
cd6042d07c33: Download complete
Status: Downloaded newer image for sameersbn/postgresql:9.4
Creating core_memcached_1...
Pulling image sameersbn/memcached:latest...
Pulling repository sameersbn/memcached
067e4a8b2ec1: Download complete
e9e06b06e14c: Download complete
a82efea989f9: Download complete
37bea4ee0c81: Download complete
07f8e8c5e660: Download complete
e1df0e53c89b: Download complete
812b85bf499b: Download complete
335b236c1885: Download complete
57ad9a54d5a9: Download complete
283f2d8c0b7f: Download complete
c44deee98cc5: Download complete
3c86902dced7: Download complete
Status: Downloaded newer image for sameersbn/memcached:latest
Creating core_redmine_1...
Pulling image sameersbn/redmine:2.6.3...
Pulling repository sameersbn/redmine
a2139158731d: Download complete
511136ea3c5a: Download complete
f3c84ac3a053: Download complete
a1a958a24818: Download complete
9fec74352904: Download complete
d0955f21bf24: Download complete
349a1686d9c1: Download complete
d93164fa41f0: Download complete
88018276f2ee: Download complete
5fd7fa7e0797: Download complete
7aba4b262c51: Download complete
ea730374a101: Download complete
6ae89f096179: Download complete
949b5c392ca0: Download complete
72f9a550729a: Download complete
e67104ebf654: Download complete
5709bb07a685: Download complete
53bd46ef3a89: Download complete
e013d0d88dba: Download complete
6fe7eef27b83: Download complete
af8c81383cc7: Download complete
Status: Downloaded newer image for sameersbn/redmine:2.6.3
core@core-01 ~ $

 プロンプトが出たら起動完了です.後はWebブラウザからアクセスしてみましょう.以下のように表示されたら成功です.

スクリーンショット 2015-05-15 19.25.58.png

ログインをクリックして,ID: admin,パスワード: adminでログインできます.

あとがき

 このように,非常に簡単にインストールすることができます.後はGitBucketやJenkinsなどと連携させて,快適な開発ライフを満喫してください.

 手元のコンピュータで動かしたら,次はどこからでも閲覧したくなります.基本的にクラウド環境やVPSなどでも同じ手順でインストールできるので,チャレンジしてみてください.

REFERENCES

  1. DOWNLOAD VAGRANT
  2. Running CoreOS on Vagrant
  3. docker-compose1.2.0のリリースノート
  4. CentOS上にRedmineサーバ(sameersbn/redmine)をDockerコンテナとして立ち上げる

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
29