LoginSignup
1
1

More than 5 years have passed since last update.

[Cloud101]#1 VirtualBox + CentOSで仮想化体験

Last updated at Posted at 2016-04-18

0.AGENDA

  1. VirtualBox install

  2. centos-minimal VM install

    • yum update/upgradeは勉強会ではやらないので自宅で
  3. centosってなんだぁ?

    • OSってなんだぁ?
    • UnixやらLinuxやら
    • RedHatやらUbuntuやら
  4. VMとのファイルのやりとり

    • VirtualBox共有フォルダ機能はあえて使わず汎用的な方法で: ssh & sftp
  5. curlを使ってみよう

  6. CentOSでhttpサーバを感じてみよう

  7. 後片付け

1.VirtualBox install

  • まずは本家のサイト確認VirtualBox
    • このソフトはGPL version2 001_VirtualBox1.PNG



- 本当は:
- access to https://www.virtualbox.org/wiki/Downloads
- 自分の環境にあったインストーラをDL & Install

  • 勉強会では:  - USBメモリに20160417最新版があるのでそこからInstall :laughing:

2.centos-minimal VM install

(1) centos-minimalのDL

  • まずは本家サイトを確認CentOS 002_CentOS1.PNG




- 勉強会では:
- USBメモリに20160417最新版がある :laughing:

(2) VirtualBoxにcentos VM作成

↓これを参考に
http://www.kakiro-web.com/memo/virtualbox-create-virtual-machine.html

※ ストレージのサイズは10Gで(可変長なので最大値を設定)

(3)CentOS Install

↓これを参考に
http://www.kakiro-web.com/memo/centos-install.html

004_VMinstall1.PNG

  • 自分のアカウントを「管理者」にチェックを入れて作成 006_VMinstall3.PNG 007_VMinstall4.PNG



- VMが立ち上がったら作成したユーザでログイン
009_VMinstall6.PNG

(4) Networkの設定

↓これを参考に
http://www.kakiro-web.com/memo/centos-network-setting.html

  • その前に コマンドプロンプト'#' と'$'について
    • $は一般ユーザを表す
    • #はroot(特権ユーザ:昔はスーパーユーザって言いました)を表す
$su -
Password:  <rootのパスワード>
#

# nmcli connection modify enp0s3 connection.autoconnect yes
# systemctl restart network.service
# ip a で確認
# exit
$ ping www.iij.ad.jp

(5)最新化

  • 本当は; Installが終わったら最新化します
$sudo yum update
......途中で DISK消費とGPG Key Installを聞かれるの両方とも 'y'
$sudo yum upgrade
... 20160417時点では何もなく終了
  • 勉強会では: どちらも行わないので自宅でやって下さい :sweat_smile:

(6)確認

  • ホストから見ると・・・ 010_VMinstall7.PNG


  • VMってホスト上はファイルです
  • 011_VMinstall8.PNG

3.centosとは何か?(スミマセン、資料は手抜きです :sweat_smile:

(1)OSって何?

(2)Linuxって何?UNIXって何?

https://ja.wikipedia.org/wiki/Linux
https://ja.wikipedia.org/wiki/UNIX

(3)MS WindowsもOSです

(4)CentOSとは

$cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

4.VMとのファイルのやりとり

(1)Macの人

  • ターミナルからCentOS VMへのssh, sftpコマンドやってみる

(2)Windowsの人

  • Windowsの人はTeraTerm入れて (USBメモリに入ってます :smile:
  • TeraTermでのSSHアクセス確認
  • TeraTerm接続画面から、ファイル→'SSH SCP...'で scpやってみる

自宅でVirtualBoxの共有フォルダ機能をやってみたい人はここを参考に
http://pc-karuma.net/virtualbox-folder-share/

5.curlを使ってみよう(CentOS)

$which curl
/usr/bin/curl

$curl --help
Usage: curl [options...] <url>
Options: (H) means HTTP/HTTPS only, (F) means FTP only
     --anyauth       Pick "any" authentication method (H)
 -a, --append        Append to target file when uploading (F/SFTP)
....
  • 使ってみる (curlでWeb Siteアクセス)
$curl http://www.nagahisa.biz

$curl http://www.nagahisa.biz > hoge.html

6.CentOSでhttpサーバを感じてみよう

(1)ワンライナーWebサーバ

  • CentOS Minimalにはpythonが入っているので'python(SimpleHTTPServer)編'

(2)Port:8000

$python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
  • ホストのWebサーバからVMのアドレス・Port=8000でアクセス, ファイルはさっきのhoge.html

(例)http://192.168.3.2:8000/hoge.html

  • ワンライナーWeb SErver止めるときは "^C" (Ctrl + C)

(3)Port:80

$ python -m SimpleHTTPServer 80
Traceback (most recent call last):
...
socket.error: [Errno 13] Permission denied

$ sudo python -m SimpleHTTPServer 80
Serving HTTP on 0.0.0.0 port 80 ...
....
  • ホストのWebサーバからVMのアドレス, ファイルはさっきのhoge.html

(例)http://192.168.3.2/hoge.html

<おまけ>

  • 自分でhtmlファイルを作ってCentOSのWebサーバで公開&ホストブラウザで表示してみる
  • htmlファイル作成の参考 http://codecamp.jp/textbooks/
$cat << EOF > index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Webページを作成してみよう</title>
</head>
<body>
初めてのWebページ
</body>
</html>
EOF

$cat index.html
$sudo python -m SimpleHTTPServer 80
[sudo] password for kenzo:
Serving HTTP on 0.0.0.0 port 80 ...
....

7.後片付け

  • CentOSのShutdown
$ sudo shutdown -h now
  • VirtualBoxマネージャでCentOSが「電源オフ」になったことを確認

おしまい :tada:

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1