CentOS7に389DSをインストールしセットアップを行う

今日はCentOS7に389DSをインストールし、初回のセットアップまでを済ませてみます。
今回行う操作は基本的に全て、CUIで行います。

インストールの詳細は本家の手順を参照してください。
389 Directory Server - Install Guide

インストール

yumで一発です。
昔はEPELのリポジトリを追加しないといけなかったようですが、(2015年6月現在)baseパッケージは標準リポジトリから落ちてくるようになっています。

# yum install -y 389-ds-base

初期設定投入用infファイルを作成

インストールしただけではLDAPとして利用できませんので、初期設定を行います。

このときCLIツールインタラクティブに設定を入力していくこともできるのですが、入力ミスなどで手戻りが起こるのも面倒ですし、今回はサイレントモードで設定を投入したいと思います。

そのためにはまず、レスポンスファイルとしてinfファイルの作成が必要です。

# vim install.inf
[General]
FullMachineName=example.demiglacesource.net
SuiteSpotUserID=nobody
[slapd]
ServerPort=389
ServerIdentifier=example
Suffix=dc=example,dc=demiglacesource,dc=net
RootDN=cn=Directory Manager
RootDNPwd=password

ここで入力したパラメータの詳細と、その他に指定可能なパラメータの一覧は公式サイトを参照してください。

389 Directory Server - Install Guide

取り急ぎ動作確認を行う場合は FullMachineName の値のみ設定を変更しファイルを保存します。
FullMachineNameはサーバーのホスト名を表します。

ホスト名の確認

インストール対象のサーバーホスト名が、install.infFullMachineNameで指定した値と一致していることを確認してみます。
※ここで書く操作が必須なのかどうかは不明。でも合わせてるにこしたことはなさそう。

# hostname
example.demiglacesource.net

もしホスト名が異なっていた場合は、以下のコマンドでサーバーホスト名の変更が可能です。
CentOS7からはこちらの方法が一般的なようですね。(sysconfigとかを手でいじらんでよくなったのは素晴らしい)

# hostnamectl set-hostname example.demiglacesource.net

※2015/7/5追記 ホスト名を設定するだけでは setup-ds.pl の実行時に名前解決ができず、エラーになりました。その場合はhostsも編集してから以降の手順に進んでください。

389DSを起動

初期設定を行うため、389DSを起動しておきます。

# systemctl start dirsrv.target

初期設定投入

サイレントモードなので、コマンド一発です。
setup-ds.plは389DSのインストールを行うと利用できるようになっています。

# setup-ds.pl -s -f install.inf
Your new DS instance 'example' was successfully created.
Exiting . . .
Log file is '/tmp/setupRv_wSN.log'

無事に初期設定の投入が完了しました。

動作確認

install.infで指定した認証情報でldapsearchができることを確認してみましょう。

# ldapsearch -D "cn=Directory Manager" -w password -b dc=example,dc=demiglacesource,dc=net *
# extended LDIF
#
# LDAPv3
# base <dc=example,dc=demiglacesource,dc=net> with scope subtree
# filter: (objectclass=*)
# requesting: anaconda-ks.cfg go1.4.1.linux-amd64.tar.gz go1.4.1.src.tar.gz gocode install.inf monitoreo packer packer_0.7.5_linux_amd64.zip 
#

# example.demiglacesource.net
dn: dc=example,dc=demiglacesource,dc=net

# Directory Administrators, example.demiglacesource.net
dn: cn=Directory Administrators,dc=example,dc=demiglacesource,dc=net

[snip]

問題なさそうですね。

まとめ

今回の記事で、389DSの基本的なセットアップを行うことができるようになりました。
この他に、admin系のツールを利用する場合などは別途、EPELリポジトリを追加しインストールを行ってください。

次回は、389DSにldapsで通信するための設定をまとめてみます。

【Mac】Vagrant + VirtualBoxのデータ領域を外付けHDDに変更する

普段開発作業は社内の仮想環境に自宅からVPN経由でアクセスし行っているのですが、先日から社内へのVPN接続が不安定で・・・思い切って週末を利用し、ローカルにVagrantの環境を構築し直すことにしました。
(VagrantはこれまでMacbook Pro Retina(2014)のSSD容量を気にして、以前に使っていたMacbook Pro(2011)上で触っていました)

今回はその時の作業を備忘録としてメモに残します。

VirtualBoxをインストール

こちらは公式の手順に従ってインストールを行ってください。
Chapter 2. Installation details

