三蔵開発メモ

Web開発やインフラ関連のメモを共有します

phantomjsとcasperjsのインストール

phantomjsのインストール

バイナリをダウンロードするやり方。ビルドはすごい時間がかかる。

cd /usr/local/src
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
tar jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2
mv phantomjs-2.1.1-linux-x86_64 phantomjs
cd phantomjs
ln -sf `pwd`/bin/phantomjs /usr/local/bin/phantomjs
phantomjs --version
#エラーになる場合は、だいたい以下を入れれば直る
sudo yum -y install fontconfig-devel

casperjsのインストール

cd /usr/local/src
git clone https://github.com/casperjs/casperjs.git
cd casperjs/

# シンボリックリンクを作成
ln -sf `pwd`/bin/casperjs /usr/local/bin/casperjs

# 動作確認
casperjs --version
1.1.2

casperjsでjQueryを使う

cd /usr/local/src/casperjs
mkdir lib
cd lib
wget https://code.jquery.com/jquery-1.9.1.min.js
mv jquery-1.9.1.min.js jquery.min.js

※casperjsのソース内で使うときはcreate時に以下のように設定

var casper = require('casper').create({
  clientScripts: [phantom.casperPath + "/lib/jquery.min.js"],
});

おまけメモ

バッチ実行する場合のsyntaxError回避 ソースの一番上にこれ入れる

#!/usr/local/bin/phantomjs /usr/local/bin/casperjs

MongoDBを少ない容量で起動させる

MongoDBを普通に起動させると、ジャーナルファイルが3GBくらい一気に容量を確保してしまうので、 開発環境などでは不便。

以下のように設定すればジャーナルファイルのサイズが128MBになる。

sudo serivce mongod stop
#失敗したら sudo killall mongod

