[Tutorial] Build your first application on CoreOS

Source: Internet
Author: User

[Tutorial] Build your first application on CoreOS

[Editor's note] the author uses his Mac notebook as an example to introduce how to install the WordPress application on CoreOS. There is not much theoretical explanation. It is a practical tutorial, we recommend that you want to quickly learn about CoreOS.

I believe you have heard of CoreOS, but have you actually deployed an application on it? Many people may not have deployed the service. It is very difficult and frustrating to build an application on CoreOS ). Because documents are scattered and you have to learn all the related technologies before you start, including etcd, systemd, and Docker. If you are just as lazy as you are, you just want to try CoreOS and don't want to worry about it, so let me help you. Next, we will create a simple WordPress application and MySQL database on CoreOS.

If you are using a Mac, you can install the command line tool to control CoreOS

Fleetctl and etcdctl are native tools for controlling CoreOS clusters. The installation steps are as follows:

  1. $ Brew install go etcdctl
    $ Git clone https://github.com/coreos/fleet.git
  2. $ Cd fleet
  3. $./Build
  4. $ Mv bin/fleetctl/usr/local/bin/
Install a local CoreOS cluster and run

Vagrant is very simple.

  1. $ Git clone https://github.com/CenturyLinkLabs/coreos-vagrant
    $ Cd coreos-vagrant/cluster
  2. $ Vagrant up -- provision

Your notebook now has a cluster consisting of the smallest three CoreOS systems. It's very simple. Now let's use fleetctl to check.

  1. $ Fleetctl list-machines MACHINE IP METADATA
  2. 09fd0a88... 10.0.2.15-
  3. 77763947... 10.0.2.15-
  4. F31c383c... 10.0.2.15-

It's great. It's running.

Deploy applications on CoreOS cluster using fleet

Now you have a CoreOS cluster. Next, the fleetctl command allows you to deploy applications on CoreOS cluster nodes, but you need to use fleet to write service files. Of course, you do not need to write it yourself. You can generate service files in a simple YAML format.

$ sudo gem install bundler fig2coreos$ cat fig.yml

-

  1. Web:
  2. Image: ctlc/wordpress
  3. Ports:
  4. -80: 80
  5. Environment:
  6. DB_USER: root
  7. DB_PASSWORD: qa1N76pWAri9
  8. Links:
  9. -Db
  10. Db:
  11. Image: ctlc/mysql
  12. Ports:
  13. -3306: 3306
  14. Environment:
  15. MYSQL_DATABASE: wordpress
  16. MYSQL_ROOT_PASSWORD: qa1N76pWAri9

-

  1. $ Fig2coreos myapp fig. yml coreos-files
  2. $ Cd coreos-files
  3. $ Ls
  4. Db-discovery.1.service
  5. Db.1.service
  6. Web-discovery.1.service
  7. Web.1.service

The fleetctl client tool uses the key-value storage of etcd to determine the server to be accessed and the server running on the etcd server in the access cluster. The following describes how to deploy your application in the CoreOS cluster.

$ fleetctl start db.1.service$ fleetctl list-unitsUNIT        LOAD    ACTIVE  SUB DESC        MACHINEdb.1.service    loaded  active  running Run db_1    9c008961.../10.0.2.15$ fleetctl start web.1.service$ fleetctl list-unitsUNIT        LOAD    ACTIVE  SUB DESC        MACHINEdb.1.service    loaded  active  running Run db_1    9c008961.../10.0.2.15web.1.service   loaded  active  running Run web_1   9c008961.../10.0.2.15 

Now your program is running, but the service has not been registered to etcd. Fortunately, fig2coreos has automatically generated service files for us.

$ fleetctl start db-discovery.1.service$ fleetctl start web-discovery.1.service$ fleetctl list-unitsUNIT            LOAD    ACTIVE  SUB DESC        MACHINEdb-discovery.1.service  loaded  active  running Announce db_1   9c008961.../10.0.2.15db.1.service        loaded  active  running Run db_1    9c008961.../10.0.2.15web-discovery.1.service loaded  active  running Announce web_1  9c008961.../10.0.2.15web.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" }
Deployment completed

That's it. You can use the Vagrant Cloud account in Vagrant 1.5 to access your WordPress application. For example:

$ cd ~/coreos-vagrant/cluster/

Find out which machine is listening to 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.2core-03: Local HTTP port: 80core-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


Conclusion

Now you can use CoreOS to do a lot of things, but at least now you have done the basic work, if you plan to use multi-host Coreos cluster in the production environment. You need to add the ambassador container to the system. In fact, you can connect to the etc server through the ambassador container. We will post another blog article next week.

How to deploy a WordPress instance in CoreOS

Initial server operating system CoreOS experience

CoreOS practice: Introduction to CoreOS and management tools

CoreOS details: click here
CoreOS: click here

Http://newlabs.wpengine.com/building-your-first-app-on-coreos/ Author: Lucas Carlson
Http://dockerone.com/article/66.

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.