2016年2月23日火曜日

CentOS7でOpenStackを構築する

このエントリーをはてなブックマークに追加
Fedora23でやろうとしたんだけど、今後、仕事でサーバ構築にFedoraを使うかというと微妙すぎた(FedoraはあくまでRedHatへのフィードバックディストリビューションの位置付け)ので、CentOS7をVMWareFusionでVM(メモリ4GB、HDD150GB)を用意して、これにRDOを使ってOpenStackをインストールすることにした。

構築の仕方はRDO QuickStartを見ながら。

RDOリポジトリの追加とアップデート

まずはパッケージのアップデートとRDOのリポジトリを追加しておく
$ yum -y install https://www.rdoproject.org/repos/rdo-release.rpm
読み込んだプラグイン:fastestmirror
rdo-release.rpm                                                                                  | 5.1 kB  00:00:00
/var/tmp/yum-root-jzdiyf/rdo-release.rpm を調べています: rdo-release-liberty-2.noarch
/var/tmp/yum-root-jzdiyf/rdo-release.rpm をインストール済みとして設定しています
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ rdo-release.noarch 0:liberty-2 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

========================================================================================================================
 Package                      アーキテクチャー        バージョン                    リポジトリー                   容量
========================================================================================================================
インストール中:
 rdo-release                  noarch                  liberty-2                     /rdo-release                  1.4 k

トランザクションの要約
========================================================================================================================
インストール  1 パッケージ

合計容量: 1.4 k
インストール容量: 1.4 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : rdo-release-liberty-2.noarch                                                            1/1
  検証中                  : rdo-release-liberty-2.noarch                                                            1/1

インストール:
  rdo-release.noarch 0:liberty-2

完了しました!

packstackコマンドをインストールする

$ yum -y install openstack-packstack

シングルノードでのOpenStack構築

$ packstack --allinone
Welcome to the Packstack setup utility

The installation log file is available at: /var/tmp/packstack/20160223-040412-NQg7pb/openstack-setup.log
Packstack changed given value  to required value /root/.ssh/id_rsa.pub

Installing:
Clean Up                                             [ DONE ]
Discovering ip protocol version                      [ DONE ]
Setting up ssh keys                                  [ DONE ]
Preparing servers                                    [ DONE ]
Pre installing Puppet and discovering hosts' details [ DONE ]
Adding pre install manifest entries                  [ DONE ]
Setting up CACERT                                    [ DONE ]
Adding AMQP manifest entries                         [ DONE ]
Adding MariaDB manifest entries                      [ DONE ]
Fixing Keystone LDAP config parameters to be undef if empty[ DONE ]
Adding Keystone manifest entries                     [ DONE ]
Adding Glance Keystone manifest entries              [ DONE ]
Adding Glance manifest entries                       [ DONE ]
Adding Cinder Keystone manifest entries              [ DONE ]
Checking if the Cinder server has a cinder-volumes vg[ DONE ]
Adding Cinder manifest entries                       [ DONE ]
Adding Nova API manifest entries                     [ DONE ]
Adding Nova Keystone manifest entries                [ DONE ]
Adding Nova Cert manifest entries                    [ DONE ]
Adding Nova Conductor manifest entries               [ DONE ]
Creating ssh keys for Nova migration                 [ DONE ]
Gathering ssh host keys for Nova migration           [ DONE ]
Adding Nova Compute manifest entries                 [ DONE ]
Adding Nova Scheduler manifest entries               [ DONE ]
Adding Nova VNC Proxy manifest entries               [ DONE ]
Adding OpenStack Network-related Nova manifest entries[ DONE ]
Adding Nova Common manifest entries                  [ DONE ]
Adding Neutron VPNaaS Agent manifest entries         [ DONE ]
Adding Neutron FWaaS Agent manifest entries          [ DONE ]
Adding Neutron LBaaS Agent manifest entries          [ DONE ]
Adding Neutron API manifest entries                  [ DONE ]
Adding Neutron Keystone manifest entries             [ DONE ]
Adding Neutron L3 manifest entries                   [ DONE ]
Adding Neutron L2 Agent manifest entries             [ DONE ]
Adding Neutron DHCP Agent manifest entries           [ DONE ]
Adding Neutron Metering Agent manifest entries       [ DONE ]
Adding Neutron Metadata Agent manifest entries       [ DONE ]
Adding Neutron SR-IOV Switch Agent manifest entries  [ DONE ]
Checking if NetworkManager is enabled and running    [ DONE ]
Adding OpenStack Client manifest entries             [ DONE ]
Adding Horizon manifest entries                      [ DONE ]
Adding Swift Keystone manifest entries               [ DONE ]
Adding Swift builder manifest entries                [ DONE ]
Adding Swift proxy manifest entries                  [ DONE ]
Adding Swift storage manifest entries                [ DONE ]
Adding Swift common manifest entries                 [ DONE ]
Adding Provisioning Demo manifest entries            [ DONE ]
Adding Provisioning Demo bridge manifest entries     [ DONE ]
Adding Provisioning Glance manifest entries          [ DONE ]
Adding MongoDB manifest entries                      [ DONE ]
Adding Redis manifest entries                        [ DONE ]
Adding Ceilometer manifest entries                   [ DONE ]
Adding Ceilometer Keystone manifest entries          [ DONE ]
Adding Nagios server manifest entries                [ DONE ]
Adding Nagios host manifest entries                  [ DONE ]
Adding post install manifest entries                 [ DONE ]
Copying Puppet modules and manifests                 [ DONE ]
Applying 172.16.33.181_prescript.pp
172.16.33.181_prescript.pp:                          [ DONE ]
Applying 172.16.33.181_amqp.pp
Applying 172.16.33.181_mariadb.pp
172.16.33.181_amqp.pp:                               [ DONE ]
172.16.33.181_mariadb.pp:                            [ DONE ]
Applying 172.16.33.181_keystone.pp
Applying 172.16.33.181_glance.pp
Applying 172.16.33.181_cinder.pp
172.16.33.181_keystone.pp:                           [ DONE ]
172.16.33.181_glance.pp:                             [ DONE ]
172.16.33.181_cinder.pp:                             [ DONE ]
Applying 172.16.33.181_api_nova.pp
172.16.33.181_api_nova.pp:                           [ DONE ]
Applying 172.16.33.181_nova.pp
172.16.33.181_nova.pp:                               [ DONE ]
Applying 172.16.33.181_neutron.pp
172.16.33.181_neutron.pp:                            [ DONE ]
Applying 172.16.33.181_osclient.pp
Applying 172.16.33.181_horizon.pp
172.16.33.181_osclient.pp:                           [ DONE ]
172.16.33.181_horizon.pp:                            [ DONE ]
Applying 172.16.33.181_ring_swift.pp
172.16.33.181_ring_swift.pp:                         [ DONE ]
Applying 172.16.33.181_swift.pp
Applying 172.16.33.181_provision_demo.pp
172.16.33.181_swift.pp:                              [ DONE ]
172.16.33.181_provision_demo.pp:                     [ DONE ]
Applying 172.16.33.181_provision_demo_bridge.pp
172.16.33.181_provision_demo_bridge.pp:              [ DONE ]
Applying 172.16.33.181_provision_glance
172.16.33.181_provision_glance:                      [ DONE ]
Applying 172.16.33.181_mongodb.pp
Applying 172.16.33.181_redis.pp
172.16.33.181_mongodb.pp:                            [ DONE ]
172.16.33.181_redis.pp:                              [ DONE ]
Applying 172.16.33.181_ceilometer.pp
172.16.33.181_ceilometer.pp:                         [ DONE ]
Applying 172.16.33.181_nagios.pp
Applying 172.16.33.181_nagios_nrpe.pp
172.16.33.181_nagios.pp:                             [ DONE ]
172.16.33.181_nagios_nrpe.pp:                        [ DONE ]
Applying 172.16.33.181_postscript.pp
172.16.33.181_postscript.pp:                         [ DONE ]
Applying Puppet manifests                            [ DONE ]
Finalizing                                           [ DONE ]

 **** Installation completed successfully ******

Additional information:
 * A new answerfile was created in: /root/packstack-answers-20160223-040413.txt
 * Time synchronization installation was skipped. Please note that unsynchronized time on server instances might be problem for some OpenStack components.
 * Warning: NetworkManager is active on 172.16.33.181. OpenStack networking currently does not work on systems that have the Network Manager service enabled.
 * File /root/keystonerc_admin has been created on OpenStack client host 172.16.33.181. To use the command line tools you need to source the file.
 * To access the OpenStack Dashboard browse to http://172.16.33.181/dashboard .
Please, find your login credentials stored in the keystonerc_admin in your home directory.
 * To use Nagios, browse to http://172.16.33.181/nagios username: nagiosadmin, password: ead818c11ae742b9
 * The installation log file is available at: /var/tmp/packstack/20160223-040412-NQg7pb/openstack-setup.log
 * The generated manifests are available at: /var/tmp/packstack/20160223-040412-NQg7pb/manifests
最後の方にこんなWarningが出てたけど、無事にdashboardにアクセスできた!
* Warning: NetworkManager is active on 172.16.33.181. OpenStack networking currently does not work on systems that have the Network Manager service enabled.
この画面でログインする時のID、PASSWORDは~/keystonerc_adminに残っているのでそのアカウントでログインする。
$ cat ~/keystonerc_admin
unset OS_SERVICE_TOKEN
export OS_USERNAME=admin
export OS_PASSWORD=ef6d2d3aa7d2474c
export OS_AUTH_URL=http://172.16.33.181:5000/v2.0
export PS1='[\u@\h \W(keystone_admin)]\$ '

export OS_TENANT_NAME=admin
export OS_REGION_NAME=RegionOne
ようやくログインできた。

2016年2月18日木曜日

中国語をpythonで形態素解析(PyNLPIR)する

このエントリーをはてなブックマークに追加
春節の折、去年あたりから中国から観光客の方が来られてるので、ここで中国語の形態素解析をしてみたいと思った。
中国語の形態素解析器はNLPIR / ICTCLASにあったのでこれを用いてみることにする。