VirtualBoxのデータ領域保存フォルダを作成

ここでいうデータ領域とは、VirtualBox仮想マシンフォルダを指しています。
HDDの部分は外付けHDDのドライブ名が入ります。

# mkdir /Voluems/HDD/VirtualBox

デフォルトの仮想マシンフォルダーを変更

VirtualBoxを起動し、[環境設定]→[一般]の順にメニューを表示します。
その中の[デフォルトの仮想マシンフォルダー]を、先ほど作成した外付けHDDのパスに変更します。

Vagrantをインストール

こちらも公式の手順に従ってインストールを行ってください。
Installing Vagrant - Vagrant Documentation

VAGRANT_HOMEを変更

Vagrantはデフォルトでユーザーのホームディレクトリ以下に .vagrant.d というフォルダが掘られ、そちらにboxファイルなどが保存されていきます。
今回はこちらのフォルダを変更してみましょう。

# mkdir /Voluems/HDD/Vagrant
# cp -r ~/.vagrant.d /Voluems/HDD/Vagrant
# vim ~/.bash_profile
export VAGRANT_HOME=/Volumes/HDD/Vagrant/.vagrant.d
export PATH=$VAGRANT_HOME:$PATH
# source ~/.bash_profile

boxファイルをダウンロード

ここまでの手順でVirtualBoxVagrantのデータ領域を外付けHDDに変更できました。
早速設定が正しく行われていることを確認するために、boxファイルのダウンロードを行ってみます。

# vagrant box add CentOS-7.1.1503-x86_64 https://github.com/holms/vagrant-centos7-box/releases/download/7.1.1503.001/CentOS-7.1.1503-x86_64-netboot.box
/opt/vagrant/bin/../embedded/gems/gems/vagrant-1.7.2/lib/vagrant/pre-rubygems.rb:31: warning: Insecure world writable dir /Volumes/HDD/Vagrant/.vagrant.d in PATH, mode 040777
/opt/vagrant/embedded/gems/gems/bundler-1.7.11/lib/bundler/runtime.rb:222: warning: Insecure world writable dir /Volumes/HDD/Vagrant/.vagrant.d in PATH, mode 040777
==> box: Adding box 'CentOS-7.1.1503-x86_64' (v0) for provider: 
    box: Downloading: https://github.com/holms/vagrant-centos7-box/releases/download/7.1.1503.001/CentOS-7.1.1503-x86_64-netboot.box
==> box: Box download is resuming from prior download progress
==> box: Successfully added box 'CentOS-7.1.1503-x86_64' (v0) for 'virtualbox'!

なにやら警告が表示されていますが、データ領域を確認してみましょう。

# ls -al /Volumes/HDD/Vagrant/.vagrant.d/boxes/
total 64
drwxrwxrwx  1 demiglacesource  staff  32768  6 28 23:39 CentOS-7.1.1503-x86_64

無事に外付けHDDにダウンロードされているようです。
当然、元のディレクトリにはなにも保存されていません。

# ls -al ~/.vagrant.d/boxes/
total 0
drwxr-xr-x  2 demiglacesource  staff   68  6 28 23:26 .
drwxr-xr-x  9 demiglacesource  staff  306  6 28 23:26 ..

先ほど表示されていた警告は、外付けHDDの権限に問題があるため表示されているようです。
他人の権限で書き込み権限が付いていると、Rubyが警告を表示しているとか。(VagrantRubyで出来ています)

vagrant init

続いて仮想マシンを起動する準備のため、vagrant initを行います。

# mkdir centos7
# cd centos7
# vagrant init CentOS-7.1.1503-x86_64
/opt/vagrant/bin/../embedded/gems/gems/vagrant-1.7.2/lib/vagrant/pre-rubygems.rb:31: warning: Insecure world writable dir /Volumes/ELEMENTS2/Vagrant/.vagrant.d in PATH, mode 040777
/opt/vagrant/embedded/gems/gems/bundler-1.7.11/lib/bundler/runtime.rb:222: warning: Insecure world writable dir /Volumes/ELEMENTS2/Vagrant/.vagrant.d in PATH, mode 040777
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

ここでも先ほどの警告が表示されましたが、それ以外の問題は無さそうです。

vagrant up

では仮想マシンを起動します。

