fish3129 发表于 2018-1-11 17:51:21

版本管理之gitlab实践教程:基础篇

  这篇文章主要介绍一下gitlab中如何进行邮件的配置,并使用163邮箱进行验证。

设定文件
  可以通过直接设定环境变量或者修正gitlab.rb的方式来设定,本文使用直接设定gitlab.rb文件方式。

设定文件所在目录gitlab.rb
/etc/gitlab
修改内容
  修改如下内容(对应的xx相关内容使用自己的邮箱地址,注意邮箱此处需要一致)
  

gitlab_rails['gitlab_email_from'] = 'xxxxxxxx@163.com'  
gitlab_rails['smtp_enable'] = true
  
gitlab_rails['smtp_address'] = "smtp.163.com"
  
gitlab_rails['smtp_port'] = 25
  
gitlab_rails['smtp_user_name'] = "xxxxxxxx@163.com"
  
gitlab_rails['smtp_password'] = "xxxxxx"
  
gitlab_rails['smtp_domain'] = "163.com"
  
gitlab_rails['smtp_authentication'] = "login"
  
gitlab_rails['smtp_enable_starttls_auto'] = false
  
gitlab_rails['smtp_openssl_verify_mode'] = 'peer'
  
user['git_user_email'] = "xxxxxxxx@163.com"
  


[*]1
[*]2
[*]3
[*]4
[*]5
[*]6
[*]7
[*]8
[*]9
[*]10
[*]11
修改起效
  修改了gitlab.rb文件,可以使用如下命令使其生效。

  gitlab-ctl reconfigure


执行log
  

# gitlab-ctl reconfigure  
Starting Chef Client, version 12.12.15
  
resolving cookbooks for run list: ["gitlab"]
  
Synchronizing Cookbooks:
  - runit (0.14.2)
  - package (0.0.0)
  - gitlab (0.0.1)
  
Installing Cookbook Gems:
  
Compiling Cookbooks...
  
...
  @@ -4,7 +4,7 @@
  


  name = GitLab
  -      email = gitlab@22bab50a8878
  
...

  autocrlf = input

  
Recipe: gitlab::gitlab-shell
  
...
  @@ -1 +1,24 @@
  +# This file is managed by gitlab-ctl. Manual changes will be
  +# erased! To change the contents below, edit /etc/gitlab/gitlab.rb
  +# and run `sudo gitlab-ctl reconfigure`.
  +
  +if Rails.env.production?
  +Gitlab::Application.config.action_mailer.delivery_method = :smtp
  +
  +ActionMailer::Base.delivery_method = :smtp
  +ActionMailer::Base.smtp_settings = {
  +    authentication: :login,
  +    address: "smtp.163.com",
  +    port: 25,
  
...
  +    domain: "163.com",
  +    enable_starttls_auto: false,
  +
  +
  +    openssl_verify_mode: "peer",
  +
  +    ca_file: "/opt/gitlab/embedded/ssl/certs/cacert.pem",
  +}
  +end
  - change mode from '' to '0644'
  - change owner from '' to 'root'
  - change group from '' to 'root'
  * link[Link /opt/gitlab/embedded/service/gitlab-rails/config/initializers/smtp_settings.rb
  
...
  

  
Running handlers:
  
Running handlers complete
  
Chef Client finished, 9/275 resources updated in 35 seconds
  
gitlab Reconfigured!
  
#
  


[*]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
创建一个用户
  输入实际的email创建用户,此邮箱可以收到一封mail,此mail中包含初次登陆时可以进行密码设
  定的链接。


log确认
  可以使用gitlab-ctl tail确认输出的日志,对问题的确认和定位很有帮助。在其中发现了发向liumiaocn@outlook.com的发送mail的信息提示。
  

==> /var/log/gitlab/gitlab-rails/production.log <==  

  
Sent mail to liumiaocn@outlook.com (921.0ms)
  
Performed ActionMailer::DeliveryJob from Sidekiq(mailers) in 1069.46ms
  

  


[*]1
[*]2
[*]3
[*]4
[*]5
mail确认
  确实已经收到邮件。


容易出现的问题
  邮件配置的时候容易出现”smtp sever reply:553 mail from must equal authorized user”的提示,这是因为设置的用户和实际发送邮件的用户不一致所致,因为default的邮箱需要重新设定一下,gitlab_email_from一定不要忘记设定。

总结
  通过设定gitlab.rb,使用gitlab-ctl reconfigure使其生效,创建用户时就能确认是否能够收到email了。
  http://www.woaipu.com/shops/zuzhuan/61406
  http://www.znds.com/tv-967956-1-1.html
  http://www.znds.com/tv-967958-1-1.html
页: [1]
查看完整版本: 版本管理之gitlab实践教程:基础篇