できればこの辺の解析はpythonで実行したいのでPyNLPIRをpipでインストールする。
# pip install pynlpir
Collecting pynlpir
  Downloading PyNLPIR-0.4.2.tar.gz (13.1MB)
    100% |████████████████████████████████| 13.1MB 3.1kB/s
Installing collected packages: pynlpir
  Running setup.py install for pynlpir
Successfully installed pynlpir-0.4.2
インストールされて動くか試してみる。PyNLPIRのページを参考にした。

まずはpythonのデフォルトエンコーディングをUTF8にしておく。/usr/lib/python2.7/site-packages/sitecustomize.pyを作成する。
import sys
sys.setdefaultencoding('utf-8')
インタラクティブモードでpythonを起動しpynlpirを試す。文章はweiboから適当に引っ張ってきた。
>>> import pynlpir
>>> pynlpir.open()
>>> s = '大阪最后一夜 关西机场附近最高建筑俯瞰大阪湾'
>>> pynlpir.segment(s)
[(u'\u5927\u962a', u'noun'), (u'\u6700\u540e', u'noun of locality'), (u'\u4e00', u'numeral'), (u'\u591c', u'classifier'), (u' ', None), (u'\u5173\u897f', u'noun'), (u'\u673a\u573a', u'noun'), (u'\u9644\u8fd1', u'noun of locality'), (u'\u6700\u9ad8', u'adjective'), (u'\u5efa\u7b51', u'noun'), (u'\u4fef\u77b0', u'verb'), (u'\u5927\u962a', u'noun'), (u'\u6e7e', u'noun')]
漢字が読めない。。。リストをタプルに分解してencodeして表示させる。
>>> words = pynlpir.segment(s)
>>> for w in words:
...     if w[0] != ' ':
...             print '単語:' + w[0].encode('utf-8') + ', 品詞:' + w[1].encode('utf-8')
...
表示結果はこんな感じ。
単語:大阪, 品詞:noun
単語:最后, 品詞:noun of locality
単語:一, 品詞:numeral
単語:夜, 品詞:classifier
単語:关西, 品詞:noun
単語:机场, 品詞:noun
単語:附近, 品詞:noun of locality
単語:最高, 品詞:adjective
単語:建筑, 品詞:noun
単語:俯瞰, 品詞:verb
単語:大阪, 品詞:noun
単語:湾, 品詞:noun
noun:名詞
noun of locality:方位詞
classifier:分類辞
numeral:数詞
adjective:形容詞
verb:動詞

あってるんかなぁ。。。中国語全然分からんけど。。。まぁ、とっかかりにはなるかなと。

2016年2月17日水曜日

VMWareFusionで仮想マシンのHDDを拡張した時にしたこと

このエントリーをはてなブックマークに追加
VMWareFusionで作った仮想マシンのHDDを60GBから150GBへ拡張した。そのままでは仮想マシン側のFedora23では拡張されたことは認識されないので、HDD拡張を認識させるためにやったことをまとめておく。


まずはfdisk -lで認識されているディスク情報を確認する。

# fdisk -l
ディスク /dev/sda: 150 GiB, 161061273600 バイト, 314572800 セクタ
単位: セクタ (1 * 512 = 512 バイト)
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
ディスクラベルのタイプ: dos
ディスク識別子: 0x4c356fd6

デバイス   起動 開始位置 最後から セクタ サイズ Id タイプ
/dev/sda1  *        2048   1026047   1024000   500M 83 Linux
/dev/sda2        1026048 125829119 124803072  59.5G 8e Linux LVM


ディスク /dev/mapper/fedora-root: 38.7 GiB, 41490055168 バイト, 81035264 セクタ
単位: セクタ (1 * 512 = 512 バイト)
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト


ディスク /dev/mapper/fedora-swap: 2 GiB, 2147483648 バイト, 4194304 セクタ
単位: セクタ (1 * 512 = 512 バイト)
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト


ディスク /dev/mapper/fedora-home: 18.9 GiB, 20254294016 バイト, 39559168 セクタ
単位: セクタ (1 * 512 = 512 バイト)
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト

/dev/sda2を拡張させればいいと分かった。ここからはpartedで実施する。

# parted
GNU Parted 3.2
/dev/sda を使用
GNU Parted へようこそ! コマンド一覧を見るには 'help' と入力してください。

素直にhelpを実行する
(parted) help
  align-check TYPE N            パーティション N のアライメント(TYPE: min|opt)をチェックする
  help [コマンド]               ヘルプ表示。コマンド指定でそのヘルプを表示
  mklabel,mktable ラベルの種類  新しいラベル(パーティションテーブル)を作る
  mkpart パーティションの種類 [ファイルシステムの種類] 開始 終了
                    パーティションを作る
  name NUMBER 名前              パーティションに名前をつける
  print [devices|free|list,all|NUMBER]
                     パーティションテーブルや、利用可能なデバイス、空き領域、
                     見つかった全てのパーティション、あるいは特定のパーティションについて表示する
  quit                          プログラムを終了する
  rescue 開始 終了              開始、終了で指定した範囲付近にあるパーティションを復活させる
  resizepart NUMBER END         パーティション NUMBER を END にリサイズする
  rm NUMBER                     パーティションを削除する
  select デバイス               操作するデバイスを選択
  disk_set FLAG STATE           選択したデバイスの FLAG を変更
  disk_toggle [FLAG]            選択したデバイスの FLAG の状態をトグル
  set NUMBER フラグ 状態        ファイルシステムのフラグと状態を設定する
  toggle [NUMBER [FLAG]]        パーティションのフラグの状態を反転する
  unit UNIT                     デフォルトの単位を UNIT にする
  version                       GNU Parted のバージョンと著作権情報を表示

念のためもう1回ディスク情報を確認する。
(parted) print all
モデル: VMware, VMware Virtual S (scsi)
ディスク /dev/sda: 161GB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: msdos
ディスクフラグ:

番号  開始    終了    サイズ  タイプ   ファイルシステム  フラグ
 1    1049kB  525MB   524MB   primary  ext4              boot
 2    525MB   64.4GB  63.9GB  primary                    lvm

パーティション番号の2を変更したいのでresizepart [partition number]を利用する。
(parted) resizepart 2
終了?  [64.4GB]? 150GB
(parted) p
モデル: VMware, VMware Virtual S (scsi)
ディスク /dev/sda: 161GB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: msdos
ディスクフラグ:

番号  開始    終了   サイズ  タイプ   ファイルシステム  フラグ
 1    1049kB  525MB  524MB   primary  ext4              boot
 2    525MB   151GB  150GB   primary                    lvm

これでパーティションが変更された。次に物理ボリュームを変更する。
現在の情報を確認する。
# pvscan
  PV /dev/sda2   VG fedora   lvm2 [59.51 GiB / 4.00 MiB free]
  Total: 1 [59.51 GiB] / in use: 1 [59.51 GiB] / in no VG: 0 [0   ]
物理ボリュームを変更する。
# pvresize /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized
変更されたか確認する。
# pvscan
  PV /dev/sda2   VG fedora   lvm2 [149.45 GiB / 89.95 GiB free]
  Total: 1 [149.45 GiB] / in use: 1 [149.45 GiB] / in no VG: 0 [0   ]

次は論理パーティションを変更する
# lvextend -L +90G /dev/mapper/fedora-root
  Insufficient free space: 23040 extents needed, but only 23026 available

そのまま拡張したサイズを指定しても1GB=1024KBの関係で拡張できないので少し小さくする。

# lvextend -L +89G /dev/mapper/fedora-root
  Size of logical volume fedora/root changed from 38.64 GiB (9892 extents) to 127.64 GiB (32676 extents).
  Logical volume root successfully resized.

ファイルシステムを最後に変更して完了。

# resize2fs /dev/mapper/fedora-root
resize2fs 1.42.13 (17-May-2015)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/fedora-root
Couldn't find valid filesystem superblock.

怒られた。

調べたらxfsのアイルシステムではresize2fsは使えないようなのでxfs_growfsを利用する。
# xfs_growfs /dev/mapper/fedora-root
meta-data=/dev/mapper/fedora-root isize=512    agcount=4, agsize=2532352 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1
data     =                       bsize=4096   blocks=10129408, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=4946, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 10129408 to 33460224

再起動してdf -hなどで確認しておく。


2016年2月16日火曜日

Ansibleを使ってFedora23にサーバを構築していく〜playbookでApacheのconfig編集

このエントリーをはてなブックマークに追加

まず今回はAnsibleでのconfファイルの編集手段の具体的な方法論の前に思いの丈からまとめておくことにする。

導入の目的を考える

先に行っておくがAnsibleで全てを自動で要件に合わせて編集するのは無理。この辺りのAnsible導入の焦点は2つあると思う。

  1. サーバ構築の手順をある程度標準化して自動化したい。環境依存、運用修正部分は直接編集
  2. サーバ構築(環境依存)〜運用修正までの手順をAnsibleのフォーマットに則ってInfrastructure as Codeしたい

この辺、きちんと目的をメンバー(プロジェクト関係者も含む)と共有しておかないと、「コマンド1つで誰でもすぐにサーバ構築できるようになったんじゃなかったの?」になっちゃうので要注意かなと思う。

#自分も含めて後でごっちゃになってきて、目的なんだったっけ?になりかねない。

2つに完全に分けるんじゃなくて導入する際のフェーズとして1→2を踏むというのはありかなと思うけど。

まずは導入の標準化を行おう


標準の/etc/httpd/conf/httpd.confを編集する。今回はだいたいいつも変えないといけないところを変えていこうかと思ったんだけど、でもAllowOverrideぐらいしかデフォルトでは変えない気がするので、そこだけ。

# DocumentRootも変えないし、変えるとしたらVirtualHost切る時だし。

