不配置SMTP都无法工作了
目前的版本Gitlab 16.9.0,管理员在创建用户的时候,管理员无法给用户指定初始密码。初始密码只能以邮件的形式,发送到用户的邮箱。
因此有了此篇博文,为我们的Gitlab服务器做好正确的SMTP配置。
找到Gitlab的config文件夹
如果您的Gitlab,是根据我们的文章安装的,那么gitlab.rb文件就是在这个位置:
volumes:
- '/mnt/disk5t/data/gitlab.amihome.cn/config:/etc/gitlab'
就是docker-compose.yml文件中配置的第一条映射,就是Gitlab容器中的config文件所在的位置
列出config文件夹下的全部文件:
root@dev-server:/mnt/disk5t/data/gitlab.amihome.cn/config# ls -l
total 204
-rw------- 1 root root 151884 Feb 25 06:35 gitlab.rb
-rw------- 1 root root 19095 Feb 26 07:27 gitlab-secrets.json
-rw------- 1 root root 505 Feb 25 06:35 ssh_host_ecdsa_key
-rw-r--r-- 1 root root 173 Feb 25 06:35 ssh_host_ecdsa_key.pub
-rw------- 1 root root 399 Feb 25 06:35 ssh_host_ed25519_key
-rw-r--r-- 1 root root 93 Feb 25 06:35 ssh_host_ed25519_key.pub
-rw------- 1 root root 2590 Feb 25 06:35 ssh_host_rsa_key
-rw-r--r-- 1 root root 565 Feb 25 06:35 ssh_host_rsa_key.pub
drwxr-xr-x 2 root root 4096 Feb 25 06:38 ssl
drwxr-xr-x 2 root root 4096 Feb 25 06:35 trusted-certs
查看gitlab.rb
Gitlab在安装成功后,SMTP部分的配置如下图:
直接编辑gitlab.rb
在Gitlab容器里,发送测试邮件
下边是完整的过程:
root@dev-server:/home/david/files# docker exec -it gitlab.amihome.cn /bin/bash
root@gitlab:/# gitlab-rails console
--------------------------------------------------------------------------------
Ruby: ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [x86_64-linux]
GitLab: 16.7.6-jh (4798a958233) EE
GitLab Shell: 14.32.0
PostgreSQL: 14.10
------------------------------------------------------------[ booted in 19.87s ]
Loading production environment (Rails 7.0.8)
irb(main):001:0> Notify.test_email('[email protected]', 'title', 'body').deliver_now
Delivered mail [email protected] (18.1ms)
/opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/net-protocol-0.1.3/lib/net/protocol.rb:46:in `connect_nonblock': SSL_connect returned=1 errno=0 peeraddr=192.168.3.250:465 state=error: certificate verify failed (self signed certificate) (OpenSSL::SSL::SSLError)
irb(main):002:0>
说明邮件发不出去,是我们的SSL证书校验失败了。
在给邮件服务器正确配置SSL证书之后,再次测试。直至成功。
完整输出如下:
root@dev-server:/home/david/files# docker exec -it gitlab.amihome.cn /bin/bash
root@gitlab:/# gitlab-rails console
--------------------------------------------------------------------------------
Ruby: ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [x86_64-linux]
GitLab: 16.7.6-jh (4798a958233) EE
GitLab Shell: 14.32.0
PostgreSQL: 14.10
------------------------------------------------------------[ booted in 19.87s ]
Loading production environment (Rails 7.0.8)
irb(main):001:0> Notify.test_email('[email protected]', 'title', 'body').deliver_now
Delivered mail [email protected] (18.1ms)
/opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/net-protocol-0.1.3/lib/net/protocol.rb:46:in `connect_nonblock': SSL_connect returned=1 errno=0 peeraddr=192.168.3.250:465 state=error: certificate verify failed (self signed certificate) (OpenSSL::SSL::SSLError)
irb(main):002:0> Notify.test_email('[email protected]', 'title', 'body').deliver_now
Delivered mail [email protected] (152.5ms)
/opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/net-smtp-0.3.3/lib/net/smtp.rb:1076:in `check_response': 550 Error: no such user <[email protected]> (Net::SMTPFatalError)
irb(main):003:0> Notify.test_email('[email protected]', 'title', 'body').deliver_now
Delivered mail [email protected] (154.8ms)
=> #<Mail::Message:2108900, Multipart: false, Headers: <Date: Thu, 29 Feb 2024 11:13:21 +0000>, <From: AMI Home Gitlab <[email protected]>>, <Reply-To: AMI Home Gitlab <[email protected]>>, <To: [email protected]>, <Message-ID: <[email protected]>>, <Subject: title>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>
irb(main):004:0>
去poste.io的后台,给邮件服务器配置SSL证书
请移步到这里:
标签:06,Gitlab,Feb,cn,gitlab,SMTP,amihome,root,邮件 From: https://www.cnblogs.com/amisoft/p/18045010/gitlab-configure-smtp