やっと手に入れたLPIC レベル2 第4版
2012/10/26に発売されたやつでVersion3.5に対応してます。
翔泳社のダウンロードページ
Linux実習環境の使い方
レベル2からが本番だと思ってるのでがんばります。
天は自ら助くる者を助く
やっと手に入れたLPIC レベル2 第4版
2012/10/26に発売されたやつでVersion3.5に対応してます。
翔泳社のダウンロードページ
Linux実習環境の使い方
レベル2からが本番だと思ってるのでがんばります。
jstdutilをインストールしたい。
jstdutilは↓を提供してくれる便利なやつ。
・JsTestDriverのコマンドラインを簡略化するjstestdirver
・ファイル更新時に自動的にテストを実行するjsautotest
jstdutilはrubyのgemからインストールできるらしい。
でもそもそもrubyすら入っていない・・・。
とりあえず手元にあったCentOS release 5.7にrubyを入れる。
yumで見たらVersionが1.8.5だった・・・。
# yum info ruby
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
* updates: ftp.iij.ad.jp
base | 1.1 kB 00:00
extras | 1.9 kB 00:00
updates | 1.9 kB 00:00
updates/primary_db | 837 kB 00:00
vz-base | 951 B 00:00
vz-updates | 951 B 00:00
Available Packages
Name : ruby
Arch : i386
Version : 1.8.5
Release : 24.el5
Size : 277 k
Repo : base
Summary : An interpreter of object-oriented scripting language
URL : http://www.ruby-lang.org/
License : Ruby License/GPL - see COPYING
Description: Ruby is the interpreted scripting language for quick and easy
: object-oriented programming. It has many features to process text
: files and to do system management tasks (as in Perl). It is simple,
: straight-forward, and extensible.
rubyのサイトを見るとどうやら最新の安定版は「ruby 1.9.3-p286」らしいので
ソースからビルドしてみる。
↑このとおりやってみた。
で、今回の目的だった「jstdutil」を入れようとする。
$ gem install jstdutil
入ったのかな?よくわかんないので動かしてみる。
$ jsautotest /usr/local/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>': It seems your ruby installation is missing psych (for YAML output). To eliminate this warning, please install libyaml and reinstall your ruby. /usr/local/lib/ruby/gems/1.9.1/gems/watchr-0.7/lib/watchr.rb:111: Use RbConfig instead of obsolete and deprecated Config. Using config file public_html/Javascript/JsTestDriver.conf An error occurred invalid byte sequence in UTF-8
どうも怒られているらしい。
Ruby 1.9.3 を導入するにあたってソースからビルドする人が気をつける事とはいったい…?!
上記サイトの内容に沿って最新のlibyamlをいれてrubyをconfigure;make;make install
$ java -jar $JSTESTDRIVER_HOME/JsTestDriver-1.3.5.jar --port 4224 setting runnermode QUIET
サーバ立てて・・・ブラウザで「Capture This Browser」クリックして・・・
$ jstestdriver --config=path/JsTestDriver.conf --tests all setting runnermode QUIET ....... Total 7 tests (Passed: 7; Fails: 0; Errors: 0) (2.00 ms) Microsoft Internet Explorer 9.0 Windows: Run 7 tests (Passed: 7; Fails: 0; Errors 0) (2.00 ms)
動いた。でも相変わらず jsautotest はだめ
$ jsautotest /usr/local/lib/ruby/gems/1.9.1/gems/watchr-0.7/lib/watchr.rb:111: Use RbConfig instead of obsolete and deprecated Config. Using config file public_html/Javascript/JsTestDriver.conf An error occurred invalid byte sequence in UTF-8
よくわかんないけどwatcharとかいうのを入れてみる。
# gem install watchr Successfully installed watchr-0.7 1 gem installed Installing ri documentation for watchr-0.7... Installing RDoc documentation for watchr-0.7...
さらに、、、どうもコンフィグのファイル名が悪いらしいのでファイル名を変更
「JsTestDriver.conf」から「jstestdriver.conf」
で今一度
$ jsautotest /usr/local/lib/ruby/gems/1.9.1/gems/watchr-0.7/lib/watchr.rb:111: Use RbConfig instead of obsolete and deprecated Config. Using config file jstestdriver.conf
おっ動いたかも。
この状態でテストケースとかを変更してみる。。。。すると。
$ jsautotest /usr/local/lib/ruby/gems/1.9.1/gems/watchr-0.7/lib/watchr.rb:111: Use RbConfig instead of obsolete and deprecated Config. Using config file jstestdriver.conf 2012-10-29 15:14:14 Running all setting runnermode QUIET Microsoft Internet Explorer: Reset Microsoft Internet Explorer: Reset ....... Total 7 tests (Passed: 7; Fails: 0; Errors: 0) (3.00 ms) Microsoft Internet Explorer 9.0 Windows: Run 7 tests (Passed: 7; Fails: 0; Errors 0) (3.00 ms)
おー動いた。rubyよくわかんないっす。。
テスト駆動Javascriptを読んでて「JsTestDriver」を導入しようと思って設定してたら
java.lang.RuntimeException: Oh Snap! No server defined!
っていうエラーが出た話。
そもそもの「JsTestDriver」の導入方法はアシアルさんが丁寧に書いてくれているのでそれを真似る。
windows版では問題なく動いたんだけどCentOS5の環境でやろうとしたらエラー出たという。。
アシアルさん:JsTestDriverで簡単テスト
$ java -jar $JSTESTDRIVER_HOME/JsTestDriver-1.3.5.jar --tests all
setting runnermode QUIET
java.lang.RuntimeException: Oh Snap! No server defined!
at com.google.jstestdriver.config.DefaultConfiguration.getServer(DefaultConfiguration.java:61)
at com.google.jstestdriver.config.Initializer.initialize(Initializer.java:99)
at com.google.jstestdriver.embedded.JsTestDriverImpl.createRunnerInjector(JsTestDriverImpl.java:368)
at com.google.jstestdriver.embedded.JsTestDriverImpl.runConfigurationWithFlags(JsTestDriverImpl.java:342)
at com.google.jstestdriver.embedded.JsTestDriverImpl.runConfiguration(JsTestDriverImpl.java:233)
at com.google.jstestdriver.Main.main(Main.java:70)
Unexpected Runner Condition: Oh Snap! No server defined!
Use --runnerMode DEBUG for more information.
jarファイル
/home/myname/bin/
`– JsTestDriver-1.3.5.jar
ソースとテストファイル
/home/myname/public_html/Javascript/
|– JsTestDriver.conf
|– src
| `– sample.js
`– test
`– sample.js
どうも原因はconfファイルを見つけられなかったことらしい。
なので明示的に対対象の設定ファイルの場所を「–config」オプションで指定するようにする。
※絶対パスで指定してるけど別に相対でも可。
$ java -jar $JSTESTDRIVER_HOME/JsTestDriver-1.3.5.jar --config /home/myname/public_html/Javascript/JsTestDriver.conf --tests all setting runnermode QUIET .. Total 2 tests (Passed: 2; Fails: 0; Errors: 0) (1.00 ms) Microsoft Internet Explorer 9.0 Windows: Run 2 tests (Passed: 2; Fails: 0; Errors 0) (1.00 ms)
動いたー!
実験機のOpenVZのゲストにjavaを入れようとしたらyumでエラーが出た。
# yum search java
Loaded plugins: fastestmirror
Determining fastest mirrors
Traceback (most recent call last):
File "/usr/bin/yum", line 29, in <module>
yummain.user_main(sys.argv[1:], exit_code=True)
File "/usr/share/yum-cli/yummain.py", line 285, in user_main
errcode = main(args)
File "/usr/share/yum-cli/yummain.py", line 136, in main
result, resultmsgs = base.doCommands()
File "/usr/share/yum-cli/cli.py", line 438, in doCommands
return self.yum_cli_commands[self.basecmd].doCommand(self, self.basecmd, self.extcmds)
File "/usr/share/yum-cli/yumcommands.py", line 686, in doCommand
return base.search(extcmds)
File "/usr/share/yum-cli/cli.py", line 1030, in search
for (po, keys, matched_value) in matching:
File "/usr/lib/python2.6/site-packages/yum/__init__.py", line 2540, in searchGenerator
for sack in self.pkgSack.sacks.values():
File "/usr/lib/python2.6/site-packages/yum/__init__.py", line 897, in <lambda>
pkgSack = property(fget=lambda self: self._getSacks(),
File "/usr/lib/python2.6/site-packages/yum/__init__.py", line 682, in _getSacks
self.repos.populateSack(which=repos)
File "/usr/lib/python2.6/site-packages/yum/repos.py", line 265, in populateSack
self.doSetup()
File "/usr/lib/python2.6/site-packages/yum/repos.py", line 92, in doSetup
self.ayum.plugins.run('postreposetup')
File "/usr/lib/python2.6/site-packages/yum/plugins.py", line 184, in run
func(conduitcls(self, self.base, conf, **kwargs))
File "/usr/lib/yum-plugins/fastestmirror.py", line 202, in postreposetup_hook
all_urls = FastestMirror(all_urls).get_mirrorlist()
File "/usr/lib/yum-plugins/fastestmirror.py", line 369, in get_mirrorlist
self._poll_mirrors()
File "/usr/lib/yum-plugins/fastestmirror.py", line 413, in _poll_mirrors
pollThread.start()
File "/usr/lib/python2.6/threading.py", line 474, in start
_start_new_thread(self.__bootstrap, ())
thread.error: can't start new thread
とりあえず「yum clean all」するも駄目。
# yum clean all Loaded plugins: fastestmirror Cleaning repos: base extras updates vz-base vz-updates Cleaning up Everything Cleaning up list of fastest mirrors
fastestmirrorが悪いのかな?と思い以下を実行
# rpm -ev --nodeps fastestmirror error: package yum-fastestmirror is not installed
そんなのは無いといわれる。
色々調べてみたところ同じような現象に遭遇していた人がいたので
そこのブログの内容を参考に対応してみる。
要するに、VPSだとyumでメモリ不足の問題が発生する事が多いから、
fastestmirror pluginは使わないでね、という事みたいですね。
ということなので同じように「–disablepplugin」してみる。
# yum --disableplugin=fastestmirror search java
できた!
こっちもおんなじ用に毎回「–disablepplugin」するの面倒なので
削除を試みる。
# rpm -qa | grep yum yum-3.2.29-30.el6.centos.noarch yum-metadata-parser-1.1.2-16.el6.i686 yum-plugin-fastestmirror-1.1.30-14.el6.noarch # rpm -ev --nodeps yum-plugin-fastestmirror-1.1.30-14.el6.noarch # yum search java
出来た
PHPでブラウザからプログラムを動かして、
作成したファイルやフォルダの権限を変更したい場合のやり方。
通常はapacehユーザでファイルやフォルダが作成
されてしまうのでプログラム中でchownを実行したいの
だけれど、chownはrootで動かさないとなのでこのまま
単純にchownを実行しても権限やグループを変えることが
できない。
そこで、sudoでapacheユーザに特定のコマンドだけを許すように設定
を変更する。
# visudo
apache ALL=(ALL) NOPASSWD: /bin/mkdir, /bin/chown
上記の場合はapacheユーザにパスワード無しで「mkdir」と「chown」の実行を許可している。
他のコマンドも許可したければ、続けて記述していけばOK。
これで大丈夫かなと思って実行してみたらchownで変更できていない。
エラーログを見ると以下のメッセーが・・・。
「sudo: sorry, you must have a tty to run sudo」
SSHクライアントとかコンソールではエラーが出ないのに。。。
調べてみると「Defaults requiretty」をコメントアウトすればいいことが判明。
# visudo
Defaults requiretty ↓ #Defaults requiretty
するとエラーが出なくなり、無事にchownが実行できた。
■参考URL
前回のエントリではindex.html無しにする場合だったので
index.html有りにする場合も書いておく。
RewriteEngine on
#TOPページの処理
RewriteRule ^$ http://example.com/index.html [R=301,L]
#下層ページの処理
#ただし/xxxxxxxx/のURLは除外
RewriteCond %{THE_REQUEST} !^.*/xxxxxxxx/
RewriteCond %{THE_REQUEST} ^.*/
RewriteRule ^(.*)/$ http://example.com/$1/index.html [R=301,L]
※除外的なものも入れてる。
PHPのプログラム内からPOSTでリクエストを飛ばしたときに
出たエラーのメモ。
$url='http://wwww.example.com/xxxx.php';
$data=array(
'data1' => 'xxxxxxxx',
'data2' => 'yyyyyyyy'
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => http_build_query($data)
)
);
$contents = file_get_contents($url, false, stream_context_create($options));
Severity: Notice –> file_get_contents() [function.file-get-contents]: Content-type not specified assuming application/x-www-form-urlencoded xxxxxxxxx.php 80
headerを追加して対応。
$url='http://wwww.example.com/xxxx.php';
$data=array(
'data1' => 'xxxxxxxx',
'data2' => 'yyyyyyyy'
);
$headers = array(
'Content-Type: application/x-www-form-urlencoded',
'Content-Length: '.strlen(http_build_query($data))
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => http_build_query($data),
'header' => implode("\r\n", $headers),
)
);
$contents = file_get_contents($url, false, stream_context_create($options));
とても簡単にPHPからPOSTリクエストを送信する方法【PHP】
[PHPエラー] Content-type not specified assuming application/x-www-form-urlencoded の対処法
OpenVZのゲスト側で他のNAS(TeraStasion)のフォルダをマウントする設定を
していたけど、すっかり忘れていたのでメモ。
ホストはCentOS6.2
ホストサーバにOpenVZをいれて複数のゲストサーバ
を立てて社内の開発環境を構築していて、ゲスト側
で社内の他のNASにアクセスできるように設定を行っている。
主にホストの「/etc/fstab」と「/etc/rc.d/rc.local」で
実現している。
「/etc/rc.d/rc.local」とは起動プロセスの最後に実行されるシェルスクリプトのこと。
今回はこれが思い出せなかった・・・。
OpenVZを使ってゲスト側で直接NAS(TeraStasion)を
マウントしようとしてもcifsのエラーが出てmount
出来なかった。
ホスト側で起動時にマウントを行うようにし、
マウントしてOpenVZが起動し終わったあとに
/etc/rc.d/rc.local
で各ゲストにbindするように設定してみた。
# # /etc/fstab # Created by anaconda on Thu Mar 15 05:40:21 2012 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/VolGroup-lv_root / ext4 defaults 1 1 UUID=2f2b3876-c89f-49b9-896b-4436a2cf4199 /boot ext4 defaults 1 2 /dev/mapper/VolGroup-lv_home /home ext4 defaults 1 2 /dev/mapper/VolGroup-lv_swap swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 # mount1 192.168.1.xx:/mnt/array1/folder1 /mnt/mout_folder1 nfs rsize=8192,wsize=8192,nolock,hard,intr 0 0 # mount2 192.168.1.xx:/mnt/array1/folder2 /mnt/mout_folder2 nfs rsize=8192,wsize=8192,hard,intr 0 0
「mnt/array1」とかなっているマウントしたい対象のNASは
今回のケースではBuffaloのTeraStation。
TeraStationはNFSの機能が付いていたのでNFSフォルダーと
NFSクライアント設定を事前に作成しておいた。
#!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. touch /var/lock/subsys/local #bind mount --bind /mnt/mout_folder1 /home/vz/root/180/var/www/html/clients 以下続く・・・。
上記はホストでマウントしたフォルダをホスト上にあるOpenVZのゲストのフォルダにbindしている。
これで結果的にゲスト側でもマウントしているような状態でファイルが操作できる。
mount –bindはマウントしたファイルシステムの一部を別のディレクトリにマウントし直すと
いうシンボリック的な役割をしてくれる。
こうやって書いてみると面倒な仕組みになってるなー。
他にやり方ないのかな?