あとは/etc/httpd/conf.d/welcome.confをリネームしておく。これらをInstallHttpd.ymlに書き加える。
---
- hosts: ChildServers
  gather_facts: no
  tasks:
    - name: install httpd by dnf
      dnf: name=httpd state=latest
      register: results
    - debug: var=results
    - name: Replace "AllowOverride None" in httpd.conf
      replace: dest=/etc/httpd/conf/httpd.conf regexp='AllowOverride None' replace='AllowOverride All' backup=yes
    - name: Replace "AllowOverride none" in httpd.conf
      replace: dest=/etc/httpd/conf/httpd.conf regexp='AllowOverride none' replace='AllowOverride All' backup=yes
    - name: rename welcome.conf
      shell: 'mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.org'
    - name: Auto Start httpd daemon
      service: name=httpd state=started enabled=yes
      register: results
    - debug: var=results

'None'と'none'が初めから混じっているのでめんどくさい。。。

でも結果としてはこれで実行したら成功した。無事にhttpd.confも書き換わってwelcome.confもリネームされていた。実際にこれぐらいであれば例となるhttpd.confを用意してcopyモジュールでコピーするのもありだと思う。
TASK: [Replace "AllowOverride None" in httpd.conf] ****************************
changed: [172.16.33.175]

TASK: [Replace "AllowOverride none" in httpd.conf] ****************************
changed: [172.16.33.175]

TASK: [rename welcome.conf] ***************************************************
changed: [172.16.33.175]

実際の運用を考えるとdnfでインストール後、テンプレートで初期起動までを作成。そのあとは環境に応じて編集および新規設定ファイルを作成した上で.confファイルはsvnやgitで管理し、メンテナンス後もリスタートをかけたトリガーでリポジトリにコミットする。そのあとは障害時にここからansibleでもってくるなど下ほうがいいのかもしれない。

2016年2月13日土曜日

Ansibleを使ってFedora23にサーバを構築していく〜playbookでApacheインストール

このエントリーをはてなブックマークに追加
少しコーナー化してきた感じもあるので、「Ansible」のラベルから纏めてみてください。


まずはApacheをインストールするためのPlaybookを作成する。InstallHttpd.ymlとかにしておく。
---
- hosts: ChildServers
  gather_facts: no
  tasks:
    - name: install httpd by dnf
      dnf: name=httpd state=latest
      register: results
    - debug: var=results
よし、実行。
# ansible-playbook InstallHttpd.yml --private-key=~/.ssh/ChildOneSV

PLAY [ChildServers] ***********************************************************

TASK: [install httpd by dnf] **************************************************
failed: [172.16.33.174] => {"failed": true}
msg: `python-dnf` is not installed, but it is required for the Ansible dnf module.

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
           to retry, use: --limit @/root/InstallHttpd.retry

172.16.33.174              : ok=0    changed=0    unreachable=0    failed=1
なるほど。勢いづいてdnfモジュールを使おうとしたけどもChildOneSVの方にpython-dnfがインストールされていないので怒られた。インストールして再チャレンジする。
# dnf -y install python-dnf
メタデータの期限切れの確認は、0:36:24 前の Sat Feb 13 01:30:53 2016 に実施しました。
依存性が解決されました。
========================================================================================================================
 Package                        アーキテクチャ        バージョン                           リポジトリ              容量
========================================================================================================================
インストール:
 pygpgme                        x86_64                0.3-13.fc23                          fedora                  77 k
 pyliblzma                      x86_64                0.5.3-14.fc23                        fedora                  54 k
 python-hawkey                  x86_64                0.6.2-3.fc23                         updates                 78 k
 python-iniparse                noarch                0.4-16.fc23                          fedora                  45 k
 python-libcomps                x86_64                0.1.7-1.fc23                         fedora                  47 k
 python-librepo                 x86_64                1.7.16-2.fc23                        fedora                  53 k
 python2-dnf                    noarch                1.1.6-2.fc23                         updates                449 k
 rpm-python                     x86_64                4.13.0-0.rc1.11.fc23                 updates                100 k

トランザクションの要約
========================================================================================================================
インストール  8 パッケージ

総ダウンロード容量: 902 k
インストール済み容量: 3.0 M
パッケージをダウンロードしています:
(1/8): pyliblzma-0.5.3-14.fc23.x86_64.rpm                                               145 kB/s |  54 kB     00:00
(2/8): python2-dnf-1.1.6-2.fc23.noarch.rpm                                              1.1 MB/s | 449 kB     00:00
(3/8): pygpgme-0.3-13.fc23.x86_64.rpm                                                   187 kB/s |  77 kB     00:00
(4/8): python-iniparse-0.4-16.fc23.noarch.rpm                                           474 kB/s |  45 kB     00:00
(5/8): python-libcomps-0.1.7-1.fc23.x86_64.rpm                                          543 kB/s |  47 kB     00:00
(6/8): python-librepo-1.7.16-2.fc23.x86_64.rpm                                          555 kB/s |  53 kB     00:00
(7/8): python-hawkey-0.6.2-3.fc23.x86_64.rpm                                            977 kB/s |  78 kB     00:00
(8/8): rpm-python-4.13.0-0.rc1.11.fc23.x86_64.rpm                                       1.2 MB/s | 100 kB     00:00
------------------------------------------------------------------------------------------------------------------------
合計                                                                                    399 kB/s | 902 kB     00:02
トランザクションの確認を実行中...
トランザクションの確認に成功しました。
トランザクションのテストを実行中...
トランザクションのテストに成功しました。
トランザクションを実行中...
  インストール    : rpm-python-4.13.0-0.rc1.11.fc23.x86_64                                                          1/8
  インストール    : python-hawkey-0.6.2-3.fc23.x86_64                                                               2/8
  インストール    : python-librepo-1.7.16-2.fc23.x86_64                                                             3/8
  インストール    : python-libcomps-0.1.7-1.fc23.x86_64                                                             4/8
  インストール    : python-iniparse-0.4-16.fc23.noarch                                                              5/8
  インストール    : pyliblzma-0.5.3-14.fc23.x86_64                                                                  6/8
  インストール    : pygpgme-0.3-13.fc23.x86_64                                                                      7/8
  インストール    : python2-dnf-1.1.6-2.fc23.noarch                                                                 8/8
  検証中          : python2-dnf-1.1.6-2.fc23.noarch                                                                 1/8
  検証中          : pygpgme-0.3-13.fc23.x86_64                                                                      2/8
  検証中          : pyliblzma-0.5.3-14.fc23.x86_64                                                                  3/8
  検証中          : python-iniparse-0.4-16.fc23.noarch                                                              4/8
  検証中          : python-libcomps-0.1.7-1.fc23.x86_64                                                             5/8
  検証中          : python-librepo-1.7.16-2.fc23.x86_64                                                             6/8
  検証中          : python-hawkey-0.6.2-3.fc23.x86_64                                                               7/8
  検証中          : rpm-python-4.13.0-0.rc1.11.fc23.x86_64                                                          8/8

インストール:
  pygpgme.x86_64 0.3-13.fc23            pyliblzma.x86_64 0.5.3-14.fc23            python-hawkey.x86_64 0.6.2-3.fc23
  python-iniparse.noarch 0.4-16.fc23    python-libcomps.x86_64 0.1.7-1.fc23       python-librepo.x86_64 1.7.16-2.fc23
  python2-dnf.noarch 1.1.6-2.fc23       rpm-python.x86_64 4.13.0-0.rc1.11.fc23

完了しました!

# ansible-playbook InstallHttpd.yml --private-key=~/.ssh/ChildOneSV

PLAY [ChildServers] ***********************************************************

TASK: [install httpd by dnf] **************************************************
changed: [172.16.33.174]

TASK: [debug var=results] *****************************************************
ok: [172.16.33.174] => {
    "var": {
        "results": {
            "changed": true,
            "invocation": {
                "module_args": "name=httpd state=latest",
                "module_complex_args": {},
                "module_name": "dnf"
            },
            "results": [
                "Installed: httpd-2.4.18-1.fc23.x86_64",
                "Installed: mailcap-2.1.45-1.fc23.noarch",
                "Installed: httpd-tools-2.4.18-1.fc23.x86_64",
                "Installed: httpd-filesystem-2.4.18-1.fc23.noarch",
                "Installed: apr-1.5.2-2.fc23.x86_64",
                "Installed: fedora-logos-httpd-22.0.0-2.fc23.noarch",
                "Installed: apr-util-1.5.4-2.fc23.x86_64"
            ]
        }
    }
}

PLAY RECAP ********************************************************************
172.16.33.174              : ok=2    changed=1    unreachable=0    failed=0

うまくいったみたいだ。インストール先のChildOneSVでhttpdが自動起動に登録されているかを見る。
# systemctl list-unit-files | grep httpd
httpd.service                               disabled
httpd.socket                                disabled
disabledになっている。これをenableにまで持って行ってみよう。先ほどのInstallHttpd.ymlに付け足す。
---
- hosts: ChildServers
  gather_facts: no
  tasks:
    - name: install httpd by dnf
      dnf: name=httpd state=latest
      register: results
    - debug: var=results
    - name: Auto Start httpd daemon
      service: name=httpd enabled=yes
      register: results
    - debug: var=results
実行あるのみ。
# ansible-playbook InstallHttpd.yml --private-key=~/.ssh/ChildOneSV

PLAY [ChildServers] ***********************************************************

TASK: [install httpd by dnf] **************************************************
changed: [172.16.33.174]

TASK: [debug var=results] *****************************************************
ok: [172.16.33.174] => {
    "var": {
        "results": {
            "changed": true,
            "invocation": {
                "module_args": "name=httpd state=latest",
                "module_complex_args": {},
                "module_name": "dnf"
            },
            "results": [
                "Installed: httpd-2.4.18-1.fc23.x86_64",
                "Installed: mailcap-2.1.45-1.fc23.noarch",
                "Installed: httpd-tools-2.4.18-1.fc23.x86_64",
                "Installed: httpd-filesystem-2.4.18-1.fc23.noarch",
                "Installed: apr-1.5.2-2.fc23.x86_64",
                "Installed: fedora-logos-httpd-22.0.0-2.fc23.noarch",
                "Installed: apr-util-1.5.4-2.fc23.x86_64"
            ]
        }
    }
}

