发布于 2016-06-19 01:23:56 | 316 次阅读 | 评论: 0 | 来源: 网友投递
WordPress开源博客平台
WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站。也可以把 WordPress当作一个内容管理系统(CMS)来使用。
CoreOS是一个专门为大规模服务器部署定制的Linux精简系统,它将操作系统和应用程序完全分离,从而降低操作系统和应用程序的耦合度,同时解决了现有Linux服务器在容器资源、权限管理方面出现的问题。就目前来说,CoreOS会是未来操作系统的发展趋势。
那你有没有亲自在CoreOS上部署一个应用程序呢?相信大多数人都没有过这样的经验,在CoreOS上建立一个应用程序可以说是非常辛苦及沮丧的。因为在开始建立程序之前你首先必须了解所有不同的技术。
下面,我们将手把手地教你来创建一个简单的WordPress应用程序,采用MySQL作为服务器,在CoreOS上运行。
1. 安装CLI来控制CoreOS
如果你的电脑是Mac,可以在本机安装fleetctl和etcdctl来控制CoreOS集群:
$ brew install go etcdctl
$ git clone https://github.com/coreos/fleet.git
$ cd fleet
$ ./build
$ mv bin/fleetctl /usr/local/bin/
使用部署虚拟化开发环境Vagrant来安装本地集群很容易:
$ git clone https://github.com/CenturyLinkLabs/coreos-vagrant
$ cd coreos-vagrant/cluster
$ vagrant up --provision
$ fleetctl list-machines
MACHINE IP METADATA
09fd0a88... 10.0.2.15 -
77763947... 10.0.2.15 -
f31c383c... 10.0.2.15 -
fleetctl命令可把应用程序部署到CoreOS集群的节点中,但要为fleet写服务文件真的是太糟糕了。幸运的是,你不必自己编写,你可以使用yaml format来生成服务文件:
$ 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 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
$ 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" }
$ cd ~/coreos-vagrant/cluster/
# find out which box is hosting your port 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