服务器维护,服务器代维,安全设置,漏洞扫描,入侵检测服务

dirtysea 发表于 2018-11-23 15:58:44

使用Docker部署Gitlab

<h1 class="postTitle" style="margin-top: 20px; margin-bottom: 10px; color: rgb(0, 0, 0); border-bottom: 1px solid rgb(221, 221, 221); font-size: 14px;"><a id="cb_post_title_url" class="postTitle2" href="https://www.cnblogs.com/int32bit/p/5310382.html" style="text-decoration-line: none; color: rgb(51, 51, 51);">使用Docker快速部署Gitlab</a></h1><div class="clear" style="clear: both;"></div><div class="postBody"><div id="cnblogs_post_body" class="blogpost-body cnblogs-markdown" style="margin-bottom: 20px; word-break: break-word;"><h1 id="使用docker部署gitlab" style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 28px; margin-top: 10px; margin-bottom: 10px; line-height: 1.5;">使用Docker部署Gitlab</h1><h2 id="下载gitlab镜像" style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 21px; margin-top: 10px; margin-bottom: 10px; line-height: 1.5;">1. 下载gitlab镜像</h2><pre class="bash" style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px; margin-top: 10px; margin-bottom: 10px; white-space: pre-wrap;"><code class="hljs" style="margin: auto; vertical-align: middle; display: block; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: &quot;Courier New&quot;, sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important;">docker pull gitlab/gitlab-ce</code></pre><h2 id="运行gitlab实例" style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 21px; margin-top: 10px; margin-bottom: 10px; line-height: 1.5;">2. 运行gitlab实例</h2><pre class="bash" style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px; margin-top: 10px; margin-bottom: 10px; white-space: pre-wrap;"><code class="hljs" style="margin: auto; vertical-align: middle; display: block; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: &quot;Courier New&quot;, sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important;">GITLAB_HOME=`<span class="hljs-built_in" style="color: rgb(0, 0, 255);">pwd</span>`/data/gitlab
docker run -d \
    --hostname gitlab \
    --publish 8443:443 --publish 80:80 --publish 2222:22 \
    --name gitlab \
    --restart always \
    --volume <span class="hljs-variable" style="color: green;">$GITLAB_HOME</span>/config:/etc/gitlab \
    --volume <span class="hljs-variable" style="color: green;">$GITLAB_HOME</span>/logs:/var/<span class="hljs-built_in" style="color: rgb(0, 0, 255);">log</span>/gitlab \
    --volume <span class="hljs-variable" style="color: green;">$GITLAB_HOME</span>/data:/var/opt/gitlab \
    gitlab/gitlab-ce</code></pre><h2 id="配置gitlab实例" style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 21px; margin-top: 10px; margin-bottom: 10px; line-height: 1.5;">3. 配置gitlab实例</h2><h3 id="配置邮箱" style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 16px; margin-top: 10px; margin-bottom: 10px; line-height: 1.5;">3.1 配置邮箱:</h3><pre class="bash" style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px; margin-top: 10px; margin-bottom: 10px; white-space: pre-wrap;"><code class="hljs" style="margin: auto; vertical-align: middle; display: block; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: &quot;Courier New&quot;, sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important;">docker <span class="hljs-built_in" style="color: rgb(0, 0, 255);">exec</span> -t -i gitlab vim /etc/gitlab/gitlab.rb</code></pre><p style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px; margin: 10px auto;">下面以网易163邮箱为例配置邮箱:</p><pre style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px; margin-top: 10px; margin-bottom: 10px; white-space: pre-wrap;"><code class="hljs perl" style="margin: auto; vertical-align: middle; display: block; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: &quot;Courier New&quot;, sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important;">gitlab_rails[<span class="hljs-string" style="color: rgb(163, 21, 21);">'smtp_enable'</span>] = true