TASK: [Auto Start httpd daemon] ***********************************************
changed: [172.16.33.174]

TASK: [debug var=results] *****************************************************
ok: [172.16.33.174] => {
    "var": {
        "results": {
            "changed": true,
            "enabled": true,
            "invocation": {
                "module_args": "name=httpd enabled=yes",
                "module_complex_args": {},
                "module_name": "service"
            },
            "name": "httpd"
        }
    }
}

PLAY RECAP ********************************************************************
172.16.33.174              : ok=4    changed=2    unreachable=0    failed=0
成功したっぽい。インストール先のChildOneSVの方で確認してみる。
# systemctl list-unit-files | grep httpd
httpd.service                               enabled
httpd.socket                                disabled
もちろんhttpdは動いていない。
# ps -aef | grep httpd
root       2162   1195  0 03:07 pts/0    00:00:00 grep --color=auto httpd
 
動かすところまでしとこう。InstallHttpd.ymlをちょっと編集。
---
- hosts: ChildServers
  gather_facts: no
  tasks:
    - name: install httpd by dnf
      dnf: name=httpd state=latest
      register: results
    - debug: var=results
    - name: Auto Start httpd daemon
      service: name=httpd state=started enabled=yes
      register: results
    - debug: var=results
# ansible-playbook InstallHttpd.yml --private-key=~/.ssh/ChildOneSV

PLAY [ChildServers] ***********************************************************

TASK: [install httpd by dnf] **************************************************
changed: [172.16.33.174]

TASK: [debug var=results] *****************************************************
ok: [172.16.33.174] => {
    "var": {
        "results": {
            "changed": true,
            "invocation": {
                "module_args": "name=httpd state=latest",
                "module_complex_args": {},
                "module_name": "dnf"
            },
            "results": [
                "Installed: httpd-2.4.18-1.fc23.x86_64",
                "Installed: mailcap-2.1.45-1.fc23.noarch",
                "Installed: httpd-tools-2.4.18-1.fc23.x86_64",
                "Installed: httpd-filesystem-2.4.18-1.fc23.noarch",
                "Installed: apr-1.5.2-2.fc23.x86_64",
                "Installed: fedora-logos-httpd-22.0.0-2.fc23.noarch",
                "Installed: apr-util-1.5.4-2.fc23.x86_64"
            ]
        }
    }
}

TASK: [Auto Start httpd daemon] ***********************************************
changed: [172.16.33.174]

TASK: [debug var=results] *****************************************************
ok: [172.16.33.174] => {
    "var": {
        "results": {
            "changed": true,
            "enabled": true,
            "invocation": {
                "module_args": "name=httpd state=started enabled=yes",
                "module_complex_args": {},
                "module_name": "service"
            },
            "name": "httpd",
            "state": "started"
        }
    }
}

PLAY RECAP ********************************************************************
172.16.33.174              : ok=4    changed=2    unreachable=0    failed=0
# ps -aef | grep httpd
root       2283      1  0 03:13 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     2285   2283  0 03:13 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     2286   2283  0 03:13 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     2290   2283  0 03:13 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     2292   2283  0 03:13 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     2294   2283  0 03:13 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
root       2297   1195  0 03:13 pts/0    00:00:00 grep --color=auto httpd
できたできた。次の回はconfigの生成(編集?)をやりたいと思います。

2016年2月12日金曜日

Ansibleを使ってFedora23にサーバを構築していく〜playbook作成

このエントリーをはてなブックマークに追加
これまでの経緯は下のリンク先を参照。


Ansibleを使ってFedora23にサーバを構築していく〜準備編(1)
Ansibleを使ってFedora23にサーバを構築していく〜準備編(2)

構成はこんな感じ。
AnsibleSV →(構成)→ ChildOneSV

ChildOneSVについてはselinuxを無効にしておく。そうでないとPlaybook実行時に怒られるので。

/etc/ansible/hosts(インベントリファイルという)を/etc/ansible/hosts.orgなどリネームし新しく下記の内容で構築先のサーバを指定し作成する。
[ChildServers]
172.16.33.173

~/AnsiblePlayBookみたいな適当なディレクトリを作って、その下にサンプルのplaybook(SamplePlaybook.yml)を作る。
playbookはYAML形式で作成するので、書き方というかお作法はこの辺が参考になった。ansible使いのためのYAML入門

まずデフォルトではansibleの接続にはrootでされるのだが、本当にそうなのかどうか確かめる簡単なplaybookを書いた。
---
- hosts: ChildServers
  tasks:
    - name: Who am I?
      shell: 'whoami'
実行してみる。sshのprivate keyをコマンドの引数に渡しているのがあまりスマートじゃない気がするけど。あと、デバッグ用に-vvvも足している。

# ansible-playbook SamplePlaybook_whoami.yml --private-key=~/.ssh/ChildOneSV -vvv
PLAY [ChildServers] ***********************************************************

GATHERING FACTS ***************************************************************
<172.16.33.174> ESTABLISH CONNECTION FOR USER: root
<172.16.33.174> REMOTE_MODULE setup
<172.16.33.174> EXEC ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o IdentityFile="/root/.ssh/ChildOneSV" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 172.16.33.174 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1455208440.15-102322756142433 && echo $HOME/.ansible/tmp/ansible-tmp-1455208440.15-102322756142433'
<172.16.33.174> PUT /tmp/tmpLs6ZDa TO /root/.ansible/tmp/ansible-tmp-1455208440.15-102322756142433/setup
<172.16.33.174> EXEC ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o IdentityFile="/root/.ssh/ChildOneSV" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 172.16.33.174 /bin/sh -c 'LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1455208440.15-102322756142433/setup; rm -rf /root/.ansible/tmp/ansible-tmp-1455208440.15-102322756142433/ >/dev/null 2>&1'
ok: [172.16.33.174]

TASK: [Who am I?] *************************************************************
<172.16.33.174> ESTABLISH CONNECTION FOR USER: root
<172.16.33.174> REMOTE_MODULE command whoami #USE_SHELL
<172.16.33.174> EXEC ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o IdentityFile="/root/.ssh/ChildOneSV" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 172.16.33.174 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1455208507.7-272410210390849 && echo $HOME/.ansible/tmp/ansible-tmp-1455208507.7-272410210390849'
<172.16.33.174> PUT /tmp/tmp7LbN5R TO /root/.ansible/tmp/ansible-tmp-1455208507.7-272410210390849/command
<172.16.33.174> EXEC ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o IdentityFile="/root/.ssh/ChildOneSV" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 172.16.33.174 /bin/sh -c 'LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1455208507.7-272410210390849/command; rm -rf /root/.ansible/tmp/ansible-tmp-1455208507.7-272410210390849/ >/dev/null 2>&1'
changed: [172.16.33.174] => {"changed": true, "cmd": "whoami", "delta": "0:00:00.003166", "end": "2016-02-12 01:35:08.740448", "rc": 0, "start": "2016-02-12 01:35:08.737282", "stderr": "", "stdout": "root", "warnings": []}

PLAY RECAP ********************************************************************
172.16.33.174              : ok=2    changed=1    unreachable=0    failed=0

最後の一行にちゃんと実行結果でrootと表示されているのがわかった。
changed: [172.16.33.174] => {"changed": true, "cmd": "whoami", "delta": "0:00:00.003166", "end": "2016-02-12 01:35:08.740448", "rc": 0, "start": "2016-02-12 01:35:08.737282", "stderr": "", "stdout": "root", "warnings": []}
しかし、やたら時間がかかるので、少し改良する。サーバ情報などを取得する"GATHERING FACTS"が邪魔なのでgather_facts: nを足す。ついでに-vvvもぬいた
---
- hosts: ChildServers
  gather_facts: no
  tasks:
    - name: Who am I?
      shell: 'whoami'

# ansible-playbook SamplePlaybook_whoami.yml --private-key=~/.ssh/ChildOneSV

PLAY [ChildServers] ***********************************************************

TASK: [Who am I?] *************************************************************
changed: [172.16.33.174]

PLAY RECAP ********************************************************************
172.16.33.174              : ok=1    changed=1    unreachable=0    failed=0

今度は結果が分からない。。。なので標準出力に出るように奮闘してみる。
---
- hosts: ChildServers
  gather_facts: no
  tasks:
    - name: Who am I?
      shell: 'whoami'
      register: result
    - debug: msg="{{result.stdout}}"]

registerresultという変数に結果を格納して、debugが実行結果をdumpするイメージ。debugを使う際にそのまま結果を出すのであればmsgパラメータに"{{result.stdout}}"として渡す。{{}}は変数としてresult.stdoutを出力してくれる。

これでrootで実行されているのは分かったので、dnf updateをしてみる。別にSamplePlaybook.ymlを作成する。
---
- hosts: ChildServers
  gather_facts: no
  tasks:
    - name: OS RPM Update by dnf
      shell: 'dnf -y update'
      register: result
    - debug: msg="{{result.stdout}}"

# ansible-playbook SamplePlaybook.yml --private-key=~/.ssh/ChildOneSV

PLAY [ChildServers] ***********************************************************

TASK: [OS RPM Update by dnf] **************************************************
changed: [172.16.33.174]

TASK: [debug msg="{{result.stdout}}"] *****************************************
ok: [172.16.33.174] => {
    "msg": "Last metadata expiration check performed 1:32:32 ago on Fri Feb 12 01:15:22 2016.\nDependencies resolved.\nNothing to do.\nComplete!"
}

PLAY RECAP ********************************************************************
172.16.33.174              : ok=2    changed=1    unreachable=0    failed=0

なにもすること無かったみたい。。。次は具体的に何かをインストールして環境の変更までやってみたいと思う。

2016年2月10日水曜日

Ansibleを使ってFedora23にサーバを構築していく〜準備編(2)

このエントリーをはてなブックマークに追加
新しくもう一台VMを起動し2台のVM構成を作る。
AnsibleSV →(構成)→ ChildOneSV
両サーバ間はSSHの鍵認証を使ってログインした後通信を行うので、AnsibleSVからChildOneSVへSSHログインできる鍵を作っておく。ここの具体的な手順はぐぐったら腐るほどでてくるので省略。

