stgraber@dakara:~$ sudo apt install juju Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: juju-2.0 Suggested packages: juju-core The following NEW packages will be installed: juju juju-2.0 0 upgraded, 2 newly installed, 0toremoveand0 not upgraded. Need toget39.7 MB of archives. After this operation, 269 MB of additional disk space will be used. Do you want tocontinue? [Y/n] Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 juju-2.0 amd64 2.0~beta7-0ubuntu1.16.04.1 [39.6 MB] Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 juju all2.0~beta7-0ubuntu1.16.04.1 [9,556 B] Fetched 39.7 MB in 0s (53.4 MB/s) Selecting previously unselected package juju-2.0. (Reading database ... 255132filesand directories currently installed.) Preparing to unpack .../juju-2.0_2.0~beta7-0ubuntu1.16.04.1_amd64.deb ... Unpacking juju-2.0 (2.0~beta7-0ubuntu1.16.04.1) ... Selecting previously unselected package juju. Preparing to unpack .../juju_2.0~beta7-0ubuntu1.16.04.1_all.deb ... Unpacking juju (2.0~beta7-0ubuntu1.16.04.1) ... Processing triggers for man-db (2.7.5-1) ... Setting up juju-2.0 (2.0~beta7-0ubuntu1.16.04.1) ... Setting up juju (2.0~beta7-0ubuntu1.16.04.1) ...
stgraber@dakara:~$ juju bootstrap localhost test Creating Juju controller "local.test" on localhost/localhost Bootstrapping model "admin" Starting new instance for initial controller Launching instance - juju-745d1be3-e93d-41a2-80d4-fbe8714230dd-machine-0 Installing Juju agent on bootstrap instance Preparing for Juju GUI 2.1.2release installation Waiting for address Attempting toconnectto10.178.150.72:22 Logging to /var/log/cloud-init-output.logon remote host Running apt-getupdate Running apt-get upgrade Installing package: curl Installing package: cpu-checker Installing package: bridge-utils Installing package: cloud-utils Installing package: cloud-image-utils Installing package: tmux Fetching tools: curl -sSfw 'tools from %{url_effective} downloaded: HTTP %{http_code}; time %{time_total}s; size %{size_download} bytes; speed %{speed_download} bytes/s '--retry 10 -o $bin/tools.tar.gz <[https://streams.canonical.com/juju/tools/agent/2.0-beta7/juju-2.0-beta7-xenial-amd64.tgz]> Bootstrapping Juju machine agent Starting Juju machine agent (jujud-machine-0) Bootstrap agent installed Waiting for API to become available: upgrade in progress (upgrade in progress) Waiting for API to become available: upgrade in progress (upgrade in progress) Waiting for API to become available: upgrade in progress (upgrade in progress) Bootstrap complete, local.test now available.
这会花费一点时间,这时你可以看到一个正在运行的一个新的 LXD 容器:
1 2 3 4 5 6 7
stgraber@dakara:~$ lxc list juju- +-----------------------------------------------------+---------+----------------------+------+------------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +-----------------------------------------------------+---------+----------------------+------+------------+-----------+ | juju-745d1be3-e93d-41a2-80d4-fbe8714230dd-machine-0 | RUNNING | 10.178.150.72 (eth0) | | PERSISTENT | 0 | +-----------------------------------------------------+---------+----------------------+------+------------+-----------+
在 Juju 这边,你可以确认它是有响应的,并且还没有服务运行:
1 2 3 4 5 6 7 8 9 10
stgraber@dakara:~$ juju status [Services] NAMESTATUS EXPOSED CHARM
[Units] ID WORKLOAD-STATUS JUJU-STATUS VERSION MACHINE PORTS PUBLIC-ADDRESS MESSAGE
[Machines] ID STATE DNS INS-ID SERIES AZ
你也可以在浏览器中访问 Juju 的 GUI 界面:
1 2 3 4 5
stgraber@dakara:~$ juju gui Opening the Juju GUI in your browser. If it does not open, openthis URL: https://10.178.150.72:17070/gui/97fa390d-96ad-44df-8b59-e15fdcfc636b/
stgraber@dakara:~$ juju deploy cs:~charmers/bundle/web-infrastructure-in-a-box added charm cs:~hp-discover/trusty/node-app-1 service api deployed (charm cs:~hp-discover/trusty/node-app-1withthe series "trusty" defined bythe bundle) annotations setfor service api added charm cs:trusty/mongodb-3 service mongodb deployed (charm cs:trusty/mongodb-3withthe series "trusty" defined bythe bundle) annotations setfor service mongodb added charm cs:~hp-discover/trusty/nginx-4 service nginx deployed (charm cs:~hp-discover/trusty/nginx-4withthe series "trusty" defined bythe bundle) annotations setfor service nginx added charm cs:~hp-discover/trusty/nginx-proxy-3 service nginx-proxy deployed (charm cs:~hp-discover/trusty/nginx-proxy-3withthe series "trusty" defined bythe bundle) annotations setfor service nginx-proxy added charm cs:~hp-discover/trusty/website-3 service website deployed (charm cs:~hp-discover/trusty/website-3withthe series "trusty" defined bythe bundle) annotations setfor service website related mongodb:database and api:mongodb related website:nginx-engine and nginx:web-engine related api:website and nginx-proxy:website related nginx-proxy:website and website:website added api/0 unit tonew machine added mongodb/0 unit tonew machine added nginx/0 unit tonew machine added nginx-proxy/0 unit tonew machine deployment of bundle "cs:~charmers/bundle/web-infrastructure-in-a-box-10" completed
[Machines] ID STATE DNS INS-ID SERIES AZ 2 started 10.178.150.98 juju-97fa390d-96ad-44df-8b59-e15fdcfc636b-machine-2 trusty 3 started 10.178.150.29 juju-97fa390d-96ad-44df-8b59-e15fdcfc636b-machine-3 trusty 4 started 10.178.150.202 juju-97fa390d-96ad-44df-8b59-e15fdcfc636b-machine-4 trusty 5 started 10.178.150.214 juju-97fa390d-96ad-44df-8b59-e15fdcfc636b-machine-5 trusty
stgraber@dakara:~$ juju destroy-controller test --destroy-all-models WARNING! This command will destroy the "local.test" controller. This includes all machines, services, data and other resources.
Continue [y/N]? y Destroying controller Waiting for hosted model resources to be reclaimed Waiting on 1 model, 4 machines, 5 services Waiting on 1 model, 4 machines, 5 services Waiting on 1 model, 4 machines, 5 services Waiting on 1 model, 4 machines, 5 services Waiting on 1 model, 4 machines, 5 services Waiting on 1 model, 4 machines, 5 services Waiting on 1 model, 4 machines Waiting on 1 model, 4 machines Waiting on 1 model, 4 machines Waiting on 1 model, 4 machines Waiting on 1 model, 4 machines Waiting on 1 model, 4 machines Waiting on 1 model, 2 machines Waiting on 1 model Waiting on 1 model All hosted models reclaimed, cleaning up controller machines
我们用下面的方式确认:
1 2 3 4 5
stgraber@dakara:~$ lxc list juju- +------+-------+------+------+------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +------+-------+------+------+------+-----------+
总结
Juju 2.0 内置的 LXD 支持使得可以用一种非常干净的方式来测试各种服务。
在 Juju charm store 中有很多预制的“组合”可以用来部署,甚至可以用多个“charm”来组合你想要的架构。
Juju 与 LXD 是一个完美的解决方案,从一个小的 Web 服务到大规模的基础设施都可以简单开发,这些都在你自己的机器上,并且不会在你的系统上造成混乱!