gitlab_rails[<span class="hljs-string" style="color: rgb(163, 21, 21);">'smtp_address'</span>] = <span class="hljs-string" style="color: rgb(163, 21, 21);">"smtp.163.com"</span>
gitlab_rails[<span class="hljs-string" style="color: rgb(163, 21, 21);">'smtp_port'</span>] = <span class="hljs-number">25</span>
gitlab_rails[<span class="hljs-string" style="color: rgb(163, 21, 21);">'smtp_user_name'</span>] = <span class="hljs-string" style="color: rgb(163, 21, 21);">"xxxx@163.com"</span>
gitlab_rails[<span class="hljs-string" style="color: rgb(163, 21, 21);">'smtp_password'</span>] = <span class="hljs-string" style="color: rgb(163, 21, 21);">"xxxxpassword"</span>
gitlab_rails[<span class="hljs-string" style="color: rgb(163, 21, 21);">'smtp_domain'</span>] = <span class="hljs-string" style="color: rgb(163, 21, 21);">"163.com"</span>
gitlab_rails[<span class="hljs-string" style="color: rgb(163, 21, 21);">'smtp_authentication'</span>] = <span class="hljs-string" style="color: rgb(163, 21, 21);">"login"</span>
gitlab_rails[<span class="hljs-string" style="color: rgb(163, 21, 21);">'smtp_enable_starttls_auto'</span>] = false
gitlab_rails[<span class="hljs-string" style="color: rgb(163, 21, 21);">'smtp_openssl_verify_mode'</span>] = <span class="hljs-string" style="color: rgb(163, 21, 21);">"peer"</span>