AnsibleSVの構築はAnsibleを使ってFedora23にサーバを構築していく〜準備編を参照。ちなみに構成先のChildOneSVにもPythonをインストールしておく。

まずはMotherSVからChildOneSVへの疎通確認をしてみる。Ansibleで通信するためには相手先のアドレスを/etc/ansible/hostsに書いておく必要がある。-m でansibleのモジュール、--private-keyでChiledOneSVにログインするための秘密鍵を指定する。今回使うのはpingモジュール。
# ansible <ChildOneSV IPAddress> -m ping --private-key=~/.ssh/ChildOneSV
<ChildOneSV IPAddress> | success >> {
    "changed": false,
    "ping": "pong"
}
ChildOneSVでのコマンドをAnsible経由で実行してみる。-a は引数付きのコマンド実行。
# ansible 172.16.33.173 -a 'uname -a' --private-key=~/.ssh/ChildOneSV
172.16.33.173 | success | rc=0 >>
Linux ChildOneSV 4.3.5-300.fc23.x86_64 #1 SMP Mon Feb 1 03:18:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
これで通信は確認できたので、次は実際にPlaybookを作ってみたいと思う。

2016年2月9日火曜日

Ansibleを使ってFedora23にサーバを構築していく〜準備編(1)

このエントリーをはてなブックマークに追加
サーバの自動構築。なんという夢の響きだろうか。あのめんどくさい作業から解放されるためなんだったら何でもやろう。という事でAnsibleを使ってやってみることにした。Chefはなんかめんどくさそうなイメージが果てしなくあったので何となくAnsibleを選んだ。


今回はVMWare Fusionを使って試すことにした。まずは準備としてFedora23 Server EditionのMinimalインストールする。そしてすぐにシャットダウンし、この.vmwareファイルをオリジナルファイル(以下、OriginalVM)として保存。それをコピーしAnsible用のマシン(以下、AnsibleVM)として構築していく。

以降、操作するのは全てAnsibleVMの方なので注意すること。

ターミナルの方がやりやすいのでiTerm2でAnsibleVMへ接続し、iTermでログの取得(Shell→Log→Start)をしておく。この方が後々役にたつはず。

$ ssh root@xxx.xxx.xxx.xxx
dnfでできるだけ早いミラーサイトからパッケージを取ってくるために/etc/dnf/dnf.confに追記。
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=true
fastestmirror=true
ここでdnfでアップデート。
# dnf update
メタデータの期限切れの確認は、0:51:03 前の Mon Feb  8 03:24:13 2016 に実施しました。
依存性が解決されました。
========================================================================================================================
 パッケージ                            アーキテクチャ   バージョン                              リポジトリ         容量
========================================================================================================================
インストール中:
 kernel                                x86_64           4.3.4-300.fc23                          updates            52 k
 kernel-core                           x86_64           4.3.4-300.fc23                          updates            20 M
 kernel-modules                        x86_64           4.3.4-300.fc23                          updates            18 M
 libsecret                             x86_64           0.18.3-1.fc23                           fedora            156 k
アップグレード中:
 GeoIP-GeoLite-data                    noarch           2015.12-1.fc23                          updates           367 k
 NetworkManager                        x86_64           1:1.0.10-2.fc23                         updates           1.9 M
 NetworkManager-libnm                  x86_64           1:1.0.10-2.fc23                         updates           481 k
 audit                                 x86_64           2.4.5-1.fc23                            updates           243 k
 audit-libs                            x86_64           2.4.5-1.fc23                            updates            95 k
 avahi-autoipd                         x86_64           0.6.32-0.4.rc.fc23                      updates            31 k
 avahi-libs                            x86_64           0.6.32-0.4.rc.fc23                      updates            62 k
 bash                                  x86_64           4.3.42-3.fc23                           updates           1.4 M
 bind99-libs                           x86_64           9.9.8-2.P3.fc23                         updates           655 k
 bind99-license                        noarch           9.9.8-2.P3.fc23                         updates            12 k
 bzip2-libs                            x86_64           1.0.6-19.fc23                           updates            45 k
 ca-certificates                       noarch           2015.2.6-1.0.fc23                       updates           432 k
 chkconfig                             x86_64           1.7-1.fc23                              updates           179 k
 coreutils                             x86_64           8.24-5.fc23                             updates           2.8 M
 crypto-policies                       noarch           20151104-1.gitf1cba5f.fc23              updates            30 k
 curl                                  x86_64           7.43.0-5.fc23                           updates           285 k
 dbus                                  x86_64           1:1.10.6-1.fc23                         updates           244 k
 dbus-glib                             x86_64           0.106-1.fc23                            updates           121 k
 dbus-libs                             x86_64           1:1.10.6-1.fc23                         updates           173 k
 deltarpm                              x86_64           3.6-13.fc23                             updates            88 k
 device-mapper                         x86_64           1.02.109-2.fc23                         updates           292 k
 device-mapper-event                   x86_64           1.02.109-2.fc23                         updates           206 k
 device-mapper-event-libs              x86_64           1.02.109-2.fc23                         updates           209 k
 device-mapper-libs                    x86_64           1.02.109-2.fc23                         updates           346 k
 dhcp-client                           x86_64           12:4.3.3-8.P1.fc23                      updates           300 k
 dhcp-common                           noarch           12:4.3.3-8.P1.fc23                      updates           194 k
 dhcp-libs                             x86_64           12:4.3.3-8.P1.fc23                      updates           138 k
 dnf                                   noarch           1.1.6-2.fc23                            updates           290 k
 dnf-conf                              noarch           1.1.6-2.fc23                            updates            91 k
 dnf-plugins-core                      noarch           0.1.16-1.fc23                           updates            37 k
 dnf-yum                               noarch           1.1.6-2.fc23                            updates            85 k
 dnsmasq                               x86_64           2.75-3.fc23                             updates           294 k
 dracut                                x86_64           043-63.git20151211.fc23                 updates           324 k
 dracut-config-rescue                  x86_64           043-63.git20151211.fc23                 updates            45 k
 ebtables                              x86_64           2.0.10-18.fc23                          updates           126 k
 elfutils-default-yama-scope           noarch           0.165-2.fc23                            updates            38 k
 elfutils-libelf                       x86_64           0.165-2.fc23                            updates           213 k
 elfutils-libs                         x86_64           0.165-2.fc23                            updates           272 k
 emacs-filesystem                      noarch           1:24.5-7.fc23                           updates            65 k
 file                                  x86_64           5.22-6.fc23                             updates            66 k
 file-libs                             x86_64           5.22-6.fc23                             updates           423 k
 findutils                             x86_64           1:4.5.16-1.fc23                         updates           563 k
 gettext                               x86_64           0.19.7-3.fc23                           updates           1.0 M
 gettext-libs                          x86_64           0.19.7-3.fc23                           updates           504 k
 glib2                                 x86_64           2.46.2-1.fc23                           updates           2.3 M
 glibc                                 x86_64           2.22-7.fc23                             updates           3.6 M
 glibc-common                          x86_64           2.22-7.fc23                             updates            11 M
 gnupg2                                x86_64           2.1.9-1.fc23                            updates           1.8 M
 gnutls                                x86_64           3.4.8-1.fc23                            updates           657 k
 grep                                  x86_64           2.22-6.fc23                             updates           275 k
 grub2                                 x86_64           1:2.02-0.25.fc23                        updates           3.8 M
 grub2-tools                           x86_64           1:2.02-0.25.fc23                        updates           7.1 M
 gsettings-desktop-schemas             x86_64           3.18.1-1.fc23                           updates           518 k
 hawkey                                x86_64           0.6.2-3.fc23                            updates            92 k
 hwdata                                noarch           0.285-2.fc23                            updates           1.4 M
 initscripts                           x86_64           9.65-1.fc23                             updates           406 k
 ipcalc                                x86_64           0.1.4-2.fc23                            updates            31 k
 iproute                               x86_64           4.1.1-3.fc23                            updates           598 k
 iputils                               x86_64           20140519-7.fc23                         updates           161 k
 kbd                                   x86_64           2.0.2-8.fc23                            updates           379 k
 kbd-legacy                            noarch           2.0.2-8.fc23                            updates           476 k
 kbd-misc                              noarch           2.0.2-8.fc23                            updates           1.4 M
 kmod                                  x86_64           22-2.fc23                               updates           112 k
 kmod-libs                             x86_64           22-2.fc23                               updates            61 k
 krb5-libs                             x86_64           1.14-7.fc23                             updates           839 k
 libarchive                            x86_64           3.1.2-14.fc23                           updates           322 k
 libassuan                             x86_64           2.4.2-1.fc23                            updates            75 k
 libblkid                              x86_64           2.27.1-2.fc23                           updates           180 k
 libcurl                               x86_64           7.43.0-5.fc23                           updates           256 k
 libdrm                                x86_64           2.4.66-1.fc23                           updates           144 k
 libfdisk                              x86_64           2.27.1-2.fc23                           updates           221 k
 libgcc                                x86_64           5.3.1-2.fc23                            updates            88 k
 libgomp                               x86_64           5.3.1-2.fc23                            updates           152 k
 libgpg-error                          x86_64           1.21-1.fc23                             updates           154 k
 libmount                              x86_64           2.27.1-2.fc23                           updates           197 k
 libnghttp2                            x86_64           1.6.0-1.fc23                            updates            65 k
 libnl3                                x86_64           3.2.27-1.fc23                           updates           265 k
 libpng                                x86_64           2:1.6.19-2.fc23                         updates           118 k
 libreport-filesystem                  x86_64           2.6.4-1.fc23                            updates            46 k
 libsmartcols                          x86_64           2.27.1-2.fc23                           updates           139 k
 libsolv                               x86_64           0.6.14-7.fc23                           updates           346 k
 libsoup                               x86_64           2.52.2-1.fc23                           updates           385 k
 libssh2                               x86_64           1.6.0-3.fc23                            updates           147 k
 libstdc++                             x86_64           5.3.1-2.fc23                            updates           425 k
 libuuid                               x86_64           2.27.1-2.fc23                           updates            79 k
 libxml2                               x86_64           2.9.3-2.fc23                            updates           684 k
 linux-firmware                        noarch           20151214-60.gitbbe4917c.fc23            updates            32 M
 lua                                   x86_64           5.3.2-2.fc23                            updates           294 k
 lvm2                                  x86_64           2.02.132-2.fc23                         updates           1.0 M
 lvm2-libs                             x86_64           2.02.132-2.fc23                         updates           927 k
 nettle                                x86_64           3.2-1.fc23                              updates           306 k
 nspr                                  x86_64           4.10.10-2.fc23                          updates           134 k
 nss                                   x86_64           3.21.0-1.1.fc23                         updates           860 k
 nss-softokn                           x86_64           3.21.0-1.1.fc23                         updates           314 k
 nss-softokn-freebl                    x86_64           3.21.0-1.1.fc23                         updates           207 k
 nss-sysinit                           x86_64           3.21.0-1.1.fc23                         updates            56 k
 nss-tools                             x86_64           3.21.0-1.1.fc23                         updates           493 k
 nss-util                              x86_64           3.21.0-1.0.fc23                         updates            81 k
 openssh                               x86_64           7.1p2-3.fc23                            updates           430 k
 openssh-clients                       x86_64           7.1p2-3.fc23                            updates           635 k
 openssh-server                        x86_64           7.1p2-3.fc23                            updates           461 k
 openssl                               x86_64           1:1.0.2f-1.fc23                         updates           496 k
 openssl-libs                          x86_64           1:1.0.2f-1.fc23                         updates           1.2 M
 os-prober                             x86_64           1.70-1.fc23                             updates            48 k
 p11-kit                               x86_64           0.23.2-1.fc23                           updates           151 k
 p11-kit-trust                         x86_64           0.23.2-1.fc23                           updates           131 k
 pcre                                  x86_64           8.38-4.fc23                             updates           495 k
 pinentry                              x86_64           0.9.6-4.fc23                            updates            81 k
 plymouth                              x86_64           0.8.9-11.2013.08.14.fc23                updates           113 k
 plymouth-core-libs                    x86_64           0.8.9-11.2013.08.14.fc23                updates           100 k
 plymouth-scripts                      x86_64           0.8.9-11.2013.08.14.fc23                updates            38 k
 policycoreutils                       x86_64           2.4-18.fc23                             updates           922 k
 python3-dbus                          x86_64           1.2.0-12.fc23                           updates           121 k
 python3-dnf                           noarch           1.1.6-2.fc23                            updates           454 k
 python3-dnf-plugins-core              noarch           0.1.16-1.fc23                           updates            80 k
 python3-gobject-base                  x86_64           3.18.2-1.fc23                           updates           296 k
 python3-hawkey                        x86_64           0.6.2-3.fc23                            updates            73 k
 python3-sssdconfig                    noarch           1.13.3-3.fc23                           updates           100 k
 rpm                                   x86_64           4.13.0-0.rc1.11.fc23                    updates           510 k
 rpm-build-libs                        x86_64           4.13.0-0.rc1.11.fc23                    updates           116 k
 rpm-libs                              x86_64           4.13.0-0.rc1.11.fc23                    updates           294 k
 rpm-plugin-selinux                    x86_64           4.13.0-0.rc1.11.fc23                    updates            51 k
 rpm-plugin-systemd-inhibit            x86_64           4.13.0-0.rc1.11.fc23                    updates            51 k
 rpm-python3                           x86_64           4.13.0-0.rc1.11.fc23                    updates           100 k
 selinux-policy                        noarch           3.13.1-158.4.fc23                       updates           435 k
 selinux-policy-targeted               noarch           3.13.1-158.4.fc23                       updates           5.6 M
 sqlite                                x86_64           3.10.2-1.fc23                           updates           476 k
 sudo                                  x86_64           1.8.15-1.fc23                           updates           691 k
 systemd                               x86_64           222-14.fc23                             updates           6.3 M
 systemd-libs                          x86_64           222-14.fc23                             updates           474 k
 tzdata                                noarch           2016a-1.fc23                            updates           409 k
 util-linux                            x86_64           2.27.1-2.fc23                           updates           2.1 M
 xkeyboard-config                      noarch           2.16-2.fc23                             updates           761 k

