问主郭宝东 發表於 2024-4-4 00:00:00

用Mac在CoreOS上搭建WordPress的教程

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        作者以自己的Mac笔记本为例,介绍了如何在CoreOS上安装WordPress应用,没有过多的理论解释,全部是实战类教程,推荐想快速了解CoreOS的同学阅读。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        我相信你一定听说过CoreOS,但是你是否真正在它上面部署过一个应用了?可能很多人都没有部署过。在CoreOS上构建一个应用是非常困难且令人沮丧的(译者注:frustrating,用了这个词,看来确实难)。因为文档比较散乱,并且你不得不在开始之前学习所有相关的技术,包括etcd、systemd、Docker。如果你和我一样比较懒惰,只是想试试CoreOS而不想小题大做,那么让我来帮你吧。接下来我们将会在CoreOS上创建一个简单的WordPress应用以及MySQL数据库。<br><strong>如果你使用的是Mac,可以通过安装命令行工具来控制CoreOS</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <img style="max-width:100%!important;height:auto!important;"title="用Mac在CoreOS上搭建WordPress的教程" alt="用Mac在CoreOS上搭建WordPress的教程" src="https://zhuji.jb51.net/uploads/img/202305/6d083673e09c30a1198df264b91fffc1.jpg"></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        fleetctl 和 etcdctl 是原生的控制CoreOS集群的工具,安装步骤如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
           </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode14" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        $ brew install go etcdctl <br>
        $ git clone https://github.com/coreos/fleet.git<br>
        $ cd fleet<br>
        $ ./build<br>
        $ mv bin/fleetctl /usr/local/bin/</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>安装一个本地的CoreOS集群,并运行</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        Vagrant是非常简单的。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
           </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode15" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        $ git clone https://github.com/CenturyLinkLabs/coreos-vagrant <br>
        $ cd coreos-vagrant/cluster<br>
        $ vagrant up --provision</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        现在你的笔记本上有一个由最小的3个CoreOS系统组成的集群。简单极了,现在让我们使用fleetctl来检查下。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
           </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode16" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        $ fleetctl list-machines MACHINE IP METADATA<br>
        09fd0a88... 10.0.2.15 -<br>
        77763947... 10.0.2.15 -<br>
        f31c383c... 10.0.2.15 -</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        太棒了,跑起来了。<br><strong>使用fleet在CoreOS集群上部署应用</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        现在你有一个CoreOS集群了。接下来fleetctl命令可以让你在CoreOS集群节点上部署应用,但要用fleet写服务文件。当然,不需要你自己来写。你可以用简单的YAML格式来生成服务(service)文件。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode17" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        $ sudo gem install bundler fig2coreos<br>
        $ cat fig.yml&lt;/p&gt; &lt;p&gt;-&lt;/p&gt; &lt;p&gt; web:<br>
        image: ctlc/wordpress<br>
        ports:<br>
        - 80:80<br>
        environment:<br>
        DB_USER: root<br>
        DB_PASSWORD: qa1N76pWAri9<br>
        links:<br>
        - db<br>
        db:<br>
        image: ctlc/mysql<br>
        ports:<br>
        - 3306:3306<br>
        environment:<br>
        MYSQL_DATABASE: wordpress<br>
        MYSQL_ROOT_PASSWORD: qa1N76pWAri9&lt;/p&gt; &lt;p&gt;-&lt;/p&gt; &lt;p&gt; $ fig2coreos myapp fig.yml coreos-files<br>
        $ cd coreos-files<br>
        $ ls<br>
        db-discovery.1.service<br>
        db.1.service<br>
        web-discovery.1.service<br>
        web.1.service</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        fleetctl客户端工具使用etcd的键值存储来确定它要访问的服务器以及访问集群中有etcd服务端运行的服务器。下面是如何在CoreOS集群中部署你的应用。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode18" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        $ fleetctl start db.1.service<br>
        $ fleetctl list-units<br>
        UNIT LOAD ACTIVE SUB DESC MACHINE<br>
        db.1.service loaded active running Run db_1 9c008961.../10.0.2.15<br>
        $ fleetctl start web.1.service<br>
        $ fleetctl list-units<br>
        UNIT LOAD ACTIVE SUB DESC MACHINE<br>
        db.1.service loaded active running Run db_1 9c008961.../10.0.2.15<br>
        web.1.service loaded active running Run web_1 9c008961.../10.0.2.15</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        现在你的程序运行起来了,但是服务还没有注册到etcd。幸运的是,fig2coreos已经为我们自动生成服务文件。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode19" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        $ fleetctl start db-discovery.1.service<br>
        $ fleetctl start web-discovery.1.service<br>
        $ fleetctl list-units<br>
        UNIT LOAD ACTIVE SUB DESC MACHINE<br>
        db-discovery.1.service loaded active running Announce db_1 9c008961.../10.0.2.15<br>
        db.1.service loaded active running Run db_1 9c008961.../10.0.2.15<br>
        web-discovery.1.service loaded active running Announce web_1 9c008961.../10.0.2.15<br>
        web.1.service loaded active running Run web_1 9c008961.../10.0.2.15<br>
        $ etcdctl ls --recursive<br>
        /services<br>
        /services/web<br>
        /services/web/web_1<br>
        /services/db<br>
        /services/db/db_1<br>
        $ etcdctl get /services/web/web_1<br>
        { "host": "core-03", "port": 80, "version": "52c7248a14" }<br>
        $ etcdctl get /services/db/db_1<br>
        { "host": "core-03", "port": 3306, "version": "52c7248a14" }</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>部署完成</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        就这样,搞定了。在Vagrant 1.5使用Vagrant Cloud账号,你可以访问你的WordPress应用。如下图:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode20" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        $ cd ~/coreos-vagrant/cluster/</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        找出哪个机器监听着你的80端口:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode21" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        $ etcdctl get /services/web/web_1<br>
        { "host": "core-03", "port": 80, "version": "52c7248a14" }&lt;/p&gt; &lt;p&gt;$ vagrant share core-03 --http 80<br>
        ==&gt; core-03: Detecting network information for machine...<br>
        core-03: Local machine address: 192.168.65.2<br>
        core-03: Local HTTP port: 80<br>
        core-03: Local HTTPS port: disabled<br>
        ==&gt; core-03: Checking authentication and authorization...<br>
        ==&gt; core-03: Creating Vagrant Share session...<br>
        core-03: Share will be at: quick-iguana-4689<br>
        ==&gt; core-03: Your Vagrant Share is running! Name: quick-iguana-4689<br>
        ==&gt; core-03: URL: http://quick-iguana-4689.vagrantshare.com</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <img style="max-width:100%!important;height:auto!important;"title="用Mac在CoreOS上搭建WordPress的教程" alt="用Mac在CoreOS上搭建WordPress的教程" src="https://zhuji.jb51.net/uploads/img/202305/88fb610fc1e50c6110f6e9af927902b5.jpg"></p>
頁: [1]
查看完整版本: 用Mac在CoreOS上搭建WordPress的教程