当前位置:网站首页>[教程]在 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
边栏推荐
- A day's work list of an ordinary programmer
- Leetcode Valentine's Day Special - looking for a single dog
- Leetcode 669 pruning binary search tree -- recursive method and iterative method
- Golang单元测试、Mock测试以及基准测试
- Golang unit test, mock test and benchmark test
- Draw some simple graphics with MFC
- 一入“远程”终不悔,几人欢喜几人愁。| 社区征文
- 数仓任务里面 跑SQL任务的时候用的数据库账号是在哪里配置的
- When absolutely positioned, the element is horizontally and vertically centered
- How to train mask r-cnn model with your own data
猜你喜欢

Records of long objects and long judgments in the stream of list

【JokerのZYNQ7020】DDS_ Compiler。

国内如何购买Google Colab会员

Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028

Kubernetes resource object introduction and common commands (III)

互聯網醫院HIS管理平臺源碼,在線問診,預約掛號 智慧醫院小程序源碼

Internet Hospital his Management Platform source, online Inquiry, appointment Registration Smart Hospital Small program source

Hongmeng fourth training

聊聊支付流程的设计与实现逻辑
![[UE4] brush Arctic pack high quality Arctic terrain pack](/img/e7/bc86bd8450b0b2bdec8980a2aa1a10.jpg)
[UE4] brush Arctic pack high quality Arctic terrain pack
随机推荐
Micro service component sentinel console call
Interviewer: why is the value nil not equal to nil?
Test your trained model
Basic grammar of interview (Part 2)
[combinatorics] recursive equation (the problem of solving recursive equation with multiple roots | the problem is raised)
c# . Net tool ecosystem
Brief introduction to the core functions of automatic penetration testing tool
How to read the source code [debug and observe the source code]
Kubernetes resource object introduction and common commands (4)
PS screen printing brush 131, many illustrators have followed suit
Tensorboard quick start (pytoch uses tensorboard)
[vscode] convert tabs to spaces
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.
Leetcode 108 converts an ordered array into a binary search tree -- recursive method
Website with JS doesn't work in IE9 until the Developer Tools is activated
Comparison of kotlin collaboration + retro build network request schemes
Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026
UE4 official charging resources, with a total price of several thousand
Vs2013 has blocked the installer, and ie10 needs to be installed
鸿蒙第三次培训