# vagrant up 
/opt/vagrant/bin/../embedded/gems/gems/vagrant-1.7.2/lib/vagrant/pre-rubygems.rb:31: warning: Insecure world writable dir /Volumes/HDD/Vagrant/.vagrant.d in PATH, mode 040777
/opt/vagrant/embedded/gems/gems/bundler-1.7.11/lib/bundler/runtime.rb:222: warning: Insecure world writable dir /Volumes/HDD/Vagrant/.vagrant.d in PATH, mode 040777
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'CentOS-7.1.1503-x86_64'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: centos7_default_1435503088775_59076
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
The private key to connect to this box via SSH has invalid permissions
set on it. The permissions of the private key should be set to 0600, otherwise SSH will
ignore the key. Vagrant tried to do this automatically for you but failed. Please set the
permissions on the following file to 0600 and then try running this command again:

/Volumes/HDD/Vagrant/.vagrant.d/insecure_private_key

最後に赤字でエラーが表示されてしまいました。

これは先ほどから出ているvagrantの警告とも同じ原因によるものなどですが、どうやら私の環境で外付けHDDに.vagrant.dフォルダをコピーした際に、 パーミッションが全て777になってしまっていることが原因のようです。

この状態ではsshコマンドによるログインは行えますが、vagrant sshによるログインが行えません。

insecure_private_keyのエラー回避

しばらく奮闘したのですが、外付けHDDの方のパーミッションを変更することができませんでした。
(sudoしてchmodでもダメ。フォーマットの問題?)

今回はいったん諦めて、ローカルに残っていたinsecure_private_keyのシンボリックリンクを外付けHDDに作成することにしました。

# rm /Volumes/HDD/Vagrant/.vagrant.d/insecure_private_key 
# ln -s ~/.vagrant.d/insecure_private_key /Volumes/HDD/Vagrant/.vagrant.d/

vagrant up (2回目)

あがれーーーー!!!

# vagrant up
/opt/vagrant/bin/../embedded/gems/gems/vagrant-1.7.2/lib/vagrant/pre-rubygems.rb:31: warning: Insecure world writable dir /Volumes/HDD/Vagrant/.vagrant.d in PATH, mode 040777
/opt/vagrant/embedded/gems/gems/bundler-1.7.11/lib/bundler/runtime.rb:222: warning: Insecure world writable dir /Volumes/HDD/Vagrant/.vagrant.d in PATH, mode 040777
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'CentOS-7.1.1503-x86_64'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: centos7_default_1435504676791_55032
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if its present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/demiglacesource/Vagrant/centos7

キタコレ

最後にVirtulBoxの仮想マシンフォルダも確認してみましょう。

# ls -l /Volumes/HDD/VirtualBox
total 64
drwxrwxrwx  1 demiglacesource  staff  32768  6 29 00:17 centos7_default_1435504676791_55032

問題無さそうですね!

まとめ

これでローカルのSSDを食い潰すことなく、快適な仮想環境ライフをエンジョイできそうです。
あとはVagrantの警告だけ、なんとかできないかなぁー・・・

OpenIDMにおけるREST APIのコンテキスト名は変更することができない

久しぶりの更新です。

さて表題の件についてですが、ソースを見てみるのが早いのでさっさとソースを見てみましょう。

FishEye: Diff - openidm/trunk/openidm-api-servlet/src/main/java/org/forgerock/openidm/servlet/internal/ServletComponent.java

@Activate
protected void activate(ComponentContext context) throws ServletException, NamespaceException {
    logger.debug("Try registering servlet at {}", SERVLET_ALIAS);
    servlet = new HttpServlet(connectionFactory, new IDMSecurityContextFactory(augmentSecurityScripts));
 
    servletRegistration.registerServlet(SERVLET_ALIAS, servlet, new Hashtable());
    logger.info("Registered servlet at {}", SERVLET_ALIAS);
}

部分的に抜粋すると、上記のソースの中でServletRegistration#registerServlet()している部分が該当のロジックです。 こちらの第一引数に SERVLET_ALIAS という定数を設定していますね。

ではこの SERVLET_ALIAS はどこで設定されているかというと、ServletComponent.javaの中で以下のように定義されています。

private static final String SERVLET_ALIAS = "/openidm";

完全に固定文字列です。
コンテキスト名を変更する場合は、ソースからの再ビルドが必要になりますね。

個人的なNode.jsの開発環境用Dockerfileを書いた

内容はほぼシェルです。

dockerfiles/develop-nodejs at master · demiglacesource/dockerfiles · GitHub

本番環境用のDockerfileであればsshはインストールしないと思うけど、今回は開発環境用途のためsshも使えるようにしています。
パスワードがシンプルなのですが、気にしないでください。
(鍵を使うようにしろとかもあるかもしれない)

