业精于勤
而荒于嬉

GitLab 服务器安装 Postfix

一、设置主机名(hostname)

查看主机名:

ubuntu@ubuntu-server:~$ hostname -f
ubuntu-server

修改主机名:

ubuntu@ubuntu-server:~$ sudo hostnamectl set-hostname gitlab-server
[sudo] password for ubuntu: 
ubuntu@ubuntu-server:~$ hostname -f
gitlab-server

二、安装 Postfix

默认安装,下一步,下一步即可。

sudo apt-get install postfix
# 查看 postfix 版本 
sudo postconf mail_version

三、配置 Postfix

vi /etc/postfix/main.cf
# 修改 hostname 
myhostname = gitlab-server
sudo vi /etc/gitlab/gitlab.rb
# 修改访问地址及端口号
external_url 'http://192.168.1.201:20180'
# 修改时区
gitlab_rails['time_zone'] = 'Asia/Shanghai'
# 修改为 发送邮件到网易邮箱
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "15541549000@163.com"
gitlab_rails['smtp_password'] = "RUTQJSZCUSXDHULB"
gitlab_rails['smtp_domain'] ="smtp.163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
### Email Settings
gitlab_rails['gitlab_email_enabled'] = true
##! If your SMTP server does not like the default 'From: gitlab@gitlab.example.com'
##! can change the 'From' with this setting.
gitlab_rails['gitlab_email_from'] = '15541549000@163.com'
gitlab_rails['gitlab_email_display_name'] = 'SIA-GitLab'

### For setting up different data storing directory
###! Docs: https://docs.gitlab.com/omnibus/settings/configuration.html#storing-git-data-in-an-alternative-directory
###! **If you want to use a single non-default directory to store git data use a
###!   path that doesn't contain symlinks.**
git_data_dirs({
  "default" => {
     "path" => "/home/data/gitlab/git-data"
    }
})

user['git_user_name'] = "GitLab"
user['git_user_email'] = "gitlab@#{node['fqdn']}"

unicorn['port'] = 8081

四、测试邮件发送

sudo gitlab-rails console
[sudo] password for ubuntu: 
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
 GitLab:       13.10.0 (5eafdaf7b07) FOSS
 GitLab Shell: 13.17.0
 PostgreSQL:   12.5
--------------------------------------------------------------------------------
Loading production environment (Rails 6.0.3.4)
irb(main):001:0> Notify.test_email('15541549000@163.com', 'Hello World', 'This is a test message').deliver_now
Notify#test_email: processed outbound mail in 1.4ms
Delivered mail 609a7b2346609_1749e58ac452bc@gitlab-server.mail (881.3ms)
Date: Tue, 11 May 2021 20:40:03 +0800
From: SIA-GitLab <15541549000@163.com>
Reply-To: SIA-GitLab <noreply@192.168.1.201>
To: 15541549000@163.com
Message-ID: <609a7b2346609_1749e58ac452bc@gitlab-server.mail>
Subject: Hello World
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>This is a test message</p></body></html>

=> #<Mail::Message:194420, Multipart: false, Headers: <Date: Tue, 11 May 2021 20:40:03 +0800>, <From: SIA-GitLab <15541549000@163.com>>, <Reply-To: SIA-GitLab <noreply@192.168.1.201>>, <To: 15541549000@163.com>, <Message-ID: <609a7b2346609_1749e58ac452bc@gitlab-server.mail>>, <Subject: Hello World>, <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):002:0> exit()
赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《GitLab 服务器安装 Postfix》
文章链接:https://ithuang.net/gitlab-postfix.html
本站资源仅供个人学习交流,本人版权所有。欢迎转载,转载请注明作者及来源链接,谢谢。