<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by CoderAFI on Medium]]></title>
        <description><![CDATA[Stories by CoderAFI on Medium]]></description>
        <link>https://medium.com/@CoderAFI?source=rss-5f5e3741110------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*eaQrR7vU9hEflDmTNPPf-Q.jpeg</url>
            <title>Stories by CoderAFI on Medium</title>
            <link>https://medium.com/@CoderAFI?source=rss-5f5e3741110------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 09:34:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@CoderAFI/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[iOS OTA 配置]]></title>
            <link>https://medium.com/@CoderAFI/ios-ota-%E9%85%8D%E7%BD%AE-e7f5d068b571?source=rss-5f5e3741110------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7f5d068b571</guid>
            <category><![CDATA[certification]]></category>
            <category><![CDATA[ci]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[CoderAFI]]></dc:creator>
            <pubDate>Wed, 06 Dec 2017 10:25:34 GMT</pubDate>
            <atom:updated>2017-12-06T10:25:34.595Z</atom:updated>
            <content:encoded><![CDATA[<p>iOS开发进入测试阶段后，在很多公司都进入了众测或者集中测试阶段，这个时候如果还是依靠技术给测试人员打包，会造成’版本不一致’或’你装的里面没有我的最新代码’等各种问题，很多公司依靠一些公共平台如：Testflight | fir.im | pgyer.com | pre.im等，但是如果自己做企业内部分发平台该怎么做?下面我将慢慢道来。</p><h4>企业(InHouse)证书的申请</h4><ol><li>登录企业账号，member center-&gt; certificates-&gt;production-&gt;选择加号-&gt;InHouse，创建 InHouse 的 certification，如下图：</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*tOvJ2NcKO4CkzNYEeHzobQ.png" /><figcaption>创建 Certification</figcaption></figure><p>2. Indentifiers-&gt;AppIDs，创建你需要的 AppID，注意这里的 AppID 不能使用通配符*号</p><p>3. 创建与Cer和AppID对应的ProvisionProfile，如下图：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*G8-TDHvwh9ndm0se_G49Jg.png" /><figcaption>创建 ProvisionProfile</figcaption></figure><h4>打包 IPA</h4><ul><li>手动的方式请参照下面的索引相关文章</li><li>自定脚本打包推荐 <a href="https://github.com/webfrogs/xcode_shell.git">Xcode_Shell</a>，里面包含了一些 Xcode 的常用打包命令，当然你也可以自己进行修改整合，同样将这组脚本配在 <a href="https://jenkins-ci.org/">Jenkins </a>或者<a href="http://hudson-ci.org/">Hudson</a> 等CI工具里是极好的。</li><li>借助 <a href="https://fastlane.tools/">fastlane</a> 和 <a href="https://travis-ci.com/">Travis CI</a> 等第三方工具和服务</li></ul><h4>服务环境配置</h4><p>通过上面的繁琐的步骤，终于把企业证书的 ipa 包打好了，这时候需要服务器来进行分发，那么苹果是怎么实现的呢?</p><h4>遵循协议</h4><p>要下载企业ipa当然苹果要给你指定一套协议，只有这种协议在可以在iOS设备上安装，这就是 <strong>itms-services</strong> 协议，一般在是在一个html中这么写:</p><pre>&lt;a href=”items-services://?action=download-manifest&amp;url=your_plist_url”&gt;快捷酒店管家。&lt;/a&gt;</pre><p>上面的your_plist_url 是你 plist 的服务路径，plist里面包含了你的ipa下载路径以及下载时候的App Icon，这里需要注意的是在iOS7.1之前这个url可以是http的，但在iOS7.1后这个地址必须是遵循https的，这就需要提供打包服务的服务器要配置 https 功能。</p><p>服务器 https 分为自签名和第三方签名的方式，大部分第三方签名都是收费的，有些提供了免费试用的机制，但都是有期限的，所以我只采用了自签名的方式，想花钱的同学，可绕行。</p><h4>配置自签名 https 服务</h4><ol><li>这里我们采用Tomcat服务器，去Tomcat官网下载，然后到你的Tomcat根目录下执行 chmod a+x apache-tomcat-7.0.64/bin/*.sh 给bin目录下的sh文件权限</li></ol><p>2. 创建客户端私钥文件</p><pre>openssl genrsa -out client.key 2048</pre><p>3. 根据客户端私钥生成客户端根证书</p><pre>openssl req -x509 -new -key client.key -out client.cer -days 730 -subj /CN=”YourCompnay CA”</pre><p>4. 创建服务端私钥</p><pre>openssl genrsa -out server.key 2048</pre><p>5. 创建服务端CSR</p><pre>openssl req -new -out server.req -key server.key -subj /CN=yourdomainname/CN=yourip/CN=localhost</pre><p>6. 用服务端CSR和客户端的生成的秘钥、证书来创建服务端SSL证书</p><pre>openssl x509 -req -in server.req -out server.cer -CAkey client.key -CA client.cer -days 36500 -CAcreateserial -CAserial server.serial</pre><p>7. 将 server.key 和 server.cer 文件导出为 .p12 证书，导出p12文件时，要设置p12文件的访问密码，这里我们设置123456</p><pre>openssl pkcs12 -export -in server.cer -inkey server.key -out server.p12 -name “server”</pre><p>8. 将 .p12 文件导入到 java keystore 中</p><pre>keytool -importkeystore -v -srckeystore server.p12 -srcstoretype pkcs12 -srcstorepass 123456 -destkeystore server.keystore -deststoretype jks -deststorepass 123456</pre><h4>环境测试</h4><p>1 .找到Tomcat下的webapps目录，这里存储着所有部署在tomcat上的web服务，我们这里借用默认的examples工程，在examples目录下创建ios_build文件夹</p><p>2. 将xxx.ipa xxx.plist xxx57.png xxx512.png client.cer拷贝到ios_build目录下</p><p>3. 修改Tomcat conf目录下server.xml中关于https的配置项，如下：</p><pre>&lt;Connector SSLEnabled=”true” protocol=”org.apache.coyote.http11.Http11Protocol” scheme=”https” secure=”true” sslProtocol=”TLS” keystoreFile=”/Users/CoderAFI/root/Software/apache-tomcat-7.0.64/server.keystore” keystorePass=”123456&quot; maxThreads=”150&quot; port=”yourport” clientAuth=”false” /&gt;</pre><p>4. 修改Tomcat conf目录下web.xml中关于ipa下载的配置项，如下：</p><pre>&lt;mime-mapping&gt;<br> &lt;extension&gt;ipa&lt;/extension&gt;<br> &lt;mime-type&gt;application/octet-stream&lt;/mime-type&gt;<br>&lt;/mime-mapping&gt;<br>&lt;mime-mapping&gt;<br> &lt;extension&gt;plist&lt;/extension&gt;<br> &lt;mime-type&gt;text/xml&lt;/mime-type&gt;<br>&lt;/mime-mapping&gt;</pre><p>5.在ios_build目录下创建index.html，源码如下：</p><pre>&lt;html&gt;<br>&lt;meta http-equiv=”content-type” content=”text/html; charset=UTF-8&quot; /&gt;<br>&lt;head&gt; &lt;title&gt;企业证书安装App &lt;/title&gt; &lt;/head&gt;<br>&lt;body&gt;<br>&lt;center&gt;<br>&lt;h2&gt; 请使用苹果的safari浏览器打开本页面，然后点击 安装 &lt;/h2&gt;<br>&lt;font size=”13&quot;&gt;<br>&lt;h1&gt;&lt;a href=”itms-services://?action=download-manifest&amp;url=<a href="https://yourip:yourport/examples/ios_build/xxx.plist">https://yourip:yourport/examples/ios_build/xxx.plist</a>&quot;&gt; 安装&lt;/a&gt; &lt;/h1&gt;<br>&lt;/font&gt;<br>&lt;/center&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h4>运行</h4><p>1. 环境基本配置完毕，到bin目录下运行startup.sh，验证服务器是否启动成功。<br>2. 安装服务器提供的端证书。<br>3. 下载plist文件，安装ipa，注意iOS9安装完毕后要在设置-描述里信任企业证书</p><p>访问地址如下：</p><pre><a href="https://yourdomainname:yourport/examples/ios_build/index.html">https://yourdomainname:yourport/examples/ios_build/index.html</a><br><a href="https://yourdomainname:yourport/examples/ios_build/client.cer">https://yourdomainname:yourport/examples/ios_build/client.cer</a><br><a href="https://yourdomainname:yourport/examples/ios_build/index.html">https://yourdomainname:yourport/examples/ios_build/index.html</a></pre><h4>遇到的问题</h4><ol><li>不能连接到服务器</li></ol><p>这种问题一般是你的服务器的 https 证书配置没有起作用，如果想验证自己的 https 是否有效可以先借用第三方的可参照<a href="http://www.cnblogs.com/geweb/p/Adhoc.html%60">http://www.cnblogs.com/geweb/p/Adhoc.html</a></p><p>2. 点击安装后无响应的问题</p><p>点击下载后没有反应，一般是你之前已经下载过几次ipa，或者这时候服务端的plist文件配置发生了变化等情况，导致手机本地Cache住了你的安装状态，所以手机一直以为你已经装过了，所以就不会给你装了，解决方法<a href="http://stackoverflow.com/questions/25733299/ios-8-cant-install-enterprise-app">参考文章</a>，我是用手机管理软件把Downloads缓存删除了一下就可以了</p><p>3. 此时无法下载xxx应用</p><p>一般都是你得plist跟ipa包里面的配置不对应造成的，请仔细核查ipa包下载地址以及bundle identitfier等配置项</p><blockquote>索引<br><a href="http://blog.csdn.net/mergerly/article/details/17352735">http://blog.csdn.net/mergerly/article/details/17352735</a><br><a href="http://my.oschina.net/u/728866/blog/175018">http://my.oschina.net/u/728866/blog/175018</a><br><a href="http://beyondvincent.com/2014/03/17/2014-03-17-five-tips-for-using-self-signed-ssl-certificates-with-ios/">http://beyondvincent.com/2014/03/17/2014-03-17-five-tips-for-using-self-signed-ssl-certificates-with-ios/</a><br><a href="http://www.bubuko.com/infodetail-163736.html">http://www.bubuko.com/infodetail-163736.html</a><br><a href="http://johntostring.github.io/p/2015/04/22/the-tomcat-configuration-https-self-signed-certificate.html">http://johntostring.github.io/p/2015/04/22/the-tomcat-configuration-https-self-signed-certificate.html</a><br><a href="http://nassir.iteye.com/blog/1983613">http://nassir.iteye.com/blog/1983613</a><br><a href="http://www.yangch.info/?p=483">http://www.yangch.info/?p=483</a><br><a href="https://blog.smemo.info/108.html">https://blog.smemo.info/108.html</a><br><a href="http://www.cnblogs.com/cocoajin/p/4082488.html">http://www.cnblogs.com/cocoajin/p/4082488.html</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7f5d068b571" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS 更新Realm 慢]]></title>
            <link>https://medium.com/@CoderAFI/ios-%E6%9B%B4%E6%96%B0realm-%E6%85%A2-c299bd5b7b19?source=rss-5f5e3741110------2</link>
            <guid isPermaLink="false">https://medium.com/p/c299bd5b7b19</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[cocoapods]]></category>
            <category><![CDATA[realm]]></category>
            <dc:creator><![CDATA[CoderAFI]]></dc:creator>
            <pubDate>Wed, 06 Dec 2017 10:05:38 GMT</pubDate>
            <atom:updated>2017-12-06T10:05:38.030Z</atom:updated>
            <content:encoded><![CDATA[<p>公司项目用到 realm 来做数据存储，但是每次更新或者重新安装 realm 依赖都会比较慢，记录下解决方法，供大家参考。</p><h4>Realm-CocoaPods</h4><p>通常在用 CocoaPods 来管理 Realm 依赖时，要去单独下载一个 core 的核心包，这个包在中国这种网速下下载还是显得有些慢的，这里给出手动下载的步骤：</p><ol><li>找到 core 的文件名(带版本号)</li></ol><pre>pod install (如果安装一直在等待，这时候可以 cancel 掉)</pre><pre>echo $TMPDIR</pre><pre>cd the_temp_dir</pre><pre>cd core_bin</pre><p>只要找到 temp 目录下的 core_bin 目录，里面就有一个缓存的正在下载的文件，就可以拿到相应版本的 core 包的文件名。</p><p>2. 手动下载</p><pre>cd ~/Downloads</pre><pre>curl -O <a href="http://static.realm.io/downloads/core/realm-core-version.tar.bz2">http://static.realm.io/downloads/core/realm-core-version.tar.bz2</a> (这个地址拼接上面的文件名)</pre><p>3. 下载完成后，将文件拷贝到 temp 中的 core_bin 目录下，重新运行 pod instal 就不会慢了</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c299bd5b7b19" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[快速制作 Cocoapods 私有镜像]]></title>
            <link>https://medium.com/@CoderAFI/%E5%BF%AB%E9%80%9F%E5%88%B6%E4%BD%9C-cocoapods-%E7%A7%81%E6%9C%89%E9%95%9C%E5%83%8F-22d232412e3?source=rss-5f5e3741110------2</link>
            <guid isPermaLink="false">https://medium.com/p/22d232412e3</guid>
            <category><![CDATA[cocoapods]]></category>
            <dc:creator><![CDATA[CoderAFI]]></dc:creator>
            <pubDate>Wed, 06 Dec 2017 09:43:46 GMT</pubDate>
            <atom:updated>2017-12-06T09:43:46.352Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Cocopods</strong> 所有第三方 <strong>Specs</strong> 描述文件都是托管在 Github 上的，但是中国国内对 Github 的访问速度时快时慢，<strong>尤其</strong>有些公司甚至对每台电脑进行网速监控，这时候如果 Cocopods repo update 便会非常的慢，此时就有必要自己做一套 <strong>Specs</strong> 镜像，托管在国内或者自己搭建的 git 服务器上。</p><p>下面介绍下我们团队的做法。</p><h4>创建私有镜像仓库</h4><p>首先，自己团队的 <strong>Specs</strong> 肯定要托管在自己内网的 Git 服务骑上，我们这边是<a href="https://medium.com/@CoderAFI/docker-gitlab-3fa06d6ec0b5">搭建了一套自己的 </a><a href="https://medium.com/@CoderAFI/docker-gitlab-3fa06d6ec0b5">Gitlab 服务</a>，然后将其托管在上面。</p><h4>拉取仓库代码</h4><p>命令如下：</p><pre>cd your_project_folder(需替换)<br>git clone your_specs_repo_url(https://medium.com/%E9%9C%80%E6%9B%BF%E6%8D%A2)</pre><p>添加Cocopods 官方 git 源</p><p>命令如下：</p><pre>git remote add CocoaPods_Specs <a href="/service/mailto:git@github.com">git@github.com</a>:CocoaPods/Specs.git</pre><h4>运行命令同步</h4><p>命令如下：</p><pre>git pull CocoaPods_Specs master<br>git push origin master</pre><h4>制作定时脚本同步(specs_sync.sh)</h4><p>脚本内容如下：</p><pre>#!/bin/sh<br>cd your_project_folder(需替换)</pre><pre>git pull CocoaPods_Specs master<br>echo ‘pull cocoapods offical specs finish !’</pre><pre>git push origin master<br>echo ‘push private specs repo finish !’</pre><pre>echo ‘~_~ ~_~ ~_~’</pre><p>赋予脚本执行权限</p><pre>chmod +x specs_sync.sh</pre><h4>定时任务添加</h4><p>命令如下：</p><pre>crontab -e</pre><p>添加如下任务：</p><pre>0 */3 * * * your_scripts_folder(需替换)/specs_sync.sh &gt; your_log_folder(需替换)/specs_sync.log 2&gt;&amp;1</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22d232412e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker+Gitlab]]></title>
            <link>https://medium.com/@CoderAFI/docker-gitlab-3fa06d6ec0b5?source=rss-5f5e3741110------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fa06d6ec0b5</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[ci]]></category>
            <dc:creator><![CDATA[CoderAFI]]></dc:creator>
            <pubDate>Wed, 06 Dec 2017 09:14:13 GMT</pubDate>
            <atom:updated>2017-12-29T08:01:45.734Z</atom:updated>
            <content:encoded><![CDATA[<p>作为码农的我们每天都在不停地搬代码，将自己的代码沉浸下来，进行不断的积累能很好的提高我们的开发效率。在这种背景下，便诞生了很多第三方代码托管平台，如：Github、Bitbucket、Beanstalk、GitSwarm、Coding.net等。码农在上面可以结合版本控制托管自己的代码，确实带来了极大的方便和易用性。</p><p>但是，如果是作为一家公司而言把代码托管到这样公开的平台下，多少有些不妥。那么有没有能够在自己公司内网搭建的这种代码托管服务？答案是肯定的，这里给出两个选择：<a href="https://about.gitlab.com/">Gitlab</a> 和 <a href="https://gogs.io/">Gogs</a>。</p><ul><li>Gitlab 起步早，较成熟，采用 ruby 框架编写，可以结合很多第三方服务（JIRA、Jenkins），自带 CI ，支持 Docker 安装</li><li>Gogs 对中文支持良好，采用 Go 语言编写，轻量级，易安装，支持 Docker 安装</li></ul><p>上面进行了简单的比较，这里记录下我用 <a href="https://docker.com/">Docker</a> 搭建 Gitlab 的过程以及遇到的一些困难，之后有时间也会分享出搭建 Gogs 的一些经验。</p><h4>硬件要求</h4><ul><li>CPU: 推荐至少是双核</li><li>Memory: 推荐是 4G RAM</li></ul><h4>搭建过程</h4><ol><li>安装 Docker</li></ol><p>Docker 官方已经给出详细的 <a href="https://docs.docker.com/engine/installation/linux/">安装教程</a>，这里就不在赘述</p><p>2. 从 <a href="https://hub.docker.com/">DockerHub</a> 获取 <a href="https://hub.docker.com/r/gitlab/gitlab-ce/">Gitlab 镜像</a>，运行如下命令：</p><pre>docker pull gitlab/gitlab-ce</pre><p>默认，该命令是获取 Gitlab 的最新版本(latest)进行安装，如果想获取指定版本，命令如下：</p><pre>docker pull gitlab/gitlab-ce:8.9.6</pre><p>3. 安装并运行 Gitlab</p><pre>docker run — detach \<br> — hostname your_ip or your_domain \<br> — publish your_https_port:443 — publish your_http_port:80 — publish your_ssh_port:22 \<br> — name your_gitlab_name \<br> — restart always \<br> — volume /srv/gitlab/config:/etc/gitlab \<br> — volume /srv/gitlab/logs:/var/log/gitlab \<br> — volume /srv/gitlab/data:/var/opt/gitlab \<br> gitlab/gitlab-ce:latest</pre><p>设置好自己的参数，运行该命令，如果顺利的话，你会得到创建成功的 Gitlab 容器的 ID，同样也可以运行 docker ps 来查看正在运行的 Docker 容器。</p><p>4. 配置Gitlab</p><p>要修改 Gitlab 的配置，修改 /srv/gitlab/config/gitlab.rb 的这个文件中的配置便可解决大部分问题，网上流传了一些 修改 application.yml或者 gitlab.yml 的解决方法都是 gitlab 非常早期的版本，针对较新的版本已经不再适用。</p><p>这里对我修改过的常用 Gitlab 配置项进行简单说明。</p><p><strong><em>访问地址配置</em></strong></p><pre>external_url ‘<a href="http://your_ip:your_port">http://your_ip:your_port</a> or your_domain’ # default: <a href="http://hostname/">http://hostname</a></pre><p><strong><em>端口号配置</em></strong></p><p>上面为访问地址配置项，<strong>如果是用 </strong><strong>ip+port 的访问方式(采用domain方式不需要配置)</strong>，需要配置上端口号，如果不配置，则在邮件发送邀请链接的时候也是不带端口号的，但是配置了端口后由于跟运行容器时的参数 hostname（不带端口号）不一致会导致容器每隔 10s 会不断的重启，解决方案是要<a href="https://gitlab.com/gitlab-org/omnibus-gitlab/issues/1010"><strong>单独配置下 </strong></a><a href="https://gitlab.com/gitlab-org/omnibus-gitlab/issues/1010"><strong>nginx 的端口号</strong></a>，如下：</p><pre>nginx[‘listen_port’] = 80</pre><p>如果不是采用默认的 22 作为 SSH 的端口号，则需要对下面配置项进行设置，如果在这种情况下不设置该项的话，在 Gitlab 上新建的 Git 项目的 SSH 地址是不带端口号的，如果要用 SSH 进行克隆则会失败,这里是<a href="http://stackoverflow.com/questions/18517189/gitlab-with-non-standard-ssh-port-on-vm-with-iptable-forwarding">解决问题的参考地址</a>，不过还是建议采用默认的 22端口来进行映射，不采用的话，新建的项目克隆的地址前面会有 ssh://<em>（有点小恶心）</em>。</p><pre>gitlab_rails[‘gitlab_shell_ssh_port’] = your_ssh_port</pre><p><strong><em>头像服务配置</em></strong></p><p>Gitlab 默认的头像系统采用的是 <a href="https://cn.gravatar.com/">Gravatar -全球公认的头像</a>，但是这套头像服务已经被墙了，需要设置国内的镜像服务器，这里我们采用了 <a href="http://duoshuo.com/">多说</a> 的镜像，这里需要注意的是在注册 Gravatar 是无法使用国内的 163 邮箱，我尝试 Gmail 是可以的，不过只要你登录进去了在内部可以手动关联任意邮箱，配置项如下：</p><pre>gitlab_rails[‘gravatar_plain_url’] = ‘http://gravatar.duoshuo.com/avatar/%{hash}?s=%{size}&amp;d=identicon&#39;</pre><p><strong>更新，</strong>多说的图床已经失效，请用如下链接：</p><pre>http://cn.gravatar.com/avatar/%{hash}?s=%{size}&amp;d=identicon</pre><p><strong><em>邮箱服务配置</em></strong></p><p>gitlab 采用 smtp 协议配置邮箱服务为发送通知邮件(<a href="https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/smtp.md">官方指南</a>)，下面给出的是邮箱服务的基本配置：</p><pre>gitlab_rails[‘gitlab_email_enabled’] = true<br>gitlab_rails[‘gitlab_email_from’] = ‘admin’s_email_address’</pre><pre><br>gitlab_rails[‘smtp_enable’] = true<br>gitlab_rails[‘smtp_address’] = “mail_smtp_server_address”<br>gitlab_rails[‘smtp_port’] = mail_smtp_server_port<br>gitlab_rails[‘smtp_user_name’] = “admin’s_email_address”<br>gitlab_rails[‘smtp_password’] = “admin’s_email_password”<br>gitlab_rails[‘smtp_domain’] = “mail_domain”<br>gitlab_rails[‘smtp_authentication’] = “login”<br>gitlab_rails[‘smtp_enable_starttls_auto’] = true</pre><ul><li><em>163 邮箱配置</em></li></ul><p>163 邮箱 smtp服务器需要授权码才可以使用，详细解释内容可以<a href="https://newlooper.github.io/2017/09/03/gitlab_163mail_smtp/">点击这里</a></p><pre># vim /etc/gitlab/gitlab.rb</pre><pre># Sending application email via SMTP<br>gitlab_rails[‘smtp_enable’] = true<br>gitlab_rails[‘smtp_address’] = “smtp.163.com”<br>gitlab_rails[‘smtp_port’] = 994 <br>gitlab_rails[‘smtp_user_name’] = “<a href="/service/mailto:xxuser@163.com">xxuser@163.com</a>”<br>gitlab_rails[‘smtp_password’] = “xxpassword” # 这里是163客户端授权密码<br>gitlab_rails[‘smtp_domain’] = “163.com”<br>gitlab_rails[‘smtp_authentication’] = &quot;login&quot;<br>gitlab_rails[‘smtp_enable_starttls_auto’] = false<br>gitlab_rails[&#39;smtp_tls&#39;] = true<br>gitlab_rails[&#39;smtp_openssl_verify_mode&#39;] = &#39;peer&#39;</pre><ul><li><em>修改gitlab配置的发信人</em></li></ul><pre># 与上面的smtp_user_name 保持一致<br>gitlab_rails[‘gitlab_email_from’] = “<a href="/service/mailto:xxuser@163.com">xxuser@163.com</a>”</pre><pre># 与上面的smtp_user_name 保持一致<br>user[“git_user_email”] = “<a href="/service/mailto:xxuser@163.com">xxuser@163.com</a>”</pre><ul><li><em>QQ 邮箱 (出现问题请自行谷歌)</em></li></ul><pre># vim /etc/gitlab/gitlab.rb</pre><pre>gitlab_rails[‘smtp_enable’] = true<br>gitlab_rails[‘smtp_address’] = “smtp.exmail.qq.com”<br>gitlab_rails[‘smtp_port’] = 465 <br>gitlab_rails[‘smtp_user_name’] = “<a href="/service/mailto:support@ttlsa.com">support@ttlsa.com</a>”<br>gitlab_rails[‘smtp_password’] = “<a href="http://www.ttlsa.com/">www.ttlsa.com</a>&quot;<br>gitlab_rails[‘smtp_domain’] = “ttlsa.com”<br>gitlab_rails[‘smtp_authentication’] = “login”<br>gitlab_rails[‘smtp_enable_starttls_auto’] = true<br>gitlab_rails[‘smtp_tls’] = true<br>gitlab_rails[‘gitlab_email_from’] = “<a href="/service/mailto:support@ttlsa.com">support@ttlsa.com</a>”</pre><p>最后还要配置下时区，要不然 Gitlab 上的时间一直显示 `UTC` 时区的时间，如下：</p><pre>gitlab_rails[‘time_zone’] = ‘Asia/Shanghai’</pre><p><strong><em>支持 HTTPS</em></strong></p><p>推荐使用 <a href="https://letsencrypt.org/">Let’s Encrypt</a>来生成免费的 SSL 证书，这里采用 <a href="https://github.com/diafygi/acme-tiny">acme-tiny</a> 这个工具来生成，将生成的 chained.pem 和 domain.key 放到 /srv/gitlab/config/ssl/ 目录下，参考命令如下：</p><pre>cp ./chained.pem /srv/gitlab/config/ssl/gitlab.pem<br>cp ./domain.key /srv/gitlab/config/ssl/gitlab.key</pre><p>然后到 gitlab.rb 配置文件中找到 nginx 配置相关的部分，修改如下配置：</p><pre>nginx[&#39;enable&#39;] = true<br>nginx[&#39;redirect_http_to_https&#39;] = true<br>nginx[&#39;ssl_certificate&#39;] = &quot;/etc/gitlab/ssl/gitlab.pem&quot;<br>nginx[&#39;ssl_certificate_key&#39;] = &quot;/etc/gitlab/ssl/gitlab.key&quot;</pre><p>然后重启下 gitlab 容器或者进入到容器中执行 gitlab-ctl reconfigure 即可。</p><p><strong><em>错误日志查看</em></strong></p><p>这些配置项在配置的过程中一旦出现错误就会导致容器循环重启的现象，这种情况下如果能看到相应的错误 log 会对解决问题非常有帮助，下面这条命令可以解决该问题：</p><pre>docker logs -f — tail 10 your_docker_container_id</pre><p>其他详细的配置项目，可以参考<a href="http://docs.gitlab.com/omnibus/"> Gitlab 官方设置文档</a> 下的 Configuring 部分</p><h4>如何使用</h4><p>以上配置项设置完成后，第一次访问 Gitlab 时候会让管理员设置相应的管理密码，之后管理员登录都以 root 和 该密码 来登录</p><ol><li>管理员</li></ol><p>日常管理员用到的最多的就是 新建用户、新建群组、新建工程 这些功能，可参考下图到相应界面进行设置。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_75sNTX15PeBfaW88TSqGQ.jpeg" /><figcaption>Gitlab 控制台</figcaption></figure><p>2. 普通用户</p><p>普通用户使用的最多的流程是新建工程，然后在该工程上进行一系列的 <a href="https://github.com/geeeeeeeeek/git-recipes">Git工作流</a> 的操作，这里特别就克隆的方式进行一下说明：</p><p>一个 Git 仓库一般都提供两种克隆方式</p><ul><li>HTTP 方便，易使用，<a href="http://suselinks.us/two-ways-to-skip-password-typing-when-using-https-github/">需要配置 Git 缓存密码</a></li></ul><pre>git config — global credential.helper osxkeychain</pre><ul><li>SSH 需要配置，速度快，不需要缓存密码，可以访问 <a href="https://github.com/CoderAFI/MDES">MDES</a> 了解详细配置流程</li></ul><p>上述 SSH 过程配置完成后用如下脚本进行验证：</p><pre>ssh -vT git@your_ip -p your_port</pre><p>如果提示如下错误：</p><pre>The programs included with the Ubuntu system are free software;<br>the exact distribution terms for each program are described in the<br>individual files in /usr/share/doc/*/copyright.</pre><pre>Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by<br>applicable law.</pre><pre>The programs included with the Ubuntu system are free software;<br>the exact distribution terms for each program are described in the<br>individual files in /usr/share/doc/*/copyright.</pre><pre>Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by<br>applicable law.</pre><pre>debug1: channel 0: free: client-session, nchannels 1<br>Transferred: sent 4116, received 3548 bytes, in 0.0 seconds<br>Bytes per second: sent 209562.5, received 180643.2<br>debug1: Exit status 254</pre><p>这时候需要管理员进入到 Docker 容器中，修改 /etc/pam.d/sshd 文件中的以下配置项：</p><pre>session required pam_loginuid.so</pre><p>将 required 改为 optional，该问题的解决方法是 <a href="https://github.com/gitlabhq/gitlabhq/issues/6537"><strong><em>参考这里</em></strong></a><strong><em>。</em></strong></p><p>3. Gitlab Workflow (待完善)</p><p>4. Gitlab CI</p><p>从 Gitlab 8.0 的版本开始，Gitlab 已经默认集成了 CI 功能，所以没有必要再像原来一样单独搭建一套 CI，还要关联起来。</p><p>Gitlab CI 需要运行首先必须要挂载打包机又称作 <a href="https://docs.gitlab.com/runner/">Runner</a>，这里我采用的是 macos 作为 Runner 机器，其他机器请参照 官方文档安装。</p><p>下载 Runner 执行文件：</p><pre>sudo curl — output /usr/local/bin/gitlab-ci-multi-runner <a href="https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-ci-multi-runner-darwin-amd64">https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-ci-multi-runner-darwin-amd64</a></pre><p>给 Runner 分配权限：</p><pre>sudo chmod +x /usr/local/bin/gitlab-ci-multi-runner</pre><p>接下来，我们要把这台安装了 Runner 脚本的机器，注册到 Gitlab 上：</p><pre>gitlab-ci-multi-runner register</pre><p>会提示输入一些问题的答案：</p><pre>Please enter the gitlab-ci coordinator URL (e.g. <a href="https://gitlab.com/ci">https://gitlab.com/ci</a> )<br><a href="http://your_ip/">http://your_ip</a> or your_domain/ci</pre><pre>Please enter the gitlab-ci token for this runner<br>xxx (需要从 Gitlab 网站上获取)</pre><pre>Please enter the gitlab-ci description for this runner<br>ios (这个地方注册的 tag 后续会在 .yaml 配置文件中用到)</pre><pre>INFO[0034] fcf5c619 Registering runner… succeeded<br>Please enter the executor: shell, docker, docker-ssh, ssh?<br>shell<br>Runner registered successfully. Feel free to start it, but if it’s running already the config should be automatically reloaded!</pre><p>到这一步，Gitlab Runner 基本配置完毕，现在可以去编写.gitlab-ci.yml 来配置自动化脚本，这里给出<a href="https://about.gitlab.com/2016/03/10/setting-up-gitlab-ci-for-ios-projects/"> iOS 自动化构建脚本</a>参考。</p><p>5. JIRA — 待完善</p><p>6. Slack — 待完善</p><h4>后期维护</h4><ol><li>备份</li></ol><p>在创建 Gitlab 容器时指定了一些 —- volume 的参数，这是为了建立容器和宿主机之间的磁盘文件映射，其中每个目录含义如下：</p><ul><li>/srv/gitlab/data /var/opt/gitlab 存储 Gitlab 内部数据 (DB)</li><li>/srv/gitlab/logs /var/log/gitlab 存储 Gitlab 日志 (包含 CI)</li><li>/srv/gitlab/config /etc/gitlab 存储 Gitlab 设置的配置文件</li></ul><p>那么 Gitlab 所有需要备份的数据都映射到了宿主机中，我们只要给宿主机设置一个文件夹定时备份任务就可以。</p><p>备份脚本 backup.sh 内容如下：</p><pre>backupDate=$(date +”%Y%m%d%H%M%S”)<br>cd /srv/ <br>tar -zcvf gitlab-backup-${backupDate}.tar.gz gitlab</pre><p>执行定时任务我们采用 cron，可以借助 <a href="http://www.corntab.com/">corntab</a> 来自定义任务的执行时间和周期，命令行模式输入 crontab -e，输入下面的定时任务脚本:</p><pre>0 8 * * * sh your_backup_script_folder/backup.sh</pre><p>至此，定时备份任务基本配置完成。</p><p>2. 恢复</p><p>如果要将 Gitlab 恢复到历史的某一个版本，需要以下四部：</p><ul><li>将现有的 Gitlab 容器给停掉</li></ul><pre>docker stop your_gitlab_container</pre><ul><li>删除该容器</li></ul><pre>docker rm your_gitlab_container</pre><ul><li>到备份目录解压指定的备份版本</li></ul><pre>cd /srv/(your_backup_folder)<br>tar -zxvf gitlab_history_date.tar.gz</pre><ul><li>重新创建 Gitlab 容器（参考安装并运行 Gitlab 部分）</li></ul><p>在此处需要注意，如果重新创建容器的时候修改了一些参数，别忘了到 /srv/gitlab/config 目录下，修改 gitlab.rb 中相应的配置项参数。</p><p>3. 迁移</p><p>如果要将 Gitlab 从 A 机器 迁移到 B 机器该怎么办？</p><p>办法其实很简单，根据上面的流程我们知道，只要有备份数据，我们就可将 Gitlab 给恢复回来，那么做迁移其实只要把 A 机器的备份数据迁移到 B 机器的指定备份目录下，然后在 B 机器上安装 Docker 并获取相应版本的 Gitlab 镜像，最后再做一次恢复就完成 Gitlab 的迁移工作了，现在的关键是怎么样把 A 机器的备份数据迁移到 B 机器，这里提供如下两种思路：</p><ul><li>利用 SSH scp 命令进行跨机器拷贝</li><li>每台服务器搭建自己的 <a href="https://wsgzao.github.io/post/vsftpd/">FTP服务</a> 或 Samba 服务</li></ul><p>4. 升级</p><p>升级的流程基本上就是把 Gitlab 容器更新到一个指定的新版本上，然后用 新版本的 Gitlab 镜像 + 备份数据 来完成升级。</p><pre>docker stop your_gitlab_container<br>docker rm your_gitlab_container<br>docker pull gitlab/gitlab-ce:your_gitlab_version<br>docker run …. (安装并运行Gitlab部分一致)</pre><p>在升级的过程中通过 docker logs 命令发现了一些问题，这里总结记录下：</p><pre>docker logs -f — tail 10 your_gitlab_container</pre><p><strong><em>升级后 Redis 权限问题尝试如下脚本</em></strong></p><pre>docker exec -it gitlab update-permissions<br>docker exec gitlab chown -R gitlab-redis /var/opt/gitlab/redis<br>docker restart gitlab</pre><p><strong><em>查看升级后数据库的迁移情况</em></strong></p><pre>docker exec -it your_gitlab_container bash<br>sudo gitlab-rake db:migrate:status</pre><p>如果所有状态都显示为 up 状态，是没问题的。如果发现 down状态，类似下面这样：</p><pre>up 20150920161119 Add line code to sent notification<br>down 20150924125150 Add project id to ci commit<br>down 20150924125436 Migrate project id for ci commits</pre><p>就需要重新手动执行<strong>数据库 migration</strong> 命令：</p><pre>sudo gitlab-rake db:migrate</pre><p>当执行结束时，重新检查数据库migrate状态，确保所有状态都为 up：</p><pre>sudo gitlab-rake db:migrate:status</pre><p>如果出现另外诡异的问题，可以通过检查 Gitlab 的运行环境来解决</p><pre>sudo gitlab-rake gitlab:check</pre><p><strong><em>清除 Cache</em></strong></p><pre>sudo gitlab-rake cache:clear</pre><p><strong><em>重新配置 Gitlab 环境</em></strong></p><pre>sudo gitlab-ctl reconfigure</pre><p><strong><em>查看升级后的 Gitlab 服务信息</em></strong></p><pre>sudo gitlab-rake gitlab:env:info RAILS_ENV=production</pre><p>得到如下结果：</p><pre>System information<br>System: <br>Current User: git<br>Using RVM: no<br>Ruby Version: 2.1.8p440<br>Gem Version: 2.5.1<br>Bundler Version:1.10.6<br>Rake Version: 10.5.0<br>Sidekiq Version:4.1.2</pre><pre>GitLab information<br>Version: 8.9.6<br>Revision: ba3d01c<br>Directory: /opt/gitlab/embedded/service/gitlab-rails<br>DB Adapter: postgresql<br>Using LDAP: no<br>Using Omniauth: no</pre><pre>GitLab Shell<br>Version: 3.0.0<br>Repositories: /var/opt/gitlab/git-data/repositories<br>Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks/<br>Git: /opt/gitlab/embedded/bin/git</pre><p>整个升级流程，其实一些大牛已经帮我们踩过这些坑了，详细的描述可以参考 <a href="http://metaphor.space/2016/01/18/gitlab-migrate/">国内升级资料</a> 和 <a href="https://cmanios.wordpress.com/2015/12/04/migrate-a-gitlab-docker-container-from-version-8-0-4-to-8-2-0/">国外升级资料</a></p><p>升级完成后，当运行完 docker restart your_gitlab_container 的时候，Gitlab 启动特别慢而且有时候还会报 500 错误，但是大概等一分钟左右就可以启动起来，有可能是低版本升上来要进行数据迁移导致。</p><p>5. 内存管理</p><p>当服务器运行一段时间后，会发现机器的可用内存越来越少，这时候如何手动的去释放一部分内存提高 Gitlab 服务的响应也非常关键。</p><p>一般情况下，linux 上查看服务器的内存占用情况可以用 free -m 和 top 两个命令。</p><p>运行 free -m 后，会报出当前机器的内存使用情况：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*UhmiPG9FcM8Pk2tfFUl8Bg.png" /><figcaption>内存使用情况</figcaption></figure><ul><li>total 内存总数</li><li>used 已经使用的内存数</li><li>free 空闲的内存数</li><li>shared 多个进程共享的内存总额</li><li>buffers Buffer Cache和cached Page Cache 磁盘缓存的大小</li><li>-buffers/cache 的内存数:used — buffers — cached</li><li>+buffers/cache 的内存数:free + buffers + cached</li></ul><p>内存恒等式：<strong>memory = used + free + buffers + cached</strong>。</p><p>那为什么 Cache 占用了这么多内存？是否是合理显现？</p><p>经过一番查证后，得知该 cached 部分的内存是 linux 为了提高 I/O 效率而设计的，就算是对 I/O 进行操作的程序结束了该部分内存也不会正常得到释放，那就需要尝试手动释放这部分内存：</p><pre>cat /proc/sys/vm/drop_caches<br>sync<br>echo 3 &gt; /proc/sys/vm/drop_caches<br>cat /proc/sys/vm/drop_caches</pre><p>再运行 free -m 发现 cache 内存已经明显被释放，<a href="http://www.linuxfly.org/post/320/">详细介绍</a>在这里，如果想深究的可以看下。</p><h4>其他</h4><p>除去上述安装方法，列出另外两种安装方法供参考：</p><ul><li><a href="https://github.com/sameersbn/docker-gitlab">第三方 Docker 镜像</a></li><li>Gitlab 官方列出的源码、安装包、分布式安装的其他方法</li></ul><h4>问题</h4><ol><li>当 clone 和 push 代码的时候，如果出现下面这种错误：</li></ol><pre>remote: GitLab: API is not accessible<br>To <a href="https://xxxx/xxx/xxxx.git">https://xxxx/xxx/xxxx.git</a><br> ! [remote rejected] master -&gt; master (pre-receive hook declined)</pre><p>表明 gitlab-shell 的 API 访问权限是有问题的（我是在提交文件上去的时候出现的这种问题，我猜测可能文件上传是单独采用的 API 来上传的）。</p><p>解决方法就是进入到 Docker-Gitlab 中，找到 /var/opt/gitlab/gitlab-shell/config.yml 配置文件，修改gitlab_url 与 /etc/gitlab/gitlab.rb 中的 external_url 保持一致。</p><p>2. gitlab 从 8.x.x 的版本升级到 9.x.x 的版本后出现如下错误：</p><pre>PG::ConnectionBad (could not connect to server: No such file or directory<br> Is the server running locally and accepting<br> connections on Unix domain socket “/var/opt/gitlab/postgresql/.s.PGSQL.5432”?<br>):</pre><p><a href="https://gitlab.com/gitlab-org/gitlab-ce/issues/2005">解决方案在这里</a></p><blockquote>参考链接</blockquote><ul><li><a href="http://docs.gitlab.com/omnibus/docker/">Gitlab官方Docker安装指南</a></li><li><a href="http://docs.gitlab.com/">官方文档</a></li><li><a href="https://doc.gitlab.cc/">中文翻译文档</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fa06d6ec0b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>