2017年12月4日 星期一

Create LXC Virtual Machine on AWS Ubuntu 16 Container



更新系統套件

ubuntu@ip-172-31-16-58:~$ sudo apt-get update
Hit:1 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:3 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Get:4 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial/main Sources [868 kB]
Get:5 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial/restricted Sources [4,808 B]
:::

Get:38 http://security.ubuntu.com/ubuntu xenial-security/multiverse Translation-en [1,336 B]
Fetched 24.5 MB in 4s (5,661 kB/s)
Reading package lists... Done

ubuntu@ip-172-31-16-58:~$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  curl dnsmasq-base dpkg klibc-utils libcurl3-gnutls libdb5.3 libklibc libpython3.5 libpython3.5-minimal
  libpython3.5-stdlib lxcfs python3.5 python3.5-minimal
13 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 9,338 kB of archives.
After this operation, 21.5 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y

安裝LXC core model

ubuntu@ip-172-31-16-58:~$ sudo apt-get install lxc
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  bridge-utils cloud-image-utils debootstrap distro-info genisoimage libaio1 libboost-iostreams1.58.0
  libboost-random1.58.0 libboost-system1.58.0 libboost-thread1.58.0 libiscsi2 libnspr4 libnss3 libnss3-nssdb
  libpam-cgfs librados2 librbd1 lxc-templates lxc1 python3-lxc qemu-block-extra qemu-utils sharutils
Suggested packages:
  cloud-utils-euca shunit2 wodim cdrkit-doc qemu-user-static lxctl bsd-mailx | mailx
The following NEW packages will be installed:
  bridge-utils cloud-image-utils debootstrap distro-info genisoimage libaio1 libboost-iostreams1.58.0
  libboost-random1.58.0 libboost-system1.58.0 libboost-thread1.58.0 libiscsi2 libnspr4 libnss3 libnss3-nssdb
  libpam-cgfs librados2 librbd1 lxc lxc-templates lxc1 python3-lxc qemu-block-extra qemu-utils sharutils
0 upgraded, 24 newly installed, 0 to remove and 0 not upgraded.
Need to get 6,843 kB of archives.
After this operation, 26.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y

Check LXC 虛擬主機範本有那些

ubuntu@ip-172-31-16-58:~$ ll /usr/share/lxc/templates
total 412
drwxr-xr-x 2 root root  4096 Dec  5 07:08 ./
drwxr-xr-x 6 root root  4096 Dec  5 07:08 ../
-rwxr-xr-x 1 root root 13042 Jun 14 20:15 lxc-alpine*
-rwxr-xr-x 1 root root 13737 Jun 14 20:15 lxc-altlinux*
-rwxr-xr-x 1 root root 11156 Jun 14 20:15 lxc-archlinux*
-rwxr-xr-x 1 root root 11649 Jun 14 20:15 lxc-busybox*
-rwxr-xr-x 1 root root 29725 Jun 14 20:15 lxc-centos*
-rwxr-xr-x 1 root root 10374 Jun 14 20:15 lxc-cirros*
-rwxr-xr-x 1 root root 20171 Jun 14 20:15 lxc-debian*
-rwxr-xr-x 1 root root 18197 Jun 14 20:15 lxc-download*
-rwxr-xr-x 1 root root 49693 Jun 14 20:15 lxc-fedora*
-rwxr-xr-x 1 root root 28259 Jun 14 20:15 lxc-gentoo*
-rwxr-xr-x 1 root root 13849 Jun 14 20:15 lxc-openmandriva*
-rwxr-xr-x 1 root root 15910 Jun 14 20:15 lxc-opensuse*
-rwxr-xr-x 1 root root 41596 Jun 14 20:15 lxc-oracle*
-rwxr-xr-x 1 root root 11463 Jun 14 20:15 lxc-plamo*
-rwxr-xr-x 1 root root 19096 Jun 14 20:15 lxc-slackware*
-rwxr-xr-x 1 root root 26667 Jun 14 20:15 lxc-sparclinux*
-rwxr-xr-x 1 root root  6822 Jun 14 20:15 lxc-sshd*
-rwxr-xr-x 1 root root 25703 Jun 14 20:15 lxc-ubuntu*
-rwxr-xr-x 1 root root 11734 Jun 14 20:15 lxc-ubuntu-cloud*

建立LXC Virtual Machine

ubuntu@ip-172-31-16-58:~$ sudo lxc-create -t ubuntu -n myBig1
:::
  en_US.UTF-8... done
Generation complete.
Creating SSH2 RSA key; this may take some time ...
2048 SHA256:KYqB7UzN+QbBtdS0+MrWd0ei6Tl3ho0TppBVoQz+uuw root@ip-172-31-16-58 (RSA)
Creating SSH2 DSA key; this may take some time ...
1024 SHA256:241q0S+tE2CVTJ1el8UiZ3rkqAw9YIxdUaMOm8qTpOE root@ip-172-31-16-58 (DSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:LZ5vr5pi/8CNPFPW8IPGYmoH7tcJ7Ih7idF6bKfltUk root@ip-172-31-16-58 (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:cfF3FfPC2G4zI7Xz/d1wHntIVijYQcJdISrxiuGAyHs root@ip-172-31-16-58 (ED25519)
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.

Current default time zone: 'Etc/UTC'
Local time is now:      Tue Dec  5 07:23:42 UTC 2017.
Universal Time is now:  Tue Dec  5 07:23:42 UTC 2017.


##
# The default user is 'ubuntu' with password 'ubuntu'!
# Use the 'sudo' command to run tasks as root in the container.
##

顯示VM的目錄內容

ubuntu@ip-172-31-16-58:~$ sudo tree -L 2 /var/lib/lxc
/var/lib/lxc
└── myBig1
    ├── config
    └── rootfs

Start and Stop Container VM

ubuntu@ip-172-31-16-58:~$ sudo lxc-start -n myBig1
lxc-start: tools/lxc_start.c: main: 301 Container is already running.
ubuntu@ip-172-31-16-58:~$ sudo lxc-stop -n myBig1

複製 LXC VM
ubuntu@ip-172-31-16-58:~$ sudo lxc-clone -o myBig1 -n myBig1_Backup
lxc-clone is deprecated in favor of lxc-copy.

Created container myBig1_Backup as copy of myBig1

ubuntu@ip-172-31-16-58:~$ sudo lxc-destroy -n myBig1_Backup (刪除 LXC VM)

ubuntu@ip-172-31-16-58:~$ sudo tree -L 2 /var/lib/lxc
/var/lib/lxc
├── myBig1
│   ├── config
│   └── rootfs
└── myBig1_Backup
    ├── config
    └── rootfs

4 directories, 2 files






沒有留言:

張貼留言

check_systemv1.1

 check_systemv1.1.bat 可用於電腦資產盤點 @echo off REM 後續命令使用的是:UTF-8編碼 chcp 65001 echo ***Thanks for your cooperation*** echo ***感謝你的合作*** timeout 1...