トランザクションの要約
========================================================================================================================
インストール      4 Packages
アップグレード  133 Packages

総ダウンロード容量: 156 M

これでパッケージのアップデートは完了したので、Ansibleをdnfでインストールすることにした。いつもは最新版が欲しいのでソースから入れる派なんだけど、Fedoraだしその辺はそれなりに新しいパッケージが入るだろうという事で。

# dnf install ansible
メタデータの期限切れの確認は、0:33:38 前の Tue Feb  9 00:39:37 2016 に実施しました。
依存性が解決されました。
========================================================================================================================
 Package                           アーキテクチャ         バージョン                      リポジトリ               容量
========================================================================================================================
インストール:
 PyYAML                            x86_64                 3.11-11.fc23                    updates                 168 k
 ansible                           noarch                 1.9.4-1.fc23                    updates                 1.7 M
 libtomcrypt                       x86_64                 1.17-25.fc23                    fedora                  229 k
 libtommath                        x86_64                 0.42.0-6.fc23                   fedora                   39 k
 libyaml                           x86_64                 0.1.6-7.fc23                    fedora                   58 k
 python                            x86_64                 2.7.10-8.fc23                   fedora                   94 k
 python-babel                      noarch                 1.3-8.fc23                      fedora                  2.5 M
 python-crypto                     x86_64                 2.6.1-7.fc23                    fedora                  468 k
 python-ecdsa                      noarch                 0.11-4.fc23                     fedora                   73 k
 python-httplib2                   noarch                 0.9.1-2.fc23                    fedora                  119 k
 python-jinja2                     noarch                 2.8-2.fc23                      fedora                  464 k
 python-keyczar                    noarch                 0.71c-5.fc23                    fedora                  222 k
 python-libs                       x86_64                 2.7.10-8.fc23                   fedora                  5.8 M
 python-markupsafe                 x86_64                 0.23-7.fc23                     fedora                   35 k
 python-paramiko                   noarch                 1.15.2-3.fc23                   fedora                  254 k
 python-pip                        noarch                 7.1.0-1.fc23                    fedora                  1.5 M
 python-pyasn1                     noarch                 0.1.8-1.fc23                    fedora                  104 k
 python-setuptools                 noarch                 18.0.1-2.fc23                   fedora                  425 k
 python-six                        noarch                 1.9.0-3.fc23                    fedora                   34 k
 pytz                              noarch                 2015.4-1.fc23                   fedora                   60 k
 sshpass                           x86_64                 1.05-8.fc23                     fedora                   25 k

トランザクションの要約
========================================================================================================================
インストール  21 パッケージ

総ダウンロード容量: 14 M
インストール済み容量: 58 M

確認してみる。
# ansible --version
ansible 1.9.4

できた、できた。

2016年2月8日月曜日

OpenShiftでPHP Gearと一緒にMySQLを使えるようにする

このエントリーをはてなブックマークに追加
PHP動いているんだったらやっぱりDBも使いたいよね。ってことでMySQLを動かしてみようと。
公式のDocumentにはこんな感じで書いてあった。
If you want to add a database to an existing application the command is similar:
$ rhc cartridge-add <dbcartridge> --app <myappname>
This command will also spin up your database server and insert the environment variables.
前回のHerokuよりも無料枠が良さげなOpenShiftでPHPをデプロイするmyphpappというアプリ名で作ったので、これで使えるようにしてみる。
まずは、使えるカートリッジを確認する。
$ rhc cartridge list
RSA 1024 bit CA certificates are loaded due to old openssl compatibility
jbossas-7                JBoss Application Server 7              web
jboss-dv-6.1.0 (!)       JBoss Data Virtualization 6             web
jbosseap-6 (*)           JBoss Enterprise Application Platform 6 web
jboss-unified-push-1 (!) JBoss Unified Push Server 1.0.0.Beta1   web
jboss-unified-push-2 (!) JBoss Unified Push Server 1.0.0.Beta2   web
jenkins-1                Jenkins Server                          web
nodejs-0.10              Node.js 0.10                            web
perl-5.10                Perl 5.10                               web
php-5.3                  PHP 5.3                                 web
php-5.4                  PHP 5.4                                 web
zend-6.1                 PHP 5.4 with Zend Server 6.1            web
python-2.6               Python 2.6                              web
python-2.7               Python 2.7                              web
python-3.3               Python 3.3                              web
ruby-1.8                 Ruby 1.8                                web
ruby-1.9                 Ruby 1.9                                web
ruby-2.0                 Ruby 2.0                                web
jbossews-1.0             Tomcat 6 (JBoss EWS 1.0)                web
jbossews-2.0             Tomcat 7 (JBoss EWS 2.0)                web
jboss-vertx-2.1 (!)      Vert.x 2.1                              web
jboss-wildfly-10 (!)     WildFly Application Server 10           web
jboss-wildfly-8 (!)      WildFly Application Server 8.2.1.Final  web
jboss-wildfly-9 (!)      WildFly Application Server 9            web
diy-0.1                  Do-It-Yourself 0.1                      web
cron-1.4                 Cron 1.4                                addon
jenkins-client-1         Jenkins Client                          addon
mongodb-2.4              MongoDB 2.4                             addon
mysql-5.1                MySQL 5.1                               addon
mysql-5.5                MySQL 5.5                               addon
phpmyadmin-4             phpMyAdmin 4.0                          addon
postgresql-8.4           PostgreSQL 8.4                          addon
postgresql-9.2           PostgreSQL 9.2                          addon
rockmongo-1.1            RockMongo 1.1                           addon
switchyard-0             SwitchYard 0.8.0                        addon
haproxy-1.4              Web Load Balancer                       addon

Note: Web cartridges can only be added to new applications.

(*) denotes a cartridge with additional usage costs.

