当前位置:网站首页>[教程]在 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
边栏推荐
- Graduation summary
- ArrayList分析3 : 删除元素
- TensorBoard快速入门(Pytorch使用TensorBoard)
- Write a program to process a list container of string type. Find a special value in the container 9.27: and delete it if found. Rewrite the above procedure with deque container.
- 一入“远程”终不悔,几人欢喜几人愁。| 社区征文
- PR second time
- Website with JS doesn't work in IE9 until the Developer Tools is activated
- Kotlin's collaboration: Context
- Wechat applet for the first time
- 远程办公工具分享|社区征文
猜你喜欢
Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
How to purchase Google colab members in China
Golang单元测试、Mock测试以及基准测试
Global and Chinese pediatric palliative care drug market development research and investment planning recommendations report 2022-2028
Research Report on competitive strategy Outlook Analysis and investment strategic planning of China's smart home equipment industry, 2022-2028
STM32实现74HC595控制
问题随记 —— 在 edge 上看视频会绿屏
How to install PHP on Ubuntu 20.04
聊聊支付流程的設計與實現邏輯
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
随机推荐
[RT thread] NXP rt10xx device driver framework -- RTC construction and use
Introduction to SolidWorks gear design software tool geartrax
Luogu: p2685 [tjoi2012] Bridge
VM11289 WAService. js:2 Do not have __ e handler in component:
1147_ Makefile learning_ Target files and dependent files in makefile
Type conversion, variable
Applet with multiple tabs and Swipers + paging of each tab
Getting started with deops
MinGW compile boost library
(9) Opencv Canny edge detection
Test your trained model
Analyse ArrayList 3: suppression d'éléments
How to deploy applications on kubernetes cluster
What is the difference between cloud server and cloud virtual machine
国内如何购买Google Colab会员
Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
Qt调节Win屏幕亮度和声音大小
[combinatorics] recursive equation (the problem of solving recursive equation with multiple roots | the problem is raised)
UE4 official charging resources, with a total price of several thousand
Create a new file from templates with bash script - create new file from templates with bash script