2016年3月2日水曜日

さくらVPSにLubuntu Descktopを入れてVDI環境を作った

このエントリーをはてなブックマークに追加
家の外でモバイルで作業する時にはノートPCを持っていくことが多いんだけれど、いつも家にあるMacの3台のどれをもっていくかで悩んでいた。本来であればiPadで全部用事すませたいところなんだけど、なかなかかゆいところに手が届かなかったりするので。。。

家にあるMacは割と特徴がそれぞれ。
  1. MacBook Pro 13インチ (Retina, 13-inch, Late 2013
    • DDR3 1600MHz 8GB
    • Corei5 2.4Ghz
    • SSD 256GB
    • 1.57kg
  2. MacBook Pro 13インチ (13-inch, Mid 2012)
    • DDR3 1600MHz 16GB
    • Corei5 2.5Ghz
    • SSD 500GB(換装済み)
    • 2.06kg
    • Windows10がBootCampで入っている。
  3. MacBook Air 11インチ (11-inch, Mid 2012)
    • DDR3 1600MHz 4GB
    • Corei5 1.7Ghz
    • SSD 64GB
    • 1.08kg

一番、性能もいいのは②、画面がRetinaでないのが残念。一番重量は重い。①はRetinaで画面もきれいながら重量もそこまでないけど、持ち歩くと腰痛持ちにはちょっと荷が重い。。。

そこで目標を③のMacBook Airに絞った、ただしハード的な制約は割とあってSSDとメモリが少ない。特にSSDが少ないので、それを補うために仮想デスクトップを用意してシンクライアントっぽく利用できればと思って、さくらのVPSに軽量LinuxのLubutu-15-10 DesktopをさくらのVPSにインストールしてみた。


Debiun系さわるのは久しぶりなので少し勘を取り戻しながらやる。
以下、インストールしていったもの。


[Google Chrome]
デフォルトでブラウザはFirefoxが入ってるのだけど拡張機能とか使い慣れているChromeが良かったので

[sysv-rc-conf]
単純にRedhat系のchkconfigみたいなのが良かっただけ。

[SSH]
基本的にデスクトップ用途なのでデフォルトでは入っていない。それでもいいんだけれど何かあったときは必要だろうと思うのでインストール。ただしGlobalIPで接続することになるのでパスワード認証なし、Rootログインなし、鍵認証は必ずしておく。さすがにIPベースで縛るのはきびしいし。

[XRDP]
デスクトップにリモート接続するために導入。VNCより使い勝手がよさそう。

IDCFクラウドでUbuntu MATE 14.10とxrdpを使うを参考にさせていただいた。

割と使いやすい。でもメモリが1GBなのであまり重い処理はできないな。。。

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:動詞

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