-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.xml
198 lines (162 loc) · 34.7 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>ZAZA BLOG</title>
<subtitle>知行合一,止于至善</subtitle>
<link href="/atom.xml" rel="self"/>
<link href="http://despot-zaza.github.io/"/>
<updated>2017-05-09T10:07:14.058Z</updated>
<id>http://despot-zaza.github.io/</id>
<author>
<name>despot-zaza</name>
</author>
<generator uri="http://hexo.io/">Hexo</generator>
<entry>
<title>Maven学习笔记</title>
<link href="http://despot-zaza.github.io/2017/05/09/Maven%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/"/>
<id>http://despot-zaza.github.io/2017/05/09/Maven学习笔记/</id>
<published>2017-05-09T10:05:00.000Z</published>
<updated>2017-05-09T10:07:14.058Z</updated>
<content type="html"><![CDATA[<h2 id="Maven常用的构建命令"><a href="#Maven常用的构建命令" class="headerlink" title="Maven常用的构建命令"></a>Maven常用的构建命令</h2><hr>
<p>mvn -v 查看maven版本<br> compile 编译<br> test 测试<br> package 打包<br> clean 删除target<br> install 安装jar包到本地仓库</p>
<h2 id="Maven自动建立目录骨架"><a href="#Maven自动建立目录骨架" class="headerlink" title="Maven自动建立目录骨架"></a>Maven自动建立目录骨架</h2><hr>
<p>创建目录的两种方式:<br>archetype:generate 按照提示进行选择<br>archetype:generate -DgroupId=组织名,公司网址的反写+项目名<br> -DartifactId=项目名+模块名<br> -Dversion=版本号<br> -Dpackage=代码所存在的包</p>
<h2 id="Maven中坐标和仓库的概念"><a href="#Maven中坐标和仓库的概念" class="headerlink" title="Maven中坐标和仓库的概念"></a>Maven中坐标和仓库的概念</h2><hr>
<p><strong>构建:</strong><br>在maven世界中任何一个依赖、插件、项目构建的输出都可以被称为构建。</p>
<p><strong>坐标:</strong><br>所有构建通过坐标作为其唯一标识。就好像我们的工作单位或家庭地址。</p>
<p><strong>仓库:</strong><br>用来管理项目的依赖,分为本地仓库和远程仓库。默认地址在maven\lib\maven-model-builder.jar解压打开后里面org\apache\maven\model\pom-4.0.0.xml。这是maven提供的超级pom,所有的maven项目都会继承这个pom。打开这个文件后<code><repository></code>标签内<code><url></code>标签就是默认的全球的中央仓库的地址,可以用浏览器打开,在里面可找到大部分的开源的java项目。</p>
<p><strong>镜像仓库</strong><br>修改镜像仓库的位置:打开maven\conf\settings.xml 找到<mirror>根据示例修改,下面是一个国内镜像仓库的demo</mirror></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="tag"><<span class="name">mirror</span>></span></div><div class="line"> <span class="tag"><<span class="name">id</span>></span>maven.net.cn<span class="tag"></<span class="name">id</span>></span></div><div class="line"> <span class="tag"><<span class="name">mirrorOf</span>></span>central<span class="tag"></<span class="name">mirrorOf</span>></span> *</div><div class="line"> <span class="tag"><<span class="name">name</span>></span>central mirror in china<span class="tag"></<span class="name">name</span>></span></div><div class="line"> <span class="tag"><<span class="name">url</span>></span>http://maven.net.cn/content/groups/public<span class="tag"></<span class="name">url</span>></span></div><div class="line"><span class="tag"></<span class="name">mirror</span>></span></div></pre></td></tr></table></figure>
<p><strong>更改仓库的位置</strong><br>默认仓库位置路径:C:\Users\username.m2\repository<br>修改时还是打开maven\conf\settings.xml,找到<code><localRepository></code></p>
<h2 id="Maven的生命周期和插件"><a href="#Maven的生命周期和插件" class="headerlink" title="Maven的生命周期和插件"></a>Maven的生命周期和插件</h2><hr>
<p><strong>完整的项目构建过程包括:</strong><br>清理、编译、测试、打包、集成测试、验证、部署<br>clean、compile、test、package、install</p>
<p><strong>maven生命周期</strong><br>clean 清理项目</p>
<ul>
<li>pre-clean 执行清理前的工作</li>
<li>clean清理上一次构建生成的所有文件</li>
<li>post-clean执行清理后的文件</li>
</ul>
<p>default 构建项目(最核心)</p>
<ul>
<li>compile test package install</li>
</ul>
<p>site 生成项目站点</p>
<ul>
<li>pre-site 在生成项目站点前要完成的工作</li>
<li>site 生成项目的站点文档</li>
<li>post-site 在生成项目站点后要完成的工作</li>
<li>site-deploy 发布生成的站点到服务器上</li>
</ul>
<p>三块生命周期彼此独立</p>
<h2 id="Maven依赖范围"><a href="#Maven依赖范围" class="headerlink" title="Maven依赖范围"></a>Maven依赖范围</h2><hr>
<p><strong>maven中提供了三种classpath:</strong><br>1、编译<br>2、测试<br>3、运行<br>将<code><scope>test</scope></code>设置为test时则只存在于测试范围中,依赖范围就是用来控制和三种classpath的关系</p>
<p><strong>scope具体属性:(可参考maven.apache.org官网guide)</strong><br>compile:默认的范围,编译、测试、运行都有效<br>provide:在编译和测试时有效<br>runtime:在测试和运行时有效<br>test:只在测试时有效<br>system:与本机系统相关联,可移植性差<br>import:导入的范围,它只使用在dependencyManagement中,表示从其他的pom中导入dependency的配置</p>
<h2 id="Maven依赖传递"><a href="#Maven依赖传递" class="headerlink" title="Maven依赖传递"></a>Maven依赖传递</h2><hr>
<p>Maven的依赖<code><dependency></code>默认会向下集成,如果构建想去除依赖可以使用<code><exclusion></code>标签。</p>
<p>补充小知识:<br> maven默认采用jdk1.5,那如何采用1.8的版本?<br>需要要修改settings.xml中找到<code><profile></code>将其中改为对应版本即可</p>
<h2 id="Maven依赖冲突"><a href="#Maven依赖冲突" class="headerlink" title="Maven依赖冲突"></a>Maven依赖冲突</h2><hr>
<p><strong>1、短路优先</strong></p>
<p>A->B->C->X(jar)<br>A->D->X(jar)<br>优先解析路径短的版本</p>
<p><strong>2、先声明先优先</strong><br>如果路径长度相同,则谁先声明,先解析谁</p>
<p><strong>聚合和继承</strong></p>
<p>聚合<br><code><modules></code>标签,将需要聚合的类加入<code><module></code></p>
<p>继承<br>父POM中将dependencies中的放入dependencyManagement,并在properties中声明版本号等属性信息。<br>子POM中加入父POM的坐标,在依赖中写入基本的坐标名即可。</p>
<h2 id="附录-Maven-pom-xml文件解析"><a href="#附录-Maven-pom-xml文件解析" class="headerlink" title="附录 Maven pom.xml文件解析"></a>附录 Maven pom.xml文件解析</h2><hr>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div></pre></td><td class="code"><pre><div class="line"><?xml version="1.0" encoding="UTF-8"?></div><div class="line"><span class="tag"><<span class="name">project</span> <span class="attr">xmlns</span>=<span class="string">"http://maven.apache.org/POM/4.0.0"</span> <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span></span></div><div class="line"> <span class="attr">xsi:schemaLocation</span>=<span class="string">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"</span>></div><div class="line"> <span class="comment"><!-- 指定了当前pom的版本 --></span></div><div class="line"> <span class="tag"><<span class="name">modelVersion</span>></span>4.0.0<span class="tag"></<span class="name">modelVersion</span>></span></div><div class="line"></div><div class="line"> <span class="tag"><<span class="name">groupId</span>></span>反写的公司网址+项目名<span class="tag"></<span class="name">groupId</span>></span></div><div class="line"> <span class="tag"><<span class="name">artifactId</span>></span>项目名+模块名<span class="tag"></<span class="name">artifactId</span>></span></div><div class="line"> <span class="comment"><!--</span></div><div class="line"> 第一个0表示大版本号</div><div class="line"> 第二个0表示分支版本号</div><div class="line"> 第三个0表示小版本号</div><div class="line"> 0.0.1</div><div class="line"> snapshot 表示快照版本</div><div class="line"> alpha 表示内部版本</div><div class="line"> beta 表示公测版本</div><div class="line"> Release 表示稳定版本</div><div class="line"> GA 表示正式发布版本</div><div class="line"> --></div><div class="line"> <span class="tag"><<span class="name">version</span>></span>当前项目的版本号<span class="tag"></<span class="name">version</span>></span></div><div class="line"> <span class="comment"><!-- 默认是jar</span></div><div class="line"> war zip pom --></div><div class="line"> <span class="tag"><<span class="name">packaging</span>></span><span class="tag"></<span class="name">packaging</span>></span></div><div class="line"> <span class="comment"><!-- 项目描述名,产生项目文档时才会使用 --></span></div><div class="line"> <span class="tag"><<span class="name">name</span>></span><span class="tag"></<span class="name">name</span>></span></div><div class="line"> <span class="comment"><!-- 项目的地址 --></span></div><div class="line"> <span class="tag"><<span class="name">url</span>></span><span class="tag"></<span class="name">url</span>></span></div><div class="line"> <span class="comment"><!-- 项目描述 --></span></div><div class="line"> <span class="tag"><<span class="name">description</span>></span><span class="tag"></<span class="name">description</span>></span></div><div class="line"> <span class="comment"><!-- 开发人员信息 --></span></div><div class="line"> <span class="tag"><<span class="name">developers</span>></span><span class="tag"></<span class="name">developers</span>></span></div><div class="line"> <span class="comment"><!-- 项目授权信息 --></span></div><div class="line"> <span class="tag"><<span class="name">licenses</span>></span><span class="tag"></<span class="name">licenses</span>></span></div><div class="line"> <span class="comment"><!-- 项目组织信息 --></span></div><div class="line"> <span class="tag"><<span class="name">organization</span>></span><span class="tag"></<span class="name">organization</span>></span></div><div class="line"></div><div class="line"> <span class="tag"><<span class="name">dependencies</span>></span></div><div class="line"> <span class="tag"><<span class="name">dependency</span>></span></div><div class="line"> <span class="tag"><<span class="name">groupId</span>></span><span class="tag"></<span class="name">groupId</span>></span></div><div class="line"> <span class="tag"><<span class="name">artifactId</span>></span><span class="tag"></<span class="name">artifactId</span>></span></div><div class="line"> <span class="tag"><<span class="name">version</span>></span><span class="tag"></<span class="name">version</span>></span></div><div class="line"> <span class="tag"><<span class="name">type</span>></span><span class="tag"></<span class="name">type</span>></span></div><div class="line"> <span class="comment"><!-- 依赖范围 --></span></div><div class="line"> <span class="tag"><<span class="name">scope</span>></span><span class="tag"></<span class="name">scope</span>></span></div><div class="line"> <span class="comment"><!-- 设置依赖是否可选,只有ture和false,默认为false --></span></div><div class="line"> <span class="tag"><<span class="name">optional</span>></span><span class="tag"></<span class="name">optional</span>></span></div><div class="line"> <span class="comment"><!-- 排除依赖传递的列表 --></span></div><div class="line"> <span class="tag"><<span class="name">exclusions</span>></span></div><div class="line"> <span class="tag"><<span class="name">exclusion</span>></span></div><div class="line"> <span class="tag"></<span class="name">exclusion</span>></span></div><div class="line"> <span class="tag"></<span class="name">exclusions</span>></span></div><div class="line"> <span class="tag"></<span class="name">dependency</span>></span></div><div class="line"> <span class="tag"></<span class="name">dependencies</span>></span></div><div class="line"> <span class="comment"><!-- 依赖管理 --></span></div><div class="line"> <span class="tag"><<span class="name">dependencyManagement</span>></span></div><div class="line"> <span class="tag"><<span class="name">dependencies</span>></span></div><div class="line"> <span class="tag"><<span class="name">dependency</span>></span></div><div class="line"> <span class="tag"></<span class="name">dependency</span>></span></div><div class="line"> <span class="tag"></<span class="name">dependencies</span>></span></div><div class="line"> <span class="tag"></<span class="name">dependencyManagement</span>></span></div><div class="line"> <span class="comment"><!-- 通常对构建的行为提供插件的支持 --></span></div><div class="line"> <span class="tag"><<span class="name">build</span>></span></div><div class="line"> <span class="comment"><!-- 插件列表 --></span></div><div class="line"> <span class="tag"><<span class="name">plugins</span>></span></div><div class="line"> <span class="tag"><<span class="name">groupId</span>></span><span class="tag"></<span class="name">groupId</span>></span></div><div class="line"> <span class="tag"><<span class="name">artifactId</span>></span><span class="tag"></<span class="name">artifactId</span>></span></div><div class="line"> <span class="tag"><<span class="name">version</span>></span><span class="tag"></<span class="name">version</span>></span></div><div class="line"> <span class="tag"></<span class="name">plugins</span>></span></div><div class="line"> <span class="tag"></<span class="name">build</span>></span></div><div class="line"> <span class="comment"><!-- 子模块对父模块的集成 --></span></div><div class="line"> <span class="tag"><<span class="name">parent</span>></span><span class="tag"></<span class="name">parent</span>></span></div><div class="line"> <span class="comment"><!-- 聚合运行多个modules项 --></span></div><div class="line"> <span class="tag"><<span class="name">modules</span>></span></div><div class="line"> <span class="tag"><<span class="name">module</span>></span><span class="tag"></<span class="name">module</span>></span></div><div class="line"> <span class="tag"></<span class="name">modules</span>></span></div><div class="line"><span class="tag"></<span class="name">project</span>></span></div></pre></td></tr></table></figure>
]]></content>
<summary type="html">
<h2 id="Maven常用的构建命令"><a href="#Maven常用的构建命令" class="headerlink" title="Maven常用的构建命令"></a>Maven常用的构建命令</h2><hr>
<p>mvn -v 查看maven版本<br> com
</summary>
<category term="code" scheme="http://despot-zaza.github.io/categories/code/"/>
<category term="java" scheme="http://despot-zaza.github.io/tags/java/"/>
<category term="maven" scheme="http://despot-zaza.github.io/tags/maven/"/>
<category term="build" scheme="http://despot-zaza.github.io/tags/build/"/>
<category term="DEVOPS" scheme="http://despot-zaza.github.io/tags/DEVOPS/"/>
</entry>
<entry>
<title>Hello World</title>
<link href="http://despot-zaza.github.io/2017/05/09/hello-world/"/>
<id>http://despot-zaza.github.io/2017/05/09/hello-world/</id>
<published>2017-05-09T03:19:20.000Z</published>
<updated>2017-05-09T06:55:56.500Z</updated>
<content type="html"><![CDATA[<p>Welcome to <a href="https://hexo.io/" target="_blank" rel="external">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/" target="_blank" rel="external">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html" target="_blank" rel="external">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues" target="_blank" rel="external">GitHub</a>.</p>
<h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo new <span class="string">"My New Post"</span></div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/writing.html" target="_blank" rel="external">Writing</a></p>
<h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo server</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/server.html" target="_blank" rel="external">Server</a></p>
<h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo generate</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/generating.html" target="_blank" rel="external">Generating</a></p>
<h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo deploy</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/deployment.html" target="_blank" rel="external">Deployment</a></p>
]]></content>
<summary type="html">
这篇文章是关于hexo的
</summary>
<category term="code" scheme="http://despot-zaza.github.io/categories/code/"/>
<category term="hexo" scheme="http://despot-zaza.github.io/tags/hexo/"/>
</entry>
<entry>
<title>搭建ngrok将你的应用发布到公网上吧</title>
<link href="http://despot-zaza.github.io/2017/05/09/%E6%90%AD%E5%BB%BAngrok%E5%B0%86%E4%BD%A0%E7%9A%84%E5%BA%94%E7%94%A8%E5%8F%91%E5%B8%83%E5%88%B0%E5%85%AC%E7%BD%91%E4%B8%8A%E5%90%A7/"/>
<id>http://despot-zaza.github.io/2017/05/09/搭建ngrok将你的应用发布到公网上吧/</id>
<published>2017-05-09T02:44:51.000Z</published>
<updated>2017-05-09T11:53:30.144Z</updated>
<content type="html"><![CDATA[<h2 id="环境准备"><a href="#环境准备" class="headerlink" title="环境准备"></a>环境准备</h2><hr>
<p>首先需要下载go环境,这里是下载的 go1.8.linux-amd64.tar.gz 的版本,其他版本可以在GO的官方网站复制对应的下载链接</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">wget http://www.golangtc.com/static/go/1.8/go1.8.linux-amd64.tar.gz</div></pre></td></tr></table></figure>
<p>将下载完的压缩解压到服务器 /usr/local/go 即可,然后将/usr/local/go/bin/* 复制到 /usr/bin/ </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span> /usr/<span class="built_in">local</span>/src/</div></pre></td></tr></table></figure>
<p>下载ngrok源代码,在github上能够搜到ngrok项目的最新版本</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git <span class="built_in">clone</span> https://github.com/inconshreveable/ngrok.git</div></pre></td></tr></table></figure>
<p>设置GOPATH环境变量</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">export</span> GOPATH=/usr/<span class="built_in">local</span>/src/ngrok/</div></pre></td></tr></table></figure>
<p>设置域名变量,为了后续方便,建议这里使用一级域名,因为ngrok会需要你的二级域名做为host(client不填二级域名的话ngrok会随机给你分配一个二级域名)</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">export</span> NGROK_DOMAIN=<span class="string">"yourdomain.com"</span></div></pre></td></tr></table></figure>
<p>打开ngrok目录,环境准备完成</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span> ngrok</div></pre></td></tr></table></figure>
<h2 id="开始编译"><a href="#开始编译" class="headerlink" title="开始编译"></a>开始编译</h2><hr>
<p>首先为根域名生成证书</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">openssl genrsa -out rootCA.key 2048</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">openssl req -x509 -new -nodes -key rootCA.key -subj <span class="string">"/CN=<span class="variable">$NGROK_DOMAIN</span>"</span> -days 5000 -out rootCA.pem</div><div class="line">openssl genrsa -out device.key 2048</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">openssl req -new -key device.key -subj <span class="string">"/CN=<span class="variable">$NGROK_DOMAIN</span>"</span> -out device.csr</div><div class="line">openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">cp rootCA.pem assets/client/tls/ngrokroot.crt</div><div class="line">cp device.crt assets/server/tls/snakeoil.crt </div><div class="line">cp device.key assets/server/tls/snakeoil.key</div></pre></td></tr></table></figure>
<p>编译服务端比较容易,先指定一下环境变量,然后再make:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">GOOS=linux GOARCH=amd64</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">make release-server</div></pre></td></tr></table></figure>
<p>编译成功后,应该可以在 /usr/local/src/ngrok/bin 下生成了一个 ngrokd 可执行文件,这就是我们的服务端了,现在启动服务端试试:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">bin/ngrokd -domain=<span class="string">"<span class="variable">$NGROK_DOMAIN</span>"</span> -httpAddr=<span class="string">":80"</span></div></pre></td></tr></table></figure>
<p>如果没有报错的话,会出现以下输出:</p>
<figure class="highlight prolog"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[<span class="number">10</span>:<span class="number">05</span>:<span class="number">48</span> <span class="symbol">CST</span> <span class="number">2015</span>/<span class="number">04</span>/<span class="number">17</span>] </div><div class="line">[<span class="symbol">INFO</span>] (ngrok/log.(*<span class="symbol">PrefixLogger</span>).<span class="symbol">Info</span>:<span class="number">83</span>) [registry] [tun] <span class="symbol">No</span> affinity cache specified</div><div class="line">[<span class="number">10</span>:<span class="number">05</span>:<span class="number">48</span> <span class="symbol">CST</span> <span class="number">2015</span>/<span class="number">04</span>/<span class="number">17</span>] [<span class="symbol">INFO</span>] (ngrok/log.(*<span class="symbol">PrefixLogger</span>).<span class="symbol">Info</span>:<span class="number">83</span>) [metrics] <span class="symbol">Reporting</span> every <span class="number">30</span> seconds</div><div class="line">[<span class="number">10</span>:<span class="number">05</span>:<span class="number">48</span> <span class="symbol">CST</span> <span class="number">2015</span>/<span class="number">04</span>/<span class="number">17</span>] [<span class="symbol">INFO</span>] (ngrok/log.<span class="symbol">Info</span>:<span class="number">112</span>) </div><div class="line"><span class="symbol">Listening</span> for public http connections on [::]:<span class="number">8000</span>[<span class="number">10</span>:<span class="number">05</span>:<span class="number">48</span> <span class="symbol">CST</span> <span class="number">2015</span>/<span class="number">04</span>/<span class="number">17</span>] [<span class="symbol">INFO</span>] (ngrok/log.<span class="symbol">Info</span>:<span class="number">112</span>) <span class="symbol">Listening</span> for public https connections on [::]:<span class="number">443</span>[<span class="number">10</span>:<span class="number">05</span>:<span class="number">48</span> <span class="symbol">CST</span> <span class="number">2015</span>/<span class="number">04</span>/<span class="number">17</span>] [<span class="symbol">INFO</span>] (ngrok/log.<span class="symbol">Info</span>:<span class="number">112</span>) <span class="symbol">Listening</span> for control and proxy connections on [::]:<span class="number">4443</span></div></pre></td></tr></table></figure>
<h2 id="编译客户端"><a href="#编译客户端" class="headerlink" title="编译客户端"></a>编译客户端</h2><hr>
<p>现在先 ctrl+c 退出,我们还需要编译客户端呢。<br><strong>首先编译linux客户端:</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span> /usr/<span class="built_in">local</span>/src/ngrok</div><div class="line">GOOS=linux GOARCH=amd64 </div><div class="line">make release-client</div></pre></td></tr></table></figure>
<blockquote>
<p>同理,这里的amd64是64位系统,32位改成386#应该会在 bin/ 目录下生成ngrok客户端程序</p>
</blockquote>
<p><strong>如果是windows下的客户端,是这样的:</strong></p>
<blockquote>
<p><strong>windows 环境有点小问题,需要go1.4版本才可以执行这里后续再更新详细步骤</strong><br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span> /usr/<span class="built_in">local</span>/go/src</div><div class="line">GOOS=windows GOARCH=amd64 ./make.bash</div><div class="line"><span class="built_in">cd</span> -</div><div class="line">GOOS=windows GOARCH=amd64 </div><div class="line">make release-client</div></pre></td></tr></table></figure></p>
<p>同理,这里的amd64是64位系统,32位改成386#应该会在 bin/windows_amd64 目录下生成ngrok客户端程序</p>
</blockquote>
<h2 id="运行客户端"><a href="#运行客户端" class="headerlink" title="运行客户端"></a>运行客户端</h2><hr>
<p>现在我们来到自己电脑上,通过scp命令将客户端文件复制到本地,并准备启动客户端。在启动之前,我们需要为客户端编写一个配置文件 ngrok.cfg :</p>
<figure class="highlight http"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="attribute">server_addr</span>: "ngrok.yourdomain.com:4443"</div><div class="line"><span class="attribute">trust_host_root_certs</span>: false</div></pre></td></tr></table></figure>
<p>然后启动客户端,假设我们要分配一个二级域名 test.yourdomain.com 执行以下命令:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">./ngrok -config=./ngrok.cfg -subdomain=<span class="built_in">test</span> 80</div></pre></td></tr></table></figure>
<p>解释一下参数:<br>-config 就是上面配置文件ngrok.cfg的路径-subdomain 就是需要分配域名的前缀部分80 就是本机websever的端口,比如apache监听的端口,一会ngrok会将请求映射到该端口上。</p>
<p>如果没错误,应该会出现以下的输出:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">Tunnel Status online</div><div class="line">Version 1.7/1.7</div><div class="line">Forwarding http://test.ngrok.ekan001.com:8000 -> 127.0.0.1:80</div><div class="line">Forwarding https://test.ngrok.ekan001.com:8000 -> 127.0.0.1:80</div><div class="line">Web Interface 127.0.0.1:4040</div><div class="line"># Conn 0</div><div class="line">Avg Conn Time 0.00ms</div></pre></td></tr></table></figure>
<h2 id="加入开机启动项"><a href="#加入开机启动项" class="headerlink" title="加入开机启动项"></a>加入开机启动项</h2><hr>
<p>由于我的服务端是Ubuntu的环境,运行在其他操作上的小伙伴可以参考下:<br>rc.local脚本是一个ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令。<br>该脚本位于/etc/路径下,需要root权限才能修改。该脚本具体格式如下:</p>
<p>将如下命令添加到脚本中即可开机自启动</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">/usr/<span class="built_in">local</span>/src/ngrok/bin/ngrokd -domain=<span class="string">"yourdomain.com"</span> -httpAddr=<span class="string">":80"</span></div></pre></td></tr></table></figure>
]]></content>
<summary type="html">
<h2 id="环境准备"><a href="#环境准备" class="headerlink" title="环境准备"></a>环境准备</h2><hr>
<p>首先需要下载go环境,这里是下载的 go1.8.linux-amd64.tar.gz 的版本,其他版本可以在GO的
</summary>
<category term="tool" scheme="http://despot-zaza.github.io/categories/tool/"/>
<category term="ngrok" scheme="http://despot-zaza.github.io/tags/ngrok/"/>
<category term="deploy" scheme="http://despot-zaza.github.io/tags/deploy/"/>
</entry>
</feed>