gitlab_rails[<span class="hljs-string" style="color: rgb(163, 21, 21);">'gitlab_email_from'</span>] = <span class="hljs-string" style="color: rgb(163, 21, 21);">"xxxx@163.com"</span>
user[<span class="hljs-string" style="color: rgb(163, 21, 21);">"git_user_email"</span>] = <span class="hljs-string" style="color: rgb(163, 21, 21);">"xxxx@163.com"</span></code></pre><p style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px; margin: 10px auto;">注意以上的<code style="margin: 1px 5px; line-height: 1.8; vertical-align: middle; display: inline-block; padding-right: 5px !important; padding-left: 5px !important; font-family: &quot;Courier New&quot;, sans-serif !important; font-size: 12px !important; background-color: rgb(245, 245, 245) !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important;">xxxx@163.com</code>代表用户名,即邮箱地址,而<code style="margin: 1px 5px; line-height: 1.8; vertical-align: middle; display: inline-block; padding-right: 5px !important; padding-left: 5px !important; font-family: &quot;Courier New&quot;, sans-serif !important; font-size: 12px !important; background-color: rgb(245, 245, 245) !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important;">xxxxpassword</code>不是邮箱的登陆密码而是网易邮箱的<strong>客户端授权密码</strong>, 再网易邮箱web页面的<code style="margin: 1px 5px; line-height: 1.8; vertical-align: middle; display: inline-block; padding-right: 5px !important; padding-left: 5px !important; font-family: &quot;Courier New&quot;, sans-serif !important; font-size: 12px !important; background-color: rgb(245, 245, 245) !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important;">设置-POP3/SMTP/IMAP-客户端授权密码</code>查看。</p><h3 id="配置外部访问url" style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 16px; margin-top: 10px; margin-bottom: 10px; line-height: 1.5;">3.2 配置外部访问URL</h3><p style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px; margin: 10px auto;">这个必须配置,否则默认以容器的主机名作为URL,刚开始由于做了端口映射<code style="margin: 1px 5px; line-height: 1.8; vertical-align: middle; display: inline-block; padding-right: 5px !important; padding-left: 5px !important; font-family: &quot;Courier New&quot;, sans-serif !important; font-size: 12px !important; background-color: rgb(245, 245, 245) !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important;">80-&gt;8080</code>, 因此设置为</p><pre style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px; margin-top: 10px; margin-bottom: 10px; white-space: pre-wrap;"><code class="hljs nginx" style="margin: auto; vertical-align: middle; display: block; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: &quot;Courier New&quot;, sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important;"><span class="hljs-attribute" style="color: rgb(163, 21, 21);">external_url</span> <span class="hljs-string" style="color: rgb(163, 21, 21);">"http://10.103.240.36:8080"</span></code></pre><p style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px; margin: 10px auto;">后来发现<strong><code style="margin: 1px 5px; line-height: 1.8; vertical-align: middle; display: inline-block; padding-right: 5px !important; padding-left: 5px !important; font-family: &quot;Courier New&quot;, sans-serif !important; font-size: 12px !important; background-color: rgb(245, 245, 245) !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important;">external_url</code>只能配置ip或者域名,不能有端口,否则不能启动</strong>。<br>于是只能把端口设置为<code style="margin: 1px 5px; line-height: 1.8; vertical-align: middle; display: inline-block; padding-right: 5px !important; padding-left: 5px !important; font-family: &quot;Courier New&quot;, sans-serif !important; font-size: 12px !important; background-color: rgb(245, 245, 245) !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important;">80-&gt;80</code>,然后<code style="margin: 1px 5px; line-height: 1.8; vertical-align: middle; display: inline-block; padding-right: 5px !important; padding-left: 5px !important; font-family: &quot;Courier New&quot;, sans-serif !important; font-size: 12px !important; background-color: rgb(245, 245, 245) !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important;">external_url</code>设置为:</p><pre style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs nginx" style="color: rgb(0, 0, 0); font-family: &quot;Courier New&quot;, sans-serif !important; font-size: 12px !important; white-space: pre-wrap; margin: auto; vertical-align: middle; display: block; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; height: auto; overflow-x: auto; padding: 5px !important; line-height: 1.5 !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important;"><span class="hljs-attribute" style="color: rgb(163, 21, 21);">external_url</span> <span class="hljs-string" style="color: rgb(163, 21, 21);">"http://10.103.240.36"</span></code><code class="hljs nginx" style="margin: auto; vertical-align: middle; display: block; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; height: auto; overflow-x: auto; padding: 5px !important; line-height: 1.5 !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important;"><span class="hljs-string" style="font-size: 12px; white-space: pre-wrap;"><font color="#a31515" face="Courier New, sans-serif">GitLab用密钥登录的方式,默认是连接的服务器的22端口,由于容器跟映射的端口变了,所以需要根据实际映射的端口修改配置:
gitlab_rails['gitlab_shell_ssh_port'] = 2222</font></span></code></pre><h2 id="重启gitlab" style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 21px; margin-top: 10px; margin-bottom: 10px; line-height: 1.5;">4. 重启gitlab</h2><pre class="bash" style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px; margin-top: 10px; margin-bottom: 10px; white-space: pre-wrap;"><code class="hljs" style="margin: auto; vertical-align: middle; display: block; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; height: auto; overflow-x: auto; color: rgb(0, 0, 0); padding: 5px !important; line-height: 1.5 !important; font-family: &quot;Courier New&quot;, sans-serif !important; font-size: 12px !important; border: 1px solid rgb(204, 204, 204) !important; border-radius: 3px !important;">docker restart gitlab</code><div><br></div></pre></div><div class="clear" style="clear: both; color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px;"></div><div id="blog_post_info_block" style="margin-top: 20px; color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px;"></div></div><p></p>

dirtysea 发表于 2018-11-23 18:02:19

gitlab 关闭开放注册功能
进入到admin area,点击settings   https://s4.51cto.com/wyfs02/M02/97/83/wKioL1kvTxTh9vHEAACeT9KlNIM180.png-wh_500x0-wm_3-wmp_4-s_1280065272.png
在sign-up Restrictions 取消sign-up enabledhttps://s1.51cto.com/wyfs02/M00/97/81/wKiom1kvT4Owwaz-AAAdAgqhoXA174.png-wh_500x0-wm_3-wmp_4-s_3672219452.png用户注册需要管理员来生成用户
[*]
Admin Area > Users >New user
页: [1]
查看完整版本: 使用Docker部署Gitlab