(!) denotes a cartridge that will not receive automatic security updates.
mysql-5.5というのがあったので、これが使えそうだ。
なので、作成してみる。
$ rhc cartridge-add mysql-5.5 --app myphpapp
RSA 1024 bit CA certificates are loaded due to old openssl compatibility
Adding mysql-5.5 to application 'myphpapp' ... done

mysql-5.5 (MySQL 5.5)
---------------------
  Gears:          Located with php-5.4
  Connection URL: mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/
  Database Name:  myphpapp
  Password:       ***********
  Username:       ***********

MySQL 5.5 database added.  Please make note of these credentials:

       Root User: ***********
   Root Password: ***********
   Database Name: myphpapp

Connection URL: mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/

You can manage your new MySQL database by also embedding phpmyadmin.
The phpmyadmin username and password will be the same as the MySQL credentials above.
MySQLへの接続は環境変数に入っているようだ。myphpappにSSHで接続して、envで確認してみる。
$ rhc ssh myphpapp

\> env | grep OPENSHIFT_MYSQL -
OPENSHIFT_MYSQL_DIR=xxxxxx
OPENSHIFT_MYSQL_DB_PORT=xxxxxx
OPENSHIFT_MYSQL_DB_HOST=xxxxxx
OPENSHIFT_MYSQL_DB_PASSWORD=xxxxxx
OPENSHIFT_MYSQL_IDENT=xxxxxx
OPENSHIFT_MYSQL_DB_USERNAME=xxxxxx
OPENSHIFT_MYSQL_DB_SOCKET=xxxxxx
OPENSHIFT_MYSQL_DB_URL=xxxxxx
OPENSHIFT_MYSQL_VERSION=5.5
OPENSHIFT_MYSQL_DB_LOG_DIR=xxxxxx
OPENSHIFT_MYSQL_LD_LIBRARY_PATH_ELEMENT=xxxxxx
接続に必要な環境変数がいっぱい出てきたので、これを元にSSHでMySQLへログインできるのかやってみる。
\> mysql -u ($OPENSHIFT_MYSQL_DB_USERNAME) -p -h ($OPENSHIFT_MYSQL_DB_HOST)
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.45 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
普通にデータベースとか見えるのかな。
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| myphpapp           |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.01 sec)

mysql> use myphpapp;
Database changed
mysql> show tables;
Empty set (0.00 sec)
結構普通に使えて超便利!

2016年2月7日日曜日

OpenShiftってSSHでログインもできるんだ

このエントリーをはてなブックマークに追加
Remote Connection (SSH)を見てみたら普通にSSHでGearにログインできるみたいなのでやってみた。


$ rhc ssh myphpapp
RSA 1024 bit CA certificates are loaded due to old openssl compatibility
Connecting to 56b61d5c89f5cf92a000003f@myphpapp-xxxxxx.rhcloud.com ...

    *********************************************************************

    You are accessing a service that is for use only by authorized users.
    If you do not have authorization, discontinue use at once.
    Any use of the services is subject to the applicable terms of the
    agreement which can be found at:
    https://www.openshift.com/legal

    *********************************************************************

    Welcome to OpenShift shell

    This shell will assist you in managing OpenShift applications.

    !!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!
    Shell access is quite powerful and it is possible for you to
    accidentally damage your application.  Proceed with care!
    If worse comes to worst, destroy your application with "rhc app delete"
    and recreate it
    !!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!

    Type "help" for more info.


[myphpapp-xxxxxx.rhcloud.com 56b61d5c89f5cf92a000003f]\>
でも使えるコマンドは限られてるみたい。
\> help
Help menu: The following commands are available to help control your openshift
application and environment.

gear            control your application (start, stop, restart, etc)
                or deps with --cart      (gear start --cart mysql-5.1)
tail_all        tail all log files
export          list available environment variables
rm              remove files / directories
ls              list files / directories
ps              list running applications
kill            kill running applications
mysql           interactive MySQL shell
mongo           interactive MongoDB shell
psql            interactive PostgreSQL shell
quota           list disk usage

Deprecated:
ctl_app         control your application (start, stop, restart, etc)
ctl_all         control application and deps like mysql in one command
簡単なの使ってみよう。
[myphpapp-xxxxxx.rhcloud.com 56b61d5c89f5cf92a000003f]\> ls
app-deployments  app-root  git php
[myphpapp-xxxxxx.rhcloud.com 56b61d5c89f5cf92a000003f]\> pwd
/var/lib/openshift/56b61d5c89f5cf92a000003f
ファイルやディレクトリは見える。
[myphpapp-xxxxxx.rhcloud.com 56b61d5c89f5cf92a000003f]\> ps -aef
UID         PID   PPID  C STIME TTY          TIME CMD
2385     182328 181214  0 13:13 ?        00:00:00 sshd: 56b61d5c89f5cf92a000003f@pts/1
2385     182339 182328  0 13:13 pts/1    00:00:00 /bin/bash --init-file /usr/bin/rhcsh -i
2385     189163 182339  2 13:14 pts/1    00:00:00 ps -aef
2385     423174      1  0 12:12 ?        00:00:00 /usr/sbin/httpd -c Include /var/lib/openshift/56b61d5c89f5cf92a000003f
2385     423175      1  0 12:12 ?        00:00:00 /usr/bin/logshifter -tag php
2385     423184 423174  0 12:12 ?        00:00:00 tee
2385     423185 423174  0 12:12 ?        00:00:00 tee
2385     423186 423174  0 12:12 ?        00:00:00 /usr/sbin/httpd -c Include /var/lib/openshift/56b61d5c89f5cf92a000003f
2385     434288 423174  0 12:14 ?        00:00:00 /usr/sbin/httpd -c Include /var/lib/openshift/56b61d5c89f5cf92a000003f
動いているプロセスも見えるみたい。
[myphpapp-xxxxxx.rhcloud.com 56b61d5c89f5cf92a000003f]\> cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.7 (Santiago)
OSはRedHat EnterPrise 6.7か。
[myphpapp-xxxxxx.rhcloud.com 56b61d5c89f5cf92a000003f]\> env
MANPATH=/opt/rh/php54/root/usr/share/man:
OPENSHIFT_SECRET_TOKEN=wD_1nmlzQ0FN8WHQ_Xs5hsUAiermXB5i7GVLGFP1N7w6_wGfnAT9PZNgwecEUpOGAJIp1ER8Ao-lGBwx8dU_8Q9fqn-R482B6JF9aySaXIXp9ScZZ8xY0Q_MeqZPzFJ1
OPENSHIFT_PHP_IDENT=redhat:php:5.4:0.0.28
OPENSHIFT_GEAR_MEMORY_MB=512
SELINUX_ROLE_REQUESTED=
OPENSHIFT_DEPLO
:
:
helpには書いてないけどenvで環境変数も見えるみたい。

Herokuよりも無料枠が良さげなOpenShiftでPHPをデプロイする

このエントリーをはてなブックマークに追加
Herokuよりも無料枠が良さげなOpenShiftをつかってみるでアカウントとGearを作ってPHP Cartridgeを用意した。

今度はGetting Started with PHPを辿ってブラウザで確認できるまでやってみる。

アカウントは作ったけどrhcコマンドはインストールしていないのでリンク先からインストールする。僕の場合はMac版をインストール。

$ sudo gem install rhc
Password:
Fetching: net-ssh-2.9.2.gem (100%)
Successfully installed net-ssh-2.9.2
Fetching: net-scp-1.2.1.gem (100%)
Successfully installed net-scp-1.2.1
Fetching: net-ssh-gateway-1.2.0.gem (100%)
Successfully installed net-ssh-gateway-1.2.0
Fetching: net-ssh-multi-1.2.1.gem (100%)
Successfully installed net-ssh-multi-1.2.1
Fetching: archive-tar-minitar-0.5.2.gem (100%)
Successfully installed archive-tar-minitar-0.5.2
Fetching: highline-1.6.21.gem (100%)
Successfully installed highline-1.6.21
Fetching: commander-4.2.1.gem (100%)
Successfully installed commander-4.2.1
Fetching: httpclient-2.7.1.gem (100%)
Successfully installed httpclient-2.7.1
Fetching: open4-1.3.4.gem (100%)
Successfully installed open4-1.3.4
Fetching: rhc-1.38.4.gem (100%)
===========================================================================

If this is your first time installing the RHC tools, please run 'rhc setup'

===========================================================================
Successfully installed rhc-1.38.4
Parsing documentation for net-ssh-2.9.2
Installing ri documentation for net-ssh-2.9.2
Parsing documentation for net-scp-1.2.1
Installing ri documentation for net-scp-1.2.1
Parsing documentation for net-ssh-gateway-1.2.0
Installing ri documentation for net-ssh-gateway-1.2.0
Parsing documentation for net-ssh-multi-1.2.1
Installing ri documentation for net-ssh-multi-1.2.1
Parsing documentation for archive-tar-minitar-0.5.2
Installing ri documentation for archive-tar-minitar-0.5.2
Parsing documentation for highline-1.6.21
Installing ri documentation for highline-1.6.21
Parsing documentation for commander-4.2.1
Installing ri documentation for commander-4.2.1
Parsing documentation for httpclient-2.7.1
Installing ri documentation for httpclient-2.7.1
^@Parsing documentation for open4-1.3.4
Installing ri documentation for open4-1.3.4
Parsing documentation for rhc-1.38.4
Installing ri documentation for rhc-1.38.4
10 gems installed

初めてのインストールだったら'rhc setup'を実行しろと書いてあるので素直にやってみる。

$ rhc setup
OpenShift Client Tools (RHC) Setup Wizard

This wizard will help you upload your SSH keys, set your application namespace, and check that other programs like Git
are properly installed.

If you have your own OpenShift server, you can specify it now. Just hit enter to use the server for OpenShift Online:
openshift.redhat.com.
Enter the server hostname: |openshift.redhat.com|

サブドメインでそのまま使っているのでEnter。

You can add more servers later using 'rhc server'.
RSA 1024 bit CA certificates are loaded due to old openssl compatibility

Login to openshift.redhat.com: xxxxxxxx@hogehoge.com
Password: *********