※2015/6/29追記
openssh-serverの設定云々は削除しました。docker execで良いじゃないと言うのが理由です。

nvm installするところで少しハマったのが、以下の部分。

RUN source /root/.bashrc && nvm install v0.12.0

個人的にはコマンドをワンライナーで実行するのはあまり好きではないのだが、こうしないとnvmコマンドが無いと言われてしまいNode.jsのインストールに失敗してしまう。

恐らくDockerはDockerfileの1行1行でコンテナを作っているので、行単位で環境変数が違っているんだろうなぁと推測。
上記のような実行の仕方に落ち着きました。

あとMariaDBなんかも入れていますが、簡単なスクリプトを書く程度のことであれば使わないこともあるため自動起動などはしないようにしています。
そもそもDBを同じコンテナに入れるのはDockerの思想的にどうなの、とかはあると思いますが、そこはあくまで個人的な開発環境なので良いかなと。

しかしsshを有効にしてるんやったら、Ansibleで構築するようにしても良かったかもしれんなぁ・・・
AnsibleはPackerから使おうとした時に、ansible-localのChef Solo感に嫌気がさして挫折中。

またどっかで勉強します。

OpenIDM 3.0.0 で追加されたPass-Through Authenticationを簡単に試せるVagrantfileを作った

demiglacesource/vagrant-openidm-pta · GitHub

予めVirtualBoxVagrantの環境構築が必要です。

インスタンスの起動は以下の手順で行います。

# git clone https://github.com/demiglacesource/vagrant-openidm-pta.git && cd vagrant-openidm-pta
# vagrant up

※少し前のお話。Tumblrに載せてたけどこっちにも転載。Tumblrはそのうち閉じる予定なので。。。

Node.jsでCloudFormationテンプレートを書く

タイトルの通りですが、Node.jsでCloudFormationテンプレートを書いてみました。
完全にネタです。

以下のコードを実行すると、標準出力にjson文字列が出力されます。

var template = {};

template['AWSTemplateFormatVersion'] = '2010-09-09';
template['description'] = 'Apache Web Server Configuration stack';

template['Parameters'] = {
  'KeyName' : {
    'Description' : 'Name of an existing EC2 KeyPair to enable SSH access',
    'Type' : 'AWS::EC2::KeyPair::KeyName'
  },
  'SubnetIDs' : {
    'Description' : 'Subnet IDs',
    'Type' : 'List<AWS::EC2::Subnet::Id>'
  },
  'InstanceType' : {
    'Description' : 'EC2 instance type (e.g. m1.small)',
    'Type' : 'String',
    'Default' : 't2.small',
    'AllowedValues' : [ 't2.micro', 't2.small' ]
  },
  'SecurityGroupName' : {
    'Description' : 'Security group name',
    'Type' : 'String'
  }
};

template['Resources'] = {
  'EC2Instance' : {
    'Type' : 'AWS::EC2::Instance',
    'Metadata' : {
      'AWS::CloudFormation::Init' : {
        'config' : {
          'packages' : {
            'yum' : {
              "git" : []
            }
          }
        }
      }
    },
    'Properties' : {
      'InstanceType' : { 'Ref' : 'InstanceType' },
      'ImageId' : 'ami-xxxxxxxx',
      'SubnetId' : { 'Ref' : 'SubnetIDs' },
      'SecurityGroups' : { 'Ref' : 'SecurityGroupName' },
      'Tags' : {
        'Key' : 'Name',
        'Value' : 'xxxxx'
      },
      'UserData' : { "Fn::Base64" : { "Fn::Join" : ["", [
        '#!/bin/bash\n',
        'yum update -y'
      ] ] } }
    }
  }
};

console.log(JSON.stringify(template, null, '    '));

はい、ほとんどjsonですね。

何が嬉しいのか

  • シンタックスエラーを事前に検知できる
  • 実験的に実行したくない部分を一時的にコメントアウトできる
  • 部品ごとに分割すれば再利用可能になる
  • コーディングしている気分になれてモチベーションが上がる

このようなアプローチの他にも各言語用に様々なラッパーライブラリがあるようですが、個人的にはこのレベルで必要十分かなーと思っています。

ネタとか言いながら個人的には本気だったり・・・。


さて最後になりましたが、この度旧ブログ(akiiiiiiiioの日記)から移転してまいりました!
(今日は主にこれを言いたかった)

今後とも宜しくお願いします!