当前位置:网站首页>[教程]在 CoreOS 上构建你的第一个应用
[教程]在 CoreOS 上构建你的第一个应用
2022-07-03 17:48:00 【星哥玩云】
【编者的话】作者以自己的Mac笔记本为例,介绍了如何在CoreOS上安装WordPress应用,没有过多的理论解释,全部是实战类教程,推荐想快速了解CoreOS的同学阅读。
我相信你一定听说过CoreOS,但是你是否真正在它上面部署过一个应用了?可能很多人都没有部署过。在CoreOS上构建一个应用是非常困难且令人沮丧的(译者注:frustrating,用了这个词,看来确实难)。因为文档比较散乱,并且你不得不在开始之前学习所有相关的技术,包括etcd、systemd、Docker。如果你和我一样比较懒惰,只是想试试CoreOS而不想小题大做,那么让我来帮你吧。接下来我们将会在CoreOS上创建一个简单的WordPress应用以及MySQL数据库。
如果你使用的是Mac,可以通过安装命令行工具来控制CoreOS
fleetctl 和 etcdctl 是原生的控制CoreOS集群的工具,安装步骤如下:
- brew install go etcdctl git clone https://github.com/coreos/fleet.git
- $ cd fleet
- $ ./build
- $ mv bin/fleetctl /usr/local/bin/
安装一个本地的CoreOS集群,并运行
Vagrant是非常简单的。
- $ git clone https://github.com/CenturyLinkLabs/coreos-vagrant $ cd coreos-vagrant/cluster
- $ vagrant up --provision
现在你的笔记本上有一个由最小的3个CoreOS系统组成的集群。简单极了,现在让我们使用fleetctl来检查下。
- $ fleetctl list-machines MACHINE IP METADATA
- 09fd0a88...10.0.2.15-
- 77763947...10.0.2.15-
- f31c383c...10.0.2.15-
太棒了,跑起来了。
使用fleet在CoreOS集群上部署应用
现在你有一个CoreOS集群了。接下来fleetctl命令可以让你在CoreOS集群节点上部署应用,但要用fleet写服务文件。当然,不需要你自己来写。你可以用简单的YAML格式来生成服务(service)文件。
$ sudo gem install bundler fig2coreos
$ cat fig.yml-
- web:
- image: ctlc/wordpress
- ports:
- - 80:80
- environment:
- DB_USER: root
- DB_PASSWORD: qa1N76pWAri9
- links:
- - db
- db:
- image: ctlc/mysql
- ports:
- - 3306:3306
- environment:
- MYSQL_DATABASE: wordpress
- MYSQL_ROOT_PASSWORD: qa1N76pWAri9
-
- $ fig2coreos myapp fig.yml coreos-files
- $ cd coreos-files
- $ ls
- db-discovery.1.service
- db.1.service
- web-discovery.1.service
- web.1.service
fleetctl客户端工具使用etcd的键值存储来确定它要访问的服务器以及访问集群中有etcd服务端运行的服务器。下面是如何在CoreOS集群中部署你的应用。
$ fleetctl start db.1.service
$ fleetctl list-units
UNIT LOAD ACTIVE SUB DESC MACHINE
db.1.service loaded active running Run db_1 9c008961.../10.0.2.15
$ fleetctl start web.1.service
$ fleetctl list-units
UNIT LOAD ACTIVE SUB DESC MACHINE
db.1.service loaded active running Run db_1 9c008961.../10.0.2.15
web.1.service loaded active running Run web_1 9c008961.../10.0.2.15 现在你的程序运行起来了,但是服务还没有注册到etcd。幸运的是,fig2coreos已经为我们自动生成服务文件。
$ fleetctl start db-discovery.1.service
$ fleetctl start web-discovery.1.service
$ fleetctl list-units
UNIT LOAD ACTIVE SUB DESC MACHINE
db-discovery.1.service loaded active running Announce db_1 9c008961.../10.0.2.15
db.1.service loaded active running Run db_1 9c008961.../10.0.2.15
web-discovery.1.service loaded active running Announce web_1 9c008961.../10.0.2.15
web.1.service loaded active running Run web_1 9c008961.../10.0.2.15
$ etcdctl ls --recursive
/services
/services/web
/services/web/web_1
/services/db
/services/db/db_1
$ etcdctl get /services/web/web_1
{ "host": "core-03", "port": 80, "version": "52c7248a14" }
$ etcdctl get /services/db/db_1
{ "host": "core-03", "port": 3306, "version": "52c7248a14" }部署完成
就这样,搞定了。在Vagrant 1.5使用Vagrant Cloud账号,你可以访问你的WordPress应用。如下图:
$ cd ~/coreos-vagrant/cluster/找出哪个机器监听着你的80端口:
$ etcdctl get /services/web/web_1
{ "host": "core-03", "port": 80, "version": "52c7248a14" }
$ vagrant share core-03 --http 80==> core-03: Detecting network information for machine...
core-03: Local machine address: 192.168.65.2
core-03: Local HTTP port: 80
core-03: Local HTTPS port: disabled
==> core-03: Checking authentication and authorization...==> core-03: Creating Vagrant Share session...
core-03: Share will be at: quick-iguana-4689==> core-03: Your Vagrant Share is running! Name: quick-iguana-4689==> core-03: URL: http://quick-iguana-4689.vagrantshare.com结论
现在你可以用CoreOS做很多事情,但至少现在你已经做完基本的工作了,如果你打算在生产环境使用多主机的Coreos集群。需要你在系统中增加ambassador容器。事实上,你可以通过ambassador容器连接etc服务器,我们将会在下周发表另外一篇博文。
原文: http://newlabs.wpengine.com/building-your-first-app-on-coreos/ 作者: Lucas Carlson 译文: http://dockerone.com/article/66
边栏推荐
- Where is the monitoring page of RDS database?
- UE4 official charging resources, with a total price of several thousand
- Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026
- Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
- List的stream中Long对象与long判等问题记录
- (9) Opencv Canny edge detection
- Leetcode Valentine's Day Special - looking for a single dog
- [combinatorics] recursive equation (four cases where the non-homogeneous part of a linear non-homogeneous recursive equation with constant coefficients is the general solution of the combination of po
- BFS - topology sort
- [combinatorics] generating function (linear property | product property)
猜你喜欢

Hongmeng third training

Automata and automatic line of non-standard design

Five problems of database operation in commodity supermarket system

聊聊支付流程的设计与实现逻辑

Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026

PS screen printing brush 131, many illustrators have followed suit

Deops入门

Implementation of Tetris in C language

Golang单元测试、Mock测试以及基准测试

Micro service component sentinel console call
随机推荐
[combinatorics] generating function (linear property | product property)
Investigation on the operation prospect of the global and Chinese Anti enkephalinase market and analysis report on the investment strategy of the 14th five year plan 2022-2028
The difference between get and post
Hongmeng third training
[combinatorics] recursive equation (summary of the solution process of recursive equation | homogeneous | double root | non-homogeneous | characteristic root is 1 | exponential form | the bottom is th
As soon as we enter "remote", we will never regret, and several people will be happy and several people will be sad| Community essay solicitation
TCP congestion control details | 3 design space
What is the difference between cloud server and cloud virtual machine
1146_ SiCp learning notes_ exponentiation
Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
Records of long objects and long judgments in the stream of list
Luogu: p2685 [tjoi2012] Bridge
[vscode] convert tabs to spaces
AcWing 4489. 最长子序列
Remote office tools sharing | community essay solicitation
Inheritance of ES6 class
Where is the monitoring page of RDS database?
1164 Good in C
Kubernetes resource object introduction and common commands (4)
Embedded-c language-7