素直に作成したアカウントのメールアドレスとパスワードを入力。

OpenShift can create and store a token on disk which allows to you to access the server without using your password. The
key is stored in your home directory and should be kept secret.  You can delete the key at any time by running 'rhc
logout'.
Generate a token now? (yes|no) yes

鍵を作っておくかと聞かれるので作っておく。

Generating an authorization token for this client ... lasts about 1 month

Saving configuration to /Users/xxxxx/.openshift/express.conf ... done

No SSH keys were found. We will generate a pair of keys for you.

    Created: /Users/xxxxxxx/.ssh/id_rsa.pub

Your public SSH key must be uploaded to the OpenShift server to access code.  Upload now? (yes|no) yes

鍵を作った後、今、サーバにアップロードをするか聞かれるのでyes

Since you do not have any keys associated with your OpenShift account, your new key will be uploaded as the 'default'
key.

Uploading key 'default' ... done

Checking for git ... found git version 2.5.4 (Apple Git-61)

Checking common problems .. done

Checking for a domain ... xxxxxxxxx

Checking for applications ... found 1

  php http://php-xxxxxxx.rhcloud.com/

  You are using 1 of 3 total gears
  The following gear sizes are available to you: small

Your client tools are now configured.

とりあえずrhcコマンドの準備は整った。

Once that is completed, open a terminal on a local machine and change into the directory where you would like the OpenShift application source code to be located. At the command prompt, enter the following command to create a PHP application:

$ rhc app create myphpapp php-5.4

アプリケーションを作成しよう。
今回は~/Documentフォルダの下に"OpenShift Project"を作成した上で、そこに移動しコマンドを入力する。

$ rhc app create myphpapp php-5.4
RSA 1024 bit CA certificates are loaded due to old openssl compatibility
Application Options
-------------------
Domain:     xxxxxxxxxx
Cartridges: php-5.4
Gear Size:  default
Scaling:    no

Creating application 'myphpapp' ... done


Waiting for your DNS name to be available ... done

Cloning into 'myphpapp'...
The authenticity of host 'myphpapp-xxxxxxxxxx.rhcloud.com (52.91.58.98)' can't be established.
RSA key fingerprint is SHA256:FeJCkIUL7D41FMGNtM5NYM4XoboxZGYEqH0WcAmOX+I.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'myphpapp-xxxxxxxxxx.rhcloud.com,52.91.58.98' (RSA) to the list of known hosts.

Your application 'myphpapp' is now available.

  URL:        http://myphpapp-xxxxxxxxxx.rhcloud.com/
  SSH to:     56b61d5c89f5cf92a000003f@myphpapp-xxxxxxxxxx.rhcloud.com
  Git remote: ssh://56b61d5c89f5cf92a000003f@myphpapp-xxxxxxxxxx.rhcloud.com/~/git/myphpapp.git/
  Cloned to:  /Users/xxxxxx/Documents/OpenShift Project/myphpapp

Run 'rhc show-app myphpapp' for more details about your app.

これでリモートリポジトリとアプリが作成された。ローカルの中にもmyphpappというディレクトリができているので、中を見てみよう。

$ cd myphpapp/
$ ls -aFCl
total 80
drwxr-xr-x   5 xxxxxx  staff    170  2  7 01:22 ./
drwxr-xr-x   3 xxxxxx  staff    102  2  7 01:22 ../
drwxr-xr-x  13 xxxxxx  staff    442  2  7 01:22 .git/
drwxr-xr-x   7 xxxxxx  staff    238  2  7 01:22 .openshift/
-rw-r--r--   1 xxxxxx  staff  39585  2  7 01:22 index.php

ここで上で表示されたURLにブラウザからアクセスしてみる。


phpinfo()を書いたphpファイルを作成してみる。test.phpとかでいいか。

<?php
phpinfo();

gitでローカルリポジトリにコミットする。

$ git add --all
$ git commit -m "add test.php"
[master 6da6e33] add test.php
 Committer: xxxxxx xxxxxx@xxxxxx-no-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 2 insertions(+)
 create mode 100644 test.php

その後、サイトにpushする。
$ git push
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 343 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Stopping PHP 5.4 cartridge (Apache+mod_php)
remote: Waiting for stop to finish
remote: Waiting for stop to finish
remote: Building git ref 'master', commit 6da6e33
remote: Checking .openshift/pear.txt for PEAR dependency...
remote: Preparing build for deployment
remote: Deployment id is ffac86ca
remote: Activating deployment
remote: Starting PHP 5.4 cartridge (Apache+mod_php)
remote: Application directory "/" selected as DocumentRoot
remote: -------------------------
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success
To ssh://56b61d5c89f5cf92a000003f@myphpapp-xxxxxx.rhcloud.com/~/git/myphpapp.git/
   9b470d5..6da6e33  master -> master

これでブラウザでアクセスしてみるときちんと反映された。

2016年2月5日金曜日

Herokuよりも無料枠が良さげなOpenShiftをつかってみる

このエントリーをはてなブックマークに追加
遅まきのHerokuデビューを無料枠でしたよ。準備編〜その1で書いたように今はdynoを落としておかないといけない時間も多くなったので、まだ制限の緩いOpenShiftを試してみることにした。

アカウント登録してサインインするとこんな画面になり新しいアプリケーションを登録することができる。


"Create your first application now"をクリックして進もう。

結構色々な"Application Type"が選べる。この中でシンプルに"PHP 5.4"を選ぶ。


ほぼデフォルトでいいだろう。Gearがサーバ、Cartridgeがパッケージみたいなものだと考えればいいのかな。セキュリティアップデートは勝手にかけてくれるらしい。若葉マークってどこの国でも一緒なのかw

PHP 5.4 Cartridge

PHP is a general-purpose server-side scripting language originally designed for Web development to produce dynamic Web pages. Popular development frameworks include CakePHP, Zend, Symfony, and Code Igniter.
OpenShift maintained
Receives automatic security updates

"Create Application"を押して、数十秒ぐらい待つと下記の画面が現れてGearが作成されたようだ。


今は"Not now, Continue"を選んで進む。


ここまででGearのベース設定は終了した。

次はGetting Started with PHPを元にソースをGearにデプロイしてブラウザで確認できるとこまでやってみよう。



2016年2月3日水曜日

遅まきのHerokuデビューを無料枠でしたよ。phpinfo()を作ってデプロイ編

このエントリーをはてなブックマークに追加
チュートリアルは分かったので、今度はスクラッチで作成して公開するまでの手順を確認しておこう。

まずは適当なディレクトリを作る。そしてそのディレクトリの下に移動。

$ mkdir phpinfo
$ cd phpinfo/

index.phpとcomposer.jsonを作る。composer.jsonは空に近い状態でいい。

phpinfo();
{
    "require": {
    }
}
このままcomposer updateを実行する。

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
そうするとvenderディレクトリが作成されているので、ここでgit initする。

$ git init
Initialized empty Git repository in /Users/hogahoga/Documents/HerokuProject/phpinfo/.git/
全てのファイルをaddし、ローカルリポジトリにコミットする。
$ git add *
$ git commit -m "Initial Commit"
[master (root-commit) 3852af9] Initial Commit
 Committer: Taro Yamada 
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 10 files changed, 520 insertions(+)
 create mode 100644 composer.json
 create mode 100644 index.php
 create mode 100644 vendor/autoload.php
 create mode 100644 vendor/composer/ClassLoader.php
 create mode 100644 vendor/composer/LICENSE
 create mode 100644 vendor/composer/autoload_classmap.php
 create mode 100644 vendor/composer/autoload_namespaces.php
 create mode 100644 vendor/composer/autoload_psr4.php
 create mode 100644 vendor/composer/autoload_real.php
 create mode 100644 vendor/composer/installed.json
ここでHerokuにログインする。
$ heroku login
Enter your Heroku credentials.
Email: Taro.Yamada@hogehoge.com
Password (typing will be hidden):
Logged in as Taro.Yamada@hogehoge.com
Heroku上にアプリを作成し、ローカルリポジトリにコミットしたファイルをHerokuにプッシュする。
$ heroku create
Creating app... done, stack is cedar-14
https://mysterious-depths-86346.herokuapp.com/ | https://git.heroku.com/mysterious-depths-86346.git
$ git push heroku master
Counting objects: 14, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (14/14), 4.72 KiB | 0 bytes/s, done.
Total 14 (delta 2), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing system packages...
remote:        NOTICE: No runtime required in composer.lock; using PHP ^5.5.17
remote:        - php (5.6.17)
remote:        - Apache (2.4.16)
remote:        - Nginx (1.8.0)
remote: -----> Enabling PHP extensions...
remote:        - ext-zend-opcache (automatic)
remote: -----> Installing dependencies...
remote:        Composer version 1.0.0-alpha11 2015-11-14 16:21:07
remote:
remote:  !     WARNING: Your Composer vendor dir is part of your Git repository.
remote:        This directory should not be under version control; only your
remote:        'composer.json' and 'composer.lock' files should be added, which
remote:        will let Composer handle installation of dependencies on deploy.
remote:        To suppress this notice, first remove the folder from your index
remote:        by running 'git rm --cached vendor/'.
remote:        Next, edit your project's '.gitignore' file and add the folder
remote:        '/vendor/' to the list.
remote:        For more info, refer to the Composer FAQ: http://bit.ly/1rlCSZU
remote:
remote:        Loading composer repositories with package information
remote:        Installing dependencies
remote:        Nothing to install or update
remote:        Generating optimized autoload files
remote: -----> Preparing runtime environment...
remote:        NOTICE: No Procfile, using 'web: vendor/bin/heroku-php-apache2'.
remote: -----> Checking for additional extensions to install...
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 73.9M
remote: -----> Launching...
remote:        Released v3
remote:        https://mysterious-depths-86346.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy.... done.
To https://git.heroku.com/mysterious-depths-86346.git
 * [new branch]      master -> master
ブラウザで確認する。
$ heroku open
Opening mysterious-depths-86346... done

よしよし、コツが分かったぞ。