「[[.NET 開発基盤部会 Wiki>http://dotnetdevelopmentinfrastructure.osscons.jp]]」は、「[[Open棟梁Project>https://github.com/OpenTouryoProject/]]」,「[[OSSコンソーシアム .NET開発基盤部会>https://www.osscons.jp/dotNetDevelopmentInfrastructure/]]」によって運営されています。 -[[戻る>Linuxを触ってみる。]] *目次 [#g71bdd61] #contents *概要 [#j38b756d] Linuxを触りたかったので、SHIRASAGIハンズオンの開発環境準備をしてみた。 *開発環境の準備 [#g8233374] 以下を参考にして、開発環境を準備する。 -シラサギハンズオン in 広島(10月20日)を開催します。 - SHIRASAGI公式サイト~ http://www.ss-proj.org/news/510.html --shirasagi/ss-vagrant: SHIRASAGI Vagrant Boxes~ https://github.com/shirasagi/ss-vagrant -SHIRASAGIハンズオンの開発環境は、Vagrant + VirtualBoxで準備する。 --Vagrant + VirtualBoxでWindows上に開発環境をサクッと構築する - Qiita~ http://qiita.com/ozawan/items/160728f7c6b10c73b97e **インストール [#r077ebb4] ***64ビット Windows [#bb30bc4d] 私はWin 10 proを用意しました。 ***VirtualBoxをインストール [#wb56dafe] -VirtualBox~ Oracle社のホストOS型の仮想マシン。 -インストール --Downloads – Oracle VM VirtualBox~ https://www.virtualbox.org/wiki/Downloads -注意 --Hyper-V とは同居できない。 --default VM folder を日本語を含まないディレクトリにする。~ 参考: incompatible character encodings: CP850 and Windows-1252 ***Vagrantをインストール [#r63595ff] >※ SHIRASAGI開発環境として、動作確認のとれた vagrant バージョンをインストールする。 --2017/9時点で、1.9.2が動作確認のとれた最新verだったので、こちらを使用。 --shirasagi/ss-vagrant: SHIRASAGI Vagrant Boxes~ https://github.com/shirasagi/ss-vagrant -Vagrant --仮想マシンの構築・管理のコマンドラインツール。 --Rubyで実装されていて、Windows、Mac OS X、Linuxで動作する。 --VirtualBoxをはじめとする仮想マシンやChefやSalt、Puppet~ といった構成管理ソフトウェアのラッパーとみなすこともできる。 --Vagrantを用いると、構成情報を記述した設定ファイルを元に、~ 仮想マシンの構築から設定までを自動的に行うことができる。 -インストール --Download - Vagrant by HashiCorp~ https://www.vagrantup.com/downloads.html ---download older versions of Vagrant~ https://releases.hashicorp.com/vagrant/?_ga=2.4413811.1171751550.1506390923-1670425373.1506390923 -注意 --ユーザ名に日本語が含まれる場合、Vagrant が起動しない場合がある。 --環境変数 AGRANT_HOME を日本語を含まないディレクトリに設定する。 --Vagrant up 時に次のエラーが表示される場合、 An error occurred while downloading the remote file. The error message, if any, is reproduced below. Please fix this error and try again. 以下をインストールする(2 つともインストール) ---Microsoft Visual C++ 2010 再頒布可能パッケージ (x86)~ https://www.microsoft.com/ja-jp/download/details.aspx?id=5555 ---Microsoft Visual C++ 2010 再頒布可能パッケージ (x64)~ https://www.microsoft.com/ja-jp/download/details.aspx?id=14632 ***Tera Termをインストール [#sbf141e6] Tera Term などの SSH クライアントが必要。 -Tera Term --SSH・telnet・シリアルの各通信プロトコルに対応したリモートログオンクライアント --Microsoft Windowsで使用できる。 -インストール --Tera Term (テラターム) プロジェクト日本語トップページ - OSDN~ https://ja.osdn.net/projects/ttssh2/ ---Tera Term のインストール方法 - Tera Term - OSDN~ https://ja.osdn.net/projects/ttssh2/howto/install **開発環境の構築 [#vb5eb532] Vagrantによる環境設定 ***Vagrantfileというファイルを作成 [#oc1f5c58] Vagrantfile は Ruby の簡単な変数代入で書かれている。~ 公式にも「Rubyの知識は必要ない」と書いてある。 -パス c:\shirasagi-dev\Vagrantfile -内容 Vagrant.configure(2) do |config| config.vm.box = "ss-vagrant-v1.6.0-rc" config.vm.box_url = "https://github.com/shirasagi/ss-vagrant/releases/download/v1.6.0-rc/ss-vagrant-virtualbox-x86_64.box" config.vm.network :forwarded_port, guest: 3000, host: 3000 config.vm.network "private_network", ip: "192.168.33.10" config.vm.network "private_network", ip: "192.168.33.11" config.vm.network "private_network", ip: "192.168.33.12" config.vm.provider :virtualbox do |vb| # see: http://blog.shibayu36.org/entry/2013/08/12/090545 # IPv6 と DNS でのネットワーク遅延対策で追記 vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"] vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"] end end ***Vagrantを使用し開発環境を起動 [#q39f97fd] -[[上記のVagrantfileのカレント・ディレクトリ>#oc1f5c58]]にcdして、以下のコマンドを実行する。 >vagrant up -以下のような表示がされるので、暫く待つ。 Bringing machine 'default' up with 'virtualbox' provider... ==> default: Box 'ss-vagrant-v1.6.0-rc' could not be found. Attempting to find and install... default: Box Provider: virtualbox default: Box Version: >= 0 ==> default: Box file was not detected as metadata. Adding it directly... ==> default: Adding box 'ss-vagrant-v1.6.0-rc' (v0) for provider: virtualbox default: Downloading: https://github.com/shirasagi/ss-vagrant/releases/download/v1.6.0-rc/ss-vagrant-virtualbox-x86_64.box default: Progress: nn% (Rate: nnnnk/s, Estimated time remaining: n:nn:nn) -設定が進むので色々と許可する。 ==> default: Successfully added box 'ss-vagrant-v1.6.0-rc' (v0) for 'virtualbox'! ==> default: Importing base box 'ss-vagrant-v1.6.0-rc'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: shirasagi-dev_default_1506394717167_57655 ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly default: Adapter 3: hostonly default: Adapter 4: hostonly ==> default: Forwarding ports... default: 3000 (guest) => 3000 (host) (adapter 1) default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Running 'pre-boot' VM customizations... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key -[[default: SSH auth method: private key から先に進まない。>#x0c6d654]] Timed out while waiting for the machine to boot. This means that Vagrant was unable to communicate with the guest machine within the configured ("config.vm.boot_timeout" value) time period. If you look above, you should be able to see the error(s) that Vagrant had when attempting to connect to the machine. These errors are usually good hints as to what may be wrong. If you're using a custom box, make sure that networking is properly working and you're able to connect to the machine. It is a common problem that networking isn't setup properly in these boxes. Verify that authentication configurations are also setup properly, as well. If the box appears to be booting properly, you may want to increase the timeout ("config.vm.boot_timeout") value. --問題を分析するために、GUIモードを有効にする(以下をVagrantfileに追加)~ vb.gui = true ---Vagrant で仮想ウィンドウを GUI モードで起動する設定 | WEB ARCH LABO~ https://weblabo.oscasierra.net/vagrant-vb-gui/ >仮想マシンを起動した際に仮想ウィンドウを表示する場合、GUI モードで起動する。 --以下のコマンドを再実行する。 >vagrant up -以下、試行錯誤 --VirtualBoxのコンソールを開いたら、設定に問題がある旨が表示されていたので修正。 >[ディスプレイ] ---> [リモートディスプレイ] ---> [サーバーを有効化]のチェックをオフ --仮想ウィンドウに「This kernel requires an x86-64 CPU, but only detected an i686 CPU.」が表示される。 ---物理マシンのBIOS設定の[Virtualization Technology] を有効にする必要がある。 >Notebook PC シリーズ - BIOS で [Virtualization Technology] を有効にするには~ https://h20628.www2.hp.com/km-ext/content-webapp/document?docId=emr_na-c03836690 ---VirtualBoxの [一般] -> [基本] -> [バージョン] から [Red Hat (64-bit)] を選択。 >VirtualBoxでゲストOSを起動すると「This kernel requires an x86-64 CPU, but only detected an i686 CPU.~ Unable to boot - please use a kernel appropriate for your CPU.」エラー - 日々精進~ http://anton0825.hatenablog.com/entry/20140510/1407818313 -無事、問題をクリアした。 default: SSH auth method: private key default: Warning: Remote connection disconnect. Retrying... default: Warning: Remote connection disconnect. Retrying... default: Warning: Remote connection disconnect. Retrying... default: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: Inserting generated public key within guest... default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Configuring and enabling network interfaces... ==> default: Mounting shared folders... default: /vagrant => C:/shirasagi-dev ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==> default: flag to force provisioning. Provisioners marked to run always will still run. **開発環境への接続 [#ue6a8f03] ***仮想ウィンドウで接続 [#la4207d5] GUIモードが有効な場合、仮想ウィンドウを使用できる。 ***Tera Termで接続 [#u87e416c] 以下からTera Termで接続する。 -Windows用定番SSHクライアント「Tera Term」の使い方 | OSDN Magazine~ https://mag.osdn.jp/09/02/02/0412259 -接続情報 host: 192.168.33.10 port: 22 ***共通 [#ee4fe43b] -ログイン user: vagrant password: vagrant -SHIRASAGI を起動 $ cd $HOME/shirasagi $ bundle exec rake unicorn:start bundle exec unicorn_rails -c /var/www/shirasagi/config/unicorn.rb -E production -D --「:」入力ができなくて、微妙にハマったり。 ---CentOS で キーボード配列が日本語106じゃない場合の対処方法 - 知識の引き出し~ http://catnapper-mar.hatenablog.com/entry/20110929/1317317106 -ホストOSからブラウザで "http://localhost:3000/" にアクセスすると、SHIRASAGIのCMSサイトにアクセスできる。 >これは、ポートフォワーディングでホスト:3000からゲスト:3000(Web Server)に接続しているため。 **Windows の共有フォルダにマウント [#q7be7a98] Windows 版 Vagrant Box の共有ファイルは非常に遅く、~ Windows の共有フォルダを使った方が、 早くて快適なので、~ 必要に応じてWindows の共有フォルダにマウントする。 ***CIFSをインストール [#wd3327ef] -以下コマンドで、CIFSをインストールする。 $ yum -y install cifs-utils -以下のように表示されたら、 Loaded plugins: fastestmirror You need to be root to perform this command. -以下を実行してroot権限を要求しパスワードを再入力。 --yumができません~ http://kajuhome.com/patio_thread/1557.shtml -再度、CIFSをインストールする。 ***Windowsの共有フォルダを作成 [#q9a3abfb] -Windows 側で開発ディレクトリを www という名前で作成・共有 -Microsoftアカウントでないローカルアカウントを作成して、~ 共有フォルダとNTFSの両方にアクセス許可を与えておく。 ***共有フォルダをマウント [#d8529408] -以下コマンドで、Windowsの共有フォルダをマウントする。~ ユーザー名(user=xxxxx)は環境に合わせて変更する。 $ sudo mkdir -p /var/www $ sudo mount -t cifs -o user=xxxxx //10.0.2.2/www /var/www Password for aaa@//10.0.2.2/www: ******* >ちなみに、10.0.2.2は、VirtualBoxのゲストOSからホストOSにアクセスするIP。 -以下のように表示されたら、 mount error(112): Host is down Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) --FW設定などを疑ってみる。 --私の場合は、SMB1.0が無効になっていたため、version指定が必要だった。 $ sudo mount -t cifs -o user=aaa,vers=2.0 //10.0.2.2/www /var/www ***マウントの確認 [#e9a17f03] 以下コマンドで、マウントできたかどうかを確認できる。 -dfコマンド $ df Filesystem 1K-blocks Used Available Use% Mounted on ・・・ //10.0.2.2/www 248540444 132646056 115894388 54% /var/www -treeコマンド $ tree -L 2 /var/www /var/www 0 directories, 0 files *動作確認 [#oca13b69] 以下のサイトに接続可能かどうか確認する。 **自治体サンプルサイト [#z4aa0fd5] http://localhost:3000/ **企業サンプルサイト [#t9938139] http://192.168.33.10:3000/ **子育て支援サンプルサイト [#u8347af9] http://192.168.33.11:3000/ **オープンデータサンプルサイト [#b793c158] http://192.168.33.12:3000/ **LPサンプルサイト [#z44327a2] http://192.168.33.13:3000/ **グループウェア [#r8bd7d01] http://localhost:3000/.g1 **管理画面 [#n1c3a3ce] http://localhost:3000/.mypage *参考 [#u3f6b1d1] **VirtualBox [#kc208c8c] -VirtualBox - Wikipedia~ https://ja.wikipedia.org/wiki/VirtualBox -ASCII.jp:ホストOS型とハイパーバイザ型の違いを知る~ (4/5)|すっきりわかった!仮想化技術~ http://ascii.jp/elem/000/000/414/414625/index-4.html -仮想マシンから抜ける方法 - Eiji James Yoshidaの記録~ http://d.hatena.ne.jp/EijiYoshida/20140625/1403689016 **Vagrant [#rcf14e2e] -Vagrant by HashiCorp~ http://www.vagrantup.com/ -Vagrant (ソフトウェア) - Wikipedia~ https://ja.wikipedia.org/wiki/Vagrant_(%E3%82%BD%E3%83%95%E3%83%88%E3%82%A6%E3%82%A7%E3%82%A2) -Vagrantの重要ファイル「Vagrantfile」の読み込みと~ その周りの挙動をちょっと細かく追ってみた - 圧倒亭グランパのブログ~ http://at-grandpa.hatenablog.jp/entry/2013/10/01/015501 **Tera Term [#p477ea18] -Tera Term - Wikipedia~ https://ja.wikipedia.org/wiki/Tera_Term ** default: SSH auth method: private key [#x0c6d654] から先に進まない。ググると色々出てくる。 から先に進まない。ググると色々出てくるが、~ 平たく言って、諸事情によりOSが起動していないケースが多い。 -Vagrant 起動時に SSH auth method: private key で止まる - Qiita~ http://qiita.com/nagomu/items/67f046d3cf2a02b0efb0 -Vagrant up “SSH auth method: private key”から進まない – KeruuWeb~ http://keruuweb.com/vagrant-up-ssh-auth-method-private-key%E3%81%8B%E3%82%89%E9%80%B2%E3%81%BE%E3%81%AA%E3%81%84/ **シラサギハンズオン in 広島 [#n102fec6] -シラサギハンズオン in 広島 - connpass~ https://connpass.com/event/67009/ -シラサギハンズオン in 広島(10月20日)開催報告 - SHIRASAGI公式サイト~ http://www.ss-proj.org/news/536.html ***懇親会 候補 [#q854c41e] -鉄ぱん屋 弁兵衛 八丁堀店- 広島流お好み焼き・鉄板料理の旨い店 -~ http://www.benbe.jp/hatchobori/ -店舗紹介【流川店】|お好み焼・鉄板焼 ちんちくりん~ http://www.chinchikurin.com/shop/nagarekawa/ -和食酒家 あんべぇ(八丁堀・幟町/居酒屋) | ホットペッパーグルメ~ https://www.hotpepper.jp/strJ000830901/ で、実際は、 -黒豚しゃぶ 四季菜食 えびす坐(和食)<ネット予約可> | ホットペッパーグルメ~ https://www.hotpepper.jp/strJ000028342/ でやった。