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
CentOS6.7でApache+FuelPHP+MongoDB環境を構築したメモ
結構つまづくところがあったので、備忘録的にメモします。
各種モジュールインストール
$sudo yum install gcc -y
$sudo yum install openssl-devel -y
※mongoのphpモジュールを入れるときコンパイルするので必要になります。
mongodbのリポジトリ追加
$sudo vi /etc/yum.repos.d/mongodb.repo
**以下を入力**
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
mongodbインストール
$sudo yum install -y mongodb-org
$sudo service mongod start
$sudo chkconfig mongod on
apacheインストール
$sudo yum install httpd -y
phpインストール
$sudo yum install php php-pear php-devel php-pdo php-dom php-mbstring -y
mongoPHPライブラリインストール
$sudo pecl install mongo
※ここでつまづきやすい。gccとopenssl-develをちゃんと入れる。何か聞かれてもデフォルトでOK
php.ini設定
$sudo vi /etc/php.ini
**以下を入力or変更**
extension=mongo.so
[中略]
date.timezone= Asia/Tokyo
[中略]
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_input = UTF-8
mbstring.http_output = pass
mbstring.encoding_translation = On
apache vhosts設定
$sudo vi /etc/httpd/conf.d/vhosts.conf
**以下を入力**
<VirtualHost *:80>
DocumentRoot /var/www/html/fuelphp/public
ErrorLog logs/fuelphp_error.log
CustomLog logs/fuelphp_access.log combined
SetEnv FUEL_ENV development
<Directory /var/www/html/fuelphp/public>
DirectoryIndex index.php
AllOwoverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
※「SetEnv FUEL_ENV」の所は環境ごとにわける。development,production等。公式のドキュメント参照
Fuelphp設置
公式サイトからダウンロードし、展開。 フォルダ名を「fuelphp」に変更。 「fuelphp」フォルダを/var/www/html/下に設置 「public/.htaccess」の以下の行をコメントアウト
#Options +FollowSymLinks -Indexes
「fuel/app/config/config.php」の該当箇所を以下のように変更。
/**
* Localization & internationalization settings
*/
'language' => 'ja', // Default language
// 'language_fallback' => 'en', // Fallback language when file isn't available for default language
'locale' => 'ja_JP.UTF-8', // PHP set_locale() setting, null to not set
[中略]
/**
* DateTime settings
*
* server_gmt_offset in seconds the server offset from gmt timestamp when time() is used
* default_timezone optional, if you want to change the server's default timezone
*/
// 'server_gmt_offset' => 0,
'default_timezone' => 'Asia/Tokyo',
設置確認
http://localhost/
にアクセスして、welcome画面が表示されれば完了。
MapKitでMKMapViewを表示し、任意の場所にピンを立てる。
MapKitの使い方で少々苦労したのでメモ
まず、「Linked Frameworks and Libraries」というところに「MapKit.framework」を追加。
(xcodeの「Build Settings」などが選択できるページの「General」タブの下部にある)
MainViewController.m
#import <MapKit/MapKit.h> @interface MainViewController ()<MKMapViewDelegate> @property (storng, nonatomic)MKMapView *mapView @end @implementation MainViewController - (id)init { self = [super init]; if (self) { } return self; } -(void)viewDidLoad { //Map表示(画面いっぱい) //大きさを指定して初期化 self.mapView = [[MKMapView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; self.mapView.delegate = self; [self.view addSubview:self.mapView]; //緯度と経度を設定(これは東京タワー) double latitude = 35.65858; double longitude = 139.745433; //Mapの表示を指定 MKCoordinateRegion region = self.mapView.region; region.span.latitudeDelta = 0.05; //緯度の倍率 region.span.longitudeDelta = 0.05; //経度の倍率 region.center = CLLocationCoordinate2DMake(latitude, longitude); //表示位置の緯度と経度 [self.mapView setRegion:region animated:YES]; //Pin表示 MKPointAnnotation *annotation = [[MKPointAnnotation alloc]init]; annotation.coordinate = CLLocationCoordinate2DMake(latitude, longitude); //ピンをたてる位置を指定 [self.mapView addAnnotation:annotation]; } @end
MKMapViewを理解する上で大事なのが、
MKCoordinateRegionとMKPointAnnotation。
ほかのUIパーツのようにパーツそのもののプロパティに色々設定するのではなく、
mapviewはただ表示だけさせる。
regionというオブジェクトでどの位置に表示させて、倍率等をどうするか指定。
pinはannotationというオブジェクトで位置などを指定。
それぞれをmapviewにセットする。
絶対に挫折しない iPhoneアプリ開発「超」入門【iOS7対応】増補改訂版
- 作者: 高橋京介
- 出版社/メーカー: SBクリエイティブ
- 発売日: 2014/01/28
- メディア: 大型本
- この商品を含むブログを見る