sudo rm /var/lib/mongodb/journal/*
#設定によっては場所が違う場合もあるので注意

sudo vi /etc/mongod.conf
#(または、mongodb.conf)
#以下を追加
----------
journal=true
smallfiles=true
----------

sudo service mongod start

dfコマンドなどで容量がすくなくなっていればOK。

Android HUAWEI端末P8Liteで Logcatを動かす方法

HUAWEIのAndroid端末はデバッグモードにしても、ログ出力が制限されている模様。

(INFOログ以上は出力された)

通話アプリを起動して

*#*#2846579#*#*

とダイヤル。

「ProjectMenu」が表示されるので、1番の「Background Settings」を選択。

3番の「LOG Settings」を選択。

「AP Log」「CP Log」「Charge Log」「Sleep Log」のすべてをチェックしてCLOSE。

これで出力されるようになります。

Vagrantで良く使うコマンドメモ。

Vagrantで良く使うコマンドのまとめ。

box系

boxの追加

以下のコマンド。1.5以降BOXの名前のみで良くなりました。

$vagrant box add chef/centos-7.1

※chefとしていますが、chef入りのというのではなく、chefが作ってるBOXです。

※chef/ 以下にosを指定すると色々なものに対応しています。(centos-6.5等)

box一覧

$vagrant box list

box削除

$vagrant box remove [box名]

vm操作系

vm初期化

$vagrant init

vm起動

$vagrant up

※initしたときに作られたvagrantfileに各種設定(指定するboxなど)を書き込んでおく

vmへログイン

$vagrant ssh

windowsは使えない。以下の設定でteraterm等でログイン

host: 127.0.0.1
port: 2222
user: vagrant
password: vagrant
rootpass: vagrant

※公開鍵認証でもログイン可「[vagrant initしたフォルダ].vagrant\machines\default\virtualbox\」の「private_key」ファイルが秘密鍵

vmシャットダウン

$vagrant halt

vm削除

$vagrant destroy

KVMでHDDを追加する時のメモ

CentOSやRHL上で動かすKVMのHDD容量を追加する時の手順。

イメージファイルを増量

まずKVMを動かしているホスト機で、増やしたいVMのイメージを追加する。

$ qemu-img resize vmtest.img +10G

※vmtestというイメージに10G追加したい場合

fdiskでパーティションを増量

VM内にログインし、fdiskコマンドでdisk容量が増えているか確認。

$ssh vmtest
$fdisk -l
Disk /dev/vda: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e180d

Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       20806     9972736   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

この場合は元が10Gでさらに10G足したので無事増えているので、/dev/vdaのパーティションを区切ります。

$fdisk /dev/vda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
    switch off the mode (command 'c') and change display units to
    sectors (command 'u').

パーティション一覧を確認します。

Command (m for help): p
Disk /dev/vda: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e180d

Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       20806     9972736   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

パーティションが2つあるので、3つ目に新たに追加します。

Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 3

次にどこのcylinderから始めるかと聞かれるので、この場合は2つ目の最後20806から+1した20807を入力します。

First cylinder (1-41610, default 1): 20807
Last cylinder, +cylinders or +size{K,M,G} (20807-41610, default 41610): 41610

ラストはデフォルトの最後まででOKです。
またpコマンドで無事追加されたのを確認します。

Command (m for help): p

Disk /dev/vda: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e180d

Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       20806     9972736   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/vda3           20807       41610    10485216   83  Linux

3つ目の追加したパーティションもLVMにします。

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/vda: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e180d

Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       20806     9972736   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/vda3           20807       41610    10485216   8e  Linux LVM

無事変わったのを確認したらセーブして再起動します。

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
$reboot -h now

追加パーティションを物理Vol化&論理Vol拡張

再度VMに入り、追加パーティションを物理ボリューム化します。

$ssh vmtest
$pvcreate /dev/vda3
Physical volume "/dev/vda3" successfully created

追加されたか確認

$pvdisplay
--- Physical volume ---
PV Name               /dev/vda2
VG Name               vg_vmtestimg1
PV Size               9.51 GiB / not usable 3.00 MiB
Allocatable           yes (but full)
PE Size               4.00 MiB
Total PE              2434
Free PE               0
Allocated PE          2434
PV UUID               XCTuf9-07iA-iwnO-CAh0-QT0u-Temb-xymCGY

"/dev/vda3" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name               /dev/vda3
VG Name
PV Size               10.00 GiB
Allocatable           NO
PE Size               0
Total PE              0
Free PE               0
Allocated PE          0
PV UUID               EZN6pR-s8OX-SY1f-faQq-y7T2-VJAe-cnPxgB

VG名を取得

$vgdisplay
--- Volume group ---
VG Name               vg_vmtestimg1
System ID
Format                lvm2
Metadata Areas        1
Metadata Sequence No  3
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                2
Open LV               2
Max PV                0
Cur PV                1
Act PV                1
VG Size               9.51 GiB
PE Size               4.00 MiB
Total PE              2434
Alloc PE / Size       2434 / 9.51 GiB
Free  PE / Size       0 / 0
VG UUID               Wfi6Mw-tK8R-SZmH-xOBm-mmuq-1bmL-hFn40B

VGを拡張&確認

$vgextend vg_vmtestimg1 /dev/vda3
Volume group "vg_vmtestimg1" successfully extended
$vgdisplay
--- Volume group ---
VG Name               vg_vmtestimg1
System ID
Format                lvm2
Metadata Areas        2
Metadata Sequence No  4
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                2
Open LV               2
Max PV                0
Cur PV                2
Act PV                2
VG Size               19.50 GiB
PE Size               4.00 MiB
Total PE              4993
Alloc PE / Size       2434 / 9.51 GiB
Free  PE / Size       2559 / 10.00 GiB
VG UUID               Wfi6Mw-tK8R-SZmH-xOBm-mmuq-1bmL-hFn40B

論理ボリューム名を確認

$lvdisplay
--- Logical volume ---
LV Path                /dev/vg_vmtestimg1/lv_root
LV Name                lv_root
VG Name                vg_vmtestimg1
LV UUID                JtIgxT-mBPj-LO1H-Uc9u-13t3-1gwX-Y11UUR
LV Write Access        read/write
LV Creation host, time dev-pfortune-img1, 2015-09-08 07:16:27 +0900
LV Status              available
# open                 1
LV Size                8.51 GiB
Current LE             2178
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:0

論理ボリュームを追加

$lvextend -l +100%FREE /dev/vg_vmtestimg1/lv_root
Size of logical volume vg_vmtestimg1/lv_root changed from 8.51 GiB (2178 extents) to 18.50 GiB (4737 extents).
Logical volume lv_root successfully resized

$resize2fs /dev/vg_vmtestimg1/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_vmtestimg1/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/vg_vmtestimg1/lv_root to 4850688 (4k) blocks.
The filesystem on /dev/vg_vmtestimg1/lv_root is now 4850688 blocks long.

centos7の場合は resize2fsではなく、xfs_growfsで拡張を行う

$xfs_growfs /dev/vg_vmtestimg1/lv_root

容量をdfコマンドで確認

$df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/mapper/vg_vmtestimg1-lv_root
                    18968780 1115892  16889024   7% /
tmpfs                   961100       0    961100   0% /dev/shm
/dev/vda1               487652   73701    388351  16% /boot

追加されていれば無事終了です。

CentOS7のコマンドとか基本的な流儀

CentOS7を試していて、変わっていた基本の部分のメモ。

serviceのかわりにsystemctl

$systemctl start [サービス名]
$systemctl stop [サービス名]
$systemctl restart [サービス名]
$systemctl status [サービス名]

chkconfig on の代わり。

$systemctl enable [サービス名]

chkconfig off の代わり

$systemctl disable [サービス名]

動いてるサービス一覧

$systemctl list-units --type=service

iptablesのかわりにfirewalld

追加できるサービス一覧を確認

$firewall-cmd --get-services

httpを追加

$firewall-cmd --add-service=http --zone=public --permanent

httpsを追加

$firewall-cmd --add-service=https --zone=public --permanent

ホスト名変更

$sudo hostnamectl set-hostname 変更したいホスト名
$sudo reboot

ntpのかわりにchrony

chronyインストール

$sudo yum install chrony
$sudo vi /etc/chrony.conf
**↓上を↓下のように変更**
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
↓
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server ntp.nict.jp iburst

自動起動

$sudo systemctl enable chronyd.service

起動

$sudo systemctl start chronyd.service

同期チェック

$sudo chronyc sources

Cronがanacronになっている

これは非常駐型で指定範囲時間にランダムに実行されてしまうそうです。 CentOS6系のcronを引き続き使いたいときは、今入っているのを削除して新しくインストールする必要があります。

$sudo yum -y install cronie-noanacron
$sudo yum -y remove cronie-anacron